Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Jan 22, 2022
1 parent fff337f commit 2947aa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gapic/utils/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def wrap(text: str, width: int, *, offset: int = None, indent: int = 0) -> str:
# Break off the first line of the string to address non-zero offsets.
first = text.split('\n')[0] + '\n'
if len(first) > width - offset:
# Ensure `break_on_hyphens` is set to `False` when using
# `textwrap.wrap` to avoid breaking hyperlinks with hyphens.
initial = textwrap.wrap(first,
break_long_words=False,
width=width - offset,
Expand Down Expand Up @@ -108,6 +110,8 @@ def wrap(text: str, width: int, *, offset: int = None, indent: int = 0) -> str:
# Wrap the remainder of the string at the desired width.
return '{first}{text}'.format(
first=first,
# Ensure `break_on_hyphens` is set to `False` when using
# `textwrap.fill` to avoid breaking hyperlinks with hyphens.
text='\n'.join([textwrap.fill(
break_long_words=False,
initial_indent=' ' * indent,
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/utils/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ def test_wrap_indent_short():

def test_wrap_short_line_preserved():
assert lines.wrap('foo\nbar\nbaz', width=80) == 'foo\nbar\nbaz'

def test_wrap_does_not_break_hyphenated_word():
assert lines.wrap('do-not-break', width=5) == 'do-not-break'

0 comments on commit 2947aa6

Please sign in to comment.