diff options
Diffstat (limited to 'tests/test_completion.py')
| -rw-r--r-- | tests/test_completion.py | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py index a51a4e1f..f749f084 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -359,7 +359,7 @@ def test_path_completion_cwd(): completions_empty = path_complete(text, line, begidx, endidx) # Run path complete with path set to the CWD - cwd = os.getcwd() + cwd = os.getcwd() + os.path.sep line = 'shell ls {}'.format(cwd) endidx = len(line) begidx = endidx - len(text) @@ -382,29 +382,48 @@ 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_invalid_syntax(): + # Test a missing separator between a ~ and path + text = '' + line = 'shell fake ~Desktop' + endidx = len(line) + begidx = endidx - len(text) + + assert path_complete(text, line, begidx, endidx) == [] + +def test_path_completion_just_tilde(): # Run path with just a tilde text = '' - if sys.platform.startswith('win'): - line = 'shell dir ~{}'.format(text) - else: - line = 'shell ls ~{}'.format(text) + line = 'shell fake ~' endidx = len(line) begidx = endidx - len(text) completions_tilde = path_complete(text, line, begidx, endidx) - # Run path complete on the user's home directory - user_dir = os.path.expanduser('~') + # 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'): - line = 'shell dir {}'.format(user_dir) + cmd = 'dir' else: - line = 'shell ls {}'.format(user_dir) + cmd = 'ls' + + line = 'shell {} ~{}'.format(cmd, os.path.sep) + endidx = len(line) + begidx = endidx - len(text) + 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) 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__) |
