~bzr-pqm/bzr/bzr.dev

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