@@ -359,7 +359,7 @@ def test_path_completion_cwd():
359359 completions_empty = path_complete (text , line , begidx , endidx )
360360
361361 # Run path complete with path set to the CWD
362- cwd = os .getcwd ()
362+ cwd = os .getcwd () + os . path . sep
363363 line = 'shell ls {}' .format (cwd )
364364 endidx = len (line )
365365 begidx = endidx - len (text )
@@ -382,29 +382,48 @@ def test_path_completion_doesnt_match_wildcards(request):
382382 # Currently path completion doesn't accept wildcards, so will always return empty results
383383 assert path_complete (text , line , begidx , endidx ) == []
384384
385- def test_path_completion_user_expansion ():
385+ def test_path_completion_invalid_syntax ():
386+ # Test a missing separator between a ~ and path
387+ text = ''
388+ line = 'shell fake ~Desktop'
389+ endidx = len (line )
390+ begidx = endidx - len (text )
391+
392+ assert path_complete (text , line , begidx , endidx ) == []
393+
394+ def test_path_completion_just_tilde ():
386395 # Run path with just a tilde
387396 text = ''
388- if sys .platform .startswith ('win' ):
389- line = 'shell dir ~{}' .format (text )
390- else :
391- line = 'shell ls ~{}' .format (text )
397+ line = 'shell fake ~'
392398 endidx = len (line )
393399 begidx = endidx - len (text )
394400 completions_tilde = path_complete (text , line , begidx , endidx )
395401
396- # Run path complete on the user's home directory
397- user_dir = os .path .expanduser ('~' )
402+ # Path complete should return a slash
403+ assert completions_tilde == [os .path .sep ]
404+
405+ def test_path_completion_user_expansion ():
406+ # Run path with a tilde and a slash
407+ text = ''
398408 if sys .platform .startswith ('win' ):
399- line = 'shell dir {}' . format ( user_dir )
409+ cmd = 'dir'
400410 else :
401- line = 'shell ls {}' .format (user_dir )
411+ cmd = 'ls'
412+
413+ line = 'shell {} ~{}' .format (cmd , os .path .sep )
414+ endidx = len (line )
415+ begidx = endidx - len (text )
416+ completions_tilde_slash = path_complete (text , line , begidx , endidx )
417+
418+ # Run path complete on the user's home directory
419+ user_dir = os .path .expanduser ('~' ) + os .path .sep
420+ line = 'shell {} {}' .format (cmd , user_dir )
402421 endidx = len (line )
403422 begidx = endidx - len (text )
404423 completions_home = path_complete (text , line , begidx , endidx )
405424
406425 # Verify that the results are the same in both cases
407- assert completions_tilde == completions_home
426+ assert completions_tilde_slash == completions_home
408427
409428def test_path_completion_directories_only (request ):
410429 test_dir = os .path .dirname (request .module .__file__ )
0 commit comments