@@ -316,8 +316,8 @@ def test_default_to_shell_completion(cmd2_app, request):
316316 assert first_match is not None and cmd2_app .completion_matches == [text + '.py ' ]
317317
318318
319- def test_path_completion_cwd (cmd2_app ):
320- # Run path complete with no search text
319+ def test_path_completion_no_text (cmd2_app ):
320+ # Run path complete with no search text which should show what's in cwd
321321 text = ''
322322 line = 'shell ls {}' .format (text )
323323 endidx = len (line )
@@ -330,13 +330,34 @@ def test_path_completion_cwd(cmd2_app):
330330 endidx = len (line )
331331 begidx = endidx - len (text )
332332
333- # We have to strip off the text from the beginning since the matches are entire paths
333+ # We have to strip off the path from the beginning since the matches are entire paths
334334 completions_cwd = [match .replace (text , '' , 1 ) for match in cmd2_app .path_complete (text , line , begidx , endidx )]
335335
336336 # Verify that the first test gave results for entries in the cwd
337337 assert completions_no_text == completions_cwd
338338 assert completions_cwd
339339
340+ def test_path_completion_no_path (cmd2_app ):
341+ # Run path complete with search text that isn't preceded by a path. This should use CWD as the path.
342+ text = 's'
343+ line = 'shell ls {}' .format (text )
344+ endidx = len (line )
345+ begidx = endidx - len (text )
346+ completions_no_text = cmd2_app .path_complete (text , line , begidx , endidx )
347+
348+ # Run path complete with path set to the CWD
349+ text = os .getcwd () + os .path .sep + 's'
350+ line = 'shell ls {}' .format (text )
351+ endidx = len (line )
352+ begidx = endidx - len (text )
353+
354+ # We have to strip off the path from the beginning since the matches are entire paths (Leave the 's')
355+ completions_cwd = [match .replace (text [:- 1 ], '' , 1 ) for match in cmd2_app .path_complete (text , line , begidx , endidx )]
356+
357+ # Verify that the first test gave results for entries in the cwd
358+ assert completions_no_text == completions_cwd
359+ assert completions_cwd
360+
340361def test_path_completion_doesnt_match_wildcards (cmd2_app , request ):
341362 test_dir = os .path .dirname (request .module .__file__ )
342363
0 commit comments