/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testmerge3.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011, 2016 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2004, 2005 by Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
from .. import (
19
 
    merge3,
20
 
    tests,
21
 
    )
22
 
from ..errors import BinaryFile
23
 
from ..sixish import (
24
 
    BytesIO,
25
 
    int2byte,
26
 
    )
27
 
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
from bzrlib.selftest import TestCaseInTempDir, TestCase
 
19
from bzrlib.merge3 import Merge3
28
20
 
29
21
def split_lines(t):
30
 
    return BytesIO(t).readlines()
31
 
 
 
22
    from cStringIO import StringIO
 
23
    return StringIO(t).readlines()
32
24
 
33
25
############################################################
34
26
# test case data from the gnu diffutils manual
35
27
# common base
36
 
TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
 
28
TZU = split_lines("""     The Nameless is the origin of Heaven and Earth;
37
29
     The named is the mother of all things.
38
 
 
 
30
     
39
31
     Therefore let there always be non-being,
40
32
       so we may see their subtlety,
41
33
     And let there always be being,
48
40
     The door of all subtleties!
49
41
""")
50
42
 
51
 
LAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
 
43
LAO = split_lines("""     The Way that can be told of is not the eternal Way;
52
44
     The name that can be named is not the eternal name.
53
45
     The Nameless is the origin of Heaven and Earth;
54
46
     The Named is the mother of all things.
62
54
""")
63
55
 
64
56
 
65
 
TAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
 
57
TAO = split_lines("""     The Way that can be told of is not the eternal Way;
66
58
     The name that can be named is not the eternal name.
67
59
     The Nameless is the origin of Heaven and Earth;
68
60
     The named is the mother of all things.
69
 
 
 
61
     
70
62
     Therefore let there always be non-being,
71
63
       so we may see their subtlety,
72
64
     And let there always be being,
74
66
     The two are the same,
75
67
     But after they are produced,
76
68
       they have different names.
77
 
 
 
69
     
78
70
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
79
71
 
80
72
""")
81
73
 
82
 
MERGED_RESULT = split_lines(b"""     The Way that can be told of is not the eternal Way;
 
74
MERGED_RESULT = split_lines("""     The Way that can be told of is not the eternal Way;
83
75
     The name that can be named is not the eternal name.
84
76
     The Nameless is the origin of Heaven and Earth;
85
77
     The Named is the mother of all things.
92
84
       they have different names.
93
85
<<<<<<< LAO
94
86
=======
95
 
 
 
87
     
96
88
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
97
89
 
98
90
>>>>>>> TAO
99
91
""")
100
92
 
101
 
 
102
 
class TestMerge3(tests.TestCase):
 
93
class TestMerge3(TestCase):
103
94
 
104
95
    def test_no_changes(self):
105
96
        """No conflicts because nothing changed"""
106
 
        m3 = merge3.Merge3([b'aaa', b'bbb'],
107
 
                           [b'aaa', b'bbb'],
108
 
                           [b'aaa', b'bbb'])
109
 
 
110
 
        self.assertEqual(m3.find_unconflicted(),
111
 
                         [(0, 2)])
112
 
 
113
 
        self.assertEqual(list(m3.find_sync_regions()),
114
 
                         [(0, 2,
115
 
                           0, 2,
116
 
                           0, 2),
117
 
                          (2, 2, 2, 2, 2, 2)])
118
 
 
119
 
        self.assertEqual(list(m3.merge_regions()),
120
 
                         [('unchanged', 0, 2)])
121
 
 
122
 
        self.assertEqual(list(m3.merge_groups()),
123
 
                         [('unchanged', [b'aaa', b'bbb'])])
 
97
        m3 = Merge3(['aaa', 'bbb'],
 
98
                    ['aaa', 'bbb'],
 
99
                    ['aaa', 'bbb'])
 
100
 
 
101
        self.assertEquals(m3.find_unconflicted(),
 
102
                          [(0, 2)])
 
103
 
 
104
        self.assertEquals(list(m3.find_sync_regions()),
 
105
                          [(0, 2,
 
106
                            0, 2,
 
107
                            0, 2),
 
108
                           (2,2, 2,2, 2,2)])
 
109
 
 
110
        self.assertEquals(list(m3.merge_regions()),
 
111
                          [('unchanged', 0, 2)])
 
112
 
 
113
        self.assertEquals(list(m3.merge_groups()),
 
114
                          [('unchanged', ['aaa', 'bbb'])])
124
115
 
125
116
    def test_front_insert(self):
126
 
        m3 = merge3.Merge3([b'zz'],
127
 
                           [b'aaa', b'bbb', b'zz'],
128
 
                           [b'zz'])
 
117
        m3 = Merge3(['zz'],
 
118
                    ['aaa', 'bbb', 'zz'],
 
119
                    ['zz'])
129
120
 
130
121
        # todo: should use a sentinal at end as from get_matching_blocks
131
122
        # to match without zz
132
 
        self.assertEqual(list(m3.find_sync_regions()),
133
 
                         [(0, 1, 2, 3, 0, 1),
134
 
                          (1, 1, 3, 3, 1, 1), ])
135
 
 
136
 
        self.assertEqual(list(m3.merge_regions()),
137
 
                         [('a', 0, 2),
138
 
                          ('unchanged', 0, 1)])
139
 
 
140
 
        self.assertEqual(list(m3.merge_groups()),
141
 
                         [('a', [b'aaa', b'bbb']),
142
 
                          ('unchanged', [b'zz'])])
143
 
 
 
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)])
 
130
 
 
131
        self.assertEquals(list(m3.merge_groups()),
 
132
                          [('a', ['aaa', 'bbb']),
 
133
                           ('unchanged', ['zz'])])
 
134
        
144
135
    def test_null_insert(self):
145
 
        m3 = merge3.Merge3([],
146
 
                           [b'aaa', b'bbb'],
147
 
                           [])
 
136
        m3 = Merge3([],
 
137
                    ['aaa', 'bbb'],
 
138
                    [])
148
139
        # todo: should use a sentinal at end as from get_matching_blocks
149
140
        # to match without zz
150
 
        self.assertEqual(list(m3.find_sync_regions()),
151
 
                         [(0, 0, 2, 2, 0, 0)])
152
 
 
153
 
        self.assertEqual(list(m3.merge_regions()),
154
 
                         [('a', 0, 2)])
155
 
 
156
 
        self.assertEqual(list(m3.merge_lines()),
157
 
                         [b'aaa', b'bbb'])
 
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)])
 
146
 
 
147
        self.assertEquals(list(m3.merge_lines()),
 
148
                          ['aaa', 'bbb'])
158
149
 
159
150
    def test_no_conflicts(self):
160
151
        """No conflicts because only one side changed"""
161
 
        m3 = merge3.Merge3([b'aaa', b'bbb'],
162
 
                           [b'aaa', b'111', b'bbb'],
163
 
                           [b'aaa', b'bbb'])
164
 
 
165
 
        self.assertEqual(m3.find_unconflicted(),
166
 
                         [(0, 1), (1, 2)])
167
 
 
168
 
        self.assertEqual(list(m3.find_sync_regions()),
169
 
                         [(0, 1, 0, 1, 0, 1),
170
 
                          (1, 2, 2, 3, 1, 2),
171
 
                          (2, 2, 3, 3, 2, 2), ])
172
 
 
173
 
        self.assertEqual(list(m3.merge_regions()),
174
 
                         [('unchanged', 0, 1),
175
 
                          ('a', 1, 2),
176
 
                          ('unchanged', 1, 2), ])
 
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()),
 
160
                          [(0,1, 0,1, 0,1),
 
161
                           (1,2, 2,3, 1,2),
 
162
                           (2,2, 3,3, 2,2),])
 
163
 
 
164
        self.assertEquals(list(m3.merge_regions()),
 
165
                          [('unchanged', 0, 1),
 
166
                           ('a', 1, 2),
 
167
                           ('unchanged', 1, 2),])
177
168
 
178
169
    def test_append_a(self):
179
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
180
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
181
 
                           [b'aaa\n', b'bbb\n'])
 
170
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
171
                    ['aaa\n', 'bbb\n', '222\n'],
 
172
                    ['aaa\n', 'bbb\n'])
182
173
 
183
 
        self.assertEqual(b''.join(m3.merge_lines()),
184
 
                         b'aaa\nbbb\n222\n')
 
174
        self.assertEquals(''.join(m3.merge_lines()),
 
175
                          'aaa\nbbb\n222\n')
185
176
 
186
177
    def test_append_b(self):
187
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
188
 
                           [b'aaa\n', b'bbb\n'],
189
 
                           [b'aaa\n', b'bbb\n', b'222\n'])
 
178
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
179
                    ['aaa\n', 'bbb\n'],
 
180
                    ['aaa\n', 'bbb\n', '222\n'])
190
181
 
191
 
        self.assertEqual(b''.join(m3.merge_lines()),
192
 
                         b'aaa\nbbb\n222\n')
 
182
        self.assertEquals(''.join(m3.merge_lines()),
 
183
                          'aaa\nbbb\n222\n')
193
184
 
194
185
    def test_append_agreement(self):
195
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
196
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
197
 
                           [b'aaa\n', b'bbb\n', b'222\n'])
 
186
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
187
                    ['aaa\n', 'bbb\n', '222\n'],
 
188
                    ['aaa\n', 'bbb\n', '222\n'])
198
189
 
199
 
        self.assertEqual(b''.join(m3.merge_lines()),
200
 
                         b'aaa\nbbb\n222\n')
 
190
        self.assertEquals(''.join(m3.merge_lines()),
 
191
                          'aaa\nbbb\n222\n')
201
192
 
202
193
    def test_append_clash(self):
203
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
204
 
                           [b'aaa\n', b'bbb\n', b'222\n'],
205
 
                           [b'aaa\n', b'bbb\n', b'333\n'])
 
194
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
195
                    ['aaa\n', 'bbb\n', '222\n'],
 
196
                    ['aaa\n', 'bbb\n', '333\n'])
206
197
 
207
 
        ml = m3.merge_lines(name_a=b'a',
208
 
                            name_b=b'b',
209
 
                            start_marker=b'<<',
210
 
                            mid_marker=b'--',
211
 
                            end_marker=b'>>')
212
 
        self.assertEqual(b''.join(ml),
213
 
                         b'''\
 
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
'''\
214
205
aaa
215
206
bbb
216
207
<< a
221
212
''')
222
213
 
223
214
    def test_insert_agreement(self):
224
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
225
 
                           [b'aaa\n', b'222\n', b'bbb\n'],
226
 
                           [b'aaa\n', b'222\n', b'bbb\n'])
 
215
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
216
                    ['aaa\n', '222\n', 'bbb\n'],
 
217
                    ['aaa\n', '222\n', 'bbb\n'])
227
218
 
228
 
        ml = m3.merge_lines(name_a=b'a',
229
 
                            name_b=b'b',
230
 
                            start_marker=b'<<',
231
 
                            mid_marker=b'--',
232
 
                            end_marker=b'>>')
233
 
        self.assertEqual(b''.join(ml), b'aaa\n222\nbbb\n')
 
219
        ml = m3.merge_lines(name_a='a',
 
220
                            name_b='b',
 
221
                            start_marker='<<',
 
222
                            mid_marker='--',
 
223
                            end_marker='>>')
 
224
        self.assertEquals(''.join(ml), 'aaa\n222\nbbb\n')
 
225
        
234
226
 
235
227
    def test_insert_clash(self):
236
228
        """Both try to insert lines in the same place."""
237
 
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
238
 
                           [b'aaa\n', b'111\n', b'bbb\n'],
239
 
                           [b'aaa\n', b'222\n', b'bbb\n'])
240
 
 
241
 
        self.assertEqual(m3.find_unconflicted(),
242
 
                         [(0, 1), (1, 2)])
243
 
 
244
 
        self.assertEqual(list(m3.find_sync_regions()),
245
 
                         [(0, 1, 0, 1, 0, 1),
246
 
                          (1, 2, 2, 3, 2, 3),
247
 
                          (2, 2, 3, 3, 3, 3), ])
248
 
 
249
 
        self.assertEqual(list(m3.merge_regions()),
250
 
                         [('unchanged', 0, 1),
251
 
                          ('conflict', 1, 1, 1, 2, 1, 2),
252
 
                          ('unchanged', 1, 2)])
253
 
 
254
 
        self.assertEqual(list(m3.merge_groups()),
255
 
                         [('unchanged', [b'aaa\n']),
256
 
                          ('conflict', [], [b'111\n'], [b'222\n']),
257
 
                          ('unchanged', [b'bbb\n']),
258
 
                          ])
259
 
 
260
 
        ml = m3.merge_lines(name_a=b'a',
261
 
                            name_b=b'b',
262
 
                            start_marker=b'<<',
263
 
                            mid_marker=b'--',
264
 
                            end_marker=b'>>')
265
 
        self.assertEqual(b''.join(ml),
266
 
                         b'''aaa
 
229
        m3 = Merge3(['aaa\n', 'bbb\n'],
 
230
                    ['aaa\n', '111\n', 'bbb\n'],
 
231
                    ['aaa\n', '222\n', 'bbb\n'])
 
232
 
 
233
        self.assertEquals(m3.find_unconflicted(),
 
234
                          [(0, 1), (1, 2)])
 
235
 
 
236
        self.assertEquals(list(m3.find_sync_regions()),
 
237
                          [(0,1, 0,1, 0,1),
 
238
                           (1,2, 2,3, 2,3),
 
239
                           (2,2, 3,3, 3,3),])
 
240
 
 
241
        self.assertEquals(list(m3.merge_regions()),
 
242
                          [('unchanged', 0,1),
 
243
                           ('conflict', 1,1, 1,2, 1,2),
 
244
                           ('unchanged', 1,2)])
 
245
 
 
246
        self.assertEquals(list(m3.merge_groups()),
 
247
                          [('unchanged', ['aaa\n']),
 
248
                           ('conflict', [], ['111\n'], ['222\n']),
 
249
                           ('unchanged', ['bbb\n']),
 
250
                           ])
 
251
 
 
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
267
259
<< a
268
260
111
269
261
--
274
266
 
275
267
    def test_replace_clash(self):
276
268
        """Both try to insert lines in the same place."""
277
 
        m3 = merge3.Merge3([b'aaa', b'000', b'bbb'],
278
 
                           [b'aaa', b'111', b'bbb'],
279
 
                           [b'aaa', b'222', b'bbb'])
280
 
 
281
 
        self.assertEqual(m3.find_unconflicted(),
282
 
                         [(0, 1), (2, 3)])
283
 
 
284
 
        self.assertEqual(list(m3.find_sync_regions()),
285
 
                         [(0, 1, 0, 1, 0, 1),
286
 
                          (2, 3, 2, 3, 2, 3),
287
 
                          (3, 3, 3, 3, 3, 3), ])
 
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
 
 
276
        self.assertEquals(list(m3.find_sync_regions()),
 
277
                          [(0,1, 0,1, 0,1),
 
278
                           (2,3, 2,3, 2,3),
 
279
                           (3,3, 3,3, 3,3),])
288
280
 
289
281
    def test_replace_multi(self):
290
282
        """Replacement with regions of different size."""
291
 
        m3 = merge3.Merge3([b'aaa', b'000', b'000', b'bbb'],
292
 
                           [b'aaa', b'111', b'111', b'111', b'bbb'],
293
 
                           [b'aaa', b'222', b'222', b'222', b'222', b'bbb'])
294
 
 
295
 
        self.assertEqual(m3.find_unconflicted(),
296
 
                         [(0, 1), (3, 4)])
297
 
 
298
 
        self.assertEqual(list(m3.find_sync_regions()),
299
 
                         [(0, 1, 0, 1, 0, 1),
300
 
                          (3, 4, 4, 5, 5, 6),
301
 
                          (4, 4, 5, 5, 6, 6), ])
 
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()),
 
292
                          [(0,1, 0,1, 0,1),
 
293
                           (3,4, 4,5, 5,6),
 
294
                           (4,4, 5,5, 6,6),])
302
295
 
303
296
    def test_merge_poem(self):
304
297
        """Test case from diff3 manual"""
305
 
        m3 = merge3.Merge3(TZU, LAO, TAO)
306
 
        ml = list(m3.merge_lines(b'LAO', b'TAO'))
 
298
        m3 = Merge3(TZU, LAO, TAO)
 
299
        ml = list(m3.merge_lines('LAO', 'TAO'))
307
300
        self.log('merge result:')
308
 
        self.log(b''.join(ml))
309
 
        self.assertEqual(ml, MERGED_RESULT)
310
 
 
311
 
    def test_minimal_conflicts_common(self):
312
 
        """Reprocessing"""
313
 
        base_text = (b"a\n" * 20).splitlines(True)
314
 
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
315
 
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
316
 
                      8 + b"c\n").splitlines(True)
317
 
        m3 = merge3.Merge3(base_text, other_text, this_text)
318
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
319
 
        merged_text = b"".join(list(m_lines))
320
 
        optimal_text = (b"a\n" * 10 + b"<<<<<<< OTHER\nc\n"
321
 
                        + 8 * b"b\n" + b"c\n=======\n"
322
 
                        + 10 * b"b\n" + b">>>>>>> THIS\n")
323
 
        self.assertEqualDiff(optimal_text, merged_text)
324
 
 
325
 
    def test_minimal_conflicts_unique(self):
326
 
        def add_newline(s):
327
 
            """Add a newline to each entry in the string"""
328
 
            return [(int2byte(x) + b'\n') for x in bytearray(s)]
329
 
 
330
 
        base_text = add_newline(b"abcdefghijklm")
331
 
        this_text = add_newline(b"abcdefghijklmNOPQRSTUVWXYZ")
332
 
        other_text = add_newline(b"abcdefghijklm1OPQRSTUVWXY2")
333
 
        m3 = merge3.Merge3(base_text, other_text, this_text)
334
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
335
 
        merged_text = b"".join(list(m_lines))
336
 
        optimal_text = b''.join(add_newline(b"abcdefghijklm")
337
 
                                + [b"<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
338
 
                                + add_newline(b'OPQRSTUVWXY')
339
 
                                + [b"<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
340
 
                                )
341
 
        self.assertEqualDiff(optimal_text, merged_text)
342
 
 
343
 
    def test_minimal_conflicts_nonunique(self):
344
 
        def add_newline(s):
345
 
            """Add a newline to each entry in the string"""
346
 
            return [(int2byte(x) + b'\n') for x in bytearray(s)]
347
 
 
348
 
        base_text = add_newline(b"abacddefgghij")
349
 
        this_text = add_newline(b"abacddefgghijkalmontfprz")
350
 
        other_text = add_newline(b"abacddefgghijknlmontfprd")
351
 
        m3 = merge3.Merge3(base_text, other_text, this_text)
352
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
353
 
        merged_text = b"".join(list(m_lines))
354
 
        optimal_text = b''.join(add_newline(b"abacddefgghijk")
355
 
                                + [b"<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
356
 
                                + add_newline(b'lmontfpr')
357
 
                                + [b"<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
358
 
                                )
359
 
        self.assertEqualDiff(optimal_text, merged_text)
360
 
 
361
 
    def test_reprocess_and_base(self):
362
 
        """Reprocessing and showing base breaks correctly"""
363
 
        base_text = (b"a\n" * 20).splitlines(True)
364
 
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
365
 
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
366
 
                      8 + b"c\n").splitlines(True)
367
 
        m3 = merge3.Merge3(base_text, other_text, this_text)
368
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True,
369
 
                                 base_marker=b'|||||||')
370
 
        self.assertRaises(merge3.CantReprocessAndShowBase, list, m_lines)
371
 
 
372
 
    def test_binary(self):
373
 
        self.assertRaises(BinaryFile, merge3.Merge3, [b'\x00'], [b'a'], [b'b'])
374
 
 
375
 
    def test_dos_text(self):
376
 
        base_text = b'a\r\n'
377
 
        this_text = b'b\r\n'
378
 
        other_text = b'c\r\n'
379
 
        m3 = merge3.Merge3(base_text.splitlines(True),
380
 
                           other_text.splitlines(True),
381
 
                           this_text.splitlines(True))
382
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
383
 
        self.assertEqual(b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
384
 
                         b'>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
385
 
 
386
 
    def test_mac_text(self):
387
 
        base_text = b'a\r'
388
 
        this_text = b'b\r'
389
 
        other_text = b'c\r'
390
 
        m3 = merge3.Merge3(base_text.splitlines(True),
391
 
                           other_text.splitlines(True),
392
 
                           this_text.splitlines(True))
393
 
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
394
 
        self.assertEqual(b'<<<<<<< OTHER\rc\r=======\rb\r'
395
 
                         b'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
396
 
 
397
 
    def test_merge3_cherrypick(self):
398
 
        base_text = b"a\nb\n"
399
 
        this_text = b"a\n"
400
 
        other_text = b"a\nb\nc\n"
401
 
        # When cherrypicking, lines in base are not part of the conflict
402
 
        m3 = merge3.Merge3(base_text.splitlines(True),
403
 
                           this_text.splitlines(True),
404
 
                           other_text.splitlines(True), is_cherrypick=True)
405
 
        m_lines = m3.merge_lines()
406
 
        self.assertEqualDiff(b'a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
407
 
                             b''.join(m_lines))
408
 
 
409
 
        # This is not symmetric
410
 
        m3 = merge3.Merge3(base_text.splitlines(True),
411
 
                           other_text.splitlines(True),
412
 
                           this_text.splitlines(True), is_cherrypick=True)
413
 
        m_lines = m3.merge_lines()
414
 
        self.assertEqualDiff(b'a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
415
 
                             b''.join(m_lines))
416
 
 
417
 
    def test_merge3_cherrypick_w_mixed(self):
418
 
        base_text = b'a\nb\nc\nd\ne\n'
419
 
        this_text = b'a\nb\nq\n'
420
 
        other_text = b'a\nb\nc\nd\nf\ne\ng\n'
421
 
        # When cherrypicking, lines in base are not part of the conflict
422
 
        m3 = merge3.Merge3(base_text.splitlines(True),
423
 
                           this_text.splitlines(True),
424
 
                           other_text.splitlines(True), is_cherrypick=True)
425
 
        m_lines = m3.merge_lines()
426
 
        self.assertEqualDiff(b'a\n'
427
 
                             b'b\n'
428
 
                             b'<<<<<<<\n'
429
 
                             b'q\n'
430
 
                             b'=======\n'
431
 
                             b'f\n'
432
 
                             b'>>>>>>>\n'
433
 
                             b'<<<<<<<\n'
434
 
                             b'=======\n'
435
 
                             b'g\n'
436
 
                             b'>>>>>>>\n',
437
 
                             b''.join(m_lines))
438
 
 
439
 
    def test_allow_objects(self):
440
 
        """Objects other than strs may be used with Merge3 when
441
 
        allow_objects=True.
442
 
 
443
 
        merge_groups and merge_regions work with non-str input.  Methods that
444
 
        return lines like merge_lines fail.
445
 
        """
446
 
        base = [(x, x) for x in 'abcde']
447
 
        a = [(x, x) for x in 'abcdef']
448
 
        b = [(x, x) for x in 'Zabcde']
449
 
        m3 = merge3.Merge3(base, a, b, allow_objects=True)
450
 
        self.assertEqual(
451
 
            [('b', 0, 1),
452
 
             ('unchanged', 0, 5),
453
 
             ('a', 5, 6)],
454
 
            list(m3.merge_regions()))
455
 
        self.assertEqual(
456
 
            [('b', [('Z', 'Z')]),
457
 
             ('unchanged', [(x, x) for x in 'abcde']),
458
 
             ('a', [('f', 'f')])],
459
 
            list(m3.merge_groups()))
 
301
        self.log(''.join(ml))
 
302
        self.assertEquals(ml, MERGED_RESULT)