Skip to content

Commit 7e2497d

Browse files
committed
Added unit test for valid case of calling is_valid_command()
1 parent d8c0b0a commit 7e2497d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/test_parsing.py

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

758758

759-
def test_is_valid_command(parser):
759+
def test_is_valid_command_invalid(parser):
760760
# Empty command
761761
valid, errmsg = parser.is_valid_command('')
762762
assert not valid and 'cannot be an empty string' in errmsg
763763

764764
# Starts with shortcut
765-
valid, errmsg = parser.is_valid_command('!cmd')
765+
valid, errmsg = parser.is_valid_command('!ls')
766766
assert not valid and 'cannot start with a shortcut' in errmsg
767767

768768
# Contains whitespace
769-
valid, errmsg = parser.is_valid_command(' ')
769+
valid, errmsg = parser.is_valid_command('shell ls')
770770
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
771771

772772
# Contains a quote
773-
valid, errmsg = parser.is_valid_command('"cmd')
773+
valid, errmsg = parser.is_valid_command('"shell"')
774774
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
775775

776776
# Contains a redirector
777-
valid, errmsg = parser.is_valid_command('>cmd')
777+
valid, errmsg = parser.is_valid_command('>shell')
778778
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
779779

780780
# Contains a terminator
781-
valid, errmsg = parser.is_valid_command(';cmd')
781+
valid, errmsg = parser.is_valid_command(';shell')
782782
assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
783783

784+
def test_is_valid_command_valid(parser):
785+
# Empty command
786+
valid, errmsg = parser.is_valid_command('shell')
787+
assert valid
788+
assert not errmsg
789+
784790

785791
def test_macro_normal_arg_pattern():
786792
# This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side

0 commit comments

Comments
 (0)