diff options
author | Greg Ward <gward@python.net> | 2002-08-22 19:47:27 +0000 |
---|---|---|
committer | Greg Ward <gward@python.net> | 2002-08-22 19:47:27 +0000 |
commit | 9ad15a3dff45359d5d6184764c9edae6f5298b29 (patch) | |
tree | 5d9e7864a3dc29791b27aa1205399156926a48e3 /Lib/test/test_textwrap.py | |
parent | 32c2ae7f4ac0594dc180efc8440f6a62eee164d6 (diff) | |
download | cpython-git-9ad15a3dff45359d5d6184764c9edae6f5298b29.tar.gz |
Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
em-dashes -- like this -- properly. (Also--like this. Although this
usage may be incompatible with fixing bug #596434; we shall see.)
Diffstat (limited to 'Lib/test/test_textwrap.py')
-rw-r--r-- | Lib/test/test_textwrap.py | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py index 227206cd3f..85403322d9 100644 --- a/Lib/test/test_textwrap.py +++ b/Lib/test/test_textwrap.py @@ -30,8 +30,8 @@ class BaseTestCase(unittest.TestCase): def check(self, result, expect): self.assertEquals(result, expect, - 'Expected:\n%s\nbut got:\n%s' % ( - self.show(result), self.show(expect))) + 'expected:\n%s\nbut got:\n%s' % ( + self.show(expect), self.show(result))) def check_wrap (self, text, width, expect): result = wrap(text, width) @@ -111,6 +111,57 @@ What a mess! ["this-is-a-useful-feature-for-reformatting-", "posts-from-tim-peters'ly"]) + def test_em_dash(self): + '''Test text with em-dashes.''' + text = "Em-dashes should be written -- thus." + self.check_wrap(text, 25, + ["Em-dashes should be", + "written -- thus."]) + + # Probe the boundaries of the properly written em-dash, + # ie. " -- ". + self.check_wrap(text, 29, + ["Em-dashes should be written", + "-- thus."]) + expect = ["Em-dashes should be written --", + "thus."] + self.check_wrap(text, 30, expect) + self.check_wrap(text, 35, expect) + self.check_wrap(text, 36, + ["Em-dashes should be written -- thus."]) + + # The improperly written em-dash is handled too, because + # it's adjacent to non-whitespace on both sides. + text = "You can also do--this or even---this." + expect = ["You can also do", + "--this or even", + "---this."] + self.check_wrap(text, 15, expect) + self.check_wrap(text, 16, expect) + expect = ["You can also do--", + "this or even---", + "this."] + self.check_wrap(text, 17, expect) + self.check_wrap(text, 19, expect) + expect = ["You can also do--this or even", + "---this."] + self.check_wrap(text, 29, expect) + self.check_wrap(text, 31, expect) + expect = ["You can also do--this or even---", + "this."] + self.check_wrap(text, 32, expect) + self.check_wrap(text, 35, expect) + + # All of the above behaviour could be deduced by probing the + # _split() method. + text = "Here's an -- em-dash and--here's another---and another!" + result = self.wrapper._split(text) + expect = ["Here's", " ", "an", " ", "--", " ", "em-", "dash", " ", + "and", "--", "here's", " ", "another", "---", + "and", " ", "another!"] + self.assertEquals(result, expect, + "\nexpected %r\n" + "but got %r" % (expect, result)) def test_split(self): '''Ensure that the standard _split() method works as advertised |