diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-02 13:05:24 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-02 13:05:24 -0500 |
commit | 06a84fd7503f9f6fd81f70111f6a39a3b7c6188d (patch) | |
tree | 001671b9f2b9a3f79f84c491c319cb6498231b07 | |
parent | 1a024579a73af258dd7bd3f6f20ebc58f7115450 (diff) | |
download | cmd2-git-06a84fd7503f9f6fd81f70111f6a39a3b7c6188d.tar.gz |
Added unit tests for index based completion
-rw-r--r-- | tests/test_completion.py | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py index c07deeaa..bdeae2e2 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -389,13 +389,12 @@ def test_path_completion_directories_only(request): assert path_complete(text, line, begidx, endidx, dir_only=True) == ['scripts' + os.path.sep] -# List of strings used with flag and index based complete functions +# List of strings used with flag and index based completion functions food_item_strs = ['Pizza', 'Hamburger', 'Ham', 'Potato'] -sports_equipment_strs = ['Soccer', 'Socks', 'Basketball', 'Football'] +sports_equipment_strs = ['Bat', 'Basket', 'Basketball', 'Football'] -# Dictionaries used with flag and index based complete functions +# Dictionary used with flag based completion functions flag_dict = {'-f': food_item_strs, '-s': sports_equipment_strs} -position_dict = {1: food_item_strs, 2: sports_equipment_strs} def test_flag_based_completion_single_end(): text = 'Pi' @@ -439,6 +438,51 @@ def test_flag_based_default_completer(request): assert flag_based_complete(text, line, begidx, endidx, flag_dict, path_complete) == ['conftest.py '] +# Dictionary used with index based completion functions +index_dict = {1: food_item_strs, 2: sports_equipment_strs} + +def test_index_based_completion_single_end(): + text = 'Foo' + line = 'command Pizza Foo' + endidx = len(line) + begidx = endidx - len(text) + + assert index_based_complete(text, line, begidx, endidx, index_dict) == ['Football '] + +def test_index_based_completion_single_mid(): + text = 'Foo' + line = 'command Pizza Foo' + begidx = len(line) - len(text) + endidx = begidx + 1 + + assert index_based_complete(text, line, begidx, endidx, index_dict) == ['Football'] + +def test_index_based_completion_multiple(): + text = '' + line = 'command Pizza ' + endidx = len(line) + begidx = endidx - len(text) + assert index_based_complete(text, line, begidx, endidx, index_dict) == sorted(sports_equipment_strs) + +def test_index_based_completion_nomatch(): + text = 'q' + line = 'command q' + endidx = len(line) + begidx = endidx - len(text) + assert index_based_complete(text, line, begidx, endidx, index_dict) == [] + +def test_index_based_default_completer(request): + test_dir = os.path.dirname(request.module.__file__) + + text = 'c' + path = os.path.join(test_dir, text) + line = 'command Pizza Bat {}'.format(path) + + endidx = len(line) + begidx = endidx - len(text) + + assert flag_based_complete(text, line, begidx, endidx, flag_dict, path_complete) == ['conftest.py '] + def test_parseline_command_and_args(cmd2_app): line = 'help history' |