tests/test-bdiff.py
changeset 30427 ede7bc45bf0a
parent 29013 9a8363d23419
child 30428 3743e5dbb824
equal deleted inserted replaced
30426:605e3b126d46 30427:ede7bc45bf0a
     9     d = bdiff.bdiff(a, b)
     9     d = bdiff.bdiff(a, b)
    10     c = a
    10     c = a
    11     if d:
    11     if d:
    12         c = mpatch.patches(a, [d])
    12         c = mpatch.patches(a, [d])
    13     if c != b:
    13     if c != b:
    14         print("***", repr(a), repr(b))
    14         print("bad diff+patch result from\n  %r to\n  %r:" % (a, b))
    15         print("bad:")
    15         print("bdiff: %r" % d)
    16         print(repr(c)[:200])
    16         print("patched: %r" % c[:200])
    17         print(repr(d))
       
    18 
    17 
    19 def test(a, b):
    18 def test(a, b):
    20     print("***", repr(a), repr(b))
    19     print("test", repr(a), repr(b))
    21     test1(a, b)
    20     test1(a, b)
    22     test1(b, a)
    21     test1(b, a)
    23 
    22 
    24 test("a\nc\n\n\n\n", "a\nb\n\n\n")
    23 test("a\nc\n\n\n\n", "a\nb\n\n\n")
    25 test("a\nb\nc\n", "a\nc\n")
    24 test("a\nb\nc\n", "a\nc\n")
    41 test("a\n", "a\n")
    40 test("a\n", "a\n")
    42 test("a\nb", "a\nb")
    41 test("a\nb", "a\nb")
    43 
    42 
    44 #issue1295
    43 #issue1295
    45 def showdiff(a, b):
    44 def showdiff(a, b):
       
    45     print('showdiff(\n  %r,\n  %r):' % (a, b))
    46     bin = bdiff.bdiff(a, b)
    46     bin = bdiff.bdiff(a, b)
    47     pos = 0
    47     pos = 0
       
    48     q = 0
    48     while pos < len(bin):
    49     while pos < len(bin):
    49         p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
    50         p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
    50         pos += 12
    51         pos += 12
    51         print(p1, p2, repr(bin[pos:pos + l]))
    52         if p1:
       
    53             print('', repr(a[q:p1]))
       
    54         print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l]))
    52         pos += l
    55         pos += l
       
    56         q = p2
       
    57     if q < len(a):
       
    58         print('', repr(a[q:]))
       
    59 
    53 showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n")
    60 showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n")
    54 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")
    61 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")
    55 # we should pick up abbbc. rather than bc.de as the longest match
    62 # we should pick up abbbc. rather than bc.de as the longest match
    56 showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
    63 showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
    57          "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n")
    64          "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n")