Skip to content

Commit f5e009e

Browse files
committed
Fixed indexing bug and unit test
1 parent eb851f4 commit f5e009e

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,15 +1576,15 @@ def path_complete(self, text, line, begidx, endidx, dir_exe_only=False, dir_only
15761576
self.allow_closing_quote = False
15771577

15781578
# Build display_matches and add a slash to directories
1579-
for cur_match in completion_matches:
1579+
for index, cur_match in enumerate(completion_matches):
15801580

15811581
# Display only the basename of this path in the tab-completion suggestions
15821582
self.display_matches.append(os.path.basename(cur_match))
15831583

15841584
# Add a separator after directories if the next character isn't already a separator
15851585
if os.path.isdir(cur_match) and add_trailing_sep_if_dir:
1586-
completion_matches[-1] += os.path.sep
1587-
self.display_matches[-1] += os.path.sep
1586+
completion_matches[index] += os.path.sep
1587+
self.display_matches[index] += os.path.sep
15881588

15891589
# Remove cwd if it was added
15901590
if cwd_added:

tests/test_completion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ def test_shell_command_completion_nomatch(cmd2_app):
222222

223223
def test_shell_command_completion_doesnt_complete_when_just_shell(cmd2_app):
224224
text = ''
225-
line = 'shell'
225+
line = 'shell {}'.format(text)
226226
endidx = len(line)
227-
begidx = 0
227+
begidx = endidx - len(text)
228228
assert cmd2_app.complete_shell(text, line, begidx, endidx) == []
229229

230230
def test_shell_command_completion_does_path_completion_when_after_command(cmd2_app, request):

0 commit comments

Comments
 (0)