Skip to content

Commit 60d6e4c

Browse files
committed
Added unit test for matches_sort_key
1 parent 5ea6525 commit 60d6e4c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/test_completion.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def do_test_delimited(self, args):
7070
def complete_test_delimited(self, text, line, begidx, endidx):
7171
return self.delimiter_complete(text, line, begidx, endidx, delimited_strs, '/')
7272

73+
def do_test_sort_key(self, args):
74+
pass
75+
76+
def complete_test_sort_key(self, text, line, begidx, endidx):
77+
num_strs = ['2', '11', '1']
78+
return self.basic_complete(text, line, begidx, endidx, num_strs)
79+
7380

7481
@pytest.fixture
7582
def cmd2_app():
@@ -129,7 +136,26 @@ def test_complete_macro(base_app, request):
129136

130137
expected = [text + 'cript.py', text + 'cript.txt', text + 'cripts' + os.path.sep]
131138
first_match = complete_tester(text, line, begidx, endidx, base_app)
132-
assert first_match is not None and base_app.completion_matches
139+
assert first_match is not None and base_app.completion_matches == expected
140+
141+
142+
def test_matches_sort_key(cmd2_app):
143+
text = ''
144+
line = 'test_sort_key {}'.format(text)
145+
endidx = len(line)
146+
begidx = endidx - len(text)
147+
148+
# First do alphabetical sorting
149+
cmd2_app.matches_sort_key = cmd2.cmd2.ALPHABETICAL_SORT_KEY
150+
expected = ['1', '11', '2']
151+
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
152+
assert first_match is not None and cmd2_app.completion_matches == expected
153+
154+
# Now switch to natural sorting
155+
cmd2_app.matches_sort_key = cmd2.cmd2.NATURAL_SORT_KEY
156+
expected = ['1', '2', '11']
157+
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
158+
assert first_match is not None and cmd2_app.completion_matches == expected
133159

134160

135161
def test_cmd2_command_completion_multiple(cmd2_app):

0 commit comments

Comments
 (0)