##// END OF EJS Templates
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler -
r30594:ea648e8f default
parent child Browse files
Show More
@@ -106,35 +106,36 b' class BdiffTests(unittest.TestCase):'
106 self.assertEqual(
106 self.assertEqual(
107 c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws))
107 c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws))
108
108
109 def showdiff(a, b):
109 def test_nice_diff_for_trivial_change(self):
110 print('showdiff(\n %r,\n %r):' % (a, b))
110 self.assertEqual(self.showdiff(
111 bin = bdiff.bdiff(a, b)
111 ''.join('<%s\n-\n' % i for i in range(5)),
112 pos = 0
112 ''.join('>%s\n-\n' % i for i in range(5))),
113 q = 0
113 [diffreplace(0, 3, '<0\n', '>0\n'),
114 while pos < len(bin):
114 '-\n',
115 p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
115 diffreplace(5, 8, '<1\n', '>1\n'),
116 pos += 12
116 '-\n',
117 if p1:
117 diffreplace(10, 13, '<2\n', '>2\n'),
118 print('', repr(a[q:p1]))
118 '-\n',
119 print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l]))
119 diffreplace(15, 18, '<3\n', '>3\n'),
120 pos += l
120 '-\n',
121 q = p2
121 diffreplace(20, 23, '<4\n', '>4\n'),
122 if q < len(a):
122 '-\n'])
123 print('', repr(a[q:]))
124
123
125 print("Nice diff for a trivial change:")
124 def test_prefer_appending(self):
126 showdiff(
125 # 1 line to 3 lines
127 ''.join('<%s\n-\n' % i for i in range(5)),
126 self.assertEqual(self.showdiff('a\n', 'a\n' * 3),
128 ''.join('>%s\n-\n' % i for i in range(5)))
127 ['a\n', diffreplace(2, 2, '', 'a\na\n')])
128 # 1 line to 5 lines
129 self.assertEqual(self.showdiff('a\n', 'a\n' * 5),
130 ['a\n', diffreplace(2, 2, '', 'a\na\na\na\n')])
129
131
130 print("Diff 1 to 3 lines - preference for appending:")
132 def test_prefer_removing_trailing(self):
131 showdiff('a\n', 'a\n' * 3)
133 # 3 lines to 1 line
132 print("Diff 1 to 5 lines - preference for appending:")
134 self.assertEqual(self.showdiff('a\n' * 3, 'a\n'),
133 showdiff('a\n', 'a\n' * 5)
135 ['a\n', diffreplace(2, 6, 'a\na\n', '')])
134 print("Diff 3 to 1 lines - preference for removing trailing lines:")
136 # 5 lines to 1 line
135 showdiff('a\n' * 3, 'a\n')
137 self.assertEqual(self.showdiff('a\n' * 5, 'a\n'),
136 print("Diff 5 to 1 lines - preference for removing trailing lines:")
138 ['a\n', diffreplace(2, 10, 'a\na\na\na\n', '')])
137 showdiff('a\n' * 5, 'a\n')
138
139
139 if __name__ == '__main__':
140 if __name__ == '__main__':
140 silenttestrunner.main(__name__)
141 silenttestrunner.main(__name__)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now