tests/test-bdiff.py
author Augie Fackler <augie@google.com>
Thu, 15 Dec 2016 10:56:26 -0500
changeset 30593 4286015285ec
parent 30592 0d8cada9998d
child 30594 ea648e8f8a34
permissions -rw-r--r--
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28734
4e51f9d1683e py3: use print_function in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28733
diff changeset
     1
from __future__ import absolute_import, print_function
30592
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
     2
import collections
8656
284fda4cd093 removed unused imports
Martin Geisler <mg@lazybytes.net>
parents: 8449
diff changeset
     3
import struct
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
     4
import unittest
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
     5
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
     6
import silenttestrunner
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
     7
28733
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
     8
from mercurial import (
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
     9
    bdiff,
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
    10
    mpatch,
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
    11
)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    12
30592
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    13
class diffreplace(
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    14
    collections.namedtuple('diffreplace', 'start end from_ to')):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    15
    def __repr__(self):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    16
        return 'diffreplace(%r, %r, %r, %r)' % self
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    17
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    18
class BdiffTests(unittest.TestCase):
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    19
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    20
    def assert_bdiff_applies(self, a, b):
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    21
        d = bdiff.bdiff(a, b)
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    22
        c = a
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    23
        if d:
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    24
            c = mpatch.patches(a, [d])
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    25
        self.assertEqual(
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    26
            c, b, ("bad diff+patch result from\n  %r to\n  "
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    27
                   "%r: \nbdiff: %r\npatched: %r" % (a, b, d, c[:200])))
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    28
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    29
    def assert_bdiff(self, a, b):
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    30
        self.assert_bdiff_applies(a, b)
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    31
        self.assert_bdiff_applies(b, a)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    32
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    33
    def test_bdiff_basic(self):
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    34
        cases = [
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    35
            ("a\nc\n\n\n\n", "a\nb\n\n\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    36
            ("a\nb\nc\n", "a\nc\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    37
            ("", ""),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    38
            ("a\nb\nc", "a\nb\nc"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    39
            ("a\nb\nc\nd\n", "a\nd\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    40
            ("a\nb\nc\nd\n", "a\nc\ne\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    41
            ("a\nb\nc\n", "a\nc\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    42
            ("a\n", "c\na\nb\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    43
            ("a\n", ""),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    44
            ("a\n", "b\nc\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    45
            ("a\n", "c\na\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    46
            ("", "adjfkjdjksdhfksj"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    47
            ("", "ab"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    48
            ("", "abc"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    49
            ("a", "a"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    50
            ("ab", "ab"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    51
            ("abc", "abc"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    52
            ("a\n", "a\n"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    53
            ("a\nb", "a\nb"),
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    54
        ]
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    55
        for a, b in cases:
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    56
            self.assert_bdiff(a, b)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    57
30592
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    58
    def showdiff(self, a, b):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    59
        bin = bdiff.bdiff(a, b)
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    60
        pos = 0
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    61
        q = 0
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    62
        actions = []
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    63
        while pos < len(bin):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    64
            p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    65
            pos += 12
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    66
            if p1:
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    67
                actions.append(a[q:p1])
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    68
            actions.append(diffreplace(p1, p2, a[p1:p2], bin[pos:pos + l]))
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    69
            pos += l
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    70
            q = p2
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    71
        if q < len(a):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    72
            actions.append(a[q:])
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    73
        return actions
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    74
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    75
    def test_issue1295(self):
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    76
        cases = [
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    77
            ("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n",
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    78
             ['x\n\nx\n\n', diffreplace(6, 6, '', 'y\n\n'), 'x\n\nx\n\nz\n']),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    79
            ("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n",
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    80
             ['x\n\nx\n\n',
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    81
              diffreplace(6, 6, '', 'y\n\n'),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    82
              'x\n\n',
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    83
              diffreplace(9, 9, '', 'y\n\n'),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    84
              'x\n\nz\n']),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    85
            # we should pick up abbbc. rather than bc.de as the longest match
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    86
            ("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    87
             "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n",
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    88
             ['a\nb\nb\n',
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    89
              diffreplace(6, 6, '', 'a\nb\nb\nb\nc\n.\n'),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    90
              'b\nc\n.\nd\ne\n',
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    91
              diffreplace(16, 18, '.\n', ''),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    92
              'f\n']),
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    93
        ]
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    94
        for old, new, want in cases:
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    95
            self.assertEqual(self.showdiff(old, new), want)
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    96
30593
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
    97
    def test_fixws(self):
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
    98
        cases = [
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
    99
            (" \ta\r b\t\n", "ab\n", 1),
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   100
            (" \ta\r b\t\n", " a b\n", 0),
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   101
            ("", "", 1),
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   102
            ("", "", 0),
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   103
        ]
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   104
        for a, b, allws in cases:
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   105
            c = bdiff.fixws(a, allws)
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   106
            self.assertEqual(
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   107
                c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws))
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   108
7104
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   109
def showdiff(a, b):
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   110
    print('showdiff(\n  %r,\n  %r):' % (a, b))
7104
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   111
    bin = bdiff.bdiff(a, b)
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   112
    pos = 0
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   113
    q = 0
7104
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   114
    while pos < len(bin):
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   115
        p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   116
        pos += 12
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   117
        if p1:
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   118
            print('', repr(a[q:p1]))
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   119
        print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l]))
7104
9514cbb6e4f6 bdiff: normalize the diff (issue1295)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 814
diff changeset
   120
        pos += l
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   121
        q = p2
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   122
    if q < len(a):
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   123
        print('', repr(a[q:]))
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   124
30431
8c0c75aa3ff4 bdiff: give slight preference to longest matches in the middle of the B side
Mads Kiilerich <madski@unity3d.com>
parents: 30429
diff changeset
   125
print("Nice diff for a trivial change:")
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   126
showdiff(
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   127
    ''.join('<%s\n-\n' % i for i in range(5)),
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   128
    ''.join('>%s\n-\n' % i for i in range(5)))
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   129
30432
3633403888ae bdiff: give slight preference to appending lines
Mads Kiilerich <madski@unity3d.com>
parents: 30431
diff changeset
   130
print("Diff 1 to 3 lines - preference for appending:")
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   131
showdiff('a\n', 'a\n' * 3)
30432
3633403888ae bdiff: give slight preference to appending lines
Mads Kiilerich <madski@unity3d.com>
parents: 30431
diff changeset
   132
print("Diff 1 to 5 lines - preference for appending:")
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   133
showdiff('a\n', 'a\n' * 5)
30433
96f2f50d923f bdiff: give slight preference to removing trailing lines
Mads Kiilerich <madski@unity3d.com>
parents: 30432
diff changeset
   134
print("Diff 3 to 1 lines - preference for removing trailing lines:")
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   135
showdiff('a\n' * 3, 'a\n')
30433
96f2f50d923f bdiff: give slight preference to removing trailing lines
Mads Kiilerich <madski@unity3d.com>
parents: 30432
diff changeset
   136
print("Diff 5 to 1 lines - preference for removing trailing lines:")
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   137
showdiff('a\n' * 5, 'a\n')
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   138
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   139
if __name__ == '__main__':
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   140
    silenttestrunner.main(__name__)