summaryrefslogtreecommitdiff
path: root/tests/test_completion.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_completion.py')
-rw-r--r--tests/test_completion.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 57424032..8b7a2d14 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -353,7 +353,7 @@ def test_default_to_shell_completion(cmd2_app, request):
def test_path_completion_cwd():
# Run path complete with no path and no search text
text = ''
- line = 'shell ls '
+ line = 'shell ls {}'.format(text)
endidx = len(line)
begidx = endidx - len(text)
completions_empty = path_complete(text, line, begidx, endidx)
@@ -369,15 +369,6 @@ def test_path_completion_cwd():
assert completions_empty == completions_cwd
assert completions_cwd
-def test_path_completion_invalid_syntax():
- text = ''
- line = 'shell ls ~'
- endidx = len(line)
- begidx = endidx
-
- # Can't have a ~ without a separating slash
- assert path_complete(text, line, begidx, endidx) == []
-
def test_path_completion_doesnt_match_wildcards(request):
test_dir = os.path.dirname(request.module.__file__)
@@ -391,9 +382,20 @@ def test_path_completion_doesnt_match_wildcards(request):
# Currently path completion doesn't accept wildcards, so will always return empty results
assert path_complete(text, line, begidx, endidx) == []
-def test_path_completion_user_expansion():
+def test_path_completion_just_tilde():
# Run path with just a tilde
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]
+
+def test_path_completion_user_expansion():
+ # Run path with a tilde and a slash
+ text = ''
if sys.platform.startswith('win'):
cmd = 'dir'
else:
@@ -401,19 +403,18 @@ def test_path_completion_user_expansion():
line = 'shell {} ~{}'.format(cmd, os.path.sep)
endidx = len(line)
- begidx = endidx - len(text)
- completions_tilde = path_complete(text, line, begidx, endidx)
+ begidx = endidx
+ completions_tilde_slash = path_complete(text, line, begidx, endidx)
# Run path complete on the user's home directory
user_dir = os.path.expanduser('~') + os.path.sep
-
line = 'shell {} {}'.format(cmd, user_dir)
endidx = len(line)
- begidx = endidx - len(text)
+ begidx = endidx
completions_home = path_complete(text, line, begidx, endidx)
# Verify that the results are the same in both cases
- assert completions_tilde == completions_home
+ assert completions_tilde_slash == completions_home
def test_path_completion_directories_only(request):
test_dir = os.path.dirname(request.module.__file__)