diff options
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 55ff018b..61fd8373 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,6 @@ # coding=utf-8 """ -Unit/functional testing for cmd2/utils.py module. +Unit testing for cmd2/utils.py module. Copyright 2018 Todd Leonhardt <todd.leonhardt@gmail.com> Released under MIT license, see LICENSE file @@ -8,9 +8,45 @@ Released under MIT license, see LICENSE file from colorama import Fore import cmd2.utils as cu +HELLO_WORLD = 'Hello, world!' + def test_strip_ansi(): - base_str = 'Hello, world!' + base_str = HELLO_WORLD ansi_str = Fore.GREEN + base_str + Fore.RESET assert base_str != ansi_str assert base_str == cu.strip_ansi(ansi_str) + +def test_strip_quotes_no_quotes(): + base_str = HELLO_WORLD + stripped = cu.strip_quotes(base_str) + assert base_str == stripped + +def test_strip_quotes_with_quotes(): + base_str = '"' + HELLO_WORLD + '"' + stripped = cu.strip_quotes(base_str) + assert stripped == HELLO_WORLD + +def test_remove_duplicates_no_duplicates(): + no_dups = [5, 4, 3, 2, 1] + assert cu.remove_duplicates(no_dups) == no_dups + +def test_remove_duplicates_with_duplicates(): + duplicates = [1, 1, 2, 3, 9, 9, 7, 8] + assert cu.remove_duplicates(duplicates) == [1, 2, 3, 9, 7, 8] + +def test_unicode_normalization(): + s1 = 'café' + s2 = 'cafe\u0301' + assert s1 != s2 + assert cu.norm_fold(s1) == cu.norm_fold(s2) + +def test_unicode_casefold(): + micro = 'µ' + micro_cf = micro.casefold() + assert micro != micro_cf + assert cu.norm_fold(micro) == cu.norm_fold(micro_cf) + +def test_alphabetical_sort(): + my_list = ['café', 'µ', 'A' , 'micro', 'unity', 'cafeteria'] + assert cu.alphabetical_sort(my_list) == ['A', 'cafeteria', 'café', 'micro', 'unity', 'µ'] |