@@ -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+
759785def 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