Skip to content
Merged
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
4 changes: 2 additions & 2 deletions did/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def shorted(text: str, width: int = MAX_WIDTH) -> str:
lines = []

for line in text.split("\n"):
if len(line) <= width:
if width == 0 or len(line) <= width:
lines.append(line)
else:
# Remove any word after first overlapping non-word character
Expand Down Expand Up @@ -257,7 +257,7 @@ def item(
if options.format == "wiki" and level == 0:
indent = 1
# Shorten the text if necessary to match the desired maximum width
width = 333
width = 0
if options is not None and options.width:
width = options.width - indent - 2
spaces = " " * indent
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ def test_shorted() -> None:
assert res == "this...\nthis..."


def test_shorted_unlimited() -> None:
long_text = "this text is longer than 6\nthis is also longer"
res = did.utils.shorted(long_text, width=0)
assert res == long_text


def test_item_unlimited_width(capsys: pytest.CaptureFixture[str]) -> None:
options = Namespace(brief=False, format="text", width=0)
long_text = "x" * 500
did.utils.item(long_text, level=0, options=options)
captured = capsys.readouterr()
assert captured.out == f"\n* {long_text}\n"


def test_item_no_options(capsys: pytest.CaptureFixture[str]) -> None:
did.utils.item("this is level 0 text", level=0, options=None)
captured = capsys.readouterr()
Expand Down
Loading