@@ -356,9 +356,9 @@ def test_path_completion_user_expansion():
356356 # Run path with just a tilde
357357 text = ''
358358 if sys .platform .startswith ('win' ):
359- line = 'shell dir ~\ {}' .format (text )
359+ line = 'shell dir ~{}' .format (text )
360360 else :
361- line = 'shell ls ~/ {}' .format (text )
361+ line = 'shell ls ~{}' .format (text )
362362 endidx = len (line )
363363 begidx = endidx - len (text )
364364 completions_tilde = path_complete (text , line , begidx , endidx )
@@ -394,7 +394,15 @@ def test_path_completion_directories_only(request):
394394sport_item_strs = ['Bat' , 'Basket' , 'Basketball' , 'Football' ]
395395
396396# Dictionary used with flag based completion functions
397- flag_dict = {'-f' : food_item_strs , '-s' : sport_item_strs }
397+ flag_dict = \
398+ {
399+ '-f' : food_item_strs , # Tab-complete food items after -f flag in command line
400+ '--food' : food_item_strs , # Tab-complete food items after --food flag in command line
401+ '-s' : sport_item_strs , # Tab-complete sport items after -s flag in command line
402+ '--sport' : sport_item_strs , # Tab-complete sport items after --sport flag in command line
403+ '-o' : path_complete , # Tab-complete using path_complete function after -o flag in command line
404+ '--other' : path_complete , # Tab-complete using path_complete function after --other flag in command line
405+ }
398406
399407def test_flag_based_completion_single_end ():
400408 text = 'Pi'
@@ -438,8 +446,33 @@ def test_flag_based_default_completer(request):
438446
439447 assert flag_based_complete (text , line , begidx , endidx , flag_dict , path_complete ) == ['conftest.py ' ]
440448
449+ def test_flag_based_callable_completer (request ):
450+ test_dir = os .path .dirname (request .module .__file__ )
451+
452+ text = 'c'
453+ path = os .path .join (test_dir , text )
454+ line = 'list_food -o {}' .format (path )
455+
456+ endidx = len (line )
457+ begidx = endidx - len (text )
458+
459+ assert flag_based_complete (text , line , begidx , endidx , flag_dict , path_complete ) == ['conftest.py ' ]
460+
461+ def test_flag_based_completion_syntax_err ():
462+ text = 'Pi'
463+ line = 'list_food -f " Pi'
464+ endidx = len (line )
465+ begidx = endidx - len (text )
466+
467+ assert flag_based_complete (text , line , begidx , endidx , flag_dict ) == []
468+
441469# Dictionary used with index based completion functions
442- index_dict = {1 : food_item_strs , 2 : sport_item_strs }
470+ index_dict = \
471+ {
472+ 1 : food_item_strs , # Tab-complete food items at index 1 in command line
473+ 2 : sport_item_strs , # Tab-complete sport items at index 2 in command line
474+ 3 : path_complete , # Tab-complete using path_complete function at index 3 in command line
475+ }
443476
444477def test_index_based_completion_single_end ():
445478 text = 'Foo'
@@ -474,14 +507,34 @@ def test_index_based_completion_nomatch():
474507def test_index_based_default_completer (request ):
475508 test_dir = os .path .dirname (request .module .__file__ )
476509
510+ text = 'c'
511+ path = os .path .join (test_dir , text )
512+ line = 'command Pizza Bat Computer {}' .format (path )
513+
514+ endidx = len (line )
515+ begidx = endidx - len (text )
516+
517+ assert index_based_complete (text , line , begidx , endidx , index_dict , path_complete ) == ['conftest.py ' ]
518+
519+ def test_index_based_callable_completer (request ):
520+ test_dir = os .path .dirname (request .module .__file__ )
521+
477522 text = 'c'
478523 path = os .path .join (test_dir , text )
479524 line = 'command Pizza Bat {}' .format (path )
480525
481526 endidx = len (line )
482527 begidx = endidx - len (text )
483528
484- assert flag_based_complete (text , line , begidx , endidx , flag_dict , path_complete ) == ['conftest.py ' ]
529+ assert index_based_complete (text , line , begidx , endidx , index_dict ) == ['conftest.py ' ]
530+
531+ def test_index_based_completion_syntax_err ():
532+ text = 'Foo'
533+ line = 'command "Pizza Foo'
534+ endidx = len (line )
535+ begidx = endidx - len (text )
536+
537+ assert index_based_complete (text , line , begidx , endidx , index_dict ) == []
485538
486539
487540def test_parseline_command_and_args (cmd2_app ):
@@ -727,7 +780,7 @@ def test_cmd2_help_subcommand_completion_single_mid(sc_app):
727780
728781def test_cmd2_help_subcommand_completion_multiple (sc_app ):
729782 text = ''
730- line = 'help base'
783+ line = 'help base '
731784 endidx = len (line )
732785 begidx = endidx - len (text )
733786 assert sc_app .complete_help (text , line , begidx , endidx ) == ['bar' , 'foo' ]
0 commit comments