Skip to content

Commit acd1d53

Browse files
committed
Add test for case when lexer has no command match on first line
1 parent 91f0ddc commit acd1d53

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/test_pt_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ def test_lex_document_no_command(self, mock_cmd_app):
174174

175175
assert tokens == [('', ' ')]
176176

177+
def test_lex_document_no_match(self, mock_cmd_app):
178+
"""Test lexing when command pattern fails to match."""
179+
# Force the pattern to not match anything
180+
mock_cmd_app.statement_parser._command_pattern = re.compile(r'something_impossible')
181+
lexer = pt_utils.Cmd2Lexer(cast(Any, mock_cmd_app))
182+
183+
line = "test command"
184+
document = Document(line)
185+
get_line = lexer.lex_document(document)
186+
tokens = get_line(0)
187+
188+
assert tokens == [('', line)]
189+
177190
def test_lex_document_arguments(self, mock_cmd_app):
178191
"""Test lexing a command with flags and values."""
179192
mock_cmd_app.all_commands = ["help"]

0 commit comments

Comments
 (0)