|
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | import litecli.packages.special |
| 7 | +from litecli.packages.special.main import parse_special_command, Verbosity |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def test_once_command(): |
@@ -57,3 +58,32 @@ def test_pipe_once_command(): |
57 | 58 | litecli.packages.special.unset_pipe_once_if_written() |
58 | 59 | f.seek(0) |
59 | 60 | assert f.read() == b"hello world\n" |
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.parametrize( |
| 64 | + "sql,expected", |
| 65 | + [ |
| 66 | + (r"\d table_name", ("\\d", Verbosity.REGULAR, "table_name")), |
| 67 | + (r"\d+ table_name", ("\\d", Verbosity.VERBOSE, "table_name")), |
| 68 | + (r"\?", ("\\?", Verbosity.REGULAR, "")), |
| 69 | + (r"\llm Question", ("\\llm", Verbosity.REGULAR, "Question")), |
| 70 | + (r"\llm-", ("\\llm", Verbosity.SUCCINCT, "")), |
| 71 | + (r"\llm+", ("\\llm", Verbosity.VERBOSE, "")), |
| 72 | + ], |
| 73 | +) |
| 74 | +def test_parse_special_command(sql, expected): |
| 75 | + """ |
| 76 | + Ensure parse_special_command correctly splits the command and mode. |
| 77 | + """ |
| 78 | + result = parse_special_command(sql) |
| 79 | + assert result == expected |
| 80 | + |
| 81 | + |
| 82 | +def test_parse_special_command_error(): |
| 83 | + sql = r"\llm* Question" |
| 84 | + with pytest.raises(ValueError): |
| 85 | + parse_special_command(sql) |
| 86 | + |
| 87 | + sql = r"\llm+- Question" |
| 88 | + with pytest.raises(ValueError): |
| 89 | + parse_special_command(sql) |
0 commit comments