summaryrefslogtreecommitdiff
path: root/tests/test_utils.py
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 /tests/test_utils.py
parent311e5fd0bc134a8dfc7450c7a6da91b0b23cf5d8 (diff)
downloadcmd2-git-68e107e614ec344a0339da9eccb1a88f0bef3478.tar.gz
Added unit tests for new utility functions and fixed a comment
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py35
1 files changed, 35 insertions, 0 deletions
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
+
+
+