Skip to content

Commit 9e98012

Browse files
committed
tests(cli/formatter): Add tests for examples suffix colorization
Add tests to verify formatter correctly colorizes section headings ending with "examples:" even without an initial "examples:" block: - Single "X examples:" heading is colorized - Multiple "X examples:" sections are all colorized
1 parent 03dac31 commit 9e98012

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/cli/test_formatter.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,49 @@ def test_help_theme_from_colors_enabled_returns_colored(
216216
assert "\033[" in theme.prog
217217
assert "\033[" in theme.action
218218
assert theme.reset == ANSI_RESET
219+
220+
221+
def test_fill_text_section_heading_with_examples_suffix(
222+
monkeypatch: pytest.MonkeyPatch,
223+
) -> None:
224+
"""Section headings ending with 'examples:' are colorized without initial block."""
225+
monkeypatch.delenv("NO_COLOR", raising=False)
226+
colors = Colors(ColorMode.ALWAYS)
227+
formatter_cls = create_themed_formatter(colors)
228+
formatter = formatter_cls("tmuxp")
229+
230+
# This is what build_description produces - no initial "examples:" block
231+
text = (
232+
"load examples:\n tmuxp load myproject\n\n"
233+
"freeze examples:\n tmuxp freeze mysession"
234+
)
235+
result = formatter._fill_text(text, 80, "")
236+
237+
# Both headings should be colorized (contain ANSI escape codes)
238+
assert "\033[" in result
239+
# Commands should be colorized
240+
assert "tmuxp" in result
241+
242+
243+
def test_fill_text_multiple_example_sections_all_colorized(
244+
monkeypatch: pytest.MonkeyPatch,
245+
) -> None:
246+
"""Multiple 'X examples:' sections should all be colorized."""
247+
monkeypatch.delenv("NO_COLOR", raising=False)
248+
colors = Colors(ColorMode.ALWAYS)
249+
formatter_cls = create_themed_formatter(colors)
250+
formatter = formatter_cls("tmuxp")
251+
252+
text = """load examples:
253+
tmuxp load myproject
254+
255+
freeze examples:
256+
tmuxp freeze mysession
257+
258+
ls examples:
259+
tmuxp ls"""
260+
result = formatter._fill_text(text, 80, "")
261+
262+
# All sections should have ANSI codes
263+
# Count ANSI escape sequences - should have at least heading + command per section
264+
assert result.count("\033[") >= 6

0 commit comments

Comments
 (0)