~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge3.py

  • Committer: Martin Pool
  • Date: 2006-05-12 08:32:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1710.
  • Revision ID: mbp@sourcefrog.net-20060512083216-221231851ad9585e
Remove TODO about knit testing printed from test suite

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2004, 2005 by Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
302
302
        self.log(''.join(ml))
303
303
        self.assertEquals(ml, MERGED_RESULT)
304
304
 
305
 
    def test_minimal_conflicts_common(self):
 
305
    def test_minimal_conflicts(self):
306
306
        """Reprocessing"""
307
307
        base_text = ("a\n" * 20).splitlines(True)
308
308
        this_text = ("a\n"*10+"b\n" * 10).splitlines(True)
310
310
        m3 = Merge3(base_text, other_text, this_text)
311
311
        m_lines = m3.merge_lines('OTHER', 'THIS', reprocess=True)
312
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)
317
 
 
318
 
    def test_minimal_conflicts_unique(self):
319
 
        def add_newline(s):
320
 
            """Add a newline to each entry in the string"""
321
 
            return [(x+'\n') for x in s]
322
 
 
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"]
333
 
            )
334
 
        self.assertEqualDiff(optimal_text, merged_text)
335
 
 
336
 
    def test_minimal_conflicts_nonunique(self):
337
 
        def add_newline(s):
338
 
            """Add a newline to each entry in the string"""
339
 
            return [(x+'\n') for x in s]
340
 
 
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"]
351
 
            )
352
 
        self.assertEqualDiff(optimal_text, merged_text)
 
313
        optimal_text = "a\n" * 10 + "<<<<<<< OTHER\nc\n=======\n>>>>>>> THIS"\
 
314
            + "\n" + 8* "b\n" + "<<<<<<< OTHER\nc\n=======\nb\nb\n>>>>>>>"\
 
315
            + " THIS\n"
 
316
        self.assertEqualDiff(merged_text, optimal_text)
353
317
 
354
318
    def test_reprocess_and_base(self):
355
319
        """Reprocessing and showing base breaks correctly"""
363
327
 
364
328
    def test_binary(self):
365
329
        self.assertRaises(BinaryFile, Merge3, ['\x00'], ['a'], ['b'])
366
 
 
367
 
    def test_dos_text(self):
368
 
        base_text = 'a\r\n'
369
 
        this_text = 'b\r\n'
370
 
        other_text = 'c\r\n'
371
 
        m3 = Merge3(base_text.splitlines(True), other_text.splitlines(True),
372
 
                    this_text.splitlines(True))
373
 
        m_lines = m3.merge_lines('OTHER', 'THIS')
374
 
        self.assertEqual('<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
375
 
            '>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
376
 
 
377
 
    def test_mac_text(self):
378
 
        base_text = 'a\r'
379
 
        this_text = 'b\r'
380
 
        other_text = 'c\r'
381
 
        m3 = Merge3(base_text.splitlines(True), other_text.splitlines(True),
382
 
                    this_text.splitlines(True))
383
 
        m_lines = m3.merge_lines('OTHER', 'THIS')
384
 
        self.assertEqual('<<<<<<< OTHER\rc\r=======\rb\r'
385
 
            '>>>>>>> THIS\r'.splitlines(True), list(m_lines))
386
 
 
387
 
    def test_merge3_cherrypick(self):
388
 
        base_text = "a\nb\n"
389
 
        this_text = "a\n"
390
 
        other_text = "a\nb\nc\n"
391
 
        # When cherrypicking, lines in base are not part of the conflict
392
 
        m3 = Merge3(base_text.splitlines(True), this_text.splitlines(True),
393
 
                    other_text.splitlines(True), is_cherrypick=True)
394
 
        m_lines = m3.merge_lines()
395
 
        self.assertEqualDiff('a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
396
 
                             ''.join(m_lines))
397
 
 
398
 
        # This is not symmetric
399
 
        m3 = Merge3(base_text.splitlines(True), other_text.splitlines(True),
400
 
                    this_text.splitlines(True), is_cherrypick=True)
401
 
        m_lines = m3.merge_lines()
402
 
        self.assertEqualDiff('a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
403
 
                             ''.join(m_lines))
404
 
 
405
 
    def test_merge3_cherrypick_w_mixed(self):
406
 
        base_text = 'a\nb\nc\nd\ne\n'
407
 
        this_text = 'a\nb\nq\n'
408
 
        other_text = 'a\nb\nc\nd\nf\ne\ng\n'
409
 
        # When cherrypicking, lines in base are not part of the conflict
410
 
        m3 = Merge3(base_text.splitlines(True), this_text.splitlines(True),
411
 
                    other_text.splitlines(True), is_cherrypick=True)
412
 
        m_lines = m3.merge_lines()
413
 
        self.assertEqualDiff('a\n'
414
 
                             'b\n'
415
 
                             '<<<<<<<\n'
416
 
                             'q\n'
417
 
                             '=======\n'
418
 
                             'f\n'
419
 
                             '>>>>>>>\n'
420
 
                             '<<<<<<<\n'
421
 
                             '=======\n'
422
 
                             'g\n'
423
 
                             '>>>>>>>\n',
424
 
                             ''.join(m_lines))