15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.tests import TestCaseInTempDir, TestCase
18
from bzrlib.selftest import TestCaseInTempDir, TestCase
19
19
from bzrlib.merge3 import Merge3
20
from bzrlib.errors import CantReprocessAndShowBase, BinaryFile
22
21
def split_lines(t):
23
22
from cStringIO import StringIO
301
300
self.log('merge result:')
302
301
self.log(''.join(ml))
303
302
self.assertEquals(ml, MERGED_RESULT)
305
def test_minimal_conflicts_common(self):
307
base_text = ("a\n" * 20).splitlines(True)
308
this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
309
other_text = ("a\n"*10+"c\n"+"b\n" * 8 + "c\n").splitlines(True)
310
m3 = Merge3(base_text, other_text, this_text)
311
m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
312
merged_text = "".join(list(m_lines))
313
optimal_text = ("a\n" * 10 + "<<<<<<< OTHER\nc\n"
314
+ 8* "b\n" + "c\n=======\n"
315
+ 10*"b\n" + ">>>>>>> THIS\n")
316
self.assertEqualDiff(optimal_text, merged_text)
318
def test_minimal_conflicts_unique(self):
320
"""Add a newline to each entry in the string"""
321
return [(x+'\n') for x in s]
323
base_text = add_newline("abcdefghijklm")
324
this_text = add_newline("abcdefghijklmNOPQRSTUVWXYZ")
325
other_text = add_newline("abcdefghijklm1OPQRSTUVWXY2")
326
m3 = Merge3(base_text, other_text, this_text)
327
m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
328
merged_text = "".join(list(m_lines))
329
optimal_text = ''.join(add_newline("abcdefghijklm")
330
+ ["<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
331
+ add_newline('OPQRSTUVWXY')
332
+ ["<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
334
self.assertEqualDiff(optimal_text, merged_text)
336
def test_minimal_conflicts_nonunique(self):
338
"""Add a newline to each entry in the string"""
339
return [(x+'\n') for x in s]
341
base_text = add_newline("abacddefgghij")
342
this_text = add_newline("abacddefgghijkalmontfprz")
343
other_text = add_newline("abacddefgghijknlmontfprd")
344
m3 = Merge3(base_text, other_text, this_text)
345
m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
346
merged_text = "".join(list(m_lines))
347
optimal_text = ''.join(add_newline("abacddefgghijk")
348
+ ["<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
349
+ add_newline('lmontfpr')
350
+ ["<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
352
self.assertEqualDiff(optimal_text, merged_text)
354
def test_reprocess_and_base(self):
355
"""Reprocessing and showing base breaks correctly"""
356
base_text = ("a\n" * 20).splitlines(True)
357
this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
358
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
base_marker='|||||||')
362
self.assertRaises(CantReprocessAndShowBase, list, m_lines)
364
def test_binary(self):
365
self.assertRaises(BinaryFile, Merge3, ['\x00'], ['a'], ['b'])