Mercurial > hg-stable
changeset 30599:ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 15 Dec 2016 11:04:09 -0500 |
parents | 4286015285ec |
children | 99bd5479d58b |
files | tests/test-bdiff.py tests/test-bdiff.py.out |
diffstat | 2 files changed, 28 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-bdiff.py Thu Dec 15 10:56:26 2016 -0500 +++ b/tests/test-bdiff.py Thu Dec 15 11:04:09 2016 -0500 @@ -106,35 +106,36 @@ self.assertEqual( c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws)) -def showdiff(a, b): - print('showdiff(\n %r,\n %r):' % (a, b)) - bin = bdiff.bdiff(a, b) - pos = 0 - q = 0 - while pos < len(bin): - p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) - pos += 12 - if p1: - print('', repr(a[q:p1])) - print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l])) - pos += l - q = p2 - if q < len(a): - print('', repr(a[q:])) + def test_nice_diff_for_trivial_change(self): + self.assertEqual(self.showdiff( + ''.join('<%s\n-\n' % i for i in range(5)), + ''.join('>%s\n-\n' % i for i in range(5))), + [diffreplace(0, 3, '<0\n', '>0\n'), + '-\n', + diffreplace(5, 8, '<1\n', '>1\n'), + '-\n', + diffreplace(10, 13, '<2\n', '>2\n'), + '-\n', + diffreplace(15, 18, '<3\n', '>3\n'), + '-\n', + diffreplace(20, 23, '<4\n', '>4\n'), + '-\n']) -print("Nice diff for a trivial change:") -showdiff( - ''.join('<%s\n-\n' % i for i in range(5)), - ''.join('>%s\n-\n' % i for i in range(5))) + def test_prefer_appending(self): + # 1 line to 3 lines + self.assertEqual(self.showdiff('a\n', 'a\n' * 3), + ['a\n', diffreplace(2, 2, '', 'a\na\n')]) + # 1 line to 5 lines + self.assertEqual(self.showdiff('a\n', 'a\n' * 5), + ['a\n', diffreplace(2, 2, '', 'a\na\na\na\n')]) -print("Diff 1 to 3 lines - preference for appending:") -showdiff('a\n', 'a\n' * 3) -print("Diff 1 to 5 lines - preference for appending:") -showdiff('a\n', 'a\n' * 5) -print("Diff 3 to 1 lines - preference for removing trailing lines:") -showdiff('a\n' * 3, 'a\n') -print("Diff 5 to 1 lines - preference for removing trailing lines:") -showdiff('a\n' * 5, 'a\n') + def test_prefer_removing_trailing(self): + # 3 lines to 1 line + self.assertEqual(self.showdiff('a\n' * 3, 'a\n'), + ['a\n', diffreplace(2, 6, 'a\na\n', '')]) + # 5 lines to 1 line + self.assertEqual(self.showdiff('a\n' * 5, 'a\n'), + ['a\n', diffreplace(2, 10, 'a\na\na\na\n', '')]) if __name__ == '__main__': silenttestrunner.main(__name__)
--- a/tests/test-bdiff.py.out Thu Dec 15 10:56:26 2016 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -Nice diff for a trivial change: -showdiff( - '<0\n-\n<1\n-\n<2\n-\n<3\n-\n<4\n-\n', - '>0\n-\n>1\n-\n>2\n-\n>3\n-\n>4\n-\n'): - 0 3 '<0\n' -> '>0\n' - '-\n' - 5 8 '<1\n' -> '>1\n' - '-\n' - 10 13 '<2\n' -> '>2\n' - '-\n' - 15 18 '<3\n' -> '>3\n' - '-\n' - 20 23 '<4\n' -> '>4\n' - '-\n' -Diff 1 to 3 lines - preference for appending: -showdiff( - 'a\n', - 'a\na\na\n'): - 'a\n' - 2 2 '' -> 'a\na\n' -Diff 1 to 5 lines - preference for appending: -showdiff( - 'a\n', - 'a\na\na\na\na\n'): - 'a\n' - 2 2 '' -> 'a\na\na\na\n' -Diff 3 to 1 lines - preference for removing trailing lines: -showdiff( - 'a\na\na\n', - 'a\n'): - 'a\n' - 2 6 'a\na\n' -> '' -Diff 5 to 1 lines - preference for removing trailing lines: -showdiff( - 'a\na\na\na\na\n', - 'a\n'): - 'a\n' - 2 10 'a\na\na\na\n' -> ''