blob: 7c6cd9ef6b81899dbae477d68b0525894613a387 [file] [log] [blame]
Tim Peters1a572962006-03-01 06:19:04 +00001#
2# This file is for everybody to add tests for bugs that aren't
3# fixed yet. Please add a test case and appropriate bug description.
4#
5# When you fix one of the bugs, please move the test to the correct
6# test_ module.
7#
8
9import unittest
10from test import test_support
11
Thomas Wouters89f507f2006-12-13 04:49:30 +000012#
Guido van Rossumd8faa362007-04-27 19:54:29 +000013# One test case for outstanding bugs at the moment:
Thomas Wouters89f507f2006-12-13 04:49:30 +000014#
Tim Peters1a572962006-03-01 06:19:04 +000015
Guido van Rossumd8faa362007-04-27 19:54:29 +000016class TestDifflibLongestMatch(unittest.TestCase):
17 # From Patch #1678339:
18 # The find_longest_match method in the difflib's SequenceMatcher has a bug.
19
20 # The bug is in turn caused by a problem with creating a b2j mapping which
21 # should contain a list of indices for each of the list elements in b.
22 # However, when the b2j mapping is being created (this is being done in
23 # __chain_b method in the SequenceMatcher) the mapping becomes broken. The
24 # cause of this is that for the frequently used elements the list of indices
25 # is removed and the element is being enlisted in the populardict mapping.
26
27 # The test case tries to match two strings like:
28 # abbbbbb.... and ...bbbbbbc
29
30 # The number of b is equal and the find_longest_match should have returned
31 # the proper amount. However, in case the number of "b"s is large enough, the
32 # method reports that the length of the longest common substring is 0. It
33 # simply can't find it.
34
35 # A bug was raised some time ago on this matter. It's ID is 1528074.
36
37 def test_find_longest_match(self):
38 import difflib
39 for i in (190, 200, 210):
40 text1 = "a" + "b"*i
41 text2 = "b"*i + "c"
42 m = difflib.SequenceMatcher(None, text1, text2)
43 (aptr, bptr, l) = m.find_longest_match(0, len(text1), 0, len(text2))
44 self.assertEquals(i, l)
45 self.assertEquals(aptr, 1)
46 self.assertEquals(bptr, 0)
47
Tim Peters1a572962006-03-01 06:19:04 +000048
49def test_main():
Guido van Rossumd8faa362007-04-27 19:54:29 +000050 test_support.run_unittest(TestDifflibLongestMatch)
Tim Peters1a572962006-03-01 06:19:04 +000051
52if __name__ == "__main__":
53 test_main()