Skip to content

Commit 7349624

Browse files
committed
Fixed a couple bugs and added unit tests
1 parent 009cb87 commit 7349624

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cmd2/parsing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ def expanded_command_line(self) -> str:
193193
rtn = self.command_and_args
194194
if self.multiline_command:
195195
rtn += constants.MULTILINE_TERMINATOR
196+
elif self.terminator:
197+
rtn += self.terminator
196198

197199
if self.suffix:
198200
rtn += ' ' + self.suffix
199201

200202
if self.pipe_to:
201-
rtn += ' | ' + self.pipe_to
203+
rtn += ' | ' + ' '.join(self.pipe_to)
202204

203205
if self.output:
204206
rtn += ' ' + self.output

tests/test_parsing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import pytest
1111

1212
import cmd2
13-
from cmd2.parsing import StatementParser
1413
from cmd2 import utils
14+
from cmd2.constants import MULTILINE_TERMINATOR
15+
from cmd2.parsing import StatementParser
16+
1517

1618
@pytest.fixture
1719
def parser():
@@ -147,6 +149,7 @@ def test_parse_word_plus_terminator(parser, line, terminator):
147149
assert statement.argv == ['termbare']
148150
assert not statement.arg_list
149151
assert statement.terminator == terminator
152+
assert statement.expanded_command_line == statement.command + statement.terminator
150153

151154
@pytest.mark.parametrize('line,terminator', [
152155
('termbare; suffx', ';'),
@@ -163,6 +166,7 @@ def test_parse_suffix_after_terminator(parser, line, terminator):
163166
assert not statement.arg_list
164167
assert statement.terminator == terminator
165168
assert statement.suffix == 'suffx'
169+
assert statement.expanded_command_line == statement.command + statement.terminator + ' ' + statement.suffix
166170

167171
def test_parse_command_with_args(parser):
168172
line = 'command with args'
@@ -258,6 +262,7 @@ def test_parse_simple_pipe(parser, line):
258262
assert statement.argv == ['simple']
259263
assert not statement.arg_list
260264
assert statement.pipe_to == ['piped']
265+
assert statement.expanded_command_line == statement.command + ' | ' + ' '.join(statement.pipe_to)
261266

262267
def test_parse_double_pipe_is_not_a_pipe(parser):
263268
line = 'double-pipe || is not a pipe'
@@ -294,6 +299,7 @@ def test_parse_redirect(parser,line, output):
294299
assert statement.args == statement
295300
assert statement.output == output
296301
assert statement.output_to == 'out.txt'
302+
assert statement.expanded_command_line == statement.command + ' ' + statement.output + ' ' + statement.output_to
297303

298304
def test_parse_redirect_with_args(parser):
299305
line = 'output into > afile.txt'
@@ -539,6 +545,7 @@ def test_parse_alias_on_multiline_command(parser):
539545
assert statement.args == statement
540546
assert statement == 'has > inside an unfinished command'
541547
assert statement.terminator == ''
548+
assert statement.expanded_command_line == statement.multiline_command + ' ' + statement + MULTILINE_TERMINATOR
542549

543550
@pytest.mark.parametrize('line,output', [
544551
('helpalias > out.txt', '>'),

0 commit comments

Comments
 (0)