@@ -716,19 +716,44 @@ def test_basic_completion_nomatch(cmd2_app) -> None:
716716 assert cmd2_app .basic_complete (text , line , begidx , endidx , food_item_strs ) == []
717717
718718
719- def test_delimiter_completion (cmd2_app ) -> None :
719+ def test_delimiter_completion_partial (cmd2_app ) -> None :
720+ """Test that a delimiter is added when an item has not been fully completed"""
720721 text = '/home/'
721722 line = f'run_script { text } '
722723 endidx = len (line )
723724 begidx = endidx - len (text )
724725
725- cmd2_app .delimiter_complete (text , line , begidx , endidx , delimited_strs , '/' )
726+ matches = cmd2_app .delimiter_complete (text , line , begidx , endidx , delimited_strs , '/' )
726727
727- # Remove duplicates from display_matches and sort it. This is typically done in complete().
728- display_list = utils . remove_duplicates ( cmd2_app .display_matches )
729- display_list = utils . alphabetical_sort ( display_list )
728+ # All matches end with the delimiter
729+ matches . sort ( key = cmd2_app .default_sort_key )
730+ expected_matches = sorted ([ "/home/other user/" , "/home/user/" ], key = cmd2_app . default_sort_key )
730731
731- assert display_list == ['other user' , 'user' ]
732+ cmd2_app .display_matches .sort (key = cmd2_app .default_sort_key )
733+ expected_display = sorted (["other user/" , "user/" ], key = cmd2_app .default_sort_key )
734+
735+ assert matches == expected_matches
736+ assert cmd2_app .display_matches == expected_display
737+
738+
739+ def test_delimiter_completion_full (cmd2_app ) -> None :
740+ """Test that no delimiter is added when an item has been fully completed"""
741+ text = '/home/other user/'
742+ line = f'run_script { text } '
743+ endidx = len (line )
744+ begidx = endidx - len (text )
745+
746+ matches = cmd2_app .delimiter_complete (text , line , begidx , endidx , delimited_strs , '/' )
747+
748+ # No matches end with the delimiter
749+ matches .sort (key = cmd2_app .default_sort_key )
750+ expected_matches = sorted (["/home/other user/maps" , "/home/other user/tests" ], key = cmd2_app .default_sort_key )
751+
752+ cmd2_app .display_matches .sort (key = cmd2_app .default_sort_key )
753+ expected_display = sorted (["maps" , "tests" ], key = cmd2_app .default_sort_key )
754+
755+ assert matches == expected_matches
756+ assert cmd2_app .display_matches == expected_display
732757
733758
734759def test_flag_based_completion_single (cmd2_app ) -> None :
@@ -964,20 +989,24 @@ def test_add_opening_quote_delimited_no_text(cmd2_app) -> None:
964989 endidx = len (line )
965990 begidx = endidx - len (text )
966991
967- # The whole list will be returned with no opening quotes added
992+ # Matches returned with no opening quote
993+ expected_matches = sorted (["/home/other user/" , "/home/user/" ], key = cmd2_app .default_sort_key )
994+ expected_display = sorted (["other user/" , "user/" ], key = cmd2_app .default_sort_key )
995+
968996 first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
969997 assert first_match is not None
970- assert cmd2_app .completion_matches == sorted (delimited_strs , key = cmd2_app .default_sort_key )
998+ assert cmd2_app .completion_matches == expected_matches
999+ assert cmd2_app .display_matches == expected_display
9711000
9721001
9731002def test_add_opening_quote_delimited_nothing_added (cmd2_app ) -> None :
974- text = '/ho '
1003+ text = '/home/ '
9751004 line = f'test_delimited { text } '
9761005 endidx = len (line )
9771006 begidx = endidx - len (text )
9781007
979- expected_matches = sorted (delimited_strs , key = cmd2_app .default_sort_key )
980- expected_display = sorted (['other user' , 'user' ], key = cmd2_app .default_sort_key )
1008+ expected_matches = sorted ([ '/home/other user/' , '/home/user/' ] , key = cmd2_app .default_sort_key )
1009+ expected_display = sorted (['other user/ ' , 'user/ ' ], key = cmd2_app .default_sort_key )
9811010
9821011 first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
9831012 assert first_match is not None
@@ -1017,7 +1046,7 @@ def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app) -> None:
10171046
10181047
10191048def test_add_opening_quote_delimited_space_in_prefix (cmd2_app ) -> None :
1020- # This test when a space appears before the part of the string that is the display match
1049+ # This tests when a space appears before the part of the string that is the display match
10211050 text = '/home/oth'
10221051 line = f'test_delimited { text } '
10231052 endidx = len (line )
0 commit comments