13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.tests import TestCaseInTempDir, TestCase
19
from bzrlib.merge3 import Merge3
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
22
from bzrlib.errors import CantReprocessAndShowBase, BinaryFile
22
24
def split_lines(t):
168
170
('unchanged', 1, 2),])
170
172
def test_append_a(self):
171
m3 = Merge3(['aaa\n', 'bbb\n'],
172
['aaa\n', 'bbb\n', '222\n'],
173
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
174
['aaa\n', 'bbb\n', '222\n'],
175
177
self.assertEquals(''.join(m3.merge_lines()),
176
178
'aaa\nbbb\n222\n')
178
180
def test_append_b(self):
179
m3 = Merge3(['aaa\n', 'bbb\n'],
181
['aaa\n', 'bbb\n', '222\n'])
181
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
183
['aaa\n', 'bbb\n', '222\n'])
183
185
self.assertEquals(''.join(m3.merge_lines()),
184
186
'aaa\nbbb\n222\n')
186
188
def test_append_agreement(self):
187
m3 = Merge3(['aaa\n', 'bbb\n'],
188
['aaa\n', 'bbb\n', '222\n'],
189
['aaa\n', 'bbb\n', '222\n'])
189
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
190
['aaa\n', 'bbb\n', '222\n'],
191
['aaa\n', 'bbb\n', '222\n'])
191
193
self.assertEquals(''.join(m3.merge_lines()),
192
194
'aaa\nbbb\n222\n')
194
196
def test_append_clash(self):
195
m3 = Merge3(['aaa\n', 'bbb\n'],
196
['aaa\n', 'bbb\n', '222\n'],
197
['aaa\n', 'bbb\n', '333\n'])
197
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
198
['aaa\n', 'bbb\n', '222\n'],
199
['aaa\n', 'bbb\n', '333\n'])
199
201
ml = m3.merge_lines(name_a='a',
215
217
def test_insert_agreement(self):
216
m3 = Merge3(['aaa\n', 'bbb\n'],
217
['aaa\n', '222\n', 'bbb\n'],
218
['aaa\n', '222\n', 'bbb\n'])
218
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
219
['aaa\n', '222\n', 'bbb\n'],
220
['aaa\n', '222\n', 'bbb\n'])
220
222
ml = m3.merge_lines(name_a='a',
225
227
self.assertEquals(''.join(ml), 'aaa\n222\nbbb\n')
228
230
def test_insert_clash(self):
229
231
"""Both try to insert lines in the same place."""
230
m3 = Merge3(['aaa\n', 'bbb\n'],
231
['aaa\n', '111\n', 'bbb\n'],
232
['aaa\n', '222\n', 'bbb\n'])
232
m3 = merge3.Merge3(['aaa\n', 'bbb\n'],
233
['aaa\n', '111\n', 'bbb\n'],
234
['aaa\n', '222\n', 'bbb\n'])
234
236
self.assertEquals(m3.find_unconflicted(),
235
237
[(0, 1), (1, 2)])
282
284
def test_replace_multi(self):
283
285
"""Replacement with regions of different size."""
284
m3 = Merge3(['aaa', '000', '000', 'bbb'],
285
['aaa', '111', '111', '111', 'bbb'],
286
['aaa', '222', '222', '222', '222', 'bbb'])
286
m3 = merge3.Merge3(['aaa', '000', '000', 'bbb'],
287
['aaa', '111', '111', '111', 'bbb'],
288
['aaa', '222', '222', '222', '222', 'bbb'])
288
290
self.assertEquals(m3.find_unconflicted(),
289
291
[(0, 1), (3, 4)])
356
358
base_text = ("a\n" * 20).splitlines(True)
357
359
this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
358
360
other_text = ("a\n"*10+"c\n"+"b\n" * 8 + "c\n").splitlines(True)
359
m3 = Merge3(base_text, other_text, this_text)
360
m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True,
361
m3 = merge3.Merge3(base_text, other_text, this_text)
362
m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True,
361
363
base_marker='|||||||')
362
364
self.assertRaises(CantReprocessAndShowBase, list, m_lines)
364
366
def test_binary(self):
365
self.assertRaises(BinaryFile, Merge3, ['\x00'], ['a'], ['b'])
367
self.assertRaises(BinaryFile, merge3.Merge3, ['\x00'], ['a'], ['b'])
369
def test_dos_text(self):
373
m3 = merge3.Merge3(base_text.splitlines(True),
374
other_text.splitlines(True),
375
this_text.splitlines(True))
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))
380
def test_mac_text(self):
384
m3 = merge3.Merge3(base_text.splitlines(True),
385
other_text.splitlines(True),
386
this_text.splitlines(True))
387
m_lines = m3.merge_lines('OTHER', 'THIS')
388
self.assertEqual('<<<<<<< OTHER\rc\r=======\rb\r'
389
'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
391
def test_merge3_cherrypick(self):
394
other_text = "a\nb\nc\n"
395
# When cherrypicking, lines in base are not part of the conflict
396
m3 = merge3.Merge3(base_text.splitlines(True),
397
this_text.splitlines(True),
398
other_text.splitlines(True), is_cherrypick=True)
399
m_lines = m3.merge_lines()
400
self.assertEqualDiff('a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
403
# This is not symmetric
404
m3 = merge3.Merge3(base_text.splitlines(True),
405
other_text.splitlines(True),
406
this_text.splitlines(True), is_cherrypick=True)
407
m_lines = m3.merge_lines()
408
self.assertEqualDiff('a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
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
416
m3 = merge3.Merge3(base_text.splitlines(True),
417
this_text.splitlines(True),
418
other_text.splitlines(True), is_cherrypick=True)
419
m_lines = m3.merge_lines()
420
self.assertEqualDiff('a\n'
433
def test_allow_objects(self):
434
"""Objects other than strs may be used with Merge3 when
437
merge_groups and merge_regions work with non-str input. Methods that
438
return lines like merge_lines fail.
440
base = [(x,x) for x in 'abcde']
441
a = [(x,x) for x in 'abcdef']
442
b = [(x,x) for x in 'Zabcde']
443
m3 = merge3.Merge3(base, a, b, allow_objects=True)
448
list(m3.merge_regions()))
450
[('b', [('Z', 'Z')]),
451
('unchanged', [(x,x) for x in 'abcde']),
452
('a', [('f', 'f')])],
453
list(m3.merge_groups()))