summaryrefslogtreecommitdiff
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-01-17 17:44:50 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-01-17 17:44:50 -0500
commit242efbdab9e9955bc20c15f0d28422f33b7936cc (patch)
tree2696093a0271fa46dfc14783833a4aa3915a7a84 /tests/test_utils.py
parentd7eee7d72d7673bbffad848170d8021465bf909f (diff)
downloadcmd2-git-242efbdab9e9955bc20c15f0d28422f33b7936cc.tar.gz
Updating unit tests
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 9b2279ae..08b282b7 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -293,6 +293,36 @@ def test_context_flag_exit_err(context_flag):
context_flag.__exit__()
+def test_truncate_string():
+ text = 'long'
+ max_width = 3
+ truncated = cu.truncate_string(text, max_width)
+ assert truncated == 'lo\N{HORIZONTAL ELLIPSIS}'
+
+def test_truncate_string_newline_in_text():
+ text = 'fo\no'
+ max_width = 2
+ with pytest.raises(ValueError):
+ cu.truncate_string(text, max_width)
+
+def test_truncate_string_width_is_too_small():
+ text = 'foo'
+ max_width = 0
+ with pytest.raises(ValueError):
+ cu.truncate_string(text, max_width)
+
+def test_truncate_string_wide_text():
+ text = '苹苹other'
+ max_width = 6
+ truncated = cu.truncate_string(text, max_width)
+ assert truncated == '苹苹o\N{HORIZONTAL ELLIPSIS}'
+
+def test_truncate_string_tabs():
+ text = 'has\ttab'
+ max_width = 9
+ truncated = cu.truncate_string(text, max_width)
+ assert truncated == 'has t\N{HORIZONTAL ELLIPSIS}'
+
def test_align_text_fill_char_is_tab():
text = 'foo'
fill_char = '\t'
@@ -300,6 +330,13 @@ def test_align_text_fill_char_is_tab():
aligned = cu.align_text(text, cu.TextAlignment.LEFT, fill_char=fill_char, width=width)
assert aligned == text + ' '
+def test_align_text_width_is_too_small():
+ text = 'foo'
+ fill_char = '-'
+ width = 0
+ with pytest.raises(ValueError):
+ cu.align_text(text, cu.TextAlignment.LEFT, fill_char=fill_char, width=width)
+
def test_align_text_fill_char_is_too_long():
text = 'foo'
fill_char = 'fill'
@@ -340,7 +377,7 @@ def test_align_text_wider_than_width_truncate():
fill_char = '-'
width = 8
aligned = cu.align_text(text, cu.TextAlignment.LEFT, fill_char=fill_char, width=width, truncate=True)
- assert aligned == 'long te' + "\N{HORIZONTAL ELLIPSIS}"
+ assert aligned == 'long te\N{HORIZONTAL ELLIPSIS}'
def test_align_text_has_unprintable():
text = 'foo\x02'