]> granicus.if.org Git - python/commitdiff
Merged revisions 76464 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Mon, 23 Nov 2009 19:02:52 +0000 (19:02 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Mon, 23 Nov 2009 19:02:52 +0000 (19:02 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76464 | senthil.kumaran | 2009-11-24 00:11:31 +0530 (Tue, 24 Nov 2009) | 4 lines

  Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
  characters.
........

Lib/difflib.py
Lib/test/test_difflib.py
Misc/NEWS

index 052a627e2141e4f376dcd880a43340e4a7bfb65f..264860e2a38c7c90934de5a7af314ac216bc515d 100644 (file)
@@ -1060,20 +1060,21 @@ class Differ:
         Example:
 
         >>> d = Differ()
-        >>> results = d._qformat('\tabcDefghiJkl\n', '\t\tabcdefGhijkl\n',
-        ...                      '  ^ ^  ^      ', '+  ^ ^  ^      ')
+        >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
+        ...                      '  ^ ^  ^      ', '  ^ ^  ^      ')
         >>> for line in results: print(repr(line))
         ...
         '- \tabcDefghiJkl\n'
         '? \t ^ ^  ^\n'
-        '+ \t\tabcdefGhijkl\n'
-        '? \t  ^ ^  ^\n'
+        '+ \tabcdefGhijkl\n'
+        '? \t ^ ^  ^\n'
         """
 
         # Can hurt, but will probably help most of the time.
         common = min(_count_leading(aline, "\t"),
                      _count_leading(bline, "\t"))
         common = min(common, _count_leading(atags[:common], " "))
+        common = min(common, _count_leading(btags[:common], " "))
         atags = atags[common:].rstrip()
         btags = btags[common:].rstrip()
 
index c314b53766720384163a831aaccc389c61a640ea..852aae9b31e77a966cbf1f864a29f5d3957fad06 100644 (file)
@@ -20,6 +20,14 @@ class TestSFbugs(unittest.TestCase):
         diff_gen = difflib.unified_diff([], [])
         self.assertRaises(StopIteration, next, diff_gen)
 
+    def test_added_tab_hint(self):
+        # Check fix for bug #1488943
+        diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"]))
+        self.assertEqual("- \tI am a buggy", diff[0])
+        self.assertEqual("?            --\n", diff[1])
+        self.assertEqual("+ \t\tI am a bug", diff[2])
+        self.assertEqual("? +\n", diff[3])
+
 patch914575_from1 = """
    1. Beautiful is beTTer than ugly.
    2. Explicit is better than implicit.
index 678e0215dfd1b9dd3b023508402bae17ae16705b..6256c693a574108b04b4796f9b7cc0c02ba15d6b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -140,6 +140,8 @@ C-API
 Library
 -------
 
+- Issue #1488943: difflib.Differ() doesn't always add hints for tab characters
+
 - Issue #6123: tarfile now opens empty archives correctly and consistently
   raises ReadError on empty files.