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

Code before:
    tmux.until { |lines| lines[-1].end_with?('> 31') }
    tmux.send_keys 'C-p'
    tmux.until { |lines| lines[-1].end_with?('> 22') }
    tmux.send_keys 'C-n'
    tmux.until { |lines| lines[-1].end_with?('> 31') }
    tmux.send_keys 0
    tmux.until { |lines| lines[-1].end_with?('> 310') }
    tmux.send_keys :Enter
    wait { File.exist?(history_file) && File.readlines(history_file) == %w[22 33 44 310].map { |e| e + $INPUT_RECORD_SEPARATOR } }

    # Respect --bind option
    tmux.send_keys "seq 100 | #{fzf(opts + ' --bind ctrl-p:next-history,ctrl-n:previous-history')}", :Enter
    tmux.until { |lines| lines[-2].include?('100/100') }
    tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'
    tmux.until { |lines| lines[-1].end_with?('33') }
    tmux.send_keys :Enter
  ensure
    File.unlink(history_file)
  end

  def test_execute
    output = '/tmp/fzf-test-execute'
    opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"]
    writelines(tempname, %w[foo'bar foo"bar foo$bar])
    tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter
    tmux.until { |lines| lines[-2] == '  3/3' }
    tmux.send_keys :Escape, :a
    tmux.send_keys :Escape, :a
    tmux.send_keys :Up
    tmux.send_keys :Escape, :b
    tmux.send_keys :Escape, :b
    tmux.send_keys :Up
    tmux.send_keys :C
    tmux.send_keys 'barfoo'
    tmux.until { |lines| lines[-2] == '  0/3' }
    tmux.send_keys :Escape, :a
    tmux.send_keys :Escape, :b
    wait do
      File.exist?(output) && File.readlines(output).map(&:chomp) == %w[/foo'bar/ /foo'bar/
                                                                       /foo"barfoo"bar/ /foo"barfoo"bar/
                                                                       /foo$barfoo$barfoo$bar/]
    end
  ensure
    begin
      File.unlink(output)
    rescue StandardError
      nil
    end
  end

  def test_execute_multi

Review comment (bug):
`execute` action switches to the alternate screen, so I was concerned that the keys we send may not register to fzf. But I could be wrong. Do you think it's fine without waits?


Code after:
    tmux.until { |lines| lines[-1].end_with?('> 31') }
    tmux.send_keys 'C-p'
    tmux.until { |lines| lines[-1].end_with?('> 22') }
    tmux.send_keys 'C-n'
    tmux.until { |lines| lines[-1].end_with?('> 31') }
    tmux.send_keys 0
    tmux.until { |lines| lines[-1].end_with?('> 310') }
    tmux.send_keys :Enter
    wait { File.exist?(history_file) && File.readlines(history_file) == %w[22 33 44 310].map { |e| e + $INPUT_RECORD_SEPARATOR } }

    # Respect --bind option
    tmux.send_keys "seq 100 | #{fzf(opts + ' --bind ctrl-p:next-history,ctrl-n:previous-history')}", :Enter
    tmux.until { |lines| lines[-2].include?('100/100') }
    tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'
    tmux.until { |lines| lines[-1].end_with?('33') }
    tmux.send_keys :Enter
  ensure
    File.unlink(history_file)
  end

  def test_execute
    output = '/tmp/fzf-test-execute'
    opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"]
    writelines(tempname, %w[foo'bar foo"bar foo$bar])
    tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter
    tmux.until { |lines| lines[-2] == '  3/3' }
    tmux.send_keys :Escape, :a
    tmux.send_keys :Escape, :a
    tmux.send_keys :Up
    tmux.send_keys :Escape, :b
    tmux.send_keys :Escape, :b
    tmux.send_keys :Up
    tmux.send_keys :C
    tmux.send_keys 'barfoo'
    tmux.until { |lines| lines[-2] == '  0/3' }
    tmux.send_keys :Escape, :a
    tmux.send_keys :Escape, :b
    wait do
      File.exist?(output) && File.readlines(output).map(&:chomp) == %w[
        /foo'bar/ /foo'bar/
        /foo"barfoo"bar/ /foo"barfoo"bar/
        /foo$barfoo$barfoo$bar/
      ]
    end
  ensure
    begin
      File.unlink(output)
    rescue StandardError
      nil
    end
  end