summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-04-24 22:40:29 -0600
committerkotfu <kotfu@kotfu.net>2018-04-24 22:40:29 -0600
commit9170550b2a32a763dafc1d7b14b43d97c542a0db (patch)
tree9576f7285c1631db8da8b2b06f47cab56a03a11f /tests
parent8297d4d1c0a4f56c6c952059fb7fc2b43b1050ed (diff)
downloadcmd2-git-9170550b2a32a763dafc1d7b14b43d97c542a0db.tar.gz
Add test for alias expansion on incomplete multiline commands
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parsing.py36
-rw-r--r--tests/test_shlexparsing.py7
2 files changed, 25 insertions, 18 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 6fa7d629..1913938e 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -19,7 +19,7 @@ def parser():
redirection_chars=['|', '<', '>'],
terminators = [';'],
multilineCommands = ['multiline'],
- aliases = {'helpalias': 'help', '42': 'theanswer'},
+ aliases = {'helpalias': 'help', '42': 'theanswer', 'anothermultiline': 'multiline'},
shortcuts = [('?', 'help'), ('!', 'shell')]
)
return parser
@@ -193,9 +193,9 @@ def test_parse_unfinished_multiliine_command(parser):
line = 'multiline has > inside an unfinished command'
statement = parser.parse(line)
assert statement.multilineCommand == 'multiline'
- assert not statement.args
+ assert statement.command == 'multiline'
+ assert statement.args == 'has > inside an unfinished command'
assert not statement.terminator
-
def test_parse_multiline_command_ignores_redirectors_within_it(parser):
line = 'multiline has > inside;'
@@ -204,14 +204,14 @@ def test_parse_multiline_command_ignores_redirectors_within_it(parser):
assert statement.args == 'has > inside'
assert statement.terminator == ';'
-# def test_parse_multiline_with_incomplete_comment(parser):
-# """A terminator within a comment will be ignored and won't terminate a multiline command.
-# Un-closed comments effectively comment out everything after the start."""
-# line = 'multiline command /* with comment in progress;'
-# statement = parser.parse(line)
-# assert statement.multilineCommand == 'multiline'
-# assert statement.args == 'command'
-# assert not statement.terminator
+def test_parse_multiline_with_incomplete_comment(parser):
+ """A terminator within a comment will be ignored and won't terminate a multiline command.
+ Un-closed comments effectively comment out everything after the start."""
+ line = 'multiline command /* with comment in progress;'
+ statement = parser.parse(line)
+ assert statement.multilineCommand == 'multiline'
+ assert statement.args == 'command'
+ assert not statement.terminator
def test_parse_multiline_with_complete_comment(parser):
line = 'multiline command /* with comment complete */ is done;'
@@ -280,10 +280,10 @@ def test_alias_and_shortcut_expansion(parser, line, command, args):
assert statement.command == command
assert statement.args == args
-def test_empty_statement_raises_exception():
- app = cmd2.Cmd()
- with pytest.raises(cmd2.cmd2.EmptyStatement):
- app._complete_statement('')
-
- with pytest.raises(cmd2.cmd2.EmptyStatement):
- app._complete_statement(' ')
+def test_alias_on_multiline_command(parser):
+ line = 'anothermultiline has > inside an unfinished command'
+ statement = parser.parse(line)
+ assert statement.multilineCommand == 'multiline'
+ assert statement.command == 'multiline'
+ assert statement.args == 'has > inside an unfinished command'
+ assert not statement.terminator
diff --git a/tests/test_shlexparsing.py b/tests/test_shlexparsing.py
index 2ff79641..c9f2e85a 100644
--- a/tests/test_shlexparsing.py
+++ b/tests/test_shlexparsing.py
@@ -11,6 +11,13 @@ Todo List
- rename test_shlexparsing.py to test_parsing.py
- look at parsed() - expands aliases and shortcuts, see if it can be refactored
+Questions:
+- say I have a command called 'fred' which is a multiline command. If I make an alias
+ for fred called 'george' is george a multiline command? I think the answer is yes.
+ If you want a multi-line synonym for a command that isn't multiline, do it like
+ example.py does. If the answer is no, then I need to rework StatementParser.parse()
+-
+
Notes:
- valid comment styles: