summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-10-02 15:47:32 (GMT)
committerGuido van Rossum <guido@python.org>2002-10-02 15:47:32 (GMT)
commiteb287a26621001fb5d945b7b6246ccac77378cc7 (patch)
tree7b4a4cc4ac6bb09bda4956f98d0242fe17f2adba
parentfb4d6ecd0757c0863b8a2e45a57a6dfec13fbff6 (diff)
downloadcpython-eb287a26621001fb5d945b7b6246ccac77378cc7.zip
cpython-eb287a26621001fb5d945b7b6246ccac77378cc7.tar.gz
cpython-eb287a26621001fb5d945b7b6246ccac77378cc7.tar.bz2
Fix an endcase bug: initial_indent was ignored when the text was short
enough to fit in one line.
-rw-r--r--Lib/test/test_textwrap.py16
-rw-r--r--Lib/textwrap.py5
2 files changed, 16 insertions, 5 deletions
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index fc5d0cc..2a6d67a 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -33,11 +33,11 @@ class BaseTestCase(unittest.TestCase):
'expected:\n%s\nbut got:\n%s' % (
self.show(expect), self.show(result)))
- def check_wrap (self, text, width, expect):
- result = wrap(text, width)
+ def check_wrap(self, text, width, expect, **kwargs):
+ result = wrap(text, width, **kwargs)
self.check(result, expect)
- def check_split (self, wrapper, text, expect):
+ def check_split(self, wrapper, text, expect):
result = wrapper._split(text)
self.assertEquals(result, expect,
"\nexpected %r\n"
@@ -101,6 +101,16 @@ What a mess!
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):
# Test breaking hyphenated words
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index f5d1915..ff5f7ef 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -237,8 +237,9 @@ class TextWrapper:
converted to space.
"""
text = self._munge_whitespace(text)
- if len(text) <= self.width:
- return [text]
+ indent = self.initial_indent
+ if len(text) + len(indent) <= self.width:
+ return [indent + text]
chunks = self._split(text)
if self.fix_sentence_endings:
self._fix_sentence_endings(chunks)