|
20 | 20 | from examples.subcommands import SubcommandsExample |
21 | 21 |
|
22 | 22 | # List of strings used with completion functions |
23 | | -food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato'] |
| 23 | +food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato', 'Cheese "Pizza"'] |
24 | 24 | sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball'] |
25 | 25 | delimited_strs = \ |
26 | 26 | [ |
@@ -83,6 +83,17 @@ def do_test_raise_exception(self, args): |
83 | 83 | def complete_test_raise_exception(self, text, line, begidx, endidx): |
84 | 84 | raise IndexError("You are out of bounds!!") |
85 | 85 |
|
| 86 | + def do_test_no_completer(self, args): |
| 87 | + """Completing this should result in completedefault() being called""" |
| 88 | + pass |
| 89 | + |
| 90 | + def completedefault(self, *ignored): |
| 91 | + """Method called to complete an input line when no command-specific |
| 92 | + complete_*() method is available. |
| 93 | +
|
| 94 | + """ |
| 95 | + return ['default'] |
| 96 | + |
86 | 97 |
|
87 | 98 | @pytest.fixture |
88 | 99 | def cmd2_app(): |
@@ -123,8 +134,9 @@ def test_complete_bogus_command(cmd2_app): |
123 | 134 | endidx = len(line) |
124 | 135 | begidx = endidx - len(text) |
125 | 136 |
|
| 137 | + expected = ['default '] |
126 | 138 | first_match = complete_tester(text, line, begidx, endidx, cmd2_app) |
127 | | - assert first_match is None |
| 139 | + assert first_match is not None and cmd2_app.completion_matches == expected |
128 | 140 |
|
129 | 141 | def test_complete_exception(cmd2_app, capsys): |
130 | 142 | text = '' |
@@ -737,6 +749,16 @@ def test_add_opening_quote_basic_quote_added(cmd2_app): |
737 | 749 | first_match = complete_tester(text, line, begidx, endidx, cmd2_app) |
738 | 750 | assert first_match is not None and cmd2_app.completion_matches == expected |
739 | 751 |
|
| 752 | +def test_add_opening_quote_basic_single_quote_added(cmd2_app): |
| 753 | + text = 'Ch' |
| 754 | + line = 'test_basic {}'.format(text) |
| 755 | + endidx = len(line) |
| 756 | + begidx = endidx - len(text) |
| 757 | + |
| 758 | + expected = ["'Cheese \"Pizza\"' "] |
| 759 | + first_match = complete_tester(text, line, begidx, endidx, cmd2_app) |
| 760 | + assert first_match is not None and cmd2_app.completion_matches == expected |
| 761 | + |
740 | 762 | def test_add_opening_quote_basic_text_is_common_prefix(cmd2_app): |
741 | 763 | # This tests when the text entered is the same as the common prefix of the matches |
742 | 764 | text = 'Ham' |
@@ -816,6 +838,25 @@ def test_add_opening_quote_delimited_space_in_prefix(cmd2_app): |
816 | 838 | os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \ |
817 | 839 | cmd2_app.display_matches == expected_display |
818 | 840 |
|
| 841 | +def test_no_completer(cmd2_app): |
| 842 | + text = '' |
| 843 | + line = 'test_no_completer {}'.format(text) |
| 844 | + endidx = len(line) |
| 845 | + begidx = endidx - len(text) |
| 846 | + |
| 847 | + expected = ['default '] |
| 848 | + first_match = complete_tester(text, line, begidx, endidx, cmd2_app) |
| 849 | + assert first_match is not None and cmd2_app.completion_matches == expected |
| 850 | + |
| 851 | +def test_quote_as_command(cmd2_app): |
| 852 | + text = '' |
| 853 | + line = '" {}'.format(text) |
| 854 | + endidx = len(line) |
| 855 | + begidx = endidx - len(text) |
| 856 | + |
| 857 | + first_match = complete_tester(text, line, begidx, endidx, cmd2_app) |
| 858 | + assert first_match is None and not cmd2_app.completion_matches |
| 859 | + |
819 | 860 | @pytest.fixture |
820 | 861 | def sc_app(): |
821 | 862 | c = SubcommandsExample() |
|
0 commit comments