@@ -465,6 +465,10 @@ def test_complete_quoted_command
465465
466466 def prepare_ctrl_r_test
467467 tmux . send_keys ':' , :Enter
468+ tmux . send_keys 'echo match-collision' , :Enter
469+ tmux . prepare
470+ tmux . send_keys 'echo "line 1' , :Enter , '2 line 2"' , :Enter
471+ tmux . prepare
468472 tmux . send_keys 'echo "foo' , :Enter , 'bar"' , :Enter
469473 tmux . prepare
470474 tmux . send_keys 'echo "bar' , :Enter , 'foo"' , :Enter
@@ -477,13 +481,24 @@ def prepare_ctrl_r_test
477481 end
478482
479483 def test_ctrl_r_accept_or_print_query
480- set_var ( 'FZF_CTRL_R_OPTS' , '--bind enter:accept-or-print-query' )
484+ set_var ( 'FZF_CTRL_R_OPTS' , '--bind enter:accept-or-print-query --exact ' )
481485 prepare_ctrl_r_test
482486 tmux . until { |lines | assert_operator lines . match_count , :> , 0 }
483- tmux . send_keys 'Lasciate ogni speranza... '
487+ tmux . send_keys 'foobar '
484488 tmux . until { |lines | assert_equal 0 , lines . match_count }
485489 tmux . send_keys :Enter
486- tmux . until { |lines | assert_equal 'Lasciate ogni speranza...' , lines [ -1 ] }
490+ tmux . until { |lines | assert_equal 'foobar' , lines [ -1 ] }
491+ end
492+
493+ def test_ctrl_r_multiline_index_collision
494+ # Leading number in multi-line history content is not confused with index
495+ prepare_ctrl_r_test
496+ tmux . send_keys "'line 1"
497+ tmux . until { |lines | assert_equal 1 , lines . match_count }
498+ tmux . send_keys :Enter
499+ tmux . until do |lines |
500+ assert_equal [ 'echo "line 1' , '2 line 2"' ] , lines [ -2 ..-1 ]
501+ end
487502 end
488503
489504 def test_ctrl_r_multi_selection
@@ -493,20 +508,19 @@ def test_ctrl_r_multi_selection
493508 tmux . until { |lines | assert_includes lines [ -2 ] , '(3)' }
494509 tmux . send_keys :Enter
495510 tmux . until do |lines |
496- assert_match ( / cat <<EOF \ | wc -c\n qux thud\n EOF \n echo "trailing"\n echo "bar\n foo"/ , lines . join ( " \n " ) )
511+ assert_equal [ ' cat <<EOF | wc -c' , 'qux thud' , 'EOF' , 'echo "trailing"' , 'echo "bar' , 'foo"' ] , lines [ - 6 ..- 1 ]
497512 end
498513 end
499514
500515 def test_ctrl_r_no_multi_selection
501516 set_var ( 'FZF_CTRL_R_OPTS' , '--no-multi' )
502517 prepare_ctrl_r_test
503518 tmux . until { |lines | assert_operator lines . match_count , :> , 0 }
504- tmux . send_keys :Up , :Up
505- tmux . until { |lines | refute_includes lines [ -2 ] , '(2 )' }
519+ tmux . send_keys :BTab , :BTab , :BTab
520+ tmux . until { |lines | refute_includes lines [ -2 ] , '(3 )' }
506521 tmux . send_keys :Enter
507522 tmux . until do |lines |
508- assert_match ( /echo "bar\n foo"/ , lines . join ( "\n " ) )
509- refute_match ( /echo "trailing"/ , lines . join ( "\n " ) )
523+ assert_equal [ 'cat <<EOF | wc -c' , 'qux thud' , 'EOF' ] , lines [ -3 ..-1 ]
510524 end
511525 end
512526end
0 commit comments