~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Author: Aaron Bentley <aaron.bentley@utoronto.ca>
from bzrlib.textmerge import Merge2
from bzrlib.tests import TestCase
class TestMerge2(TestCase):
    def test_agreed(self):
        lines = "a\nb\nc\nd\ne\nf\n".splitlines(True)
        mlines = list(Merge2(lines, lines).merge_lines()[0])
        self.assertEqualDiff(mlines, lines)

    def test_conflict(self):
        lines_a = "a\nb\nc\nd\ne\nf\ng\nh\n".splitlines(True)
        lines_b = "z\nb\nx\nd\ne\ne\nf\ng\ny\n".splitlines(True)
        expected = "<\na\n=\nz\n>\nb\n<\nc\n=\nx\n>\nd\ne\n<\n=\ne\n>\nf\n"\
                   "g\n<\nh\n=\ny\n>\n"
        m2 = Merge2(lines_a, lines_b, '<\n', '>\n', '=\n')
        mlines= m2.merge_lines()[0]
        self.assertEqualDiff(''.join(mlines), expected)
        mlines= m2.merge_lines(reprocess=True)[0]
        self.assertEqualDiff(''.join(mlines), expected)

    def test_reprocess(self):
        struct = [('a', 'b'), ('c',), ('def','geh'), ('i',)]
        expect = [('a', 'b'), ('c',), ('d', 'g'), ('e',), ('f', 'h'), ('i',)]
        result = Merge2.reprocess_struct(struct)
        self.assertEqual(list(result), expect)