summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-21 09:54:39 -0400
committerGitHub <noreply@github.com>2018-09-21 09:54:39 -0400
commit69b16f1631c0f808964d797d84a943c862284ab5 (patch)
treef6a9027a31537181a4b98ccb9e2967d282f14193 /tests
parente17d0e96990e0d8215ff1f1d234c46ca7c8f01ac (diff)
parent89097505f50d295a3879b3be3eec45bcdb9d08eb (diff)
downloadcmd2-git-69b16f1631c0f808964d797d84a943c862284ab5.tar.gz
Merge branch 'master' into colorize
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py20
-rw-r--r--tests/test_utils.py35
2 files changed, 54 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index e2a3d854..0f1c5ab9 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -73,7 +73,7 @@ def test_base_invalid_option(base_app, capsys):
out = normalize(out)
err = normalize(err)
assert 'Error: unrecognized arguments: -z' in err[0]
- assert out[0] == 'Usage: set settable{0..2} [-h] [-a] [-l]'
+ assert out[0] == 'Usage: set [param] [value] [-h] [-a] [-l]'
def test_base_shortcuts(base_app):
out = run_cmd(base_app, 'shortcuts')
@@ -1795,6 +1795,24 @@ def test_create_invalid_alias(base_app, alias_name, capsys):
out, err = capsys.readouterr()
assert "can not contain" in err
+def test_complete_unalias(base_app):
+ text = 'f'
+ line = text
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ # Validate there are no completions when there are no aliases
+ assert base_app.complete_unalias(text, line, begidx, endidx) == []
+
+ # Create a few aliases - two the start with 'f' and one that doesn't
+ run_cmd(base_app, 'alias fall quit')
+ run_cmd(base_app, 'alias fake pyscript')
+ run_cmd(base_app, 'alias carapace shell')
+
+ # Validate that there are now completions
+ expected = ['fake', 'fall']
+ assert base_app.complete_unalias(text, line, begidx, endidx) == expected
+
def test_ppaged(base_app):
msg = 'testing...'
end = '\n'
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 691abdf8..8c8daa39 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -76,3 +76,38 @@ def test_natural_sort():
assert cu.natural_sort(my_list) == ['A', 'café', 'micro', 'unity', 'X0', 'x1', 'X2', 'X11', 'x22', 'µ']
my_list = ['a3', 'a22', 'A2', 'A11', 'a1']
assert cu.natural_sort(my_list) == ['a1', 'A2', 'a3', 'A11', 'a22']
+
+def test_is_quoted_short():
+ my_str = ''
+ assert not cu.is_quoted(my_str)
+ your_str = '"'
+ assert not cu.is_quoted(your_str)
+
+def test_is_quoted_yes():
+ my_str = '"This is a test"'
+ assert cu.is_quoted(my_str)
+ your_str = "'of the emergengy broadcast system'"
+ assert cu.is_quoted(your_str)
+
+def test_is_quoted_no():
+ my_str = '"This is a test'
+ assert not cu.is_quoted(my_str)
+ your_str = "of the emergengy broadcast system'"
+ assert not cu.is_quoted(your_str)
+ simple_str = "hello world"
+ assert not cu.is_quoted(simple_str)
+
+def test_quote_string_if_needed_yes():
+ my_str = "Hello World"
+ assert cu.quote_string_if_needed(my_str) == '"' + my_str + '"'
+ your_str = '"foo" bar'
+ assert cu.quote_string_if_needed(your_str) == "'" + your_str + "'"
+
+def test_quot_string_if_needed_no():
+ my_str = "HelloWorld"
+ assert cu.quote_string_if_needed(my_str) == my_str
+ your_str = "'Hello World'"
+ assert cu.quote_string_if_needed(your_str) == your_str
+
+
+