@@ -462,6 +462,84 @@ def test_complete_quoted_command
462462 tmux . send_keys 'C-c'
463463 end
464464 end
465+
466+ # Helper function to run test with Perl and again with Awk
467+ def self . test_perl_and_awk ( name , &block )
468+ define_method ( "test_#{ name } " ) do
469+ instance_eval ( &block )
470+ end
471+
472+ define_method ( "test_#{ name } _awk" ) do
473+ tmux . send_keys "unset 'commands[perl]'" , :Enter
474+ tmux . prepare
475+ # Verify perl is actually unset (0 = not found)
476+ tmux . send_keys 'echo ${+commands[perl]}' , :Enter
477+ tmux . until { |lines | assert_equal '0' , lines [ -1 ] }
478+ tmux . prepare
479+ instance_eval ( &block )
480+ end
481+ end
482+
483+ def prepare_ctrl_r_test
484+ tmux . send_keys ':' , :Enter
485+ tmux . send_keys 'echo match-collision' , :Enter
486+ tmux . prepare
487+ tmux . send_keys 'echo "line 1' , :Enter , '2 line 2"' , :Enter
488+ tmux . prepare
489+ tmux . send_keys 'echo "foo' , :Enter , 'bar"' , :Enter
490+ tmux . prepare
491+ tmux . send_keys 'echo "bar' , :Enter , 'foo"' , :Enter
492+ tmux . prepare
493+ tmux . send_keys 'echo "trailing_space "' , :Enter
494+ tmux . prepare
495+ tmux . send_keys 'cat <<EOF | wc -c' , :Enter , 'qux thud' , :Enter , 'EOF' , :Enter
496+ tmux . prepare
497+ tmux . send_keys 'C-l' , 'C-r'
498+ end
499+
500+ test_perl_and_awk 'ctrl_r_accept_or_print_query' do
501+ set_var ( 'FZF_CTRL_R_OPTS' , '--bind enter:accept-or-print-query' )
502+ prepare_ctrl_r_test
503+ tmux . until { |lines | assert_operator lines . match_count , :> , 0 }
504+ tmux . send_keys '1 foobar'
505+ tmux . until { |lines | assert_equal 0 , lines . match_count }
506+ tmux . send_keys :Enter
507+ tmux . until { |lines | assert_equal '1 foobar' , lines [ -1 ] }
508+ end
509+
510+ test_perl_and_awk 'ctrl_r_multiline_index_collision' do
511+ # Leading number in multi-line history content is not confused with index
512+ prepare_ctrl_r_test
513+ tmux . send_keys "'line 1"
514+ tmux . until { |lines | assert_equal 1 , lines . match_count }
515+ tmux . send_keys :Enter
516+ tmux . until do |lines |
517+ assert_equal [ 'echo "line 1' , '2 line 2"' ] , lines [ -2 ..]
518+ end
519+ end
520+
521+ test_perl_and_awk 'ctrl_r_multi_selection' do
522+ prepare_ctrl_r_test
523+ tmux . until { |lines | assert_operator lines . match_count , :> , 0 }
524+ tmux . send_keys :BTab , :BTab , :BTab
525+ tmux . until { |lines | assert_includes lines [ -2 ] , '(3)' }
526+ tmux . send_keys :Enter
527+ tmux . until do |lines |
528+ assert_equal [ 'cat <<EOF | wc -c' , 'qux thud' , 'EOF' , 'echo "trailing_space "' , 'echo "bar' , 'foo"' ] , lines [ -6 ..]
529+ end
530+ end
531+
532+ test_perl_and_awk 'ctrl_r_no_multi_selection' do
533+ set_var ( 'FZF_CTRL_R_OPTS' , '--no-multi' )
534+ prepare_ctrl_r_test
535+ tmux . until { |lines | assert_operator lines . match_count , :> , 0 }
536+ tmux . send_keys :BTab , :BTab , :BTab
537+ tmux . until { |lines | refute_includes lines [ -2 ] , '(3)' }
538+ tmux . send_keys :Enter
539+ tmux . until do |lines |
540+ assert_equal [ 'cat <<EOF | wc -c' , 'qux thud' , 'EOF' ] , lines [ -3 ..]
541+ end
542+ end
465543end
466544
467545class TestFish < TestBase
0 commit comments