113
113
lines = udiff_lines(['boo\n'], ['boo'])
114
114
self.check_patch(lines)
115
self.assertEquals(lines[5], '\\ No newline at end of file\n')
115
self.assertEqual(lines[5], '\\ No newline at end of file\n')
116
116
## "expected no-nl, got %r" % lines[5]
118
118
def check_patch(self, lines):
119
self.assert_(len(lines) > 1)
119
self.assertTrue(len(lines) > 1)
120
120
## "Not enough lines for a file header for patch:\n%s" % "".join(lines)
121
self.assert_(lines[0].startswith ('---'))
121
self.assertTrue(lines[0].startswith ('---'))
122
122
## 'No orig line for patch:\n%s' % "".join(lines)
123
self.assert_(lines[1].startswith ('+++'))
123
self.assertTrue(lines[1].startswith ('+++'))
124
124
## 'No mod line for patch:\n%s' % "".join(lines)
125
self.assert_(len(lines) > 2)
125
self.assertTrue(len(lines) > 2)
126
126
## "No hunks for patch:\n%s" % "".join(lines)
127
self.assert_(lines[2].startswith('@@'))
127
self.assertTrue(lines[2].startswith('@@'))
128
128
## "No hunk header for patch:\n%s" % "".join(lines)
129
self.assert_('@@' in lines[2][2:])
129
self.assertTrue('@@' in lines[2][2:])
130
130
## "Unterminated hunk header for patch:\n%s" % "".join(lines)
132
132
def test_binary_lines(self):
864
864
b = ''.join([unichr(i) for i in range(4300, 4800, 2)])
865
865
sm = self._PatienceSequenceMatcher(None, a, b)
866
866
mb = sm.get_matching_blocks()
867
self.assertEquals(35, len(mb))
867
self.assertEqual(35, len(mb))
869
869
def test_unique_lcs(self):
870
870
unique_lcs = self._unique_lcs
871
self.assertEquals(unique_lcs('', ''), [])
872
self.assertEquals(unique_lcs('', 'a'), [])
873
self.assertEquals(unique_lcs('a', ''), [])
874
self.assertEquals(unique_lcs('a', 'a'), [(0,0)])
875
self.assertEquals(unique_lcs('a', 'b'), [])
876
self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
877
self.assertEquals(unique_lcs('abcde', 'cdeab'), [(2,0), (3,1), (4,2)])
878
self.assertEquals(unique_lcs('cdeab', 'abcde'), [(0,2), (1,3), (2,4)])
879
self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1),
871
self.assertEqual(unique_lcs('', ''), [])
872
self.assertEqual(unique_lcs('', 'a'), [])
873
self.assertEqual(unique_lcs('a', ''), [])
874
self.assertEqual(unique_lcs('a', 'a'), [(0,0)])
875
self.assertEqual(unique_lcs('a', 'b'), [])
876
self.assertEqual(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
877
self.assertEqual(unique_lcs('abcde', 'cdeab'), [(2,0), (3,1), (4,2)])
878
self.assertEqual(unique_lcs('cdeab', 'abcde'), [(0,2), (1,3), (2,4)])
879
self.assertEqual(unique_lcs('abXde', 'abYde'), [(0,0), (1,1),
881
self.assertEquals(unique_lcs('acbac', 'abc'), [(2,1)])
881
self.assertEqual(unique_lcs('acbac', 'abc'), [(2,1)])
883
883
def test_recurse_matches(self):
884
884
def test_one(a, b, matches):
885
885
test_matches = []
886
886
self._recurse_matches(
887
887
a, b, 0, 0, len(a), len(b), test_matches, 10)
888
self.assertEquals(test_matches, matches)
888
self.assertEqual(test_matches, matches)
890
890
test_one(['a', '', 'b', '', 'c'], ['a', 'a', 'b', 'c', 'c'],
891
891
[(0, 0), (2, 2), (4, 4)])
1500
1499
None, None, None)
1501
1500
for _, scenario in EncodingAdapter.encoding_scenarios:
1502
1501
encoding = scenario['encoding']
1503
dirname = scenario['info']['directory']
1502
dirname = scenario['info']['directory']
1504
1503
filename = scenario['info']['filename']
1506
1505
self.overrideAttr(diffobj, '_fenc', lambda: encoding)
1507
1506
relpath = dirname + u'/' + filename
1508
1507
fullpath = diffobj._safe_filename('safe', relpath)
1511
fullpath.encode(encoding).decode(encoding)
1513
self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1508
self.assertEqual(fullpath,
1509
fullpath.encode(encoding).decode(encoding))
1510
self.assertTrue(fullpath.startswith(diffobj._root + '/safe'))
1515
1512
def test_unencodable_filename(self):
1516
1513
diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
1517
1514
None, None, None)
1518
1515
for _, scenario in EncodingAdapter.encoding_scenarios:
1519
1516
encoding = scenario['encoding']
1520
dirname = scenario['info']['directory']
1517
dirname = scenario['info']['directory']
1521
1518
filename = scenario['info']['filename']
1523
1520
if encoding == 'iso-8859-1':