summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-21 09:02:04 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-21 09:02:04 -0400
commit68e107e614ec344a0339da9eccb1a88f0bef3478 (patch)
tree9b888672798ac304321cf0da91c32cef14e143b3
parent311e5fd0bc134a8dfc7450c7a6da91b0b23cf5d8 (diff)
downloadcmd2-git-68e107e614ec344a0339da9eccb1a88f0bef3478.tar.gz
Added unit tests for new utility functions and fixed a comment
-rw-r--r--cmd2/utils.py2
-rw-r--r--tests/test_utils.py35
2 files changed, 36 insertions, 1 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index f7ca29c2..9cbea915 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -24,7 +24,7 @@ def is_quoted(arg: str) -> bool:
"""
Checks if a string is quoted
:param arg: the string being checked for quotes
- :return: True if a string is quotes
+ :return: True if a string is quoted
"""
return len(arg) > 1 and arg[0] == arg[-1] and arg[0] in constants.QUOTES
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
+
+
+