]> granicus.if.org Git - python/commitdiff
Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
authorSenthil Kumaran <orsenthil@gmail.com>
Mon, 23 Nov 2009 18:41:31 +0000 (18:41 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Mon, 23 Nov 2009 18:41:31 +0000 (18:41 +0000)
characters.

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

index 679bd2a01a1981f43cce91a9a1385fe3f70183e8..b43dc970e254fa855737d4ea2c3ff0a77ebab10c 100644 (file)
@@ -1061,20 +1061,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 011ef17b033ccfa0cbeac8216ff23c63769250ca..93f5c742e95d3be590d95f7e8e19756f5f9c3a23 100644 (file)
@@ -20,6 +20,14 @@ class TestSFbugs(unittest.TestCase):
         diff_gen = difflib.unified_diff([], [])
         self.assertRaises(StopIteration, diff_gen.next)
 
+    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 d6616402f7d0acca8f24209090907f525cb873bb..356e3a1fae99ae810ab5d0a029f534bc676b8bd6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -476,6 +476,8 @@ Core and Builtins
 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.