Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 2947aa6

Browse files
committed
add test
1 parent fff337f commit 2947aa6

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

gapic/utils/lines.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def wrap(text: str, width: int, *, offset: int = None, indent: int = 0) -> str:
7878
# Break off the first line of the string to address non-zero offsets.
7979
first = text.split('\n')[0] + '\n'
8080
if len(first) > width - offset:
81+
# Ensure `break_on_hyphens` is set to `False` when using
82+
# `textwrap.wrap` to avoid breaking hyperlinks with hyphens.
8183
initial = textwrap.wrap(first,
8284
break_long_words=False,
8385
width=width - offset,
@@ -108,6 +110,8 @@ def wrap(text: str, width: int, *, offset: int = None, indent: int = 0) -> str:
108110
# Wrap the remainder of the string at the desired width.
109111
return '{first}{text}'.format(
110112
first=first,
113+
# Ensure `break_on_hyphens` is set to `False` when using
114+
# `textwrap.fill` to avoid breaking hyperlinks with hyphens.
111115
text='\n'.join([textwrap.fill(
112116
break_long_words=False,
113117
initial_indent=' ' * indent,

tests/unit/utils/test_lines.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ def test_wrap_indent_short():
8787

8888
def test_wrap_short_line_preserved():
8989
assert lines.wrap('foo\nbar\nbaz', width=80) == 'foo\nbar\nbaz'
90+
91+
def test_wrap_does_not_break_hyphenated_word():
92+
assert lines.wrap('do-not-break', width=5) == 'do-not-break'

0 commit comments

Comments
 (0)