15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.selftest import InTempDir, TestBase
18
from bzrlib.selftest import TestCaseInTempDir, TestCase
19
19
from bzrlib.merge3 import Merge3
25
class NoChanges(TestBase):
26
"""No conflicts because nothing changed"""
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"""
28
97
m3 = Merge3(['aaa', 'bbb'],
169
221
start_marker='<<',
172
self.assertEquals(''.join(m3.merge_lines()),
178
class InsertClash(TestBase):
179
"""Both try to insert lines in the same place."""
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."""
181
229
m3 = Merge3(['aaa\n', 'bbb\n'],
182
230
['aaa\n', '111\n', 'bbb\n'],
183
231
['aaa\n', '222\n', 'bbb\n'])
234
279
(3,3, 3,3, 3,3),])
238
class ReplaceMulti(TestBase):
239
"""Replacement with regions of different size."""
281
def test_replace_multi(self):
282
"""Replacement with regions of different size."""
241
283
m3 = Merge3(['aaa', '000', '000', 'bbb'],
242
284
['aaa', '111', '111', '111', 'bbb'],
243
285
['aaa', '222', '222', '222', '222', 'bbb'])
252
294
(4,4, 5,5, 6,6),])
261
from cStringIO import StringIO
262
return StringIO(t).readlines()
266
############################################################
267
# test case from the gnu diffutils manual
270
TZU = split_lines(""" The Nameless is the origin of Heaven and Earth;
271
The named is the mother of all things.
273
Therefore let there always be non-being,
274
so we may see their subtlety,
275
And let there always be being,
276
so we may see their outcome.
277
The two are the same,
278
But after they are produced,
279
they have different names.
280
They both may be called deep and profound.
281
Deeper and more profound,
282
The door of all subtleties!
285
LAO = split_lines(""" The Way that can be told of is not the eternal Way;
286
The name that can be named is not the eternal name.
287
The Nameless is the origin of Heaven and Earth;
288
The Named is the mother of all things.
289
Therefore let there always be non-being,
290
so we may see their subtlety,
291
And let there always be being,
292
so we may see their outcome.
293
The two are the same,
294
But after they are produced,
295
they have different names.
299
TAO = split_lines(""" The Way that can be told of is not the eternal Way;
300
The name that can be named is not the eternal name.
301
The Nameless is the origin of Heaven and Earth;
302
The named is the mother of all things.
304
Therefore let there always be non-being,
305
so we may see their subtlety,
306
And let there always be being,
307
so we may see their result.
308
The two are the same,
309
But after they are produced,
310
they have different names.
312
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
316
MERGED_RESULT = split_lines(""" The Way that can be told of is not the eternal Way;
317
The name that can be named is not the eternal name.
318
The Nameless is the origin of Heaven and Earth;
319
The Named is the mother of all things.
320
Therefore let there always be non-being,
321
so we may see their subtlety,
322
And let there always be being,
323
so we may see their result.
324
The two are the same,
325
But after they are produced,
326
they have different names.
330
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
337
class MergePoem(TestBase):
338
"""Test case from diff3 manual"""
296
def test_merge_poem(self):
297
"""Test case from diff3 manual"""
340
298
m3 = Merge3(TZU, LAO, TAO)
341
299
ml = list(m3.merge_lines('LAO', 'TAO'))
342
300
self.log('merge result:')
343
301
self.log(''.join(ml))
344
302
self.assertEquals(ml, MERGED_RESULT)