@@ -47,7 +47,7 @@ def check_split(self, text, expect):
4747class WrapTestCase (BaseTestCase ):
4848
4949 def setUp (self ):
50- self .wrapper = TextWrapper (width = 45 , fix_sentence_endings = True )
50+ self .wrapper = TextWrapper (width = 45 )
5151
5252 def test_simple (self ):
5353 # Simple case: just words, spaces, and a bit of punctuation
@@ -84,13 +84,51 @@ def test_whitespace(self):
8484 "wrapped. Some lines are tabbed too. What a" ,
8585 "mess!" ]
8686
87- result = self .wrapper .wrap (text )
87+ wrapper = TextWrapper (45 , fix_sentence_endings = True )
88+ result = wrapper .wrap (text )
8889 self .check (result , expect )
8990
90- result = self . wrapper .fill (text )
91+ result = wrapper .fill (text )
9192 self .check (result , '\n ' .join (expect ))
9293
93-
94+ def test_fix_sentence_endings (self ):
95+ wrapper = TextWrapper (60 , fix_sentence_endings = True )
96+
97+ # SF #847346: ensure that fix_sentence_endings=True does the
98+ # right thing even on input short enough that it doesn't need to
99+ # be wrapped.
100+ text = "A short line. Note the single space."
101+ expect = ["A short line. Note the single space." ]
102+ self .check (wrapper .wrap (text ), expect )
103+
104+ # Test some of the hairy end cases that _fix_sentence_endings()
105+ # is supposed to handle (the easy stuff is tested in
106+ # test_whitespace() above).
107+ text = "Well, Doctor? What do you think?"
108+ expect = ["Well, Doctor? What do you think?" ]
109+ self .check (wrapper .wrap (text ), expect )
110+
111+ text = "Well, Doctor?\n What do you think?"
112+ self .check (wrapper .wrap (text ), expect )
113+
114+ text = 'I say, chaps! Anyone for "tennis?"\n Hmmph!'
115+ expect = ['I say, chaps! Anyone for "tennis?" Hmmph!' ]
116+ self .check (wrapper .wrap (text ), expect )
117+
118+ wrapper .width = 20
119+ expect = ['I say, chaps!' , 'Anyone for "tennis?"' , 'Hmmph!' ]
120+ self .check (wrapper .wrap (text ), expect )
121+
122+ text = 'And she said, "Go to hell!"\n Can you believe that?'
123+ expect = ['And she said, "Go to' ,
124+ 'hell!" Can you' ,
125+ 'believe that?' ]
126+ self .check (wrapper .wrap (text ), expect )
127+
128+ wrapper .width = 60
129+ expect = ['And she said, "Go to hell!" Can you believe that?' ]
130+ self .check (wrapper .wrap (text ), expect )
131+
94132 def test_wrap_short (self ):
95133 # Wrapping to make short lines longer
96134
0 commit comments