mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
This commit is contained in:
parent
133f8468d3
commit
d751e0686d
@ -1,4 +1,5 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
import collections
|
||||
import struct
|
||||
import unittest
|
||||
|
||||
@ -9,6 +10,11 @@ from mercurial import (
|
||||
mpatch,
|
||||
)
|
||||
|
||||
class diffreplace(
|
||||
collections.namedtuple('diffreplace', 'start end from_ to')):
|
||||
def __repr__(self):
|
||||
return 'diffreplace(%r, %r, %r, %r)' % self
|
||||
|
||||
class BdiffTests(unittest.TestCase):
|
||||
|
||||
def assert_bdiff_applies(self, a, b):
|
||||
@ -49,7 +55,45 @@ class BdiffTests(unittest.TestCase):
|
||||
for a, b in cases:
|
||||
self.assert_bdiff(a, b)
|
||||
|
||||
#issue1295
|
||||
def showdiff(self, a, b):
|
||||
bin = bdiff.bdiff(a, b)
|
||||
pos = 0
|
||||
q = 0
|
||||
actions = []
|
||||
while pos < len(bin):
|
||||
p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
|
||||
pos += 12
|
||||
if p1:
|
||||
actions.append(a[q:p1])
|
||||
actions.append(diffreplace(p1, p2, a[p1:p2], bin[pos:pos + l]))
|
||||
pos += l
|
||||
q = p2
|
||||
if q < len(a):
|
||||
actions.append(a[q:])
|
||||
return actions
|
||||
|
||||
def test_issue1295(self):
|
||||
cases = [
|
||||
("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n",
|
||||
['x\n\nx\n\n', diffreplace(6, 6, '', 'y\n\n'), 'x\n\nx\n\nz\n']),
|
||||
("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n",
|
||||
['x\n\nx\n\n',
|
||||
diffreplace(6, 6, '', 'y\n\n'),
|
||||
'x\n\n',
|
||||
diffreplace(9, 9, '', 'y\n\n'),
|
||||
'x\n\nz\n']),
|
||||
# we should pick up abbbc. rather than bc.de as the longest match
|
||||
("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
|
||||
"a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n",
|
||||
['a\nb\nb\n',
|
||||
diffreplace(6, 6, '', 'a\nb\nb\nb\nc\n.\n'),
|
||||
'b\nc\n.\nd\ne\n',
|
||||
diffreplace(16, 18, '.\n', ''),
|
||||
'f\n']),
|
||||
]
|
||||
for old, new, want in cases:
|
||||
self.assertEqual(self.showdiff(old, new), want)
|
||||
|
||||
def showdiff(a, b):
|
||||
print('showdiff(\n %r,\n %r):' % (a, b))
|
||||
bin = bdiff.bdiff(a, b)
|
||||
@ -66,14 +110,6 @@ def showdiff(a, b):
|
||||
if q < len(a):
|
||||
print('', repr(a[q:]))
|
||||
|
||||
showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n")
|
||||
showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n")
|
||||
# we should pick up abbbc. rather than bc.de as the longest match
|
||||
showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
|
||||
"a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n")
|
||||
|
||||
print("done")
|
||||
|
||||
def testfixws(a, b, allws):
|
||||
c = bdiff.fixws(a, allws)
|
||||
if c != b:
|
||||
|
@ -1,26 +1,3 @@
|
||||
showdiff(
|
||||
'x\n\nx\n\nx\n\nx\n\nz\n',
|
||||
'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'):
|
||||
'x\n\nx\n\n'
|
||||
6 6 '' -> 'y\n\n'
|
||||
'x\n\nx\n\nz\n'
|
||||
showdiff(
|
||||
'x\n\nx\n\nx\n\nx\n\nz\n',
|
||||
'x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n'):
|
||||
'x\n\nx\n\n'
|
||||
6 6 '' -> 'y\n\n'
|
||||
'x\n\n'
|
||||
9 9 '' -> 'y\n\n'
|
||||
'x\n\nz\n'
|
||||
showdiff(
|
||||
'a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n',
|
||||
'a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n'):
|
||||
'a\nb\nb\n'
|
||||
6 6 '' -> 'a\nb\nb\nb\nc\n.\n'
|
||||
'b\nc\n.\nd\ne\n'
|
||||
16 18 '.\n' -> ''
|
||||
'f\n'
|
||||
done
|
||||
done
|
||||
Nice diff for a trivial change:
|
||||
showdiff(
|
||||
|
Loading…
Reference in New Issue
Block a user