diff options
author | Raymond Hettinger <python@rcn.com> | 2011-04-11 19:42:59 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-04-11 19:42:59 (GMT) |
commit | 2498c9f06e4adfa121e169127f2a729e8ef3250b (patch) | |
tree | eb14640218c9f3e04e75023d586b5f09bfa49b74 /Lib/test | |
parent | a3359eec7d96237eff157e513ccfd5c5370088bc (diff) | |
parent | 49353d0e8f1faf526e7bc90d7422b3e050ad74bb (diff) | |
download | cpython-2498c9f06e4adfa121e169127f2a729e8ef3250b.zip cpython-2498c9f06e4adfa121e169127f2a729e8ef3250b.tar.gz cpython-2498c9f06e4adfa121e169127f2a729e8ef3250b.tar.bz2 |
Issue #11747: Fix range formatting in context and unified diffs.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_difflib.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py index a263ee6..b08be53 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -236,6 +236,22 @@ class TestOutputFormat(unittest.TestCase): cd = difflib.context_diff(*args, lineterm='') self.assertEqual(list(cd)[0:2], ["*** Original", "--- Current"]) + def test_range_format(self): + # Per the diff spec at http://www.unix.org/single_unix_specification/ + spec = '''\ + Each <range> field shall be of the form: + %1d", <beginning line number> if the range contains exactly one line, + and: + "%1d,%1d", <beginning line number>, <number of lines> otherwise. + If a range is empty, its beginning line number shall be the number of + the line just before the range, or 0 if the empty range starts the file. + ''' + fmt = difflib._format_range + self.assertEqual(fmt(3,3), '3,0') + self.assertEqual(fmt(3,4), '4') + self.assertEqual(fmt(3,5), '4,2') + self.assertEqual(fmt(3,6), '4,3') + self.assertEqual(fmt(0,0), '0,0') def test_main(): difflib.HtmlDiff._default_prefix = 0 |