Skip to content

Commit 46bd94a

Browse files
committed
Added more code coverage with unit tests
1 parent c2b1f61 commit 46bd94a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cmd2/cmd2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,10 @@ def complete_help_subcommand(self, text: str, line: str, begidx: int, endidx: in
25732573
if not tokens:
25742574
return []
25752575

2576+
# Must have at least 3 args for 'help command subcommand'
2577+
if len(tokens) < 3:
2578+
return []
2579+
25762580
# Find where the command is by skipping past any flags
25772581
cmd_index = 1
25782582
for cur_token in tokens[cmd_index:]:

tests/test_completion.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,23 @@ def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app):
948948
first_match = complete_tester(text, line, begidx, endidx, scu_app)
949949
assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport']
950950

951+
def test_complete_help_subcommand_with_no_command(scu_app):
952+
# No command because not enough tokens
953+
text = ''
954+
line = 'help '
955+
endidx = len(line)
956+
begidx = endidx - len(text)
957+
958+
assert not scu_app.complete_help_subcommand(text, line, begidx, endidx)
959+
960+
# No command because everything is a flag
961+
text = '-v'
962+
line = 'help -f -v'
963+
endidx = len(line)
964+
begidx = endidx - len(text)
965+
966+
assert not scu_app.complete_help_subcommand(text, line, begidx, endidx)
967+
951968

952969
def test_cmd2_help_subcommand_completion_nomatch_scu(scu_app):
953970
text = 'z'

0 commit comments

Comments
 (0)