summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-20 17:55:18 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-20 17:55:18 -0400
commit7c563413767ecc50ad459517004f2ff5d694977a (patch)
treec7abae3d9fcd6829cf9771221b6fba5850dc9608
parent8ba1e4e723982918ccd179dd1ae008daea20c619 (diff)
downloadcmd2-git-7c563413767ecc50ad459517004f2ff5d694977a.tar.gz
Fixed some unit tests
-rw-r--r--cmd2.py15
-rw-r--r--tests/test_completion.py6
2 files changed, 12 insertions, 9 deletions
diff --git a/cmd2.py b/cmd2.py
index 07600add..c81946b3 100644
--- a/cmd2.py
+++ b/cmd2.py
@@ -1578,12 +1578,12 @@ class Cmd(cmd.Cmd):
# If the line starts with a shortcut that has no break between the search text,
# then the text variable will start with the shortcut if its not a completer delimiter
- text_shortcut = ''
+ shortcut_to_restore = ''
if begidx == 0:
for (shortcut, expansion) in self.shortcuts:
if text.startswith(shortcut):
# Save the shortcut to adjust the line later
- text_shortcut = shortcut
+ shortcut_to_restore = shortcut
# Adjust text and where it begins
text = text[len(shortcut):]
@@ -1726,14 +1726,14 @@ class Cmd(cmd.Cmd):
readline.rl.mode.endidx += 1
# If a shortcut started text, then we need to make sure it doesn't get erased on the command line
- if text_shortcut:
+ if shortcut_to_restore:
# If matches_to_display has not been set, then display the actual matches
# that do not show the shortcut character at the beginning of each match.
if matches_to_display is None:
set_matches_to_display(self.completion_matches)
# Given readline the restored shortcut character since that's what its expecting
- self.completion_matches = [text_shortcut + match for match in self.completion_matches]
+ self.completion_matches = [shortcut_to_restore + match for match in self.completion_matches]
# Handle single result
if len(self.completion_matches) == 1:
@@ -2637,8 +2637,11 @@ Usage: Usage: unalias [-a] name [name ...]
# Get the index of the token being completed
index = len(tokens) - 1
+ if index < shell_cmd_index:
+ return []
+
# Complete the shell command
- if index == shell_cmd_index:
+ elif index == shell_cmd_index:
completion_token = tokens[index]
@@ -2665,7 +2668,7 @@ Usage: Usage: unalias [-a] name [name ...]
return path_complete(text, line, begidx, endidx, dir_exe_only=True)
# We are past the shell command, so do path completion
- elif index > shell_cmd_index:
+ else:
return path_complete(text, line, begidx, endidx)
def cmd_with_subs_completer(self, text, line, begidx, endidx, base):
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 40a328da..323eb0d0 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -381,7 +381,7 @@ def test_path_completion_doesnt_match_wildcards(request):
def test_path_completion_invalid_syntax():
# Test a missing separator between a ~ and path
- text = ''
+ text = '~Desktop'
line = 'shell fake ~Desktop'
endidx = len(line)
begidx = endidx - len(text)
@@ -390,14 +390,14 @@ def test_path_completion_invalid_syntax():
def test_path_completion_just_tilde():
# Run path with just a tilde
- text = ''
+ text = '~'
line = 'shell fake ~'
endidx = len(line)
begidx = endidx - len(text)
completions_tilde = path_complete(text, line, begidx, endidx)
# Path complete should return a slash
- assert completions_tilde == [os.path.sep]
+ assert completions_tilde == ['~' + os.path.sep]
def test_path_completion_user_expansion():
# Run path with a tilde and a slash