Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions humanfriendly/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
concatenate,
dedent,
generate_slug,
join_lines,
pluralize,
random_string,
trim_empty_lines,
Expand All @@ -130,6 +131,21 @@ class HumanFriendlyTestCase(TestCase):

"""Container for the `humanfriendly` test suite."""

def test_join_lines_consecutive_short_lines(self):
"""Join every hard wrap even when an intervening line has one character."""
assert join_lines('a\nb\nc\nd') == 'a b c d'
assert join_lines('one\na\nword') == 'one a word'

def test_join_lines_windows_line_endings(self):
"""Join CRLF hard wraps without leaving carriage returns behind."""
assert join_lines('first\r\nsecond\r\nthird') == 'first second third'
assert join_lines('a\r\nb\r\nc') == 'a b c'

def test_join_lines_preserves_paragraphs_and_indentation(self):
"""Leave paragraph boundaries and indented lines intact."""
for text in ('a\n\nb', 'a\r\n\r\nb', 'a\n b', 'a \nb', '\na\n', ''):
assert join_lines(text) == text

def test_case_insensitive_dict(self):
"""Test the CaseInsensitiveDict class."""
# Test support for the dict(iterable) signature.
Expand Down
2 changes: 1 addition & 1 deletion humanfriendly/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def join_lines(text):
break :func:`join_lines()` (in that case you can use :func:`dedent()`
before calling :func:`join_lines()`).
"""
return re.sub(r'(\S)\n(\S)', r'\1 \2', text)
return re.sub(r'(?<=\S)\r?\n(?=\S)', ' ', text)


def pluralize(count, singular, plural=None):
Expand Down