Coverage for tests/test_cli.py: 100.00%
26 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-03 19:58 +0200
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-03 19:58 +0200
1"""Tests for the `cli` module."""
3from __future__ import annotations
5import pytest
7from shellman import cli
8from shellman.cli import main as cli_main
9from shellman.templates import filters
10from tests.conftest import get_fake_script
13def test_main() -> None:
14 """Basic CLI test."""
15 assert cli_main([]) == 1
16 assert cli_main(["-c", "hello=world"]) == 0
17 assert cli_main([get_fake_script("simple.sh")]) == 0
20def test_show_help(capsys: pytest.CaptureFixture) -> None:
21 """Show help.
23 Parameters:
24 capsys: Pytest fixture to capture output.
25 """
26 with pytest.raises(SystemExit):
27 cli.main(["-h"])
28 captured = capsys.readouterr()
29 assert "shellman" in captured.out
32def test_do_groffautoemphasis() -> None:
33 """Test Groff auto-emphasis on uppercase words."""
34 string = "I'm SO emphaSIzed!"
35 assert filters.do_groffautoemphasis(string) == "I'm \\fISO\\fR emphaSIzed!"
38def test_do_groffautostrong() -> None:
39 """Test Groff auto-strong on words prefixed with `-` or `--`."""
40 string = "I'm -so --strong!"
41 assert filters.do_groffautostrong(string) == "I'm \\fB-so\\fR \\fB--strong\\fR!"
44def test_do_smartwrap() -> None:
45 """Test smart-wrapping algorithm."""
46 text = (
47 "Some text.\n\n"
48 "A very long line: Lorem ipsum dolor sit amet, "
49 "consectetur adipiscing elit, sed do eiusmod tempor incididunt "
50 "ut labore et dolore magna aliqua."
51 )
52 code_blocks = (
53 "Code block:\n hello\nEnd.\n\n "
54 "another code block\n with very long lines: "
55 "Lorem ipsum dolor sit amet, consectetur "
56 "adipiscing elit, sed do eiusmod tempor incididunt "
57 "ut labore et dolore magna aliqua."
58 )
60 assert (
61 filters.do_smartwrap(text, width=40) == " Some text.\n\n"
62 " A very long line: Lorem ipsum dolor\n"
63 " sit amet, consectetur adipiscing\n"
64 " elit, sed do eiusmod tempor\n"
65 " incididunt ut labore et dolore magna\n"
66 " aliqua."
67 )
68 assert (
69 filters.do_smartwrap(code_blocks, width=40) == " Code block:\n"
70 " hello\n"
71 " End.\n\n"
72 " another code block\n"
73 " with very long lines: Lorem ipsum dolor sit amet, "
74 "consectetur adipiscing elit, sed do eiusmod tempor incididunt "
75 "ut labore et dolore magna aliqua."
76 )