@@ -257,6 +257,21 @@ def test_shell_command_completion_does_path_completion_when_after_command(cmd2_a
257257 first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
258258 assert first_match is not None and cmd2_app .completion_matches == [text + '.py ' ]
259259
260+ def test_shell_commmand_complete_in_path (cmd2_app , request ):
261+ test_dir = os .path .dirname (request .module .__file__ )
262+
263+ text = os .path .join (test_dir , 's' )
264+ line = 'shell {}' .format (text )
265+
266+ endidx = len (line )
267+ begidx = endidx - len (text )
268+
269+ # Since this will look for directories and executables in the given path,
270+ # we expect to see the scripts dir among the results
271+ expected = os .path .join (test_dir , 'scripts' + os .path .sep )
272+ first_match = complete_tester (text , line , begidx , endidx , cmd2_app )
273+ assert first_match is not None and expected in cmd2_app .completion_matches
274+
260275
261276def test_path_completion_single_end (cmd2_app , request ):
262277 test_dir = os .path .dirname (request .module .__file__ )
@@ -316,8 +331,8 @@ def test_default_to_shell_completion(cmd2_app, request):
316331 assert first_match is not None and cmd2_app .completion_matches == [text + '.py ' ]
317332
318333
319- def test_path_completion_cwd (cmd2_app ):
320- # Run path complete with no search text
334+ def test_path_completion_no_text (cmd2_app ):
335+ # Run path complete with no search text which should show what's in cwd
321336 text = ''
322337 line = 'shell ls {}' .format (text )
323338 endidx = len (line )
@@ -330,13 +345,34 @@ def test_path_completion_cwd(cmd2_app):
330345 endidx = len (line )
331346 begidx = endidx - len (text )
332347
333- # We have to strip off the text from the beginning since the matches are entire paths
348+ # We have to strip off the path from the beginning since the matches are entire paths
334349 completions_cwd = [match .replace (text , '' , 1 ) for match in cmd2_app .path_complete (text , line , begidx , endidx )]
335350
336351 # Verify that the first test gave results for entries in the cwd
337352 assert completions_no_text == completions_cwd
338353 assert completions_cwd
339354
355+ def test_path_completion_no_path (cmd2_app ):
356+ # Run path complete with search text that isn't preceded by a path. This should use CWD as the path.
357+ text = 's'
358+ line = 'shell ls {}' .format (text )
359+ endidx = len (line )
360+ begidx = endidx - len (text )
361+ completions_no_text = cmd2_app .path_complete (text , line , begidx , endidx )
362+
363+ # Run path complete with path set to the CWD
364+ text = os .getcwd () + os .path .sep + 's'
365+ line = 'shell ls {}' .format (text )
366+ endidx = len (line )
367+ begidx = endidx - len (text )
368+
369+ # We have to strip off the path from the beginning since the matches are entire paths (Leave the 's')
370+ completions_cwd = [match .replace (text [:- 1 ], '' , 1 ) for match in cmd2_app .path_complete (text , line , begidx , endidx )]
371+
372+ # Verify that the first test gave results for entries in the cwd
373+ assert completions_no_text == completions_cwd
374+ assert completions_cwd
375+
340376def test_path_completion_doesnt_match_wildcards (cmd2_app , request ):
341377 test_dir = os .path .dirname (request .module .__file__ )
342378
@@ -399,7 +435,7 @@ def test_path_completion_directories_only(cmd2_app, request):
399435
400436 expected = [text + 'cripts' + os .path .sep ]
401437
402- assert cmd2_app .path_complete (text , line , begidx , endidx , dir_only = True ) == expected
438+ assert cmd2_app .path_complete (text , line , begidx , endidx , os . path . isdir ) == expected
403439
404440def test_basic_completion_single (cmd2_app ):
405441 text = 'Pi'
0 commit comments