@@ -177,18 +177,27 @@ def test_cmd2_help_completion_nomatch(cmd2_app):
177177 assert cmd2_app .complete_help (text , line , begidx , endidx ) == []
178178
179179
180- def test_shell_command_completion (cmd2_app ):
180+ def test_shell_command_completion_shortcut (cmd2_app ):
181+ # Made sure ! runs a shell command and all matches start with ! since there
182+ # isn't a space between ! and the shell command. Display matches won't
183+ # begin with the !.
181184 if sys .platform == "win32" :
182- text = 'calc'
183- expected = ['calc.exe' ]
185+ text = '!calc'
186+ expected = ['!calc.exe ' ]
187+ expected_display = ['calc.exe' ]
184188 else :
185- text = 'egr'
186- expected = ['egrep' ]
189+ text = '!egr'
190+ expected = ['!egrep ' ]
191+ expected_display = ['egrep' ]
187192
188- line = 'shell {}' . format ( text )
193+ line = text
189194 endidx = len (line )
190- begidx = endidx - len (text )
191- assert cmd2_app .complete_shell (text , line , begidx , endidx ) == expected
195+ begidx = 0
196+
197+ first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
198+ assert first_match is not None and \
199+ cmd2_app .completion_matches == expected and \
200+ cmd2_app .display_matches == expected_display
192201
193202def test_shell_command_completion_doesnt_match_wildcards (cmd2_app ):
194203 if sys .platform == "win32" :
@@ -742,7 +751,7 @@ def test_cmd2_help_subcommand_completion_nomatch(sc_app):
742751def test_subcommand_tab_completion (sc_app ):
743752 # This makes sure the correct completer for the sport subcommand is called
744753 text = 'Foot'
745- line = 'base sport Foot'
754+ line = 'base sport {}' . format ( text )
746755 endidx = len (line )
747756 begidx = endidx - len (text )
748757
@@ -755,12 +764,37 @@ def test_subcommand_tab_completion_with_no_completer(sc_app):
755764 # This tests what happens when a subcommand has no completer
756765 # In this case, the foo subcommand has no completer defined
757766 text = 'Foot'
758- line = 'base foo Foot'
767+ line = 'base foo {}' .format (text )
768+ endidx = len (line )
769+ begidx = endidx - len (text )
770+
771+ first_match = complete_tester (text , line , begidx , endidx , sc_app )
772+ assert first_match is None
773+
774+ def test_subcommand_tab_completion_add_quote (sc_app ):
775+ # This makes sure an opening quote is added to the readline line buffer
776+ text = 'Space'
777+ line = 'base sport {}' .format (text )
759778 endidx = len (line )
760779 begidx = endidx - len (text )
761780
762781 first_match = complete_tester (text , line , begidx , endidx , sc_app )
782+
783+ # No matches are returned when an opening quote is added to the screen
763784 assert first_match is None
785+ assert readline .get_line_buffer () == 'base sport "Space Ball" '
786+
787+ def test_subcommand_tab_completion_space_in_text (sc_app ):
788+ text = 'B'
789+ line = 'base sport "Space {}' .format (text )
790+ endidx = len (line )
791+ begidx = endidx - len (text )
792+
793+ first_match = complete_tester (text , line , begidx , endidx , sc_app )
794+
795+ assert first_match is not None and \
796+ sc_app .completion_matches == ['Ball" ' ] and \
797+ sc_app .display_matches == ['Space Ball' ]
764798
765799class SecondLevel (cmd2 .Cmd ):
766800 """To be used as a second level command class. """
0 commit comments