Skip to content

Commit 5c1c427

Browse files
committed
Add unit tests to check for multiple terminators
1 parent 18b42fc commit 5c1c427

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tests/test_parsing.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ def test_parse_redirect_inside_terminator(parser):
250250
assert statement.argv == ['has', '>', 'inside']
251251
assert statement.terminator == ';'
252252

253+
@pytest.mark.parametrize('line,terminator',[
254+
('multiline with | inside;', ';'),
255+
('multiline with | inside ;', ';'),
256+
('multiline with | inside;;;', ';'),
257+
('multiline with | inside;; ;;', ';'),
258+
('multiline with | inside&', '&'),
259+
('multiline with | inside &;', '&'),
260+
('multiline with | inside&&;', '&'),
261+
('multiline with | inside &; &;', '&'),
262+
])
263+
def test_parse_multiple_terminators(parser, line, terminator):
264+
statement = parser.parse(line)
265+
assert statement.multiline_command == 'multiline'
266+
assert statement.args == 'has | inside'
267+
assert statement.argv == ['multiline', 'has', '|', 'inside']
268+
assert statement.terminator == terminator
269+
253270
def test_parse_unfinished_multiliine_command(parser):
254271
line = 'multiline has > inside an unfinished command'
255272
statement = parser.parse(line)
@@ -261,7 +278,10 @@ def test_parse_unfinished_multiliine_command(parser):
261278

262279
@pytest.mark.parametrize('line,terminator',[
263280
('multiline has > inside;', ';'),
281+
('multiline has > inside;;;', ';'),
282+
('multiline has > inside;; ;;', ';'),
264283
('multiline has > inside &', '&'),
284+
('multiline has > inside & &', '&'),
265285
])
266286
def test_parse_multiline_command_ignores_redirectors_within_it(parser, line, terminator):
267287
statement = parser.parse(line)
@@ -388,8 +408,15 @@ def test_parse_alias_pipe(parser, line):
388408
assert not statement.args
389409
assert statement.pipe_to == ['less']
390410

391-
def test_parse_alias_terminator_no_whitespace(parser):
392-
line = 'helpalias;'
411+
@pytest.mark.parametrize('line', [
412+
'helpalias;',
413+
'helpalias;;',
414+
'helpalias;; ;',
415+
'helpalias ;',
416+
'helpalias ; ;',
417+
'helpalias ;; ;',
418+
])
419+
def test_parse_alias_terminator_no_whitespace(parser, line):
393420
statement = parser.parse(line)
394421
assert statement.command == 'help'
395422
assert not statement.args
@@ -448,13 +475,20 @@ def test_parse_command_only_quoted_args(parser):
448475
'helpalias>>out.txt',
449476
'help|less',
450477
'helpalias;',
478+
'help ;;',
479+
'help; ;;',
451480
])
452481
def test_parse_command_only_specialchars(parser, line):
453482
statement = parser.parse_command_only(line)
454483
assert statement.command == 'help'
455484

456485
@pytest.mark.parametrize('line', [
457486
';',
487+
';;',
488+
';; ;',
489+
'&',
490+
'& &',
491+
' && &',
458492
'>',
459493
"'",
460494
'"',

0 commit comments

Comments
 (0)