| Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 1 | # | 
|  | 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 |  | 
|  | 9 | import unittest | 
|  | 10 | from test import test_support | 
|  | 11 |  | 
| Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 12 | # | 
| Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 13 | # One test case for outstanding bugs at the moment: | 
| Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 14 | # | 
| Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 15 |  | 
| Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 16 | class 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 Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | def test_main(): | 
| Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 50 | test_support.run_unittest(TestDifflibLongestMatch) | 
| Tim Peters | 1a57296 | 2006-03-01 06:19:04 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | if __name__ == "__main__": | 
|  | 53 | test_main() |