Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3906bef5
Commit
3906bef5
authored
Oct 02, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an endcase bug: initial_indent was ignored when the text was short
enough to fit in one line.
parent
33aca606
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
Lib/test/test_textwrap.py
Lib/test/test_textwrap.py
+13
-3
Lib/textwrap.py
Lib/textwrap.py
+3
-2
No files found.
Lib/test/test_textwrap.py
View file @
3906bef5
...
@@ -33,11 +33,11 @@ class BaseTestCase(unittest.TestCase):
...
@@ -33,11 +33,11 @@ class BaseTestCase(unittest.TestCase):
'expected:
\
n
%s
\
n
but got:
\
n
%s'
%
(
'expected:
\
n
%s
\
n
but 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
,
"
\
n
expected %r
\
n
"
"
\
n
expected %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
...
...
Lib/textwrap.py
View file @
3906bef5
...
@@ -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)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment