@@ -410,22 +410,6 @@ def test_basic_completion_nomatch(cmd2_app):
410410
411411 assert cmd2_app .basic_complete (text , line , begidx , endidx , food_item_strs ) == []
412412
413- def test_basic_completion_quoted (cmd2_app ):
414- text = 'Pi'
415- line = 'list_food -f "{}"' .format (text )
416- endidx = len (line ) - 1
417- begidx = endidx - len (text ) + 1
418-
419- assert cmd2_app .basic_complete (text , line , begidx , endidx , food_item_strs ) == ['Pizza' ]
420-
421- def test_basic_completion_unclosed_quote (cmd2_app ):
422- text = 'Pi'
423- line = 'list_food -f "{}' .format (text )
424- endidx = len (line )
425- begidx = endidx - len (text )
426-
427- assert cmd2_app .basic_complete (text , line , begidx , endidx , food_item_strs ) == ['Pizza' ]
428-
429413
430414def test_flag_based_completion_single (cmd2_app ):
431415 text = 'Pi'
@@ -476,6 +460,7 @@ def test_flag_based_callable_completer(cmd2_app, request):
476460 assert cmd2_app .flag_based_complete (text , line , begidx , endidx ,
477461 flag_dict ) == [text + 'onftest.py' ]
478462
463+
479464def test_index_based_completion_single (cmd2_app ):
480465 text = 'Foo'
481466 line = 'command Pizza {}' .format (text )
@@ -524,6 +509,74 @@ def test_index_based_callable_completer(cmd2_app, request):
524509 assert cmd2_app .index_based_complete (text , line , begidx , endidx , index_dict ) == [text + 'onftest.py' ]
525510
526511
512+ def test_tokens_for_completion_quoted (cmd2_app ):
513+ text = 'Pi'
514+ line = 'list_food "{}"' .format (text )
515+ endidx = len (line )
516+ begidx = endidx
517+
518+ expected_tokens = ['list_food' , 'Pi' , '' ]
519+ expected_raw_tokens = ['list_food' , '"Pi"' , '' ]
520+
521+ tokens , raw_tokens = cmd2_app .tokens_for_completion (line , begidx , endidx )
522+ assert expected_tokens == tokens
523+ assert expected_raw_tokens == raw_tokens
524+
525+ def test_tokens_for_completion_unclosed_quote (cmd2_app ):
526+ text = 'Pi'
527+ line = 'list_food "{}' .format (text )
528+ endidx = len (line )
529+ begidx = endidx - len (text )
530+
531+ expected_tokens = ['list_food' , 'Pi' ]
532+ expected_raw_tokens = ['list_food' , '"Pi' ]
533+
534+ tokens , raw_tokens = cmd2_app .tokens_for_completion (line , begidx , endidx )
535+ assert expected_tokens == tokens
536+ assert expected_raw_tokens == raw_tokens
537+
538+ def test_tokens_for_completion_redirect (cmd2_app ):
539+ text = '>>file'
540+ line = 'command | < {}' .format (text )
541+ endidx = len (line )
542+ begidx = endidx - len (text )
543+
544+ cmd2_app .allow_redirection = True
545+ expected_tokens = ['command' , '|' , '<' , '>>' , 'file' ]
546+ expected_raw_tokens = ['command' , '|' , '<' , '>>' , 'file' ]
547+
548+ tokens , raw_tokens = cmd2_app .tokens_for_completion (line , begidx , endidx )
549+ assert expected_tokens == tokens
550+ assert expected_raw_tokens == raw_tokens
551+
552+ def test_tokens_for_completion_quoted_redirect (cmd2_app ):
553+ text = '>file'
554+ line = 'command "{}' .format (text )
555+ endidx = len (line )
556+ begidx = endidx - len (text )
557+
558+ cmd2_app .allow_redirection = True
559+ expected_tokens = ['command' , '>file' ]
560+ expected_raw_tokens = ['command' , '">file' ]
561+
562+ tokens , raw_tokens = cmd2_app .tokens_for_completion (line , begidx , endidx )
563+ assert expected_tokens == tokens
564+ assert expected_raw_tokens == raw_tokens
565+
566+ def test_tokens_for_completion_redirect_off (cmd2_app ):
567+ text = '>file'
568+ line = 'command {}' .format (text )
569+ endidx = len (line )
570+ begidx = endidx - len (text )
571+
572+ cmd2_app .allow_redirection = False
573+ expected_tokens = ['command' , '>file' ]
574+ expected_raw_tokens = ['command' , '>file' ]
575+
576+ tokens , raw_tokens = cmd2_app .tokens_for_completion (line , begidx , endidx )
577+ assert expected_tokens == tokens
578+ assert expected_raw_tokens == raw_tokens
579+
527580def test_parseline_command_and_args (cmd2_app ):
528581 line = 'help history'
529582 command , args , out_line = cmd2_app .parseline (line )
0 commit comments