From a8ad949196481aac2ae648e566a7566dbac9aa59 Mon Sep 17 00:00:00 2001 From: kotfu Date: Sun, 15 Jul 2018 16:32:41 -0600 Subject: Add tests for StatementParser() created with no arguments. --- tests/test_parsing.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/test_parsing.py') diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 0865b6f6..7a091720 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -26,6 +26,32 @@ def parser(): ) return parser +@pytest.fixture +def default_parser(): + parser = StatementParser() + return parser + +def test_parse_empty_string_default(default_parser): + statement = default_parser.parse('') + assert not statement.command + assert not statement.args + assert statement == '' + assert statement.raw == '' + +@pytest.mark.parametrize('line,tokens', [ + ('command', ['command']), + ('command /* with some comment */ arg', ['command', 'arg']), + ('command arg1 arg2 # comment at the end', ['command', 'arg1', 'arg2']), + ('termbare ; > /tmp/output', ['termbare', ';', '>', '/tmp/output']), + ('termbare; > /tmp/output', ['termbare', ';', '>', '/tmp/output']), + ('termbare & > /tmp/output', ['termbare', '&', '>', '/tmp/output']), + ('termbare& > /tmp/output', ['termbare&', '>', '/tmp/output']), + ('help|less', ['help', '|', 'less']), +]) +def test_tokenize_default(default_parser, line, tokens): + tokens_to_test = default_parser.tokenize(line) + assert tokens_to_test == tokens + def test_parse_empty_string(parser): statement = parser.parse('') assert not statement.command -- cgit v1.2.1