tests/test-bdiff.py
author Augie Fackler <augie@google.com>
Thu, 15 Dec 2016 11:04:09 -0500
changeset 30594 ea648e8f8a34
parent 30593 4286015285ec
child 30595 99bd5479d58b
permissions -rw-r--r--
tests: finish updating test-bdiff to unittest (part 4 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
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   109
    def test_nice_diff_for_trivial_change(self):
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   110
        self.assertEqual(self.showdiff(
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   111
            ''.join('<%s\n-\n' % i for i in range(5)),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   112
            ''.join('>%s\n-\n' % i for i in range(5))),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   113
                         [diffreplace(0, 3, '<0\n', '>0\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   114
                          '-\n',
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   115
                          diffreplace(5, 8, '<1\n', '>1\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   116
                          '-\n',
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   117
                          diffreplace(10, 13, '<2\n', '>2\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   118
                          '-\n',
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   119
                          diffreplace(15, 18, '<3\n', '>3\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   120
                          '-\n',
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   121
                          diffreplace(20, 23, '<4\n', '>4\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   122
                          '-\n'])
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   123
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   124
    def test_prefer_appending(self):
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   125
        # 1 line to 3 lines
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   126
        self.assertEqual(self.showdiff('a\n', 'a\n' * 3),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   127
                         ['a\n', diffreplace(2, 2, '', 'a\na\n')])
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   128
        # 1 line to 5 lines
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   129
        self.assertEqual(self.showdiff('a\n', 'a\n' * 5),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   130
                         ['a\n', diffreplace(2, 2, '', 'a\na\na\na\n')])
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   131
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   132
    def test_prefer_removing_trailing(self):
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   133
        # 3 lines to 1 line
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   134
        self.assertEqual(self.showdiff('a\n' * 3, 'a\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   135
                         ['a\n', diffreplace(2, 6, 'a\na\n', '')])
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   136
        # 5 lines to 1 line
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   137
        self.assertEqual(self.showdiff('a\n' * 5, 'a\n'),
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   138
                         ['a\n', diffreplace(2, 10, 'a\na\na\na\n', '')])
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   139
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   140
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
   141
    silenttestrunner.main(__name__)