summaryrefslogtreecommitdiff
path: root/tests/test_parsing.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-03 10:26:07 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-03 10:26:07 -0400
commit42af9e9733826e84fe884be46bd09220bce2d116 (patch)
treeb48f0660d8c46db7056f12fde37bc84a798bf0f3 /tests/test_parsing.py
parent418f63acbc5e2706cd90cfe20ee9e8b0285f930b (diff)
downloadcmd2-git-42af9e9733826e84fe884be46bd09220bce2d116.tar.gz
Added unit test for is_valid_command
Diffstat (limited to 'tests/test_parsing.py')
-rw-r--r--tests/test_parsing.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 1fa460a5..a637bf8d 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -756,6 +756,32 @@ def test_statement_is_immutable():
statement.raw = 'baz'
+def test_is_valid_command(parser):
+ # Empty command
+ valid, errmsg = parser.is_valid_command('')
+ assert not valid and 'cannot be an empty string' in errmsg
+
+ # Starts with shortcut
+ valid, errmsg = parser.is_valid_command('!cmd')
+ assert not valid and 'cannot start with a shortcut' in errmsg
+
+ # Contains whitespace
+ valid, errmsg = parser.is_valid_command(' ')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a quote
+ valid, errmsg = parser.is_valid_command('"cmd')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a redirector
+ valid, errmsg = parser.is_valid_command('>cmd')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a terminator
+ valid, errmsg = parser.is_valid_command(';cmd')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+
def test_macro_normal_arg_pattern():
# This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side
from cmd2.parsing import MacroArg