|
21 | 21 | ColorMode, |
22 | 22 | Colors, |
23 | 23 | UnknownStyleColor, |
| 24 | + build_description, |
24 | 25 | get_color_mode, |
25 | 26 | style, |
26 | 27 | ) |
@@ -312,3 +313,50 @@ def test_heading_applies_bright_cyan_bold(monkeypatch: pytest.MonkeyPatch) -> No |
312 | 313 | assert ANSI_BOLD in result |
313 | 314 | assert "Local workspaces:" in result |
314 | 315 | assert ANSI_RESET in result |
| 316 | + |
| 317 | + |
| 318 | +# build_description tests |
| 319 | + |
| 320 | + |
| 321 | +def test_build_description_named_heading_includes_examples_suffix() -> None: |
| 322 | + """Named heading should include 'examples:' suffix for formatter detection.""" |
| 323 | + result = build_description("My tool.", [("sync", ["mytool sync repo"])]) |
| 324 | + |
| 325 | + # Should be "sync examples:" not just "sync:" |
| 326 | + assert "sync examples:" in result |
| 327 | + # Verify the old format is not present (unless contained in "sync examples:") |
| 328 | + lines = result.split("\n") |
| 329 | + heading_line = next(line for line in lines if "sync" in line.lower()) |
| 330 | + assert heading_line == "sync examples:" |
| 331 | + |
| 332 | + |
| 333 | +def test_build_description_no_heading_uses_examples() -> None: |
| 334 | + """Heading=None should produce bare 'examples:' title.""" |
| 335 | + result = build_description("My tool.", [(None, ["mytool run"])]) |
| 336 | + |
| 337 | + assert "examples:" in result |
| 338 | + assert result.count("examples:") == 1 # Just one |
| 339 | + |
| 340 | + |
| 341 | +def test_build_description_multiple_named_headings() -> None: |
| 342 | + """Multiple named headings should all have 'examples:' suffix.""" |
| 343 | + result = build_description( |
| 344 | + "My tool.", |
| 345 | + [ |
| 346 | + ("load", ["mytool load"]), |
| 347 | + ("freeze", ["mytool freeze"]), |
| 348 | + ("ls", ["mytool ls"]), |
| 349 | + ], |
| 350 | + ) |
| 351 | + |
| 352 | + assert "load examples:" in result |
| 353 | + assert "freeze examples:" in result |
| 354 | + assert "ls examples:" in result |
| 355 | + |
| 356 | + |
| 357 | +def test_build_description_empty_intro() -> None: |
| 358 | + """Empty intro should not add blank sections.""" |
| 359 | + result = build_description("", [(None, ["cmd"])]) |
| 360 | + |
| 361 | + assert result.startswith("examples:") |
| 362 | + assert "cmd" in result |
0 commit comments