summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-24 16:39:12 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-24 16:39:12 -0400
commit11797774735febb1f6d5c7d4b8f3d798288dbd5e (patch)
tree25eb8b8534ac692c41d048cf0cfab4116d86d952 /tests
parentb72a8ba7eed899ee8c44da36aa2636496bff89c7 (diff)
downloadcmd2-git-11797774735febb1f6d5c7d4b8f3d798288dbd5e.tar.gz
Added some path completion unit tests
Also added some command completion unit tests for cases where there are no matches
Diffstat (limited to 'tests')
-rw-r--r--tests/test_completion.py70
1 files changed, 69 insertions, 1 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 98f4387a..c5094bc4 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -8,6 +8,7 @@ file system paths, and shell commands.
Copyright 2017 Todd Leonhardt <todd.leonhardt@gmail.com>
Released under MIT license, see LICENSE file
"""
+import os
import sys
import cmd2
@@ -44,6 +45,13 @@ def test_cmd2_command_completion_multiple(cmd2_app):
# It is not at end of line, so no extra space
assert cmd2_app.completenames(text, line, begidx, endidx) == ['help', 'history']
+def test_cmd2_command_completion_nomatch(cmd2_app):
+ text = 'z'
+ line = 'z'
+ begidx = 0
+ endidx = 1
+ assert cmd2_app.completenames(text, line, begidx, endidx) == []
+
def test_cmd2_help_completion_single_end(cmd2_app):
text = 'he'
line = 'help he'
@@ -66,6 +74,13 @@ def test_cmd2_help_completion_multiple(cmd2_app):
endidx = 6
assert cmd2_app.completenames(text, line, begidx, endidx) == ['help', 'history']
+def test_cmd2_help_completion_nomatch(cmd2_app):
+ text = 'z'
+ line = 'help z'
+ begidx = 5
+ endidx = 6
+ assert cmd2_app.completenames(text, line, begidx, endidx) == []
+
def test_shell_command_completion(cmd2_app):
if sys.platform == "win32":
text = 'calc'
@@ -94,4 +109,57 @@ def test_shell_command_completion_multiple(cmd2_app):
endidx = 2
assert 'ls' in cmd2_app.complete_shell(text, line, begidx, endidx)
-# TODO: Add tests for path completion
+def test_shell_command_completion_nomatch(cmd2_app):
+ text = 'zzzz'
+ line = 'shell zzzz'
+ begidx = 6
+ endidx = 10
+ assert cmd2_app.complete_shell(text, line, begidx, endidx) == []
+
+def test_path_completion_single_end(cmd2_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+
+ text = 'c'
+ path = os.path.join(test_dir, text)
+ line = '!cat {}'.format(path)
+
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ assert cmd2_app.path_complete(text, line, begidx, endidx) == ['conftest.py ']
+
+def test_path_completion_single_mid(cmd2_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+
+ text = 'tes'
+ path = os.path.join(test_dir, 'c')
+ line = '!cat {}'.format(path)
+
+ begidx = line.find(text)
+ endidx = begidx + len(text)
+
+ assert cmd2_app.path_complete(text, line, begidx, endidx) == ['tests/']
+
+def test_path_completion_multiple(cmd2_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+
+ text = 's'
+ path = os.path.join(test_dir, text)
+ line = '!cat {}'.format(path)
+
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ assert cmd2_app.path_complete(text, line, begidx, endidx) == ['script.py', 'script.txt']
+
+def test_path_completion_nomatch(cmd2_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+
+ text = 'z'
+ path = os.path.join(test_dir, text)
+ line = '!cat {}'.format(path)
+
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ assert cmd2_app.path_complete(text, line, begidx, endidx) == []