/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
821 by Martin Pool
- start code for built-in diff3-style resolve
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
821 by Martin Pool
- start code for built-in diff3-style resolve
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
821 by Martin Pool
- start code for built-in diff3-style resolve
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
821 by Martin Pool
- start code for built-in diff3-style resolve
16
17
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
18
from .. import (
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
19
    merge3,
20
    tests,
21
    )
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
22
from ..errors import BinaryFile
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
23
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
24
    BytesIO,
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
25
    int2byte,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
26
    )
821 by Martin Pool
- start code for built-in diff3-style resolve
27
1102 by Martin Pool
- merge test refactoring from robertc
28
def split_lines(t):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
29
    return BytesIO(t).readlines()
1102 by Martin Pool
- merge test refactoring from robertc
30
31
############################################################
32
# test case data from the gnu diffutils manual
33
# common base
6791.2.3 by Jelmer Vernooij
Fix more imports.
34
TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
1102 by Martin Pool
- merge test refactoring from robertc
35
     The named is the mother of all things.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
36
1102 by Martin Pool
- merge test refactoring from robertc
37
     Therefore let there always be non-being,
38
       so we may see their subtlety,
39
     And let there always be being,
40
       so we may see their outcome.
41
     The two are the same,
42
     But after they are produced,
43
       they have different names.
44
     They both may be called deep and profound.
45
     Deeper and more profound,
46
     The door of all subtleties!
47
""")
48
6791.2.3 by Jelmer Vernooij
Fix more imports.
49
LAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
50
     The name that can be named is not the eternal name.
51
     The Nameless is the origin of Heaven and Earth;
52
     The Named is the mother of all things.
53
     Therefore let there always be non-being,
54
       so we may see their subtlety,
55
     And let there always be being,
56
       so we may see their outcome.
57
     The two are the same,
58
     But after they are produced,
59
       they have different names.
60
""")
61
62
6791.2.3 by Jelmer Vernooij
Fix more imports.
63
TAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
64
     The name that can be named is not the eternal name.
65
     The Nameless is the origin of Heaven and Earth;
66
     The named is the mother of all things.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
67
1102 by Martin Pool
- merge test refactoring from robertc
68
     Therefore let there always be non-being,
69
       so we may see their subtlety,
70
     And let there always be being,
71
       so we may see their result.
72
     The two are the same,
73
     But after they are produced,
74
       they have different names.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
75
1102 by Martin Pool
- merge test refactoring from robertc
76
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
77
78
""")
79
6791.2.3 by Jelmer Vernooij
Fix more imports.
80
MERGED_RESULT = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
81
     The name that can be named is not the eternal name.
82
     The Nameless is the origin of Heaven and Earth;
83
     The Named is the mother of all things.
84
     Therefore let there always be non-being,
85
       so we may see their subtlety,
86
     And let there always be being,
87
       so we may see their result.
88
     The two are the same,
89
     But after they are produced,
90
       they have different names.
974.1.50 by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9
91
<<<<<<< LAO
92
=======
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
93
1102 by Martin Pool
- merge test refactoring from robertc
94
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
95
974.1.50 by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9
96
>>>>>>> TAO
1102 by Martin Pool
- merge test refactoring from robertc
97
""")
98
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
99
class TestMerge3(tests.TestCase):
1102 by Martin Pool
- merge test refactoring from robertc
100
101
    def test_no_changes(self):
102
        """No conflicts because nothing changed"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
103
        m3 = merge3.Merge3([b'aaa', b'bbb'],
104
                           [b'aaa', b'bbb'],
105
                           [b'aaa', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
106
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
107
        self.assertEqual(m3.find_unconflicted(),
821 by Martin Pool
- start code for built-in diff3-style resolve
108
                          [(0, 2)])
109
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
110
        self.assertEqual(list(m3.find_sync_regions()),
824 by Martin Pool
- Merge3.find_sync_regions yields just a 6-tuple, not a tuple of tuples
111
                          [(0, 2,
112
                            0, 2,
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
113
                            0, 2),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
114
                           (2, 2, 2, 2, 2, 2)])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
115
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
116
        self.assertEqual(list(m3.merge_regions()),
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
117
                          [('unchanged', 0, 2)])
118
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
119
        self.assertEqual(list(m3.merge_groups()),
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
120
                          [('unchanged', [b'aaa', b'bbb'])])
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
121
1102 by Martin Pool
- merge test refactoring from robertc
122
    def test_front_insert(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
123
        m3 = merge3.Merge3([b'zz'],
124
                           [b'aaa', b'bbb', b'zz'],
125
                           [b'zz'])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
126
127
        # todo: should use a sentinal at end as from get_matching_blocks
128
        # to match without zz
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
129
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
130
                          [(0, 1, 2, 3, 0, 1),
131
                           (1, 1, 3, 3, 1, 1),])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
132
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
133
        self.assertEqual(list(m3.merge_regions()),
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
134
                          [('a', 0, 2),
135
                           ('unchanged', 0, 1)])
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
136
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
137
        self.assertEqual(list(m3.merge_groups()),
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
138
                          [('a', [b'aaa', b'bbb']),
139
                           ('unchanged', [b'zz'])])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
140
1102 by Martin Pool
- merge test refactoring from robertc
141
    def test_null_insert(self):
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
142
        m3 = merge3.Merge3([],
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
143
                           [b'aaa', b'bbb'],
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
144
                           [])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
145
        # todo: should use a sentinal at end as from get_matching_blocks
146
        # to match without zz
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
147
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
148
                          [(0, 0, 2, 2, 0, 0)])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
149
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
150
        self.assertEqual(list(m3.merge_regions()),
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
151
                          [('a', 0, 2)])
828 by Martin Pool
- code to represent merges in regular text conflict form
152
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
153
        self.assertEqual(list(m3.merge_lines()),
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
154
                          [b'aaa', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
155
1102 by Martin Pool
- merge test refactoring from robertc
156
    def test_no_conflicts(self):
157
        """No conflicts because only one side changed"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
158
        m3 = merge3.Merge3([b'aaa', b'bbb'],
159
                           [b'aaa', b'111', b'bbb'],
160
                           [b'aaa', b'bbb'])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
161
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
162
        self.assertEqual(m3.find_unconflicted(),
822 by Martin Pool
- Renamed merge3 test suite for easier access.
163
                          [(0, 1), (1, 2)])
164
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
165
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
166
                          [(0, 1, 0, 1, 0, 1),
167
                           (1, 2, 2, 3, 1, 2),
168
                           (2, 2, 3, 3, 2, 2),])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
169
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
170
        self.assertEqual(list(m3.merge_regions()),
826 by Martin Pool
- Actually merge unsynchronized regions. Woot!
171
                          [('unchanged', 0, 1),
172
                           ('a', 1, 2),
173
                           ('unchanged', 1, 2),])
174
1102 by Martin Pool
- merge test refactoring from robertc
175
    def test_append_a(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
176
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
177
                           [b'aaa\n', b'bbb\n', b'222\n'],
178
                           [b'aaa\n', b'bbb\n'])
836 by Martin Pool
- more merge tests from john
179
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
180
        self.assertEqual(b''.join(m3.merge_lines()),
181
                          b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
182
1102 by Martin Pool
- merge test refactoring from robertc
183
    def test_append_b(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
184
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
185
                           [b'aaa\n', b'bbb\n'],
186
                           [b'aaa\n', b'bbb\n', b'222\n'])
836 by Martin Pool
- more merge tests from john
187
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
188
        self.assertEqual(b''.join(m3.merge_lines()),
189
                          b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
190
1102 by Martin Pool
- merge test refactoring from robertc
191
    def test_append_agreement(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
192
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
193
                           [b'aaa\n', b'bbb\n', b'222\n'],
194
                           [b'aaa\n', b'bbb\n', b'222\n'])
836 by Martin Pool
- more merge tests from john
195
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
196
        self.assertEqual(b''.join(m3.merge_lines()),
197
                          b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
198
1102 by Martin Pool
- merge test refactoring from robertc
199
    def test_append_clash(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
200
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
201
                           [b'aaa\n', b'bbb\n', b'222\n'],
202
                           [b'aaa\n', b'bbb\n', b'333\n'])
836 by Martin Pool
- more merge tests from john
203
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
204
        ml = m3.merge_lines(name_a=b'a',
205
                            name_b=b'b',
206
                            start_marker=b'<<',
207
                            mid_marker=b'--',
208
                            end_marker=b'>>')
209
        self.assertEqual(b''.join(ml),
210
b'''\
836 by Martin Pool
- more merge tests from john
211
aaa
212
bbb
213
<< a
214
222
215
--
216
333
217
>> b
218
''')
219
1102 by Martin Pool
- merge test refactoring from robertc
220
    def test_insert_agreement(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
221
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
222
                           [b'aaa\n', b'222\n', b'bbb\n'],
223
                           [b'aaa\n', b'222\n', b'bbb\n'])
830 by Martin Pool
- handle chunks which differ from the base but agree
224
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
225
        ml = m3.merge_lines(name_a=b'a',
226
                            name_b=b'b',
227
                            start_marker=b'<<',
228
                            mid_marker=b'--',
229
                            end_marker=b'>>')
230
        self.assertEqual(b''.join(ml), b'aaa\n222\nbbb\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
231
830 by Martin Pool
- handle chunks which differ from the base but agree
232
1102 by Martin Pool
- merge test refactoring from robertc
233
    def test_insert_clash(self):
234
        """Both try to insert lines in the same place."""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
235
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
236
                           [b'aaa\n', b'111\n', b'bbb\n'],
237
                           [b'aaa\n', b'222\n', b'bbb\n'])
821 by Martin Pool
- start code for built-in diff3-style resolve
238
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
239
        self.assertEqual(m3.find_unconflicted(),
821 by Martin Pool
- start code for built-in diff3-style resolve
240
                          [(0, 1), (1, 2)])
241
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
242
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
243
                          [(0, 1, 0, 1, 0, 1),
244
                           (1, 2, 2, 3, 2, 3),
245
                           (2, 2, 3, 3, 3, 3),])
821 by Martin Pool
- start code for built-in diff3-style resolve
246
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
247
        self.assertEqual(list(m3.merge_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
248
                          [('unchanged', 0, 1),
249
                           ('conflict', 1, 1, 1, 2, 1, 2),
250
                           ('unchanged', 1, 2)])
826 by Martin Pool
- Actually merge unsynchronized regions. Woot!
251
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
252
        self.assertEqual(list(m3.merge_groups()),
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
253
                          [('unchanged', [b'aaa\n']),
254
                           ('conflict', [], [b'111\n'], [b'222\n']),
255
                           ('unchanged', [b'bbb\n']),
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
256
                           ])
257
6973.11.5 by Jelmer Vernooij
Update python3.passing.
258
        ml = m3.merge_lines(name_a=b'a',
259
                            name_b=b'b',
260
                            start_marker=b'<<',
261
                            mid_marker=b'--',
262
                            end_marker=b'>>')
263
        self.assertEqual(b''.join(ml),
264
b'''aaa
829 by Martin Pool
- More merge3 cvs-form stuff
265
<< a
266
111
267
--
268
222
269
>> b
270
bbb
271
''')
828 by Martin Pool
- code to represent merges in regular text conflict form
272
1102 by Martin Pool
- merge test refactoring from robertc
273
    def test_replace_clash(self):
274
        """Both try to insert lines in the same place."""
6973.11.5 by Jelmer Vernooij
Update python3.passing.
275
        m3 = merge3.Merge3([b'aaa', b'000', b'bbb'],
276
                           [b'aaa', b'111', b'bbb'],
277
                           [b'aaa', b'222', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
278
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
279
        self.assertEqual(m3.find_unconflicted(),
821 by Martin Pool
- start code for built-in diff3-style resolve
280
                          [(0, 1), (2, 3)])
281
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
282
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
283
                          [(0, 1, 0, 1, 0, 1),
284
                           (2, 3, 2, 3, 2, 3),
285
                           (3, 3, 3, 3, 3, 3),])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
286
1102 by Martin Pool
- merge test refactoring from robertc
287
    def test_replace_multi(self):
288
        """Replacement with regions of different size."""
6973.11.5 by Jelmer Vernooij
Update python3.passing.
289
        m3 = merge3.Merge3([b'aaa', b'000', b'000', b'bbb'],
290
                           [b'aaa', b'111', b'111', b'111', b'bbb'],
291
                           [b'aaa', b'222', b'222', b'222', b'222', b'bbb'])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
292
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
293
        self.assertEqual(m3.find_unconflicted(),
822 by Martin Pool
- Renamed merge3 test suite for easier access.
294
                          [(0, 1), (3, 4)])
295
296
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
297
        self.assertEqual(list(m3.find_sync_regions()),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
298
                          [(0, 1, 0, 1, 0, 1),
299
                           (3, 4, 4, 5, 5, 6),
300
                           (4, 4, 5, 5, 6, 6),])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
301
1102 by Martin Pool
- merge test refactoring from robertc
302
    def test_merge_poem(self):
303
        """Test case from diff3 manual"""
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
304
        m3 = merge3.Merge3(TZU, LAO, TAO)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
305
        ml = list(m3.merge_lines(b'LAO', b'TAO'))
831 by Martin Pool
- add merge3 test case from Lao-Tzu
306
        self.log('merge result:')
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
307
        self.log(b''.join(ml))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
308
        self.assertEqual(ml, MERGED_RESULT)
1185.24.1 by Aaron Bentley
Got reprocessing working
309
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
310
    def test_minimal_conflicts_common(self):
1185.24.1 by Aaron Bentley
Got reprocessing working
311
        """Reprocessing"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
312
        base_text = (b"a\n" * 20).splitlines(True)
313
        this_text = (b"a\n"*10+b"b\n" * 10).splitlines(True)
314
        other_text = (b"a\n"*10+b"c\n"+b"b\n" * 8 + b"c\n").splitlines(True)
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
315
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
316
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
317
        merged_text = b"".join(list(m_lines))
318
        optimal_text = (b"a\n" * 10 + b"<<<<<<< OTHER\nc\n"
319
            + 8* b"b\n" + b"c\n=======\n"
320
            + 10*b"b\n" + b">>>>>>> THIS\n")
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
321
        self.assertEqualDiff(optimal_text, merged_text)
322
323
    def test_minimal_conflicts_unique(self):
324
        def add_newline(s):
325
            """Add a newline to each entry in the string"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
326
            return [(int2byte(x)+b'\n') for x in bytearray(s)]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
327
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
328
        base_text = add_newline(b"abcdefghijklm")
329
        this_text = add_newline(b"abcdefghijklmNOPQRSTUVWXYZ")
330
        other_text = add_newline(b"abcdefghijklm1OPQRSTUVWXY2")
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
331
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
332
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
333
        merged_text = b"".join(list(m_lines))
334
        optimal_text = b''.join(add_newline(b"abcdefghijklm")
335
            + [b"<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
336
            + add_newline(b'OPQRSTUVWXY')
337
            + [b"<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
338
            )
339
        self.assertEqualDiff(optimal_text, merged_text)
340
341
    def test_minimal_conflicts_nonunique(self):
342
        def add_newline(s):
343
            """Add a newline to each entry in the string"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
344
            return [(int2byte(x)+b'\n') for x in bytearray(s)]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
345
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
346
        base_text = add_newline(b"abacddefgghij")
347
        this_text = add_newline(b"abacddefgghijkalmontfprz")
348
        other_text = add_newline(b"abacddefgghijknlmontfprd")
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
349
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
350
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
351
        merged_text = b"".join(list(m_lines))
352
        optimal_text = b''.join(add_newline(b"abacddefgghijk")
353
            + [b"<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
354
            + add_newline(b'lmontfpr')
355
            + [b"<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
356
            )
357
        self.assertEqualDiff(optimal_text, merged_text)
1185.24.1 by Aaron Bentley
Got reprocessing working
358
359
    def test_reprocess_and_base(self):
360
        """Reprocessing and showing base breaks correctly"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
361
        base_text = (b"a\n" * 20).splitlines(True)
362
        this_text = (b"a\n"*10+b"b\n" * 10).splitlines(True)
363
        other_text = (b"a\n"*10+b"c\n"+b"b\n" * 8 + b"c\n").splitlines(True)
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
364
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
365
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True,
366
                                 base_marker=b'|||||||')
367
        self.assertRaises(merge3.CantReprocessAndShowBase, list, m_lines)
1558.15.6 by Aaron Bentley
Added more tests
368
369
    def test_binary(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
370
        self.assertRaises(BinaryFile, merge3.Merge3, [b'\x00'], [b'a'], [b'b'])
1551.10.38 by Aaron Bentley
merge3 auto-detects line endings for conflict markers
371
372
    def test_dos_text(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
373
        base_text = b'a\r\n'
374
        this_text = b'b\r\n'
375
        other_text = b'c\r\n'
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
376
        m3 = merge3.Merge3(base_text.splitlines(True),
377
                           other_text.splitlines(True),
378
                           this_text.splitlines(True))
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
379
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
380
        self.assertEqual(b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
381
            b'>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
1551.10.38 by Aaron Bentley
merge3 auto-detects line endings for conflict markers
382
383
    def test_mac_text(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
384
        base_text = b'a\r'
385
        this_text = b'b\r'
386
        other_text = b'c\r'
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
387
        m3 = merge3.Merge3(base_text.splitlines(True),
388
                           other_text.splitlines(True),
389
                           this_text.splitlines(True))
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
390
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
391
        self.assertEqual(b'<<<<<<< OTHER\rc\r=======\rb\r'
392
            b'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
393
394
    def test_merge3_cherrypick(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
395
        base_text = b"a\nb\n"
396
        this_text = b"a\n"
397
        other_text = b"a\nb\nc\n"
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
398
        # When cherrypicking, lines in base are not part of the conflict
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
399
        m3 = merge3.Merge3(base_text.splitlines(True),
400
                           this_text.splitlines(True),
401
                           other_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
402
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
403
        self.assertEqualDiff(b'a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
404
                             b''.join(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
405
406
        # This is not symmetric
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
407
        m3 = merge3.Merge3(base_text.splitlines(True),
408
                           other_text.splitlines(True),
409
                           this_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
410
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
411
        self.assertEqualDiff(b'a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
412
                             b''.join(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
413
414
    def test_merge3_cherrypick_w_mixed(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
415
        base_text = b'a\nb\nc\nd\ne\n'
416
        this_text = b'a\nb\nq\n'
417
        other_text = b'a\nb\nc\nd\nf\ne\ng\n'
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
418
        # When cherrypicking, lines in base are not part of the conflict
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
419
        m3 = merge3.Merge3(base_text.splitlines(True),
420
                           this_text.splitlines(True),
421
                           other_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
422
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
423
        self.assertEqualDiff(b'a\n'
424
                             b'b\n'
425
                             b'<<<<<<<\n'
426
                             b'q\n'
427
                             b'=======\n'
428
                             b'f\n'
429
                             b'>>>>>>>\n'
430
                             b'<<<<<<<\n'
431
                             b'=======\n'
432
                             b'g\n'
433
                             b'>>>>>>>\n',
434
                             b''.join(m_lines))
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
435
436
    def test_allow_objects(self):
437
        """Objects other than strs may be used with Merge3 when
438
        allow_objects=True.
439
        
440
        merge_groups and merge_regions work with non-str input.  Methods that
441
        return lines like merge_lines fail.
442
        """
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
443
        base = [(x, x) for x in 'abcde']
444
        a = [(x, x) for x in 'abcdef']
445
        b = [(x, x) for x in 'Zabcde']
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
446
        m3 = merge3.Merge3(base, a, b, allow_objects=True)
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
447
        self.assertEqual(
448
            [('b', 0, 1),
449
             ('unchanged', 0, 5),
450
             ('a', 5, 6)],
451
            list(m3.merge_regions()))
452
        self.assertEqual(
453
            [('b', [('Z', 'Z')]),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
454
             ('unchanged', [(x, x) for x in 'abcde']),
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
455
             ('a', [('f', 'f')])],
456
            list(m3.merge_groups()))
457