Commit 3906bef5 authored by Guido van Rossum's avatar Guido van Rossum

Fix an endcase bug: initial_indent was ignored when the text was short

enough to fit in one line.
parent 33aca606
...@@ -33,11 +33,11 @@ class BaseTestCase(unittest.TestCase): ...@@ -33,11 +33,11 @@ class BaseTestCase(unittest.TestCase):
'expected:\n%s\nbut got:\n%s' % ( 'expected:\n%s\nbut got:\n%s' % (
self.show(expect), self.show(result))) self.show(expect), self.show(result)))
def check_wrap (self, text, width, expect): def check_wrap(self, text, width, expect, **kwargs):
result = wrap(text, width) result = wrap(text, width, **kwargs)
self.check(result, expect) self.check(result, expect)
def check_split (self, wrapper, text, expect): def check_split(self, wrapper, text, expect):
result = wrapper._split(text) result = wrapper._split(text)
self.assertEquals(result, expect, self.assertEquals(result, expect,
"\nexpected %r\n" "\nexpected %r\n"
...@@ -101,6 +101,16 @@ What a mess! ...@@ -101,6 +101,16 @@ What a mess!
self.check_wrap(text, 40, ["This is a short paragraph."]) self.check_wrap(text, 40, ["This is a short paragraph."])
def test_wrap_short_1line(self):
# Test endcases
text = "This is a short line."
self.check_wrap(text, 30, ["This is a short line."])
self.check_wrap(text, 30, ["(1) This is a short line."],
initial_indent="(1) ")
def test_hyphenated(self): def test_hyphenated(self):
# Test breaking hyphenated words # Test breaking hyphenated words
......
...@@ -237,8 +237,9 @@ class TextWrapper: ...@@ -237,8 +237,9 @@ class TextWrapper:
converted to space. converted to space.
""" """
text = self._munge_whitespace(text) text = self._munge_whitespace(text)
if len(text) <= self.width: indent = self.initial_indent
return [text] if len(text) + len(indent) <= self.width:
return [indent + text]
chunks = self._split(text) chunks = self._split(text)
if self.fix_sentence_endings: if self.fix_sentence_endings:
self._fix_sentence_endings(chunks) self._fix_sentence_endings(chunks)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment