~bzr-pqm/bzr/bzr.dev

821 by Martin Pool
- start code for built-in diff3-style resolve
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
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.
7
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.
12
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
from bzrlib.selftest import InTempDir, TestBase
19
from bzrlib.merge3 import Merge3
20
21
class NoChanges(TestBase):
22
    """No conflicts because nothing changed"""
23
    def runTest(self):
24
        m3 = Merge3(['aaa', 'bbb'],
25
                    ['aaa', 'bbb'],
26
                    ['aaa', 'bbb'])
27
28
        self.assertEquals(m3.find_unconflicted(),
29
                          [(0, 2)])
30
822 by Martin Pool
- Renamed merge3 test suite for easier access.
31
        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
32
                          [(0, 2,
33
                            0, 2,
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
34
                            0, 2),
35
                           (2,2, 2,2, 2,2)])
36
37
        self.assertEquals(list(m3.merge_regions()),
38
                          [('unchanged', 0, 2)])
39
40
41
class FrontInsert(TestBase):
42
    def runTest(self):
43
        m3 = Merge3(['zz'],
44
                    ['aaa', 'bbb', 'zz'],
45
                    ['zz'])
46
47
        # todo: should use a sentinal at end as from get_matching_blocks
48
        # to match without zz
49
        self.assertEquals(list(m3.find_sync_regions()),
50
                          [(0,1, 2,3, 0,1),
51
                           (1,1, 3,3, 1,1),])
52
53
        self.assertEquals(list(m3.merge_regions()),
54
                          [('a', 0, 2),
55
                           ('unchanged', 0, 1)])
56
        
57
    
58
59
class NullInsert(TestBase):
60
    def runTest(self):
61
        m3 = Merge3([],
62
                    ['aaa', 'bbb'],
63
                    [])
64
65
        # todo: should use a sentinal at end as from get_matching_blocks
66
        # to match without zz
67
        self.assertEquals(list(m3.find_sync_regions()),
68
                          [(0,0, 2,2, 0,0)])
69
70
        self.assertEquals(list(m3.merge_regions()),
71
                          [('a', 0, 2)])
72
        
821 by Martin Pool
- start code for built-in diff3-style resolve
73
    
74
822 by Martin Pool
- Renamed merge3 test suite for easier access.
75
class NoConflicts(TestBase):
76
    """No conflicts because only one side changed"""
77
    def runTest(self):
78
        m3 = Merge3(['aaa', 'bbb'],
79
                    ['aaa', '111', 'bbb'],
80
                    ['aaa', 'bbb'])
81
82
        self.assertEquals(m3.find_unconflicted(),
83
                          [(0, 1), (1, 2)])
84
85
        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
86
                          [(0,1, 0,1, 0,1),
87
                           (1,2, 2,3, 1,2),
88
                           (2,2, 3,3, 2,2),])
89
90
822 by Martin Pool
- Renamed merge3 test suite for easier access.
91
92
821 by Martin Pool
- start code for built-in diff3-style resolve
93
class InsertClash(TestBase):
94
    """Both try to insert lines in the same place."""
95
    def runTest(self):
96
        m3 = Merge3(['aaa', 'bbb'],
97
                    ['aaa', '111', 'bbb'],
98
                    ['aaa', '222', 'bbb'])
99
100
        self.assertEquals(m3.find_unconflicted(),
101
                          [(0, 1), (1, 2)])
102
822 by Martin Pool
- Renamed merge3 test suite for easier access.
103
        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
104
                          [(0,1, 0,1, 0,1),
105
                           (1,2, 2,3, 2,3),
106
                           (2,2, 3,3, 3,3),])
821 by Martin Pool
- start code for built-in diff3-style resolve
107
108
109
110
class ReplaceClash(TestBase):
111
    """Both try to insert lines in the same place."""
112
    def runTest(self):
113
        m3 = Merge3(['aaa', '000', 'bbb'],
114
                    ['aaa', '111', 'bbb'],
115
                    ['aaa', '222', 'bbb'])
116
117
        self.assertEquals(m3.find_unconflicted(),
118
                          [(0, 1), (2, 3)])
119
822 by Martin Pool
- Renamed merge3 test suite for easier access.
120
        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
121
                          [(0,1, 0,1, 0,1),
122
                           (2,3, 2,3, 2,3),
123
                           (3,3, 3,3, 3,3),])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
124
125
126
127
class ReplaceMulti(TestBase):
128
    """Replacement with regions of different size."""
129
    def runTest(self):
130
        m3 = Merge3(['aaa', '000', '000', 'bbb'],
131
                    ['aaa', '111', '111', '111', 'bbb'],
132
                    ['aaa', '222', '222', '222', '222', 'bbb'])
133
134
        self.assertEquals(m3.find_unconflicted(),
135
                          [(0, 1), (3, 4)])
136
137
138
        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
139
                          [(0,1, 0,1, 0,1),
140
                           (3,4, 4,5, 5,6),
141
                           (4,4, 5,5, 6,6),])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
142
143
        
821 by Martin Pool
- start code for built-in diff3-style resolve
144