~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testdiff.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-06 06:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: john@arbash-meinel.com-20051106064625-bb31d4e6fb25930a
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        self.assert_('@@' in lines[2][2:])
48
48
            ## "Unterminated hunk header for patch:\n%s" % "".join(lines)
49
49
 
 
50
class TestCDVDiffLib(TestCase):
 
51
 
 
52
    def test_matching_blocks(self):
 
53
        from bzrlib.cdvdifflib import SequenceMatcher
 
54
 
 
55
        def chk_blocks(a, b, matching):
 
56
            # difflib always adds a signature of the total
 
57
            # length, with no matching entries at the end
 
58
            matching = matching + [(len(a), len(b), 0)]
 
59
            s = SequenceMatcher(None, a, b)
 
60
            self.assertEquals(s.get_matching_blocks(), matching)
 
61
 
 
62
        chk_blocks('', '', [])
 
63
        chk_blocks([], [], [])
 
64
        chk_blocks('abcd', 'abcd', [(0, 0, 4)])
 
65
        chk_blocks('abcd', 'abce', [(0, 0, 3)])
 
66
        chk_blocks('eabc', 'abce', [(1, 0, 3)])
 
67
        chk_blocks('eabce', 'abce', [(1, 0, 4)])
 
68
        chk_blocks('abcde', 'abXde', [(0, 0, 2), (3, 3, 2)])
 
69
        chk_blocks('abcde', 'abXde', [(0, 0, 2), (3, 3, 2)])
 
70
 
 
71
 
 
72