[Python-checkins] python/dist/src/Lib/test test_textwrap.py,1.8,1.9

gward@users.sourceforge.net gward@users.sourceforge.net
Thu, 22 Aug 2002 12:47:29 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv13611

Modified Files:
	test_textwrap.py 
Log Message:
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.)


Index: test_textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_textwrap.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_textwrap.py	22 Aug 2002 19:06:45 -0000	1.8
--- test_textwrap.py	22 Aug 2002 19:47:27 -0000	1.9
***************
*** 31,36 ****
      def check(self, result, expect):
          self.assertEquals(result, expect, 
!             'Expected:\n%s\nbut got:\n%s' % (
!                 self.show(result), self.show(expect)))
  
      def check_wrap (self, text, width, expect):
--- 31,36 ----
      def check(self, result, expect):
          self.assertEquals(result, expect, 
!             'expected:\n%s\nbut got:\n%s' % (
!                 self.show(expect), self.show(result)))
  
      def check_wrap (self, text, width, expect):
***************
*** 112,115 ****
--- 112,166 ----
                           "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):