Repository: junegunn/fzf
File: test/test_shell_integration.rb (Ruby)

Code before:
    tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
    tmux.send_keys :Up, :Up
    tmux.until { |lines| refute_includes lines[-2], '(2)' }
    tmux.send_keys :Enter
    tmux.until do |lines|
      assert_match(/echo "bar\nfoo"/, lines.join("\n"))
      refute_match(/echo "trailing"/, lines.join("\n"))
    end
  end
end

# When Perl is not available on the system, fallback to using awk
class TestZshNoPerl < TestZsh
  def setup
    super
    disable_perl
  end

  def disable_perl
    tmux.send_keys "unset 'commands[perl]'", :Enter
    tmux.prepare
    # Verify perl is actually unset (0 = not found)
    tmux.send_keys 'echo ${+commands[perl]}', :Enter
    tmux.until { |lines| assert_equal '0', lines[-1] }
    tmux.prepare
  end
end

class TestFish < TestBase
  include TestShell

  def shell
    :fish
  end

  def new_shell
    tmux.send_keys 'env FZF_TMUX=1 FZF_DEFAULT_OPTS=--no-scrollbar fish', :Enter
    tmux.send_keys 'function fish_prompt; end; clear', :Enter
    tmux.until { |lines| assert_empty lines }
  end

  def set_var(name, val)
    tmux.prepare
    tmux.send_keys "set -g #{name} '#{val}'", :Enter
    tmux.prepare
  end

  def test_ctrl_r_multi
    tmux.send_keys ':', :Enter
    tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter
    tmux.prepare

Review comment (refactor):
I didn't want to duplicate the logic from `TestZsh` for running with `unset 'commands[perl]'`.

As an unwanted side effect, this now triggers not just the `test_ctrl_r_*` tests, but also unrelated tests.

```txt
TestZsh#test_alt_c = 0.28 s = .
TestZshNoPerl#test_ctrl_r_multi_selection = 0.56 s = .
TestZshNoPerl#test_ctrl_r_abort = 0.62 s = .
TestZshNoPerl#test_unset_completion = 0.59 s = .
TestZshNoPerl#test_ssh_completion = 0.47 s = .
TestZshNoPerl#test_file_completion_unicode = 0.38 s = .
TestZshNoPerl#test_ctrl_r = 0.84 s = .
TestZshNoPerl#test_dir_completion = 0.37 s = .
TestZshNoPerl#test_ctrl_r_multiline = 0.37 s = .
TestZshNoPerl#test_process_completion = 0.41 s = .
TestZshNoPerl#test_file_completion_root = 0.28 s = .
TestZshNoPerl#test_ctrl_t = 0.49 s = .
TestZshNoPerl#test_ctrl_r_accept_or_print_query = 0.69 s = .
TestZshNoPerl#test_file_completion = 0.70 s = .
TestZshNoPerl#test_alt_c_command = 0.62 s = .
TestZshNoPerl#test_ctrl_r_no_multi_selection = 0.70 s = .
TestZshNoPerl#test_ctrl_t_unicode = 0.52 s = .
TestZshNoPerl#test_custom_completion_api = 0.66 s = .
TestZshNoPerl#test_custom_completion = 0.36 s = .
TestZshNoPerl#test_complete_quoted_command = 0.78 s = .
TestZshNoPerl#test_completion_in_command_sequence = 1.55 s = .
TestZshNoPerl#test_alt_c = 0.42 s = .
TestRaw#test_raw_mode = 0.17 s =
```

Code after:
    tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
    tmux.send_keys '1 foobar'
    tmux.until { |lines| assert_equal 0, lines.match_count }
    tmux.send_keys :Enter
    tmux.until { |lines| assert_equal '1 foobar', lines[-1] }
  end

  test_perl_and_awk 'ctrl_r_multiline_index_collision' do
    # Leading number in multi-line history content is not confused with index
    prepare_ctrl_r_test
    tmux.send_keys "'line 1"
    tmux.until { |lines| assert_equal 1, lines.match_count }
    tmux.send_keys :Enter
    tmux.until do |lines|
      assert_equal ['echo "line 1', '2 line 2"'], lines[-2..]
    end
  end

  test_perl_and_awk 'ctrl_r_multi_selection' do
    prepare_ctrl_r_test
    tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
    tmux.send_keys :BTab, :BTab, :BTab
    tmux.until { |lines| assert_includes lines[-2], '(3)' }
    tmux.send_keys :Enter
    tmux.until do |lines|
      assert_equal ['cat <<EOF | wc -c', 'qux thud', 'EOF', 'echo "trailing_space "', 'echo "bar', 'foo"'], lines[-6..]
    end
  end

  test_perl_and_awk 'ctrl_r_no_multi_selection' do
    set_var('FZF_CTRL_R_OPTS', '--no-multi')
    prepare_ctrl_r_test
    tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
    tmux.send_keys :BTab, :BTab, :BTab
    tmux.until { |lines| refute_includes lines[-2], '(3)' }
    tmux.send_keys :Enter
    tmux.until do |lines|
      assert_equal ['cat <<EOF | wc -c', 'qux thud', 'EOF'], lines[-3..]
    end
  end
end

class TestFish < TestBase
  include TestShell

  def shell
    :fish
  end

  def new_shell
    tmux.send_keys 'env FZF_TMUX=1 FZF_DEFAULT_OPTS=--no-scrollbar fish', :Enter