Skip to content

Commit 42af9e9

Browse files
committed
Added unit test for is_valid_command
1 parent 418f63a commit 42af9e9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_parsing.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,32 @@ def test_statement_is_immutable():
756756
statement.raw = 'baz'
757757

758758

759+
def test_is_valid_command(parser):
760+
# Empty command
761+
valid, errmsg = parser.is_valid_command('')
762+
assert not valid and 'cannot be an empty string' in errmsg
763+
764+
# Starts with shortcut
765+
valid, errmsg = parser.is_valid_command('!cmd')
766+
assert not valid and 'cannot start with a shortcut' in errmsg
767+
768+
# Contains whitespace
769+
valid, errmsg = parser.is_valid_command(' ')
770+
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
771+
772+
# Contains a quote
773+
valid, errmsg = parser.is_valid_command('"cmd')
774+
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
775+
776+
# Contains a redirector
777+
valid, errmsg = parser.is_valid_command('>cmd')
778+
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
779+
780+
# Contains a terminator
781+
valid, errmsg = parser.is_valid_command(';cmd')
782+
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
783+
784+
759785
def test_macro_normal_arg_pattern():
760786
# This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side
761787
from cmd2.parsing import MacroArg

0 commit comments

Comments
 (0)