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 |
||
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
18 |
from bzrlib.selftest import TestCaseInTempDir, TestCase |
821
by Martin Pool
- start code for built-in diff3-style resolve |
19 |
from bzrlib.merge3 import Merge3 |
20 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
21 |
def split_lines(t): |
22 |
from cStringIO import StringIO |
|
23 |
return StringIO(t).readlines() |
|
24 |
||
25 |
############################################################
|
|
26 |
# test case data from the gnu diffutils manual
|
|
27 |
# common base
|
|
28 |
TZU = split_lines(""" The Nameless is the origin of Heaven and Earth; |
|
29 |
The named is the mother of all things.
|
|
30 |
|
|
31 |
Therefore let there always be non-being,
|
|
32 |
so we may see their subtlety,
|
|
33 |
And let there always be being,
|
|
34 |
so we may see their outcome.
|
|
35 |
The two are the same,
|
|
36 |
But after they are produced,
|
|
37 |
they have different names.
|
|
38 |
They both may be called deep and profound.
|
|
39 |
Deeper and more profound,
|
|
40 |
The door of all subtleties!
|
|
41 |
""") |
|
42 |
||
43 |
LAO = split_lines(""" The Way that can be told of is not the eternal Way; |
|
44 |
The name that can be named is not the eternal name.
|
|
45 |
The Nameless is the origin of Heaven and Earth;
|
|
46 |
The Named is the mother of all things.
|
|
47 |
Therefore let there always be non-being,
|
|
48 |
so we may see their subtlety,
|
|
49 |
And let there always be being,
|
|
50 |
so we may see their outcome.
|
|
51 |
The two are the same,
|
|
52 |
But after they are produced,
|
|
53 |
they have different names.
|
|
54 |
""") |
|
55 |
||
56 |
||
57 |
TAO = split_lines(""" The Way that can be told of is not the eternal Way; |
|
58 |
The name that can be named is not the eternal name.
|
|
59 |
The Nameless is the origin of Heaven and Earth;
|
|
60 |
The named is the mother of all things.
|
|
61 |
|
|
62 |
Therefore let there always be non-being,
|
|
63 |
so we may see their subtlety,
|
|
64 |
And let there always be being,
|
|
65 |
so we may see their result.
|
|
66 |
The two are the same,
|
|
67 |
But after they are produced,
|
|
68 |
they have different names.
|
|
69 |
|
|
70 |
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
|
|
71 |
||
72 |
""") |
|
73 |
||
74 |
MERGED_RESULT = split_lines(""" The Way that can be told of is not the eternal Way; |
|
75 |
The name that can be named is not the eternal name.
|
|
76 |
The Nameless is the origin of Heaven and Earth;
|
|
77 |
The Named is the mother of all things.
|
|
78 |
Therefore let there always be non-being,
|
|
79 |
so we may see their subtlety,
|
|
80 |
And let there always be being,
|
|
81 |
so we may see their result.
|
|
82 |
The two are the same,
|
|
83 |
But after they are produced,
|
|
84 |
they have different names.
|
|
974.1.50
by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9 |
85 |
<<<<<<< LAO
|
86 |
=======
|
|
1102
by Martin Pool
- merge test refactoring from robertc |
87 |
|
88 |
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
|
|
89 |
||
974.1.50
by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9 |
90 |
>>>>>>> TAO
|
1102
by Martin Pool
- merge test refactoring from robertc |
91 |
""") |
92 |
||
93 |
class TestMerge3(TestCase): |
|
94 |
||
95 |
def test_no_changes(self): |
|
96 |
"""No conflicts because nothing changed"""
|
|
821
by Martin Pool
- start code for built-in diff3-style resolve |
97 |
m3 = Merge3(['aaa', 'bbb'], |
98 |
['aaa', 'bbb'], |
|
99 |
['aaa', 'bbb']) |
|
100 |
||
101 |
self.assertEquals(m3.find_unconflicted(), |
|
102 |
[(0, 2)]) |
|
103 |
||
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
104 |
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 |
105 |
[(0, 2, |
106 |
0, 2, |
|
825
by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to |
107 |
0, 2), |
108 |
(2,2, 2,2, 2,2)]) |
|
109 |
||
110 |
self.assertEquals(list(m3.merge_regions()), |
|
111 |
[('unchanged', 0, 2)]) |
|
112 |
||
827
by Martin Pool
- new Merge3.merge_groups feeds back the merged lines |
113 |
self.assertEquals(list(m3.merge_groups()), |
114 |
[('unchanged', ['aaa', 'bbb'])]) |
|
115 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
116 |
def test_front_insert(self): |
825
by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to |
117 |
m3 = Merge3(['zz'], |
118 |
['aaa', 'bbb', 'zz'], |
|
119 |
['zz']) |
|
120 |
||
121 |
# todo: should use a sentinal at end as from get_matching_blocks
|
|
122 |
# to match without zz
|
|
123 |
self.assertEquals(list(m3.find_sync_regions()), |
|
124 |
[(0,1, 2,3, 0,1), |
|
125 |
(1,1, 3,3, 1,1),]) |
|
126 |
||
127 |
self.assertEquals(list(m3.merge_regions()), |
|
128 |
[('a', 0, 2), |
|
129 |
('unchanged', 0, 1)]) |
|
827
by Martin Pool
- new Merge3.merge_groups feeds back the merged lines |
130 |
|
131 |
self.assertEquals(list(m3.merge_groups()), |
|
132 |
[('a', ['aaa', 'bbb']), |
|
133 |
('unchanged', ['zz'])]) |
|
825
by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to |
134 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
135 |
def test_null_insert(self): |
825
by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to |
136 |
m3 = Merge3([], |
137 |
['aaa', 'bbb'], |
|
138 |
[])
|
|
139 |
# todo: should use a sentinal at end as from get_matching_blocks
|
|
140 |
# to match without zz
|
|
141 |
self.assertEquals(list(m3.find_sync_regions()), |
|
142 |
[(0,0, 2,2, 0,0)]) |
|
143 |
||
144 |
self.assertEquals(list(m3.merge_regions()), |
|
145 |
[('a', 0, 2)]) |
|
828
by Martin Pool
- code to represent merges in regular text conflict form |
146 |
|
147 |
self.assertEquals(list(m3.merge_lines()), |
|
148 |
['aaa', 'bbb']) |
|
821
by Martin Pool
- start code for built-in diff3-style resolve |
149 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
150 |
def test_no_conflicts(self): |
151 |
"""No conflicts because only one side changed"""
|
|
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
152 |
m3 = Merge3(['aaa', 'bbb'], |
153 |
['aaa', '111', 'bbb'], |
|
154 |
['aaa', 'bbb']) |
|
155 |
||
156 |
self.assertEquals(m3.find_unconflicted(), |
|
157 |
[(0, 1), (1, 2)]) |
|
158 |
||
159 |
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 |
160 |
[(0,1, 0,1, 0,1), |
161 |
(1,2, 2,3, 1,2), |
|
162 |
(2,2, 3,3, 2,2),]) |
|
163 |
||
826
by Martin Pool
- Actually merge unsynchronized regions. Woot! |
164 |
self.assertEquals(list(m3.merge_regions()), |
165 |
[('unchanged', 0, 1), |
|
166 |
('a', 1, 2), |
|
167 |
('unchanged', 1, 2),]) |
|
168 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
169 |
def test_append_a(self): |
836
by Martin Pool
- more merge tests from john |
170 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
171 |
['aaa\n', 'bbb\n', '222\n'], |
|
172 |
['aaa\n', 'bbb\n']) |
|
173 |
||
174 |
self.assertEquals(''.join(m3.merge_lines()), |
|
175 |
'aaa\nbbb\n222\n') |
|
176 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
177 |
def test_append_b(self): |
836
by Martin Pool
- more merge tests from john |
178 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
179 |
['aaa\n', 'bbb\n'], |
|
180 |
['aaa\n', 'bbb\n', '222\n']) |
|
181 |
||
182 |
self.assertEquals(''.join(m3.merge_lines()), |
|
183 |
'aaa\nbbb\n222\n') |
|
184 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
185 |
def test_append_agreement(self): |
836
by Martin Pool
- more merge tests from john |
186 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
187 |
['aaa\n', 'bbb\n', '222\n'], |
|
188 |
['aaa\n', 'bbb\n', '222\n']) |
|
189 |
||
190 |
self.assertEquals(''.join(m3.merge_lines()), |
|
191 |
'aaa\nbbb\n222\n') |
|
192 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
193 |
def test_append_clash(self): |
836
by Martin Pool
- more merge tests from john |
194 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
195 |
['aaa\n', 'bbb\n', '222\n'], |
|
196 |
['aaa\n', 'bbb\n', '333\n']) |
|
197 |
||
198 |
ml = m3.merge_lines(name_a='a', |
|
199 |
name_b='b', |
|
200 |
start_marker='<<', |
|
201 |
mid_marker='--', |
|
202 |
end_marker='>>') |
|
203 |
self.assertEquals(''.join(ml), |
|
204 |
'''\
|
|
205 |
aaa
|
|
206 |
bbb
|
|
207 |
<< a
|
|
208 |
222
|
|
209 |
--
|
|
210 |
333
|
|
211 |
>> b
|
|
212 |
''') |
|
213 |
||
1102
by Martin Pool
- merge test refactoring from robertc |
214 |
def test_insert_agreement(self): |
830
by Martin Pool
- handle chunks which differ from the base but agree |
215 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
216 |
['aaa\n', '222\n', 'bbb\n'], |
|
217 |
['aaa\n', '222\n', 'bbb\n']) |
|
218 |
||
836
by Martin Pool
- more merge tests from john |
219 |
ml = m3.merge_lines(name_a='a', |
220 |
name_b='b', |
|
221 |
start_marker='<<', |
|
222 |
mid_marker='--', |
|
223 |
end_marker='>>') |
|
1143
by Martin Pool
- remove dead code and remove some small errors (pychecker) |
224 |
self.assertEquals(''.join(ml), 'aaa\n222\nbbb\n') |
225 |
||
830
by Martin Pool
- handle chunks which differ from the base but agree |
226 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
227 |
def test_insert_clash(self): |
228 |
"""Both try to insert lines in the same place."""
|
|
829
by Martin Pool
- More merge3 cvs-form stuff |
229 |
m3 = Merge3(['aaa\n', 'bbb\n'], |
230 |
['aaa\n', '111\n', 'bbb\n'], |
|
231 |
['aaa\n', '222\n', 'bbb\n']) |
|
821
by Martin Pool
- start code for built-in diff3-style resolve |
232 |
|
233 |
self.assertEquals(m3.find_unconflicted(), |
|
234 |
[(0, 1), (1, 2)]) |
|
235 |
||
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
236 |
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 |
237 |
[(0,1, 0,1, 0,1), |
238 |
(1,2, 2,3, 2,3), |
|
239 |
(2,2, 3,3, 3,3),]) |
|
821
by Martin Pool
- start code for built-in diff3-style resolve |
240 |
|
826
by Martin Pool
- Actually merge unsynchronized regions. Woot! |
241 |
self.assertEquals(list(m3.merge_regions()), |
242 |
[('unchanged', 0,1), |
|
827
by Martin Pool
- new Merge3.merge_groups feeds back the merged lines |
243 |
('conflict', 1,1, 1,2, 1,2), |
826
by Martin Pool
- Actually merge unsynchronized regions. Woot! |
244 |
('unchanged', 1,2)]) |
245 |
||
827
by Martin Pool
- new Merge3.merge_groups feeds back the merged lines |
246 |
self.assertEquals(list(m3.merge_groups()), |
829
by Martin Pool
- More merge3 cvs-form stuff |
247 |
[('unchanged', ['aaa\n']), |
248 |
('conflict', [], ['111\n'], ['222\n']), |
|
249 |
('unchanged', ['bbb\n']), |
|
827
by Martin Pool
- new Merge3.merge_groups feeds back the merged lines |
250 |
])
|
251 |
||
829
by Martin Pool
- More merge3 cvs-form stuff |
252 |
ml = m3.merge_lines(name_a='a', |
253 |
name_b='b', |
|
254 |
start_marker='<<', |
|
255 |
mid_marker='--', |
|
256 |
end_marker='>>') |
|
257 |
self.assertEquals(''.join(ml), |
|
258 |
'''aaa
|
|
259 |
<< a
|
|
260 |
111
|
|
261 |
--
|
|
262 |
222
|
|
263 |
>> b
|
|
264 |
bbb
|
|
265 |
''') |
|
828
by Martin Pool
- code to represent merges in regular text conflict form |
266 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
267 |
def test_replace_clash(self): |
268 |
"""Both try to insert lines in the same place."""
|
|
821
by Martin Pool
- start code for built-in diff3-style resolve |
269 |
m3 = Merge3(['aaa', '000', 'bbb'], |
270 |
['aaa', '111', 'bbb'], |
|
271 |
['aaa', '222', 'bbb']) |
|
272 |
||
273 |
self.assertEquals(m3.find_unconflicted(), |
|
274 |
[(0, 1), (2, 3)]) |
|
275 |
||
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
276 |
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 |
277 |
[(0,1, 0,1, 0,1), |
278 |
(2,3, 2,3, 2,3), |
|
279 |
(3,3, 3,3, 3,3),]) |
|
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
280 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
281 |
def test_replace_multi(self): |
282 |
"""Replacement with regions of different size."""
|
|
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
283 |
m3 = Merge3(['aaa', '000', '000', 'bbb'], |
284 |
['aaa', '111', '111', '111', 'bbb'], |
|
285 |
['aaa', '222', '222', '222', '222', 'bbb']) |
|
286 |
||
287 |
self.assertEquals(m3.find_unconflicted(), |
|
288 |
[(0, 1), (3, 4)]) |
|
289 |
||
290 |
||
291 |
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 |
292 |
[(0,1, 0,1, 0,1), |
293 |
(3,4, 4,5, 5,6), |
|
294 |
(4,4, 5,5, 6,6),]) |
|
822
by Martin Pool
- Renamed merge3 test suite for easier access. |
295 |
|
1102
by Martin Pool
- merge test refactoring from robertc |
296 |
def test_merge_poem(self): |
297 |
"""Test case from diff3 manual"""
|
|
831
by Martin Pool
- add merge3 test case from Lao-Tzu |
298 |
m3 = Merge3(TZU, LAO, TAO) |
299 |
ml = list(m3.merge_lines('LAO', 'TAO')) |
|
300 |
self.log('merge result:') |
|
301 |
self.log(''.join(ml)) |
|
302 |
self.assertEquals(ml, MERGED_RESULT) |