@@ -22,7 +22,7 @@ def show(self, textin):
2222 result = []
2323 for i in range (len (textin )):
2424 result .append (" %d: %r" % (i , textin [i ]))
25- result = ' \n ' .join (result )
25+ result = " \n " .join (result ) if result else " no lines"
2626 elif isinstance (textin , str ):
2727 result = " %s\n " % repr (textin )
2828 return result
@@ -66,6 +66,15 @@ def test_simple(self):
6666 "I'm glad to hear it!" ])
6767 self .check_wrap (text , 80 , [text ])
6868
69+ def test_empty_string (self ):
70+ # Check that wrapping the empty string returns an empty list.
71+ self .check_wrap ("" , 6 , [])
72+ self .check_wrap ("" , 6 , [], drop_whitespace = False )
73+
74+ def test_empty_string_with_initial_indent (self ):
75+ # Check that the empty string is not indented.
76+ self .check_wrap ("" , 6 , [], initial_indent = "++" )
77+ self .check_wrap ("" , 6 , [], initial_indent = "++" , drop_whitespace = False )
6978
7079 def test_whitespace (self ):
7180 # Whitespace munging and end-of-sentence detection
@@ -331,7 +340,32 @@ def test_funky_parens (self):
331340 ["blah" , " " , "(ding" , " " , "dong)," ,
332341 " " , "wubba" ])
333342
334- def test_initial_whitespace (self ):
343+ def test_drop_whitespace_false (self ):
344+ # Check that drop_whitespace=False preserves whitespace.
345+ # SF patch #1581073
346+ text = " This is a sentence with much whitespace."
347+ self .check_wrap (text , 10 ,
348+ [" This is a" , " " , "sentence " ,
349+ "with " , "much white" , "space." ],
350+ drop_whitespace = False )
351+
352+ def test_drop_whitespace_false_whitespace_only (self ):
353+ # Check that drop_whitespace=False preserves a whitespace-only string.
354+ self .check_wrap (" " , 6 , [" " ], drop_whitespace = False )
355+
356+ def test_drop_whitespace_false_whitespace_only_with_indent (self ):
357+ # Check that a whitespace-only string gets indented (when
358+ # drop_whitespace is False).
359+ self .check_wrap (" " , 6 , [" " ], drop_whitespace = False ,
360+ initial_indent = " " )
361+
362+ def test_drop_whitespace_whitespace_only (self ):
363+ # Check drop_whitespace on a whitespace-only string.
364+ self .check_wrap (" " , 6 , [])
365+
366+ def test_drop_whitespace_leading_whitespace (self ):
367+ # Check that drop_whitespace does not drop leading whitespace (if
368+ # followed by non-whitespace).
335369 # SF bug #622849 reported inconsistent handling of leading
336370 # whitespace; let's test that a bit, shall we?
337371 text = " This is a sentence with leading whitespace."
@@ -340,13 +374,27 @@ def test_initial_whitespace(self):
340374 self .check_wrap (text , 30 ,
341375 [" This is a sentence with" , "leading whitespace." ])
342376
343- def test_no_drop_whitespace (self ):
344- # SF patch #1581073
345- text = " This is a sentence with much whitespace."
346- self . check_wrap ( text , 10 ,
347- [ " This is a" , " " , "sentence " ,
348- "with " , "much white" , "space. " ],
377+ def test_drop_whitespace_whitespace_line (self ):
378+ # Check that drop_whitespace skips the whole line if a non-leading
379+ # line consists only of whitespace.
380+ text = "abcd efgh"
381+ # Include the result for drop_whitespace=False for comparison.
382+ self . check_wrap ( text , 6 , [ "abcd" , " " , "efgh " ],
349383 drop_whitespace = False )
384+ self .check_wrap (text , 6 , ["abcd" , "efgh" ])
385+
386+ def test_drop_whitespace_whitespace_only_with_indent (self ):
387+ # Check that initial_indent is not applied to a whitespace-only
388+ # string. This checks a special case of the fact that dropping
389+ # whitespace occurs before indenting.
390+ self .check_wrap (" " , 6 , [], initial_indent = "++" )
391+
392+ def test_drop_whitespace_whitespace_indent (self ):
393+ # Check that drop_whitespace does not drop whitespace indents.
394+ # This checks a special case of the fact that dropping whitespace
395+ # occurs before indenting.
396+ self .check_wrap ("abcd efgh" , 6 , [" abcd" , " efgh" ],
397+ initial_indent = " " , subsequent_indent = " " )
350398
351399 def test_split (self ):
352400 # Ensure that the standard _split() method works as advertised
0 commit comments