177 # to match without zz |
177 # to match without zz |
178 self.assertEqual(list(m3.find_sync_regions()), [(0, 0, 2, 2, 0, 0)]) |
178 self.assertEqual(list(m3.find_sync_regions()), [(0, 0, 2, 2, 0, 0)]) |
179 |
179 |
180 self.assertEqual(list(m3.merge_regions()), [(b'a', 0, 2)]) |
180 self.assertEqual(list(m3.merge_regions()), [(b'a', 0, 2)]) |
181 |
181 |
182 self.assertEqual(m3.merge_lines(), ([b'aaa', b'bbb'], False)) |
182 self.assertEqual(simplemerge.merge_lines(m3), ([b'aaa', b'bbb'], False)) |
183 |
183 |
184 def test_no_conflicts(self): |
184 def test_no_conflicts(self): |
185 """No conflicts because only one side changed""" |
185 """No conflicts because only one side changed""" |
186 m3 = Merge3( |
186 m3 = Merge3( |
187 [b'aaa', b'bbb'], [b'aaa', b'111', b'bbb'], [b'aaa', b'bbb'] |
187 [b'aaa', b'bbb'], [b'aaa', b'111', b'bbb'], [b'aaa', b'bbb'] |
202 [b'aaa\n', b'bbb\n'], |
202 [b'aaa\n', b'bbb\n'], |
203 [b'aaa\n', b'bbb\n', b'222\n'], |
203 [b'aaa\n', b'bbb\n', b'222\n'], |
204 [b'aaa\n', b'bbb\n'], |
204 [b'aaa\n', b'bbb\n'], |
205 ) |
205 ) |
206 |
206 |
207 self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
207 self.assertEqual( |
|
208 b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' |
|
209 ) |
208 |
210 |
209 def test_append_b(self): |
211 def test_append_b(self): |
210 m3 = Merge3( |
212 m3 = Merge3( |
211 [b'aaa\n', b'bbb\n'], |
213 [b'aaa\n', b'bbb\n'], |
212 [b'aaa\n', b'bbb\n'], |
214 [b'aaa\n', b'bbb\n'], |
213 [b'aaa\n', b'bbb\n', b'222\n'], |
215 [b'aaa\n', b'bbb\n', b'222\n'], |
214 ) |
216 ) |
215 |
217 |
216 self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
218 self.assertEqual( |
|
219 b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' |
|
220 ) |
217 |
221 |
218 def test_append_agreement(self): |
222 def test_append_agreement(self): |
219 m3 = Merge3( |
223 m3 = Merge3( |
220 [b'aaa\n', b'bbb\n'], |
224 [b'aaa\n', b'bbb\n'], |
221 [b'aaa\n', b'bbb\n', b'222\n'], |
225 [b'aaa\n', b'bbb\n', b'222\n'], |
222 [b'aaa\n', b'bbb\n', b'222\n'], |
226 [b'aaa\n', b'bbb\n', b'222\n'], |
223 ) |
227 ) |
224 |
228 |
225 self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
229 self.assertEqual( |
|
230 b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' |
|
231 ) |
226 |
232 |
227 def test_append_clash(self): |
233 def test_append_clash(self): |
228 m3 = Merge3( |
234 m3 = Merge3( |
229 [b'aaa\n', b'bbb\n'], |
235 [b'aaa\n', b'bbb\n'], |
230 [b'aaa\n', b'bbb\n', b'222\n'], |
236 [b'aaa\n', b'bbb\n', b'222\n'], |
231 [b'aaa\n', b'bbb\n', b'333\n'], |
237 [b'aaa\n', b'bbb\n', b'333\n'], |
232 ) |
238 ) |
233 |
239 |
234 ml, conflicts = m3.merge_lines( |
240 ml, conflicts = simplemerge.merge_lines( |
|
241 m3, |
235 name_a=b'a', |
242 name_a=b'a', |
236 name_b=b'b', |
243 name_b=b'b', |
237 start_marker=b'<<', |
244 start_marker=b'<<', |
238 mid_marker=b'--', |
245 mid_marker=b'--', |
239 end_marker=b'>>', |
246 end_marker=b'>>', |
248 [b'aaa\n', b'bbb\n'], |
255 [b'aaa\n', b'bbb\n'], |
249 [b'aaa\n', b'222\n', b'bbb\n'], |
256 [b'aaa\n', b'222\n', b'bbb\n'], |
250 [b'aaa\n', b'222\n', b'bbb\n'], |
257 [b'aaa\n', b'222\n', b'bbb\n'], |
251 ) |
258 ) |
252 |
259 |
253 ml, conflicts = m3.merge_lines( |
260 ml, conflicts = simplemerge.merge_lines( |
|
261 m3, |
254 name_a=b'a', |
262 name_a=b'a', |
255 name_b=b'b', |
263 name_b=b'b', |
256 start_marker=b'<<', |
264 start_marker=b'<<', |
257 mid_marker=b'--', |
265 mid_marker=b'--', |
258 end_marker=b'>>', |
266 end_marker=b'>>', |
336 ) |
345 ) |
337 |
346 |
338 def test_merge_poem(self): |
347 def test_merge_poem(self): |
339 """Test case from diff3 manual""" |
348 """Test case from diff3 manual""" |
340 m3 = Merge3(TZU, LAO, TAO) |
349 m3 = Merge3(TZU, LAO, TAO) |
341 ml, conflicts = m3.merge_lines(b'LAO', b'TAO') |
350 ml, conflicts = simplemerge.merge_lines(m3, b'LAO', b'TAO') |
342 self.log(b'merge result:') |
351 self.log(b'merge result:') |
343 self.log(b''.join(ml)) |
352 self.log(b''.join(ml)) |
344 self.assertEqual(ml, MERGED_RESULT) |
353 self.assertEqual(ml, MERGED_RESULT) |
345 |
354 |
346 def test_binary(self): |
355 def test_binary(self): |
354 m3 = Merge3( |
363 m3 = Merge3( |
355 base_text.splitlines(True), |
364 base_text.splitlines(True), |
356 other_text.splitlines(True), |
365 other_text.splitlines(True), |
357 this_text.splitlines(True), |
366 this_text.splitlines(True), |
358 ) |
367 ) |
359 m_lines, conflicts = m3.merge_lines(b'OTHER', b'THIS') |
368 m_lines, conflicts = simplemerge.merge_lines(m3, b'OTHER', b'THIS') |
360 self.assertEqual( |
369 self.assertEqual( |
361 b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n' |
370 b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n' |
362 b'>>>>>>> THIS\r\n'.splitlines(True), |
371 b'>>>>>>> THIS\r\n'.splitlines(True), |
363 m_lines, |
372 m_lines, |
364 ) |
373 ) |
370 m3 = Merge3( |
379 m3 = Merge3( |
371 base_text.splitlines(True), |
380 base_text.splitlines(True), |
372 other_text.splitlines(True), |
381 other_text.splitlines(True), |
373 this_text.splitlines(True), |
382 this_text.splitlines(True), |
374 ) |
383 ) |
375 m_lines, conflicts = m3.merge_lines(b'OTHER', b'THIS') |
384 m_lines, conflicts = simplemerge.merge_lines(m3, b'OTHER', b'THIS') |
376 self.assertEqual( |
385 self.assertEqual( |
377 b'<<<<<<< OTHER\rc\r=======\rb\r' |
386 b'<<<<<<< OTHER\rc\r=======\rb\r' |
378 b'>>>>>>> THIS\r'.splitlines(True), |
387 b'>>>>>>> THIS\r'.splitlines(True), |
379 m_lines, |
388 m_lines, |
380 ) |
389 ) |