15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.selftest import TestCaseInTempDir, TestCase
18
from bzrlib.selftest import InTempDir, TestBase
19
19
from bzrlib.merge3 import Merge3
22
from cStringIO import StringIO
23
return StringIO(t).readlines()
25
############################################################
26
# test case data from the gnu diffutils manual
28
TZU = split_lines(""" The Nameless is the origin of Heaven and Earth;
29
The named is the mother of all things.
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.
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!
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.
52
But after they are produced,
53
they have different names.
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.
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.
67
But after they are produced,
68
they have different names.
70
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
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.
83
But after they are produced,
84
they have different names.
88
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
93
class TestMerge3(TestCase):
95
def test_no_changes(self):
96
"""No conflicts because nothing changed"""
25
class NoChanges(TestBase):
26
"""No conflicts because nothing changed"""
97
28
m3 = Merge3(['aaa', 'bbb'],
167
107
('unchanged', 1, 2),])
169
def test_append_a(self):
170
m3 = Merge3(['aaa\n', 'bbb\n'],
171
['aaa\n', 'bbb\n', '222\n'],
174
self.assertEquals(''.join(m3.merge_lines()),
177
def test_append_b(self):
178
m3 = Merge3(['aaa\n', 'bbb\n'],
180
['aaa\n', 'bbb\n', '222\n'])
182
self.assertEquals(''.join(m3.merge_lines()),
185
def test_append_agreement(self):
186
m3 = Merge3(['aaa\n', 'bbb\n'],
187
['aaa\n', 'bbb\n', '222\n'],
188
['aaa\n', 'bbb\n', '222\n'])
190
self.assertEquals(''.join(m3.merge_lines()),
193
def test_append_clash(self):
194
m3 = Merge3(['aaa\n', 'bbb\n'],
195
['aaa\n', 'bbb\n', '222\n'],
196
['aaa\n', 'bbb\n', '333\n'])
198
ml = m3.merge_lines(name_a='a',
203
self.assertEquals(''.join(ml),
214
def test_insert_agreement(self):
111
class InsertAgreement(TestBase):
215
113
m3 = Merge3(['aaa\n', 'bbb\n'],
216
114
['aaa\n', '222\n', 'bbb\n'],
217
115
['aaa\n', '222\n', 'bbb\n'])
219
ml = m3.merge_lines(name_a='a',
224
self.assertEquals(''.join(ml), 'aaa\n222\nbbb\n')
227
def test_insert_clash(self):
228
"""Both try to insert lines in the same place."""
117
self.assertEquals(''.join(m3.merge_lines()),
122
class InsertClash(TestBase):
123
"""Both try to insert lines in the same place."""
229
125
m3 = Merge3(['aaa\n', 'bbb\n'],
230
126
['aaa\n', '111\n', 'bbb\n'],
231
127
['aaa\n', '222\n', 'bbb\n'])
279
178
(3,3, 3,3, 3,3),])
281
def test_replace_multi(self):
282
"""Replacement with regions of different size."""
182
class ReplaceMulti(TestBase):
183
"""Replacement with regions of different size."""
283
185
m3 = Merge3(['aaa', '000', '000', 'bbb'],
284
186
['aaa', '111', '111', '111', 'bbb'],
285
187
['aaa', '222', '222', '222', '222', 'bbb'])
294
196
(4,4, 5,5, 6,6),])
296
def test_merge_poem(self):
297
"""Test case from diff3 manual"""
205
from cStringIO import StringIO
206
return StringIO(t).readlines()
210
TZU = split_lines(""" The Nameless is the origin of Heaven and Earth;
211
The named is the mother of all things.
213
Therefore let there always be non-being,
214
so we may see their subtlety,
215
And let there always be being,
216
so we may see their outcome.
217
The two are the same,
218
But after they are produced,
219
they have different names.
220
They both may be called deep and profound.
221
Deeper and more profound,
222
The door of all subtleties!
225
LAO = split_lines(""" The Way that can be told of is not the eternal Way;
226
The name that can be named is not the eternal name.
227
The Nameless is the origin of Heaven and Earth;
228
The Named is the mother of all things.
229
Therefore let there always be non-being,
230
so we may see their subtlety,
231
And let there always be being,
232
so we may see their outcome.
233
The two are the same,
234
But after they are produced,
235
they have different names.
239
TAO = split_lines(""" The Way that can be told of is not the eternal Way;
240
The name that can be named is not the eternal name.
241
The Nameless is the origin of Heaven and Earth;
242
The named is the mother of all things.
244
Therefore let there always be non-being,
245
so we may see their subtlety,
246
And let there always be being,
247
so we may see their result.
248
The two are the same,
249
But after they are produced,
250
they have different names.
252
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
256
MERGED_RESULT = split_lines(""" The Way that can be told of is not the eternal Way;
257
The name that can be named is not the eternal name.
258
The Nameless is the origin of Heaven and Earth;
259
The Named is the mother of all things.
260
Therefore let there always be non-being,
261
so we may see their subtlety,
262
And let there always be being,
263
so we may see their result.
264
The two are the same,
265
But after they are produced,
266
they have different names.
270
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
277
class MergePoem(TestBase):
278
"""Test case from diff3 manual"""
298
280
m3 = Merge3(TZU, LAO, TAO)
299
281
ml = list(m3.merge_lines('LAO', 'TAO'))
300
282
self.log('merge result:')