diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-16 17:47:01 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-16 17:47:01 -0400 |
commit | fd9657d651ccdd7d42730489fe32448a90992ef6 (patch) | |
tree | 90e0373930d5e41718289b007a03eb6097bebfe3 /tests/test_completion.py | |
parent | c4c1f441c11df9b0045918b3003b07b71e9ee3fd (diff) | |
download | cmd2-git-fd9657d651ccdd7d42730489fe32448a90992ef6.tar.gz |
Added unit tests for alias, unalias, and basic_complete
Diffstat (limited to 'tests/test_completion.py')
-rw-r--r-- | tests/test_completion.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py index 7eac5366..a9f75dce 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -17,7 +17,7 @@ import cmd2 import mock import pytest -from cmd2 import path_complete, flag_based_complete, index_based_complete +from cmd2 import path_complete, basic_complete, flag_based_complete, index_based_complete @pytest.fixture def cmd2_app(): @@ -399,7 +399,7 @@ def test_path_completion_no_tokens(): assert path_complete(text, line, begidx, endidx) == [] -# List of strings used with flag and index based completion functions +# List of strings used with basic, flag, and index based completion functions food_item_strs = ['Pizza', 'Hamburger', 'Ham', 'Potato'] sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football'] @@ -414,6 +414,39 @@ flag_dict = \ '--other': path_complete, # Tab-complete using path_complete function after --other flag in command line } +def test_basic_completion_single_end(): + text = 'Pi' + line = 'list_food -f Pi' + endidx = len(line) + begidx = endidx - len(text) + + assert basic_complete(text, line, begidx, endidx, food_item_strs) == ['Pizza '] + +def test_basic_completion_single_mid(): + text = 'Pi' + line = 'list_food -f Pi' + begidx = len(line) - len(text) + endidx = begidx + 1 + + assert basic_complete(text, line, begidx, endidx, food_item_strs) == ['Pizza'] + +def test_basic_completion_multiple(): + text = '' + line = 'list_food -f ' + endidx = len(line) + begidx = endidx - len(text) + + assert basic_complete(text, line, begidx, endidx, food_item_strs) == sorted(food_item_strs) + +def test_basic_completion_nomatch(): + text = 'q' + line = 'list_food -f q' + endidx = len(line) + begidx = endidx - len(text) + + assert basic_complete(text, line, begidx, endidx, food_item_strs) == [] + + def test_flag_based_completion_single_end(): text = 'Pi' line = 'list_food -f Pi' @@ -435,6 +468,7 @@ def test_flag_based_completion_multiple(): line = 'list_food -f ' endidx = len(line) begidx = endidx - len(text) + assert flag_based_complete(text, line, begidx, endidx, flag_dict) == sorted(food_item_strs) def test_flag_based_completion_nomatch(): @@ -442,6 +476,7 @@ def test_flag_based_completion_nomatch(): line = 'list_food -f q' endidx = len(line) begidx = endidx - len(text) + assert flag_based_complete(text, line, begidx, endidx, flag_dict) == [] def test_flag_based_default_completer(request): |