@@ -359,7 +359,7 @@ def test_path_completion_cwd():
359
359
completions_empty = path_complete (text , line , begidx , endidx )
360
360
361
361
# Run path complete with path set to the CWD
362
- cwd = os .getcwd ()
362
+ cwd = os .getcwd () + os . path . sep
363
363
line = 'shell ls {}' .format (cwd )
364
364
endidx = len (line )
365
365
begidx = endidx - len (text )
@@ -382,29 +382,48 @@ def test_path_completion_doesnt_match_wildcards(request):
382
382
# Currently path completion doesn't accept wildcards, so will always return empty results
383
383
assert path_complete (text , line , begidx , endidx ) == []
384
384
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 ():
386
395
# Run path with just a tilde
387
396
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 ~'
392
398
endidx = len (line )
393
399
begidx = endidx - len (text )
394
400
completions_tilde = path_complete (text , line , begidx , endidx )
395
401
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 = ''
398
408
if sys .platform .startswith ('win' ):
399
- line = 'shell dir {}' . format ( user_dir )
409
+ cmd = 'dir'
400
410
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 )
402
421
endidx = len (line )
403
422
begidx = endidx - len (text )
404
423
completions_home = path_complete (text , line , begidx , endidx )
405
424
406
425
# Verify that the results are the same in both cases
407
- assert completions_tilde == completions_home
426
+ assert completions_tilde_slash == completions_home
408
427
409
428
def test_path_completion_directories_only (request ):
410
429
test_dir = os .path .dirname (request .module .__file__ )
0 commit comments