/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
821 by Martin Pool
- start code for built-in diff3-style resolve
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
821 by Martin Pool
- start code for built-in diff3-style resolve
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
821 by Martin Pool
- start code for built-in diff3-style resolve
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
821 by Martin Pool
- start code for built-in diff3-style resolve
16
7479.2.1 by Jelmer Vernooij
Drop python2 support.
17
from io import BytesIO
821 by Martin Pool
- start code for built-in diff3-style resolve
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
20
    merge3,
21
    tests,
22
    )
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
23
from ..errors import BinaryFile
821 by Martin Pool
- start code for built-in diff3-style resolve
24
7143.15.2 by Jelmer Vernooij
Run autopep8.
25
1102 by Martin Pool
- merge test refactoring from robertc
26
def split_lines(t):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
27
    return BytesIO(t).readlines()
1102 by Martin Pool
- merge test refactoring from robertc
28
7143.15.2 by Jelmer Vernooij
Run autopep8.
29
1102 by Martin Pool
- merge test refactoring from robertc
30
############################################################
31
# test case data from the gnu diffutils manual
32
# common base
6791.2.3 by Jelmer Vernooij
Fix more imports.
33
TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
1102 by Martin Pool
- merge test refactoring from robertc
34
     The named is the mother of all things.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
35
1102 by Martin Pool
- merge test refactoring from robertc
36
     Therefore let there always be non-being,
37
       so we may see their subtlety,
38
     And let there always be being,
39
       so we may see their outcome.
40
     The two are the same,
41
     But after they are produced,
42
       they have different names.
43
     They both may be called deep and profound.
44
     Deeper and more profound,
45
     The door of all subtleties!
46
""")
47
6791.2.3 by Jelmer Vernooij
Fix more imports.
48
LAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
49
     The name that can be named is not the eternal name.
50
     The Nameless is the origin of Heaven and Earth;
51
     The Named is the mother of all things.
52
     Therefore let there always be non-being,
53
       so we may see their subtlety,
54
     And let there always be being,
55
       so we may see their outcome.
56
     The two are the same,
57
     But after they are produced,
58
       they have different names.
59
""")
60
61
6791.2.3 by Jelmer Vernooij
Fix more imports.
62
TAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
63
     The name that can be named is not the eternal name.
64
     The Nameless is the origin of Heaven and Earth;
65
     The named is the mother of all things.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
66
1102 by Martin Pool
- merge test refactoring from robertc
67
     Therefore let there always be non-being,
68
       so we may see their subtlety,
69
     And let there always be being,
70
       so we may see their result.
71
     The two are the same,
72
     But after they are produced,
73
       they have different names.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
74
1102 by Martin Pool
- merge test refactoring from robertc
75
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
76
77
""")
78
6791.2.3 by Jelmer Vernooij
Fix more imports.
79
MERGED_RESULT = split_lines(b"""     The Way that can be told of is not the eternal Way;
1102 by Martin Pool
- merge test refactoring from robertc
80
     The name that can be named is not the eternal name.
81
     The Nameless is the origin of Heaven and Earth;
82
     The Named is the mother of all things.
83
     Therefore let there always be non-being,
84
       so we may see their subtlety,
85
     And let there always be being,
86
       so we may see their result.
87
     The two are the same,
88
     But after they are produced,
89
       they have different names.
974.1.50 by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9
90
<<<<<<< LAO
91
=======
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
92
1102 by Martin Pool
- merge test refactoring from robertc
93
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
94
974.1.50 by aaron.bentley at utoronto
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9
95
>>>>>>> TAO
1102 by Martin Pool
- merge test refactoring from robertc
96
""")
97
7143.15.2 by Jelmer Vernooij
Run autopep8.
98
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
99
class TestMerge3(tests.TestCase):
1102 by Martin Pool
- merge test refactoring from robertc
100
101
    def test_no_changes(self):
102
        """No conflicts because nothing changed"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
103
        m3 = merge3.Merge3([b'aaa', b'bbb'],
104
                           [b'aaa', b'bbb'],
105
                           [b'aaa', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
106
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
107
        self.assertEqual(m3.find_unconflicted(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
108
                         [(0, 2)])
821 by Martin Pool
- start code for built-in diff3-style resolve
109
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
110
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
111
                         [(0, 2,
112
                           0, 2,
113
                           0, 2),
114
                          (2, 2, 2, 2, 2, 2)])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
115
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
116
        self.assertEqual(list(m3.merge_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
117
                         [('unchanged', 0, 2)])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
118
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
119
        self.assertEqual(list(m3.merge_groups()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
120
                         [('unchanged', [b'aaa', b'bbb'])])
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
121
1102 by Martin Pool
- merge test refactoring from robertc
122
    def test_front_insert(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
123
        m3 = merge3.Merge3([b'zz'],
124
                           [b'aaa', b'bbb', b'zz'],
125
                           [b'zz'])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
126
127
        # todo: should use a sentinal at end as from get_matching_blocks
128
        # to match without zz
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
129
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
130
                         [(0, 1, 2, 3, 0, 1),
131
                          (1, 1, 3, 3, 1, 1), ])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
132
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
133
        self.assertEqual(list(m3.merge_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
134
                         [('a', 0, 2),
135
                          ('unchanged', 0, 1)])
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
136
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
137
        self.assertEqual(list(m3.merge_groups()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                         [('a', [b'aaa', b'bbb']),
139
                          ('unchanged', [b'zz'])])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
140
1102 by Martin Pool
- merge test refactoring from robertc
141
    def test_null_insert(self):
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
142
        m3 = merge3.Merge3([],
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
143
                           [b'aaa', b'bbb'],
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
144
                           [])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
145
        # todo: should use a sentinal at end as from get_matching_blocks
146
        # to match without zz
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
147
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
148
                         [(0, 0, 2, 2, 0, 0)])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
149
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
150
        self.assertEqual(list(m3.merge_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
151
                         [('a', 0, 2)])
828 by Martin Pool
- code to represent merges in regular text conflict form
152
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
153
        self.assertEqual(list(m3.merge_lines()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
154
                         [b'aaa', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
155
1102 by Martin Pool
- merge test refactoring from robertc
156
    def test_no_conflicts(self):
157
        """No conflicts because only one side changed"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
158
        m3 = merge3.Merge3([b'aaa', b'bbb'],
159
                           [b'aaa', b'111', b'bbb'],
160
                           [b'aaa', b'bbb'])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
161
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
162
        self.assertEqual(m3.find_unconflicted(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
163
                         [(0, 1), (1, 2)])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
164
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
165
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
166
                         [(0, 1, 0, 1, 0, 1),
167
                          (1, 2, 2, 3, 1, 2),
168
                          (2, 2, 3, 3, 2, 2), ])
825 by Martin Pool
- Merge3.find_sync_regions always returns a zero-length sentinal at the end to
169
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
170
        self.assertEqual(list(m3.merge_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
171
                         [('unchanged', 0, 1),
172
                          ('a', 1, 2),
173
                          ('unchanged', 1, 2), ])
826 by Martin Pool
- Actually merge unsynchronized regions. Woot!
174
1102 by Martin Pool
- merge test refactoring from robertc
175
    def test_append_a(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
176
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
177
                           [b'aaa\n', b'bbb\n', b'222\n'],
178
                           [b'aaa\n', b'bbb\n'])
836 by Martin Pool
- more merge tests from john
179
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
180
        self.assertEqual(b''.join(m3.merge_lines()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
181
                         b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
182
1102 by Martin Pool
- merge test refactoring from robertc
183
    def test_append_b(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
184
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
185
                           [b'aaa\n', b'bbb\n'],
186
                           [b'aaa\n', b'bbb\n', b'222\n'])
836 by Martin Pool
- more merge tests from john
187
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
188
        self.assertEqual(b''.join(m3.merge_lines()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
189
                         b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
190
1102 by Martin Pool
- merge test refactoring from robertc
191
    def test_append_agreement(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
192
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
193
                           [b'aaa\n', b'bbb\n', b'222\n'],
194
                           [b'aaa\n', b'bbb\n', b'222\n'])
836 by Martin Pool
- more merge tests from john
195
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
196
        self.assertEqual(b''.join(m3.merge_lines()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
197
                         b'aaa\nbbb\n222\n')
836 by Martin Pool
- more merge tests from john
198
1102 by Martin Pool
- merge test refactoring from robertc
199
    def test_append_clash(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
200
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
201
                           [b'aaa\n', b'bbb\n', b'222\n'],
202
                           [b'aaa\n', b'bbb\n', b'333\n'])
836 by Martin Pool
- more merge tests from john
203
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
204
        ml = m3.merge_lines(name_a=b'a',
205
                            name_b=b'b',
206
                            start_marker=b'<<',
207
                            mid_marker=b'--',
208
                            end_marker=b'>>')
209
        self.assertEqual(b''.join(ml),
7143.15.2 by Jelmer Vernooij
Run autopep8.
210
                         b'''\
836 by Martin Pool
- more merge tests from john
211
aaa
212
bbb
213
<< a
214
222
215
--
216
333
217
>> b
218
''')
219
1102 by Martin Pool
- merge test refactoring from robertc
220
    def test_insert_agreement(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
221
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
222
                           [b'aaa\n', b'222\n', b'bbb\n'],
223
                           [b'aaa\n', b'222\n', b'bbb\n'])
830 by Martin Pool
- handle chunks which differ from the base but agree
224
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
225
        ml = m3.merge_lines(name_a=b'a',
226
                            name_b=b'b',
227
                            start_marker=b'<<',
228
                            mid_marker=b'--',
229
                            end_marker=b'>>')
230
        self.assertEqual(b''.join(ml), b'aaa\n222\nbbb\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
231
1102 by Martin Pool
- merge test refactoring from robertc
232
    def test_insert_clash(self):
233
        """Both try to insert lines in the same place."""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
234
        m3 = merge3.Merge3([b'aaa\n', b'bbb\n'],
235
                           [b'aaa\n', b'111\n', b'bbb\n'],
236
                           [b'aaa\n', b'222\n', b'bbb\n'])
821 by Martin Pool
- start code for built-in diff3-style resolve
237
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
238
        self.assertEqual(m3.find_unconflicted(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
239
                         [(0, 1), (1, 2)])
821 by Martin Pool
- start code for built-in diff3-style resolve
240
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
241
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
242
                         [(0, 1, 0, 1, 0, 1),
243
                          (1, 2, 2, 3, 2, 3),
244
                          (2, 2, 3, 3, 3, 3), ])
821 by Martin Pool
- start code for built-in diff3-style resolve
245
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
246
        self.assertEqual(list(m3.merge_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
247
                         [('unchanged', 0, 1),
248
                          ('conflict', 1, 1, 1, 2, 1, 2),
249
                          ('unchanged', 1, 2)])
826 by Martin Pool
- Actually merge unsynchronized regions. Woot!
250
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
251
        self.assertEqual(list(m3.merge_groups()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
252
                         [('unchanged', [b'aaa\n']),
253
                          ('conflict', [], [b'111\n'], [b'222\n']),
254
                          ('unchanged', [b'bbb\n']),
255
                          ])
827 by Martin Pool
- new Merge3.merge_groups feeds back the merged lines
256
6973.11.5 by Jelmer Vernooij
Update python3.passing.
257
        ml = m3.merge_lines(name_a=b'a',
258
                            name_b=b'b',
259
                            start_marker=b'<<',
260
                            mid_marker=b'--',
261
                            end_marker=b'>>')
262
        self.assertEqual(b''.join(ml),
7143.15.2 by Jelmer Vernooij
Run autopep8.
263
                         b'''aaa
829 by Martin Pool
- More merge3 cvs-form stuff
264
<< a
265
111
266
--
267
222
268
>> b
269
bbb
270
''')
828 by Martin Pool
- code to represent merges in regular text conflict form
271
1102 by Martin Pool
- merge test refactoring from robertc
272
    def test_replace_clash(self):
273
        """Both try to insert lines in the same place."""
6973.11.5 by Jelmer Vernooij
Update python3.passing.
274
        m3 = merge3.Merge3([b'aaa', b'000', b'bbb'],
275
                           [b'aaa', b'111', b'bbb'],
276
                           [b'aaa', b'222', b'bbb'])
821 by Martin Pool
- start code for built-in diff3-style resolve
277
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
278
        self.assertEqual(m3.find_unconflicted(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
279
                         [(0, 1), (2, 3)])
821 by Martin Pool
- start code for built-in diff3-style resolve
280
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
281
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
282
                         [(0, 1, 0, 1, 0, 1),
283
                          (2, 3, 2, 3, 2, 3),
284
                          (3, 3, 3, 3, 3, 3), ])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
285
1102 by Martin Pool
- merge test refactoring from robertc
286
    def test_replace_multi(self):
287
        """Replacement with regions of different size."""
6973.11.5 by Jelmer Vernooij
Update python3.passing.
288
        m3 = merge3.Merge3([b'aaa', b'000', b'000', b'bbb'],
289
                           [b'aaa', b'111', b'111', b'111', b'bbb'],
290
                           [b'aaa', b'222', b'222', b'222', b'222', b'bbb'])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
291
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
292
        self.assertEqual(m3.find_unconflicted(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
293
                         [(0, 1), (3, 4)])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
294
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
295
        self.assertEqual(list(m3.find_sync_regions()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
296
                         [(0, 1, 0, 1, 0, 1),
297
                          (3, 4, 4, 5, 5, 6),
298
                          (4, 4, 5, 5, 6, 6), ])
822 by Martin Pool
- Renamed merge3 test suite for easier access.
299
1102 by Martin Pool
- merge test refactoring from robertc
300
    def test_merge_poem(self):
301
        """Test case from diff3 manual"""
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
302
        m3 = merge3.Merge3(TZU, LAO, TAO)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
303
        ml = list(m3.merge_lines(b'LAO', b'TAO'))
831 by Martin Pool
- add merge3 test case from Lao-Tzu
304
        self.log('merge result:')
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
305
        self.log(b''.join(ml))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
306
        self.assertEqual(ml, MERGED_RESULT)
1185.24.1 by Aaron Bentley
Got reprocessing working
307
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
308
    def test_minimal_conflicts_common(self):
1185.24.1 by Aaron Bentley
Got reprocessing working
309
        """Reprocessing"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
310
        base_text = (b"a\n" * 20).splitlines(True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
311
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
312
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
313
                      8 + b"c\n").splitlines(True)
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
314
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
315
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
316
        merged_text = b"".join(list(m_lines))
317
        optimal_text = (b"a\n" * 10 + b"<<<<<<< OTHER\nc\n"
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
318
                        + 8 * b"b\n" + b"c\n=======\n"
319
                        + 10 * b"b\n" + b">>>>>>> THIS\n")
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
320
        self.assertEqualDiff(optimal_text, merged_text)
321
322
    def test_minimal_conflicts_unique(self):
323
        def add_newline(s):
324
            """Add a newline to each entry in the string"""
7479.2.1 by Jelmer Vernooij
Drop python2 support.
325
            return [(bytes([x]) + b'\n') for x in bytearray(s)]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
326
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
327
        base_text = add_newline(b"abcdefghijklm")
328
        this_text = add_newline(b"abcdefghijklmNOPQRSTUVWXYZ")
329
        other_text = add_newline(b"abcdefghijklm1OPQRSTUVWXY2")
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
330
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
331
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
332
        merged_text = b"".join(list(m_lines))
333
        optimal_text = b''.join(add_newline(b"abcdefghijklm")
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
334
                                + [b"<<<<<<< OTHER\n1\n=======\nN\n>>>>>>> THIS\n"]
335
                                + add_newline(b'OPQRSTUVWXY')
336
                                + [b"<<<<<<< OTHER\n2\n=======\nZ\n>>>>>>> THIS\n"]
337
                                )
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
338
        self.assertEqualDiff(optimal_text, merged_text)
339
340
    def test_minimal_conflicts_nonunique(self):
341
        def add_newline(s):
342
            """Add a newline to each entry in the string"""
7479.2.1 by Jelmer Vernooij
Drop python2 support.
343
            return [(bytes([x]) + b'\n') for x in bytearray(s)]
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
344
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
345
        base_text = add_newline(b"abacddefgghij")
346
        this_text = add_newline(b"abacddefgghijkalmontfprz")
347
        other_text = add_newline(b"abacddefgghijknlmontfprd")
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
348
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
349
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True)
350
        merged_text = b"".join(list(m_lines))
351
        optimal_text = b''.join(add_newline(b"abacddefgghijk")
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
352
                                + [b"<<<<<<< OTHER\nn\n=======\na\n>>>>>>> THIS\n"]
353
                                + add_newline(b'lmontfpr')
354
                                + [b"<<<<<<< OTHER\nd\n=======\nz\n>>>>>>> THIS\n"]
355
                                )
1711.2.25 by John Arbash Meinel
Update the merge3 tests, so that they test more realistic data on 'minimal_conflicts'
356
        self.assertEqualDiff(optimal_text, merged_text)
1185.24.1 by Aaron Bentley
Got reprocessing working
357
358
    def test_reprocess_and_base(self):
359
        """Reprocessing and showing base breaks correctly"""
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
360
        base_text = (b"a\n" * 20).splitlines(True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
361
        this_text = (b"a\n" * 10 + b"b\n" * 10).splitlines(True)
362
        other_text = (b"a\n" * 10 + b"c\n" + b"b\n" *
363
                      8 + b"c\n").splitlines(True)
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
364
        m3 = merge3.Merge3(base_text, other_text, this_text)
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
365
        m_lines = m3.merge_lines(b'OTHER', b'THIS', reprocess=True,
366
                                 base_marker=b'|||||||')
367
        self.assertRaises(merge3.CantReprocessAndShowBase, list, m_lines)
1558.15.6 by Aaron Bentley
Added more tests
368
369
    def test_binary(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
370
        self.assertRaises(BinaryFile, merge3.Merge3, [b'\x00'], [b'a'], [b'b'])
1551.10.38 by Aaron Bentley
merge3 auto-detects line endings for conflict markers
371
372
    def test_dos_text(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
373
        base_text = b'a\r\n'
374
        this_text = b'b\r\n'
375
        other_text = b'c\r\n'
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
376
        m3 = merge3.Merge3(base_text.splitlines(True),
377
                           other_text.splitlines(True),
378
                           this_text.splitlines(True))
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
379
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
380
        self.assertEqual(b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
381
                         b'>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
1551.10.38 by Aaron Bentley
merge3 auto-detects line endings for conflict markers
382
383
    def test_mac_text(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
384
        base_text = b'a\r'
385
        this_text = b'b\r'
386
        other_text = b'c\r'
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
387
        m3 = merge3.Merge3(base_text.splitlines(True),
388
                           other_text.splitlines(True),
389
                           this_text.splitlines(True))
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
390
        m_lines = m3.merge_lines(b'OTHER', b'THIS')
391
        self.assertEqual(b'<<<<<<< OTHER\rc\r=======\rb\r'
7143.15.2 by Jelmer Vernooij
Run autopep8.
392
                         b'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
393
394
    def test_merge3_cherrypick(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
395
        base_text = b"a\nb\n"
396
        this_text = b"a\n"
397
        other_text = b"a\nb\nc\n"
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
398
        # When cherrypicking, lines in base are not part of the conflict
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
399
        m3 = merge3.Merge3(base_text.splitlines(True),
400
                           this_text.splitlines(True),
401
                           other_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
402
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
403
        self.assertEqualDiff(b'a\n<<<<<<<\n=======\nc\n>>>>>>>\n',
404
                             b''.join(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
405
406
        # This is not symmetric
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
407
        m3 = merge3.Merge3(base_text.splitlines(True),
408
                           other_text.splitlines(True),
409
                           this_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
410
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
411
        self.assertEqualDiff(b'a\n<<<<<<<\nb\nc\n=======\n>>>>>>>\n',
412
                             b''.join(m_lines))
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
413
414
    def test_merge3_cherrypick_w_mixed(self):
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
415
        base_text = b'a\nb\nc\nd\ne\n'
416
        this_text = b'a\nb\nq\n'
417
        other_text = b'a\nb\nc\nd\nf\ne\ng\n'
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
418
        # When cherrypicking, lines in base are not part of the conflict
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
419
        m3 = merge3.Merge3(base_text.splitlines(True),
420
                           this_text.splitlines(True),
421
                           other_text.splitlines(True), is_cherrypick=True)
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
422
        m_lines = m3.merge_lines()
7029.4.1 by Jelmer Vernooij
Fix a bunch of merge tests.
423
        self.assertEqualDiff(b'a\n'
424
                             b'b\n'
425
                             b'<<<<<<<\n'
426
                             b'q\n'
427
                             b'=======\n'
428
                             b'f\n'
429
                             b'>>>>>>>\n'
430
                             b'<<<<<<<\n'
431
                             b'=======\n'
432
                             b'g\n'
433
                             b'>>>>>>>\n',
434
                             b''.join(m_lines))
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
435
436
    def test_allow_objects(self):
437
        """Objects other than strs may be used with Merge3 when
438
        allow_objects=True.
7143.15.2 by Jelmer Vernooij
Run autopep8.
439
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
440
        merge_groups and merge_regions work with non-str input.  Methods that
441
        return lines like merge_lines fail.
442
        """
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
443
        base = [(x, x) for x in 'abcde']
444
        a = [(x, x) for x in 'abcdef']
445
        b = [(x, x) for x in 'Zabcde']
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
446
        m3 = merge3.Merge3(base, a, b, allow_objects=True)
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
447
        self.assertEqual(
448
            [('b', 0, 1),
449
             ('unchanged', 0, 5),
450
             ('a', 5, 6)],
451
            list(m3.merge_regions()))
452
        self.assertEqual(
453
            [('b', [('Z', 'Z')]),
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
454
             ('unchanged', [(x, x) for x in 'abcde']),
5158.5.3 by Andrew Bennetts
Add a test for the allow_objects param of Merge3.
455
             ('a', [('f', 'f')])],
456
            list(m3.merge_groups()))