2015-01-16 19:55:29 +00:00
|
|
|
|
#!/usr/bin/env ruby
|
2017-08-04 14:29:02 +00:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2015-01-16 19:55:29 +00:00
|
|
|
|
require 'minitest/autorun'
|
2015-02-28 18:00:36 +00:00
|
|
|
|
require 'fileutils'
|
2017-08-04 14:29:02 +00:00
|
|
|
|
require 'English'
|
|
|
|
|
require 'shellwords'
|
2020-02-28 06:38:39 +00:00
|
|
|
|
require 'erb'
|
|
|
|
|
require 'tempfile'
|
2022-12-20 16:29:19 +00:00
|
|
|
|
require 'net/http'
|
2023-09-03 07:30:35 +00:00
|
|
|
|
require 'json'
|
2020-02-28 06:38:39 +00:00
|
|
|
|
|
|
|
|
|
TEMPLATE = DATA.read
|
|
|
|
|
UNSETS = %w[
|
|
|
|
|
FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS
|
2020-10-23 10:54:45 +00:00
|
|
|
|
FZF_TMUX FZF_TMUX_OPTS
|
2020-02-28 06:38:39 +00:00
|
|
|
|
FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS
|
|
|
|
|
FZF_ALT_C_COMMAND
|
|
|
|
|
FZF_ALT_C_OPTS FZF_CTRL_R_OPTS
|
2023-07-20 14:42:09 +00:00
|
|
|
|
FZF_API_KEY
|
2020-02-28 06:38:39 +00:00
|
|
|
|
].freeze
|
2020-10-23 10:54:45 +00:00
|
|
|
|
DEFAULT_TIMEOUT = 10
|
2015-04-25 01:39:04 +00:00
|
|
|
|
|
2015-11-30 08:32:16 +00:00
|
|
|
|
FILE = File.expand_path(__FILE__)
|
2020-02-28 06:38:39 +00:00
|
|
|
|
BASE = File.expand_path('..', __dir__)
|
|
|
|
|
Dir.chdir(BASE)
|
2024-05-19 02:26:32 +00:00
|
|
|
|
FZF = "FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer \\> --marker \\>\" FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf"
|
2015-03-28 12:37:37 +00:00
|
|
|
|
|
2024-06-24 08:05:53 +00:00
|
|
|
|
def wait(timeout = DEFAULT_TIMEOUT)
|
2015-04-25 01:39:04 +00:00
|
|
|
|
since = Time.now
|
2020-04-21 01:12:00 +00:00
|
|
|
|
begin
|
2020-10-23 10:54:45 +00:00
|
|
|
|
yield or raise Minitest::Assertion, 'Assertion failure'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
rescue Minitest::Assertion
|
2024-06-24 08:05:53 +00:00
|
|
|
|
raise if Time.now - since > timeout
|
2020-04-12 15:23:31 +00:00
|
|
|
|
|
|
|
|
|
sleep(0.05)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
retry
|
2015-01-24 04:25:11 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
class Shell
|
|
|
|
|
class << self
|
|
|
|
|
def bash
|
2020-02-28 06:38:39 +00:00
|
|
|
|
@bash ||=
|
|
|
|
|
begin
|
|
|
|
|
bashrc = '/tmp/fzf.bash'
|
|
|
|
|
File.open(bashrc, 'w') do |f|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
f.puts ERB.new(TEMPLATE).result(binding)
|
2020-02-28 06:38:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
"bash --rcfile #{bashrc}"
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def zsh
|
2020-02-28 06:38:39 +00:00
|
|
|
|
@zsh ||=
|
|
|
|
|
begin
|
|
|
|
|
zdotdir = '/tmp/fzf-zsh'
|
|
|
|
|
FileUtils.rm_rf(zdotdir)
|
|
|
|
|
FileUtils.mkdir_p(zdotdir)
|
|
|
|
|
File.open("#{zdotdir}/.zshrc", 'w') do |f|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
f.puts ERB.new(TEMPLATE).result(binding)
|
2020-02-28 06:38:39 +00:00
|
|
|
|
end
|
|
|
|
|
"ZDOTDIR=#{zdotdir} zsh"
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
2016-08-13 10:26:36 +00:00
|
|
|
|
|
|
|
|
|
def fish
|
2024-06-12 04:56:20 +00:00
|
|
|
|
"unset #{UNSETS.join(' ')}; rm -f ~/.local/share/fish/fzf_test_history; FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer '>' --marker '>'\" fish_history=fzf_test fish"
|
2016-08-13 10:26:36 +00:00
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-16 19:55:29 +00:00
|
|
|
|
class Tmux
|
|
|
|
|
attr_reader :win
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def initialize(shell = :bash)
|
2020-02-28 11:06:38 +00:00
|
|
|
|
@win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first
|
|
|
|
|
go(%W[set-window-option -t #{@win} pane-base-index 0])
|
2017-08-04 14:29:02 +00:00
|
|
|
|
return unless shell == :fish
|
2020-02-28 06:38:39 +00:00
|
|
|
|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
send_keys 'function fish_prompt; end; clear', :Enter
|
2020-10-23 10:54:45 +00:00
|
|
|
|
self.until(&:empty?)
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def kill
|
2020-02-28 11:06:38 +00:00
|
|
|
|
go(%W[kill-window -t #{win}])
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2020-03-31 13:18:09 +00:00
|
|
|
|
def focus
|
|
|
|
|
go(%W[select-window -t #{win}])
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def send_keys(*args)
|
2020-03-31 13:18:09 +00:00
|
|
|
|
go(%W[send-keys -t #{win}] + args.map(&:to_s))
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def paste(str)
|
2020-02-21 00:51:34 +00:00
|
|
|
|
system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')
|
2016-07-10 03:27:01 +00:00
|
|
|
|
end
|
|
|
|
|
|
2020-03-31 13:18:09 +00:00
|
|
|
|
def capture
|
2020-04-17 17:34:38 +00:00
|
|
|
|
go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-06-24 08:05:53 +00:00
|
|
|
|
def until(refresh = false, timeout: DEFAULT_TIMEOUT)
|
2015-02-28 18:00:36 +00:00
|
|
|
|
lines = nil
|
2015-05-09 18:25:14 +00:00
|
|
|
|
begin
|
2024-06-24 08:05:53 +00:00
|
|
|
|
wait(timeout) do
|
2020-03-31 13:18:09 +00:00
|
|
|
|
lines = capture
|
2015-05-09 18:25:14 +00:00
|
|
|
|
class << lines
|
2017-01-07 16:30:31 +00:00
|
|
|
|
def counts
|
2017-08-04 14:29:02 +00:00
|
|
|
|
lazy
|
2020-10-23 11:44:04 +00:00
|
|
|
|
.map { |l| l.scan(%r{^. ([0-9]+)/([0-9]+)( \(([0-9]+)\))?}) }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
.reject(&:empty?)
|
|
|
|
|
.first&.first&.map(&:to_i)&.values_at(0, 1, 3) || [0, 0, 0]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def match_count
|
|
|
|
|
counts[0]
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-09 18:25:14 +00:00
|
|
|
|
def item_count
|
2017-01-07 16:30:31 +00:00
|
|
|
|
counts[1]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def select_count
|
|
|
|
|
counts[2]
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def any_include?(val)
|
2017-01-07 16:30:31 +00:00
|
|
|
|
method = val.is_a?(Regexp) ? :match : :include?
|
2020-04-12 15:23:31 +00:00
|
|
|
|
find { |line| line.send(method, val) }
|
2015-05-09 18:25:14 +00:00
|
|
|
|
end
|
2015-04-24 16:09:05 +00:00
|
|
|
|
end
|
2017-01-20 19:17:51 +00:00
|
|
|
|
yield(lines).tap do |ok|
|
|
|
|
|
send_keys 'C-l' if refresh && !ok
|
|
|
|
|
end
|
2015-04-24 16:09:05 +00:00
|
|
|
|
end
|
2020-04-21 01:12:00 +00:00
|
|
|
|
rescue Minitest::Assertion
|
2017-08-04 14:29:02 +00:00
|
|
|
|
puts $ERROR_INFO.backtrace
|
2015-05-09 18:25:14 +00:00
|
|
|
|
puts '>' * 80
|
|
|
|
|
puts lines
|
|
|
|
|
puts '<' * 80
|
|
|
|
|
raise
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
lines
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def prepare
|
2015-04-24 16:09:05 +00:00
|
|
|
|
tries = 0
|
|
|
|
|
begin
|
2021-01-13 01:52:15 +00:00
|
|
|
|
self.until(true) do |lines|
|
|
|
|
|
message = "Prepare[#{tries}]"
|
|
|
|
|
send_keys ' ', 'C-u', :Enter, message, :Left, :Right
|
|
|
|
|
lines[-1] == message
|
2016-10-21 15:01:21 +00:00
|
|
|
|
end
|
2020-04-21 01:12:00 +00:00
|
|
|
|
rescue Minitest::Assertion
|
2015-04-24 16:09:05 +00:00
|
|
|
|
(tries += 1) < 5 ? retry : raise
|
|
|
|
|
end
|
2021-01-13 01:52:15 +00:00
|
|
|
|
send_keys 'C-u', 'C-l'
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
2017-08-04 14:29:02 +00:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2020-02-28 11:06:38 +00:00
|
|
|
|
def go(args)
|
2020-04-12 15:23:31 +00:00
|
|
|
|
IO.popen(%w[tmux] + args) { |io| io.readlines(chomp: true) }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
class TestBase < Minitest::Test
|
2024-05-25 02:53:09 +00:00
|
|
|
|
TEMPNAME = Dir::Tmpname.create(%w[fzf]) {}
|
|
|
|
|
FIFONAME = Dir::Tmpname.create(%w[fzf-fifo]) {}
|
2015-01-17 04:38:42 +00:00
|
|
|
|
|
2015-01-24 04:25:11 +00:00
|
|
|
|
attr_reader :tmux
|
2015-01-17 03:37:24 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
def writelines(lines)
|
|
|
|
|
File.write(TEMPNAME, lines.join("\n"))
|
|
|
|
|
end
|
|
|
|
|
|
2015-06-13 17:44:22 +00:00
|
|
|
|
def tempname
|
2024-05-25 02:53:09 +00:00
|
|
|
|
TEMPNAME
|
2015-06-13 17:44:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
def fzf_output
|
|
|
|
|
@thread.join.value.chomp.tap { @thread = nil }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
def fzf_output_lines
|
|
|
|
|
fzf_output.lines(chomp: true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
FileUtils.rm_f([TEMPNAME, FIFONAME])
|
|
|
|
|
File.mkfifo(FIFONAME)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
|
FileUtils.rm_f([TEMPNAME, FIFONAME])
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-10-31 01:56:24 +00:00
|
|
|
|
alias assert_equal_org assert_equal
|
|
|
|
|
def assert_equal(expected, actual)
|
|
|
|
|
# Ignore info separator
|
|
|
|
|
actual = actual&.sub(/\s*─+$/, '') if actual.is_a?(String) && actual&.match?(%r{\d+/\d+})
|
|
|
|
|
assert_equal_org(expected, actual)
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
# Run fzf with its output piped to a fifo
|
2015-01-29 08:37:35 +00:00
|
|
|
|
def fzf(*opts)
|
2024-05-25 02:53:09 +00:00
|
|
|
|
raise 'fzf_output not taken' if @thread
|
|
|
|
|
|
|
|
|
|
@thread = Thread.new { File.read(FIFONAME) }
|
|
|
|
|
fzf!(*opts) + " > #{FIFONAME}"
|
2015-02-18 03:07:54 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def fzf!(*opts)
|
2017-08-04 14:29:02 +00:00
|
|
|
|
opts = opts.map do |o|
|
2015-01-29 08:37:35 +00:00
|
|
|
|
case o
|
|
|
|
|
when Symbol
|
|
|
|
|
o = o.to_s
|
2017-08-04 14:29:02 +00:00
|
|
|
|
o.length > 1 ? "--#{o.tr('_', '-')}" : "-#{o}"
|
2015-01-29 08:37:35 +00:00
|
|
|
|
when String, Numeric
|
|
|
|
|
o.to_s
|
|
|
|
|
end
|
2017-08-04 14:29:02 +00:00
|
|
|
|
end.compact
|
2020-04-12 15:23:31 +00:00
|
|
|
|
"#{FZF} #{opts.join(' ')}"
|
2015-01-29 08:37:35 +00:00
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class TestGoFZF < TestBase
|
|
|
|
|
def setup
|
|
|
|
|
super
|
|
|
|
|
@tmux = Tmux.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def teardown
|
2024-05-25 02:53:09 +00:00
|
|
|
|
super
|
2015-02-28 18:00:36 +00:00
|
|
|
|
@tmux.kill
|
|
|
|
|
end
|
2015-01-29 08:37:35 +00:00
|
|
|
|
|
2015-01-16 19:55:29 +00:00
|
|
|
|
def test_vanilla
|
2015-01-29 08:37:35 +00:00
|
|
|
|
tmux.send_keys "seq 1 100000 | #{fzf}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '>', lines.last
|
|
|
|
|
assert_equal ' 100000/100000', lines[-2]
|
|
|
|
|
end
|
2015-01-16 19:55:29 +00:00
|
|
|
|
lines = tmux.capture
|
|
|
|
|
assert_equal ' 2', lines[-4]
|
|
|
|
|
assert_equal '> 1', lines[-3]
|
|
|
|
|
assert_equal ' 100000/100000', lines[-2]
|
|
|
|
|
assert_equal '>', lines[-1]
|
|
|
|
|
|
|
|
|
|
# Testing basic key bindings
|
|
|
|
|
tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'
|
2019-11-02 05:55:13 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal '> 3910', lines[-4]
|
|
|
|
|
assert_equal ' 391', lines[-3]
|
|
|
|
|
assert_equal ' 856/100000', lines[-2]
|
|
|
|
|
assert_equal '> 391', lines[-1]
|
2019-11-02 05:55:13 +00:00
|
|
|
|
end
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '3910', fzf_output
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_fzf_default_command
|
2015-11-03 13:49:32 +00:00
|
|
|
|
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> hello', lines[-3] }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal 'hello', fzf_output
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-06-30 16:13:15 +00:00
|
|
|
|
def test_fzf_default_command_failure
|
|
|
|
|
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], ' [Command failed: false] ─' }
|
2017-06-30 16:13:15 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-17 02:20:00 +00:00
|
|
|
|
def test_key_bindings
|
2015-04-14 13:23:11 +00:00
|
|
|
|
tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> foo bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-A
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-A', '('
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (foo bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# META-F
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys :Escape, :f, ')'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (foo) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-B
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-B', 'var'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (foovar) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# Left, CTRL-D
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys :Left, :Left, 'C-D'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (foovr) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# META-BS
|
|
|
|
|
tmux.send_keys :Escape, :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (r) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-Y
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-Y', 'C-Y'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> (foovfoovr) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# META-B
|
|
|
|
|
tmux.send_keys :Escape, :b, :Space, :Space
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( foovfoovr) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-F / Right
|
|
|
|
|
tmux.send_keys 'C-F', :Right, '/'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( fo/ovfoovr) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-H / BS
|
|
|
|
|
tmux.send_keys 'C-H', :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-bar', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-E
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-E', 'baz'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-U
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-U'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-Y
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-Y'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-W
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-W', 'bar-foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> ( fovfoovr) bar bar-foo', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# META-D
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, 'C-A', 'C-Y'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> bar( fovfoovr) bar -foo', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
|
|
|
|
|
# CTRL-M
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-M'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| refute_equal '>', lines.last }
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
2015-01-17 02:07:04 +00:00
|
|
|
|
|
2017-01-15 10:42:28 +00:00
|
|
|
|
def test_file_word
|
|
|
|
|
tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> --/foo bar/foo-bar/baz', lines.last }
|
2017-01-15 10:42:28 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
tmux.send_keys :Escape, :d
|
|
|
|
|
tmux.send_keys :Escape, :f
|
|
|
|
|
tmux.send_keys :Escape, :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> --///baz', lines.last }
|
2017-01-15 10:42:28 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-17 02:20:00 +00:00
|
|
|
|
def test_multi_order
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 10 | #{fzf(:multi)}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines.last }
|
2015-01-17 02:07:04 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2
|
|
|
|
|
'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6
|
|
|
|
|
:PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/10 (6)', lines[-2] }
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'C-M'
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[3 2 5 6 8 7], fzf_output_lines
|
2015-01-17 02:07:04 +00:00
|
|
|
|
end
|
2015-01-17 02:20:00 +00:00
|
|
|
|
|
2019-11-02 03:55:26 +00:00
|
|
|
|
def test_multi_max
|
|
|
|
|
tmux.send_keys "seq 1 10 | #{FZF} -m 3 --bind A:select-all,T:toggle-all --preview 'echo [{+}]/{}'", :Enter
|
|
|
|
|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
2019-11-02 03:55:26 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys '1'
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [1]/1 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 2/10 ')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys 'A'
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [1 10]/1 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 2/10 (2/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }
|
2019-11-02 03:55:26 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys 'T'
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [2 3 4]/1 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 (3/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
%w[T A].each do |key|
|
|
|
|
|
tmux.send_keys key
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [1 5 6]/1 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 (3/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :BTab
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [5 6]/2 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 (2/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
[:BTab, :BTab, 'A'].each do |key|
|
|
|
|
|
tmux.send_keys key
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [5 6 2]/3 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 (3/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys '2'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 1/10 (3/3)') }
|
2019-11-02 03:55:26 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys 'T'
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [5 6]/2 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 1/10 (2/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }
|
2019-11-02 03:55:26 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys 'A'
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines[1], ' [5 6 1]/1 '
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 (3/3)')
|
2019-11-02 03:55:26 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-27 08:38:06 +00:00
|
|
|
|
def test_multi_action
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --bind 'a:change-multi,b:change-multi(3),c:change-multi(xxx),d:change-multi(0)'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 ') }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0)') }
|
|
|
|
|
tmux.send_keys 'b'
|
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0/3)') }
|
|
|
|
|
tmux.send_keys :BTab
|
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (1/3)') }
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.send_keys :BTab
|
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }
|
|
|
|
|
tmux.send_keys 'd'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines[-2]&.start_with?(' 10/10 ') && !lines[-2]&.include?('(')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-17 02:20:00 +00:00
|
|
|
|
def test_with_nth
|
|
|
|
|
[true, false].each do |multi|
|
|
|
|
|
tmux.send_keys "(echo ' 1st 2nd 3rd/';
|
|
|
|
|
echo ' first second third/') |
|
2020-04-12 15:23:31 +00:00
|
|
|
|
#{fzf(multi && :multi, :x, :nth, 2, :with_nth, '2,-1,1')}",
|
2017-08-04 14:29:02 +00:00
|
|
|
|
:Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal multi ? ' 2/2 (0)' : ' 2/2', lines[-2] }
|
2015-01-17 02:20:00 +00:00
|
|
|
|
|
|
|
|
|
# Transformed list
|
|
|
|
|
lines = tmux.capture
|
|
|
|
|
assert_equal ' second third/first', lines[-4]
|
|
|
|
|
assert_equal '> 2nd 3rd/1st', lines[-3]
|
|
|
|
|
|
|
|
|
|
# However, the output must not be transformed
|
|
|
|
|
if multi
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal [' 1st 2nd 3rd/', ' first second third/'], fzf_output_lines
|
2015-01-17 02:20:00 +00:00
|
|
|
|
else
|
|
|
|
|
tmux.send_keys '^', '3'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/2', lines[-2] }
|
2015-01-17 02:20:00 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal [' 1st 2nd 3rd/'], fzf_output_lines
|
2015-01-17 02:20:00 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-17 03:21:38 +00:00
|
|
|
|
|
|
|
|
|
def test_scroll
|
|
|
|
|
[true, false].each do |rev|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(rev && :reverse)}", :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[rev ? 1 : -2] }
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys(*Array.new(110) { rev ? :Down : :Up })
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 100' }
|
2015-01-17 03:21:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '100', fzf_output
|
2015-01-17 03:21:38 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-17 03:37:24 +00:00
|
|
|
|
|
|
|
|
|
def test_select_1
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[5555 55], fzf_output_lines
|
2015-01-17 03:37:24 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_exit_0
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[555555], fzf_output_lines
|
2015-01-17 03:37:24 +00:00
|
|
|
|
end
|
2015-01-24 04:26:33 +00:00
|
|
|
|
|
2015-02-17 15:51:44 +00:00
|
|
|
|
def test_select_1_exit_0_fail
|
2017-08-04 14:29:02 +00:00
|
|
|
|
[:'0', :'1', %i[1 0]].each do |opt|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(:print_query, :multi, :q, 5, *opt)}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 5', lines.last }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[5 5 50 51], fzf_output_lines
|
2015-02-17 15:51:44 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-24 04:26:33 +00:00
|
|
|
|
def test_query_unicode
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.paste "(echo abc; echo $'\\352\\260\\200\\353\\202\\230\\353\\213\\244') | #{fzf(:query, "$'\\352\\260\\200\\353\\213\\244'")}"
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/2', lines[-2] }
|
2015-01-24 04:26:33 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[가나다], fzf_output_lines
|
2015-01-24 04:26:33 +00:00
|
|
|
|
end
|
2015-02-18 03:07:54 +00:00
|
|
|
|
|
|
|
|
|
def test_sync
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{FZF} --multi | awk '{print $1 $1}' | #{fzf(:sync)}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2015-02-18 03:07:54 +00:00
|
|
|
|
tmux.send_keys 9
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 19/100 (0)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2015-02-18 03:07:54 +00:00
|
|
|
|
tmux.send_keys 'C-K', :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[9090], fzf_output_lines
|
2015-02-18 03:07:54 +00:00
|
|
|
|
end
|
2015-02-25 16:42:15 +00:00
|
|
|
|
|
|
|
|
|
def test_tac
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (3)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[1000 999 998], fzf_output_lines
|
2015-02-25 16:42:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_tac_sort
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2015-02-25 16:42:15 +00:00
|
|
|
|
tmux.send_keys '99'
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 28/1000 (0)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 28/1000 (3)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[99 999 998], fzf_output_lines
|
2015-02-25 16:42:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_tac_nosort
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :no_sort, :multi)}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2015-02-25 16:42:15 +00:00
|
|
|
|
tmux.send_keys '00'
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/1000 (0)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/1000 (3)', lines[-2] }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[1000 900 800], fzf_output_lines
|
2015-02-25 16:42:15 +00:00
|
|
|
|
end
|
2015-03-28 17:59:32 +00:00
|
|
|
|
|
|
|
|
|
def test_expect
|
|
|
|
|
test = lambda do |key, feed, expected = key|
|
2024-05-06 16:06:42 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(:expect, key, :prompt, "[#{key}]")}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2015-03-28 17:59:32 +00:00
|
|
|
|
tmux.send_keys '55'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/100', lines[-2] }
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys(*feed)
|
2016-04-15 03:57:38 +00:00
|
|
|
|
tmux.prepare
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal [expected, '55'], fzf_output_lines
|
2015-03-28 17:59:32 +00:00
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
test.call('ctrl-t', 'C-T')
|
|
|
|
|
test.call('ctrl-t', 'Enter', '')
|
|
|
|
|
test.call('alt-c', %i[Escape c])
|
|
|
|
|
test.call('f1', 'f1')
|
|
|
|
|
test.call('f2', 'f2')
|
|
|
|
|
test.call('f3', 'f3')
|
|
|
|
|
test.call('f2,f4', 'f2', 'f2')
|
|
|
|
|
test.call('f2,f4', 'f4', 'f4')
|
|
|
|
|
test.call('alt-/', %i[Escape /])
|
2016-05-18 13:25:09 +00:00
|
|
|
|
%w[f5 f6 f7 f8 f9 f10].each do |key|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
test.call('f5,f6,f7,f8,f9,f10', key, key)
|
2016-05-18 13:25:09 +00:00
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
test.call('@', '@')
|
2015-03-28 17:59:32 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-05-22 11:39:09 +00:00
|
|
|
|
def test_expect_with_bound_actions
|
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf('--query 1 --print-query --expect z --bind z:up+up')}", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 20, lines.match_count }
|
|
|
|
|
tmux.send_keys('z')
|
2024-06-01 04:20:12 +00:00
|
|
|
|
assert_equal %w[1 z 1], fzf_output_lines
|
2024-05-22 11:39:09 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-03-28 17:59:32 +00:00
|
|
|
|
def test_expect_print_query
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf('--expect=alt-z', :print_query)}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2015-03-28 17:59:32 +00:00
|
|
|
|
tmux.send_keys '55'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/100', lines[-2] }
|
2015-03-28 17:59:32 +00:00
|
|
|
|
tmux.send_keys :Escape, :z
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[55 alt-z 55], fzf_output_lines
|
2015-03-28 17:59:32 +00:00
|
|
|
|
end
|
2015-03-31 11:52:16 +00:00
|
|
|
|
|
2016-09-17 19:45:21 +00:00
|
|
|
|
def test_expect_printable_character_print_query
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf('--expect=z --print-query')}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2016-09-17 19:45:21 +00:00
|
|
|
|
tmux.send_keys '55'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/100', lines[-2] }
|
2016-09-17 19:45:21 +00:00
|
|
|
|
tmux.send_keys 'z'
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[55 z 55], fzf_output_lines
|
2016-09-17 19:45:21 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-03-31 11:52:16 +00:00
|
|
|
|
def test_expect_print_query_select_1
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf('-q55 -1 --expect=alt-z --print-query')}", :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal ['55', '', '55'], fzf_output_lines
|
2015-03-31 11:52:16 +00:00
|
|
|
|
end
|
2015-03-31 13:05:02 +00:00
|
|
|
|
|
|
|
|
|
def test_toggle_sort
|
2015-05-21 12:06:52 +00:00
|
|
|
|
['--toggle-sort=ctrl-r', '--bind=ctrl-r:toggle-sort'].each do |opt|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 111 | #{fzf("-m +s --tac #{opt} -q11")}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 111', lines[-3] }
|
2015-05-21 12:06:52 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 4/111 -S (1)', lines[-2] }
|
2015-05-21 12:06:52 +00:00
|
|
|
|
tmux.send_keys 'C-R'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 11', lines[-3] }
|
2015-05-21 12:06:52 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 4/111 +S (2)', lines[-2] }
|
2015-05-21 12:06:52 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[111 11], fzf_output_lines
|
2015-05-21 12:06:52 +00:00
|
|
|
|
end
|
2015-03-31 13:05:02 +00:00
|
|
|
|
end
|
2015-04-14 12:45:37 +00:00
|
|
|
|
|
|
|
|
|
def test_unicode_case
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(%w[строКА1 СТРОКА2 строка3 Строка4])
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.lines(chomp: true)
|
|
|
|
|
assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_tiebreak
|
|
|
|
|
input = %w[
|
|
|
|
|
--foobar--------
|
|
|
|
|
-----foobar---
|
|
|
|
|
----foobar--
|
|
|
|
|
-------foobar-
|
|
|
|
|
]
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(input)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
|
|
|
|
|
by_length = %w[
|
|
|
|
|
----foobar--
|
|
|
|
|
-----foobar---
|
|
|
|
|
-------foobar-
|
|
|
|
|
--foobar--------
|
|
|
|
|
]
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.lines(chomp: true)
|
|
|
|
|
assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
|
|
|
|
|
by_begin = %w[
|
|
|
|
|
--foobar--------
|
|
|
|
|
----foobar--
|
|
|
|
|
-----foobar---
|
|
|
|
|
-------foobar-
|
|
|
|
|
]
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.lines(chomp: true)
|
|
|
|
|
assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
|
|
|
|
|
assert_equal %w[
|
|
|
|
|
-------foobar-
|
|
|
|
|
----foobar--
|
|
|
|
|
-----foobar---
|
|
|
|
|
--foobar--------
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.lines(chomp: true)
|
2016-01-12 18:07:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-09-07 00:58:18 +00:00
|
|
|
|
def test_tiebreak_index_begin
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines([
|
2020-04-12 15:23:31 +00:00
|
|
|
|
'xoxxxxxoxx',
|
|
|
|
|
'xoxxxxxox',
|
|
|
|
|
'xxoxxxoxx',
|
|
|
|
|
'xxxoxoxxx',
|
|
|
|
|
'xxxxoxox',
|
|
|
|
|
' xxoxoxxx'
|
|
|
|
|
])
|
2016-01-12 18:07:42 +00:00
|
|
|
|
|
2016-09-07 00:58:18 +00:00
|
|
|
|
assert_equal [
|
|
|
|
|
'xxxxoxox',
|
|
|
|
|
' xxoxoxxx',
|
|
|
|
|
'xxxoxoxxx',
|
|
|
|
|
'xxoxxxoxx',
|
|
|
|
|
'xoxxxxxox',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxoxx'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -foo < #{tempname}`.lines(chomp: true)
|
2016-01-12 18:07:42 +00:00
|
|
|
|
|
2016-09-07 00:58:18 +00:00
|
|
|
|
assert_equal [
|
|
|
|
|
'xxxoxoxxx',
|
|
|
|
|
'xxxxoxox',
|
|
|
|
|
' xxoxoxxx',
|
|
|
|
|
'xxoxxxoxx',
|
|
|
|
|
'xoxxxxxoxx',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxox'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -foo --tiebreak=index < #{tempname}`.lines(chomp: true)
|
2016-09-07 00:58:18 +00:00
|
|
|
|
|
|
|
|
|
# Note that --tiebreak=begin is now based on the first occurrence of the
|
|
|
|
|
# first character on the pattern
|
|
|
|
|
assert_equal [
|
|
|
|
|
' xxoxoxxx',
|
|
|
|
|
'xxxoxoxxx',
|
|
|
|
|
'xxxxoxox',
|
|
|
|
|
'xxoxxxoxx',
|
|
|
|
|
'xoxxxxxoxx',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxox'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -foo --tiebreak=begin < #{tempname}`.lines(chomp: true)
|
2016-01-12 18:07:42 +00:00
|
|
|
|
|
2016-09-07 00:58:18 +00:00
|
|
|
|
assert_equal [
|
|
|
|
|
' xxoxoxxx',
|
|
|
|
|
'xxxoxoxxx',
|
|
|
|
|
'xxxxoxox',
|
|
|
|
|
'xxoxxxoxx',
|
|
|
|
|
'xoxxxxxox',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxoxx'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -foo --tiebreak=begin,length < #{tempname}`.lines(chomp: true)
|
2015-04-16 05:19:28 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-02-02 17:14:14 +00:00
|
|
|
|
def test_tiebreak_begin_algo_v2
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['baz foo bar',
|
|
|
|
|
'foo bar baz'])
|
2017-02-02 17:14:14 +00:00
|
|
|
|
assert_equal [
|
|
|
|
|
'foo bar baz',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'baz foo bar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -fbar --tiebreak=begin --algo=v2 < #{tempname}`.lines(chomp: true)
|
2017-02-02 17:14:14 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-09-07 00:58:18 +00:00
|
|
|
|
def test_tiebreak_end
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['xoxxxxxxxx',
|
|
|
|
|
'xxoxxxxxxx',
|
|
|
|
|
'xxxoxxxxxx',
|
|
|
|
|
'xxxxoxxxx',
|
|
|
|
|
'xxxxxoxxx',
|
|
|
|
|
' xxxxoxxx'])
|
2016-01-13 16:32:03 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
2016-09-07 00:58:18 +00:00
|
|
|
|
' xxxxoxxx',
|
|
|
|
|
'xxxxoxxxx',
|
|
|
|
|
'xxxxxoxxx',
|
|
|
|
|
'xoxxxxxxxx',
|
|
|
|
|
'xxoxxxxxxx',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xxxoxxxxxx'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -fo < #{tempname}`.lines(chomp: true)
|
2016-01-13 16:32:03 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
2016-09-07 00:58:18 +00:00
|
|
|
|
'xxxxxoxxx',
|
|
|
|
|
' xxxxoxxx',
|
|
|
|
|
'xxxxoxxxx',
|
|
|
|
|
'xxxoxxxxxx',
|
|
|
|
|
'xxoxxxxxxx',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxxxx'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -fo --tiebreak=end < #{tempname}`.lines(chomp: true)
|
2016-01-13 16:32:03 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
2016-09-07 00:58:18 +00:00
|
|
|
|
'xxxxxoxxx',
|
2016-10-17 16:11:04 +00:00
|
|
|
|
' xxxxoxxx',
|
2016-09-07 00:58:18 +00:00
|
|
|
|
'xxxxoxxxx',
|
|
|
|
|
'xxxoxxxxxx',
|
|
|
|
|
'xxoxxxxxxx',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'xoxxxxxxxx'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)
|
2023-12-26 14:40:20 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['/bar/baz', '/foo/bar/baz'])
|
2023-12-26 14:40:20 +00:00
|
|
|
|
assert_equal [
|
|
|
|
|
'/foo/bar/baz',
|
2023-12-26 16:33:34 +00:00
|
|
|
|
'/bar/baz'
|
2023-12-26 14:40:20 +00:00
|
|
|
|
], `#{FZF} -fbaz --tiebreak=end < #{tempname}`.lines(chomp: true)
|
2016-01-13 16:32:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-08-01 14:13:24 +00:00
|
|
|
|
def test_tiebreak_length_with_nth
|
|
|
|
|
input = %w[
|
|
|
|
|
1:hell
|
|
|
|
|
123:hello
|
|
|
|
|
12345:he
|
|
|
|
|
1234567:h
|
|
|
|
|
]
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(input)
|
2015-08-01 14:13:24 +00:00
|
|
|
|
|
|
|
|
|
output = %w[
|
|
|
|
|
1:hell
|
|
|
|
|
12345:he
|
|
|
|
|
123:hello
|
|
|
|
|
1234567:h
|
|
|
|
|
]
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal output, `#{FZF} -fh < #{tempname}`.lines(chomp: true)
|
2015-08-01 14:13:24 +00:00
|
|
|
|
|
2017-06-02 04:25:35 +00:00
|
|
|
|
# Since 0.16.8, --nth doesn't affect --tiebreak
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.lines(chomp: true)
|
2015-10-02 09:40:20 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-08-02 04:44:55 +00:00
|
|
|
|
def test_tiebreak_chunk
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['1 foobarbaz ba',
|
|
|
|
|
'2 foobar baz',
|
|
|
|
|
'3 foo barbaz'])
|
2022-08-02 04:44:55 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
|
|
|
|
'3 foo barbaz',
|
|
|
|
|
'2 foobar baz',
|
2022-08-03 13:18:26 +00:00
|
|
|
|
'1 foobarbaz ba'
|
2022-08-02 04:44:55 +00:00
|
|
|
|
], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true)
|
2022-08-03 13:18:26 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
|
|
|
|
'1 foobarbaz ba',
|
|
|
|
|
'2 foobar baz',
|
|
|
|
|
'3 foo barbaz'
|
|
|
|
|
], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)
|
2022-11-18 07:18:11 +00:00
|
|
|
|
|
|
|
|
|
assert_equal [
|
|
|
|
|
'3 foo barbaz'
|
|
|
|
|
], `#{FZF} -f'!foobar' --tiebreak=chunk < #{tempname}`.lines(chomp: true)
|
2022-08-02 04:44:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-21 13:10:14 +00:00
|
|
|
|
def test_invalid_cache
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 2/3', lines[-2] }
|
2015-04-21 13:10:14 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 3/3', lines[-2] }
|
2015-04-21 13:10:14 +00:00
|
|
|
|
tmux.send_keys :D
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/3', lines[-2] }
|
2015-04-21 13:10:14 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-08 04:22:30 +00:00
|
|
|
|
def test_invalid_cache_query_type
|
2024-05-25 02:53:09 +00:00
|
|
|
|
command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{FZF}]
|
2017-08-08 04:22:30 +00:00
|
|
|
|
|
|
|
|
|
# Suffix match
|
|
|
|
|
tmux.send_keys command, :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 104, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys 'foo$'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys 'bar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
|
|
|
|
|
# Prefix match
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys command, :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 104, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys '^bar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys 'C-a', 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
|
|
|
|
|
# Exact match
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys command, :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 104, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys "'12"
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
tmux.send_keys 'C-a', 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-08-08 04:22:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-21 13:18:05 +00:00
|
|
|
|
def test_smart_case_for_each_term
|
|
|
|
|
assert_equal 1, `echo Foo bar | #{FZF} -x -f "foo Fbar" | wc -l`.to_i
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-20 12:25:15 +00:00
|
|
|
|
def test_bind
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:accept,u:up,T:toggle-up,t:toggle')}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2015-05-21 12:06:52 +00:00
|
|
|
|
tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j'
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[4 5 6 9], fzf_output_lines
|
2015-05-20 12:25:15 +00:00
|
|
|
|
end
|
2015-06-02 16:48:02 +00:00
|
|
|
|
|
2016-05-12 15:51:15 +00:00
|
|
|
|
def test_bind_print_query
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:print-query')}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2016-05-12 15:51:15 +00:00
|
|
|
|
tmux.send_keys 'print-my-query', 'C-j'
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[print-my-query], fzf_output_lines
|
2016-05-12 15:51:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 04:08:55 +00:00
|
|
|
|
def test_bind_replace_query
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1 1000 | #{fzf('--print-query --bind=ctrl-j:replace-query')}", :Enter
|
2017-12-01 04:08:55 +00:00
|
|
|
|
tmux.send_keys '1'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 272/1000', lines[-2] }
|
2017-12-01 04:08:55 +00:00
|
|
|
|
tmux.send_keys 'C-k', 'C-j'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 29/1000', lines[-2] }
|
|
|
|
|
tmux.until { |lines| assert_equal '> 10', lines[-1] }
|
2017-12-01 04:08:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-02 16:48:02 +00:00
|
|
|
|
def test_long_line
|
|
|
|
|
data = '.' * 256 * 1024
|
|
|
|
|
File.open(tempname, 'w') do |f|
|
|
|
|
|
f << data
|
|
|
|
|
end
|
2016-01-12 18:07:42 +00:00
|
|
|
|
assert_equal data, `#{FZF} -f . < #{tempname}`.chomp
|
2015-06-02 16:48:02 +00:00
|
|
|
|
end
|
2015-06-08 14:27:50 +00:00
|
|
|
|
|
2015-06-21 08:29:58 +00:00
|
|
|
|
def test_read0
|
2020-04-21 01:12:00 +00:00
|
|
|
|
lines = `find .`.lines(chomp: true)
|
2015-06-08 14:27:50 +00:00
|
|
|
|
assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal \
|
2017-08-04 14:29:02 +00:00
|
|
|
|
lines.last,
|
|
|
|
|
`find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp
|
2015-06-08 14:27:50 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-09 14:44:54 +00:00
|
|
|
|
def test_select_all_deselect_all_toggle_all
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi')}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (3)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys 'C-t'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (97)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys 'C-a'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (100)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (98)', lines[-2] }
|
2019-11-02 10:41:59 +00:00
|
|
|
|
tmux.send_keys '100'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2019-11-02 10:41:59 +00:00
|
|
|
|
tmux.send_keys 'C-d'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/100 (97)', lines[-2] }
|
2019-11-02 10:41:59 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys 'C-d'
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }
|
2019-11-02 10:41:59 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (2)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys 0
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/100 (2)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys 'C-a'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/100 (12)', lines[-2] }
|
2015-06-09 14:44:54 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2019-11-02 10:41:59 +00:00
|
|
|
|
assert_equal %w[1 2 10 20 30 40 50 60 70 80 90 100],
|
2024-05-25 02:53:09 +00:00
|
|
|
|
fzf_output_lines
|
2015-06-09 14:44:54 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-13 15:43:44 +00:00
|
|
|
|
def test_history
|
|
|
|
|
history_file = '/tmp/fzf-test-history'
|
|
|
|
|
|
|
|
|
|
# History with limited number of entries
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(history_file)
|
2015-06-18 16:03:25 +00:00
|
|
|
|
opts = "--history=#{history_file} --history-size=4"
|
2020-04-21 01:12:00 +00:00
|
|
|
|
input = %w[00 11 22 33 44]
|
2015-06-13 15:43:44 +00:00
|
|
|
|
input.each do |keys|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys keys
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/100', lines[-2] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists history_file
|
2023-01-12 14:37:23 +00:00
|
|
|
|
assert_equal input[1..], File.readlines(history_file, chomp: true)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
end
|
2015-06-13 15:43:44 +00:00
|
|
|
|
|
|
|
|
|
# Update history entries (not changed on disk)
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 'C-p'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 44', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 'C-p'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 33', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 3', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 1
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 31', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 'C-p'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 22', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 'C-n'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 31', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 0
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 310', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists history_file
|
|
|
|
|
assert_equal %w[22 33 44 310], File.readlines(history_file, chomp: true)
|
|
|
|
|
end
|
2015-06-13 15:43:44 +00:00
|
|
|
|
|
|
|
|
|
# Respect --bind option
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} #{opts} --bind ctrl-p:next-history,ctrl-n:previous-history", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100', lines[-2] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 33', lines[-1] }
|
2015-06-13 15:43:44 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
ensure
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(history_file)
|
2015-06-13 15:43:44 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-14 03:25:08 +00:00
|
|
|
|
def test_execute
|
|
|
|
|
output = '/tmp/fzf-test-execute'
|
2024-02-01 07:25:53 +00:00
|
|
|
|
opts = %[--bind "alt-a:execute(echo /{}/ >> #{output})+change-header(alt-a),alt-b:execute[echo /{}{}/ >> #{output}]+change-header(alt-b),C:execute(echo /{}{}{}/ >> #{output})+change-header(C)"]
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(%w[foo'bar foo"bar foo$bar])
|
|
|
|
|
tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter
|
2024-02-01 08:04:15 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.item_count }
|
2024-02-01 07:25:53 +00:00
|
|
|
|
|
|
|
|
|
ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-a')
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :b
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-b')
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.send_keys :Escape, :a
|
|
|
|
|
ready.call('alt-a')
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :b
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-b')
|
|
|
|
|
|
2015-06-14 03:25:08 +00:00
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.send_keys :C
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('C')
|
|
|
|
|
|
2016-06-07 17:04:40 +00:00
|
|
|
|
tmux.send_keys 'barfoo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/3', lines[-2] }
|
2024-02-01 07:25:53 +00:00
|
|
|
|
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-a')
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :b
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-b')
|
|
|
|
|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
wait do
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_path_exists output
|
|
|
|
|
assert_equal %w[
|
2024-02-01 07:25:53 +00:00
|
|
|
|
/foo'bar/ /foo'barfoo'bar/
|
|
|
|
|
/foo"bar/ /foo"barfoo"bar/
|
2020-04-17 17:34:38 +00:00
|
|
|
|
/foo$barfoo$barfoo$bar/
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], File.readlines(output, chomp: true)
|
2020-04-17 17:34:38 +00:00
|
|
|
|
end
|
2015-06-14 03:25:08 +00:00
|
|
|
|
ensure
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2015-06-14 03:25:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-08 16:42:01 +00:00
|
|
|
|
def test_execute_multi
|
|
|
|
|
output = '/tmp/fzf-test-execute-multi'
|
2024-02-01 07:25:53 +00:00
|
|
|
|
opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})+change-header(alt-a),alt-b:change-header(alt-b)"]
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(%w[foo'bar foo"bar foo$bar foobar])
|
|
|
|
|
tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }
|
|
|
|
|
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 4/4 (0)', lines[-2] }
|
2015-11-08 16:42:01 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-a')
|
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
ready.call('alt-b')
|
|
|
|
|
|
2015-11-08 16:42:01 +00:00
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }
|
2015-11-08 16:42:01 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-a')
|
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
ready.call('alt-b')
|
|
|
|
|
|
2015-11-08 16:42:01 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }
|
2015-11-08 16:42:01 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
2024-02-01 07:25:53 +00:00
|
|
|
|
ready.call('alt-a')
|
2020-04-17 17:34:38 +00:00
|
|
|
|
wait do
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_path_exists output
|
|
|
|
|
assert_equal [
|
2020-04-17 17:34:38 +00:00
|
|
|
|
%(foo'bar/foo'bar),
|
|
|
|
|
%(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar),
|
|
|
|
|
%(foo'bar foo"bar foobar/foo'bar foo"bar foobar)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], File.readlines(output, chomp: true)
|
2020-04-17 17:34:38 +00:00
|
|
|
|
end
|
2015-11-08 16:42:01 +00:00
|
|
|
|
ensure
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2015-11-08 16:42:01 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-01-27 07:38:42 +00:00
|
|
|
|
def test_execute_plus_flag
|
2017-08-04 14:29:02 +00:00
|
|
|
|
output = tempname + '.tmp'
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['foo bar', '123 456'])
|
2017-01-27 07:38:42 +00:00
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys "cat #{tempname} | #{FZF} --multi --bind 'x:execute-silent(echo {+}/{}/{+2}/{2} >> #{output})'", :Enter
|
2017-01-27 07:38:42 +00:00
|
|
|
|
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.send_keys 'xy'
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/2 (0)', lines[-2] }
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.send_keys 'xy'
|
|
|
|
|
tmux.until { |lines| assert_equal ' 0/2 (1)', lines[-2] }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal ' 2/2 (1)', lines[-2] }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.send_keys 'xy'
|
|
|
|
|
tmux.until { |lines| assert_equal ' 0/2 (2)', lines[-2] }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
wait do
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_path_exists output
|
|
|
|
|
assert_equal [
|
2020-04-17 17:34:38 +00:00
|
|
|
|
%(foo bar/foo bar/bar/bar),
|
|
|
|
|
%(123 456/foo bar/456/bar),
|
|
|
|
|
%(123 456 foo bar/foo bar/456 bar/bar)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
], File.readlines(output, chomp: true)
|
2020-04-17 17:34:38 +00:00
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
rescue StandardError
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2017-01-27 07:38:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-02-02 19:46:02 +00:00
|
|
|
|
def test_execute_shell
|
|
|
|
|
# Custom script to use as $SHELL
|
|
|
|
|
output = tempname + '.out'
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"])
|
2020-04-12 15:23:31 +00:00
|
|
|
|
system("chmod +x #{tempname}")
|
2016-02-02 19:46:02 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/1', lines[-2] }
|
2016-02-02 19:46:02 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/1', lines[-2] }
|
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists output
|
|
|
|
|
assert_equal ["-c / 'foo'bar"], File.readlines(output, chomp: true)
|
|
|
|
|
end
|
2016-02-02 19:46:02 +00:00
|
|
|
|
ensure
|
2023-01-30 12:39:18 +00:00
|
|
|
|
FileUtils.rm_f(output)
|
2016-02-02 19:46:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-16 14:14:57 +00:00
|
|
|
|
def test_cycle
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 8 | #{FZF} --cycle", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 8/8', lines[-2] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
tmux.send_keys :Down
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 8', lines[-10] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
tmux.send_keys :Down
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 7', lines[-9] }
|
2017-05-24 04:20:13 +00:00
|
|
|
|
tmux.send_keys :Up
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 8', lines[-10] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
tmux.send_keys :PgUp
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 8', lines[-10] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
tmux.send_keys :Up
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-3] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
tmux.send_keys :PgDn
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-3] }
|
2017-05-24 04:20:13 +00:00
|
|
|
|
tmux.send_keys :Down
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 8', lines[-10] }
|
2015-06-16 14:14:57 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-07-22 04:45:38 +00:00
|
|
|
|
def test_header_lines
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5')}", :Enter
|
2015-07-22 04:45:38 +00:00
|
|
|
|
2.times do
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 18/90', lines[-2]
|
|
|
|
|
assert_equal ' 1', lines[-3]
|
|
|
|
|
assert_equal ' 2', lines[-4]
|
|
|
|
|
assert_equal '> 50', lines[-13]
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '50', fzf_output
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_header_lines_reverse
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --reverse')}", :Enter
|
2015-07-22 04:45:38 +00:00
|
|
|
|
2.times do
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 18/90', lines[1]
|
|
|
|
|
assert_equal ' 1', lines[2]
|
|
|
|
|
assert_equal ' 2', lines[3]
|
|
|
|
|
assert_equal '> 50', lines[12]
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '50', fzf_output
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-06-09 16:41:50 +00:00
|
|
|
|
def test_header_lines_reverse_list
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --layout=reverse-list')}", :Enter
|
2018-06-09 16:41:50 +00:00
|
|
|
|
2.times do
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal '> 50', lines[0]
|
|
|
|
|
assert_equal ' 2', lines[-4]
|
|
|
|
|
assert_equal ' 1', lines[-3]
|
|
|
|
|
assert_equal ' 18/90', lines[-2]
|
2018-06-09 16:41:50 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '50', fzf_output
|
2018-06-09 16:41:50 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-07-22 04:45:38 +00:00
|
|
|
|
def test_header_lines_overflow
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--header-lines=200')}", :Enter
|
2015-07-22 12:22:59 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 0/0', lines[-2]
|
|
|
|
|
assert_equal ' 1', lines[-3]
|
2015-07-22 12:22:59 +00:00
|
|
|
|
end
|
2015-07-22 04:45:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '', fzf_output
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-07-22 12:24:02 +00:00
|
|
|
|
def test_header_lines_with_nth
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{fzf('--header-lines 5 --with-nth 1,1,1,1,1')}", :Enter
|
2015-07-22 12:24:02 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 95/95', lines[-2]
|
|
|
|
|
assert_equal ' 11111', lines[-3]
|
|
|
|
|
assert_equal ' 55555', lines[-7]
|
|
|
|
|
assert_equal '> 66666', lines[-8]
|
2015-07-22 12:24:02 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '6', fzf_output
|
2015-07-22 12:24:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-09-15 10:04:53 +00:00
|
|
|
|
def test_header
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})"], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2015-07-22 04:45:38 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 100/100', lines[-2]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]
|
|
|
|
|
assert_equal '> 1', lines[-8]
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-15 10:04:53 +00:00
|
|
|
|
def test_header_reverse
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --reverse], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2015-07-22 04:45:38 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 100/100', lines[1]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[2..6]
|
|
|
|
|
assert_equal '> 1', lines[7]
|
2018-06-09 16:41:50 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_header_reverse_list
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --layout=reverse-list], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2018-06-09 16:41:50 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 100/100', lines[-2]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]
|
|
|
|
|
assert_equal '> 1', lines[0]
|
2015-07-22 04:45:38 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-15 10:04:53 +00:00
|
|
|
|
def test_header_and_header_lines
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --header-lines 10 --header "$(head -5 #{FILE})"], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2015-09-15 10:04:53 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 90/90', lines[-2]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]
|
|
|
|
|
assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]
|
2015-09-15 10:04:53 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_header_and_header_lines_reverse
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --reverse --header-lines 10 --header "$(head -5 #{FILE})"], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2015-09-15 10:04:53 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 90/90', lines[1]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[2...7]
|
|
|
|
|
assert_equal (' 1'..' 10').to_a, lines[7...17]
|
2015-09-15 10:04:53 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-09 16:41:50 +00:00
|
|
|
|
def test_header_and_header_lines_reverse_list
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys %[seq 100 | #{FZF} --layout=reverse-list --header-lines 10 --header "$(head -5 #{FILE})"], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
header = File.readlines(FILE, chomp: true).take(5)
|
2018-06-09 16:41:50 +00:00
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ' 90/90', lines[-2]
|
|
|
|
|
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]
|
|
|
|
|
assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]
|
2018-06-09 16:41:50 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-25 13:11:15 +00:00
|
|
|
|
def test_toggle_header
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys "seq 4 | #{FZF} --header-lines 2 --header foo --bind space:toggle-header --header-first --height 10 --border rounded", :Enter
|
2023-07-25 13:11:15 +00:00
|
|
|
|
before = <<~OUTPUT
|
|
|
|
|
╭───────
|
|
|
|
|
│
|
|
|
|
|
│ 4
|
|
|
|
|
│ > 3
|
|
|
|
|
│ 2/2
|
|
|
|
|
│ >
|
|
|
|
|
│ 2
|
|
|
|
|
│ 1
|
|
|
|
|
│ foo
|
|
|
|
|
╰───────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(before, _1) }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
after = <<~OUTPUT
|
|
|
|
|
╭───────
|
|
|
|
|
│
|
|
|
|
|
│
|
|
|
|
|
│
|
|
|
|
|
│
|
|
|
|
|
│ 4
|
|
|
|
|
│ > 3
|
|
|
|
|
│ 2/2
|
|
|
|
|
│ >
|
|
|
|
|
╰───────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(after, _1) }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { assert_block(before, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-12 15:44:27 +00:00
|
|
|
|
def test_cancel
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --bind 2:cancel", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/10', lines[-2] }
|
2015-07-22 13:56:53 +00:00
|
|
|
|
tmux.send_keys '123'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '> 3', lines[-1]
|
|
|
|
|
assert_equal ' 1/10', lines[-2]
|
|
|
|
|
end
|
2015-07-23 12:05:33 +00:00
|
|
|
|
tmux.send_keys 'C-y', 'C-y'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 311', lines[-1] }
|
2015-07-23 12:05:33 +00:00
|
|
|
|
tmux.send_keys 2
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2015-07-22 13:56:53 +00:00
|
|
|
|
tmux.send_keys 2
|
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-26 14:02:04 +00:00
|
|
|
|
def test_margin
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '', lines[4]
|
|
|
|
|
assert_equal ' y', lines[5]
|
|
|
|
|
end
|
2015-07-26 14:02:04 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_margin_reverse
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --margin 7,5 --reverse", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000', lines[1 + 7] }
|
2015-07-26 14:02:04 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-09 16:41:50 +00:00
|
|
|
|
def test_margin_reverse_list
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3 --layout=reverse-list", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '', lines[4]
|
|
|
|
|
assert_equal ' > y', lines[5]
|
|
|
|
|
end
|
2018-06-09 16:41:50 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-30 08:35:03 +00:00
|
|
|
|
def test_tabstop
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(%W[f\too\tba\tr\tbaz\tbarfooq\tux])
|
2015-11-30 08:35:03 +00:00
|
|
|
|
{
|
|
|
|
|
1 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
2 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
3 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
4 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
5 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
6 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
7 => '> f oo ba r baz barfooq ux',
|
|
|
|
|
8 => '> f oo ba r baz barfooq ux',
|
2017-08-04 14:29:02 +00:00
|
|
|
|
9 => '> f oo ba r baz barfooq ux'
|
2015-11-30 08:35:03 +00:00
|
|
|
|
}.each do |ts, exp|
|
|
|
|
|
tmux.prepare
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys %(cat #{tempname} | fzf --tabstop=#{ts}), :Enter
|
|
|
|
|
tmux.until(true) do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal exp, lines[-3]
|
2017-08-04 14:29:02 +00:00
|
|
|
|
end
|
2015-11-30 08:35:03 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def test_with_nth_basic
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['hello world ', 'byebye'])
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal \
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'hello world ',
|
|
|
|
|
`#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 < #{tempname}`.chomp
|
2015-08-26 14:35:31 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_with_nth_ansi
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye'])
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal \
|
2017-08-04 14:29:02 +00:00
|
|
|
|
'hello world ',
|
|
|
|
|
`#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi < #{tempname}`.chomp
|
2015-08-26 14:35:31 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-08-28 12:23:10 +00:00
|
|
|
|
def test_with_nth_no_ansi
|
|
|
|
|
src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines([src, 'byebye'])
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal \
|
2017-08-04 14:29:02 +00:00
|
|
|
|
src,
|
|
|
|
|
`#{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi < #{tempname}`.chomp
|
2015-08-28 12:23:10 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-09-15 04:21:51 +00:00
|
|
|
|
def test_exit_0_exit_code
|
|
|
|
|
`echo foo | #{FZF} -q bar -0`
|
2017-08-04 14:29:02 +00:00
|
|
|
|
assert_equal 1, $CHILD_STATUS.exitstatus
|
2015-09-15 04:21:51 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_invalid_option
|
|
|
|
|
lines = `#{FZF} --foobar 2>&1`
|
2017-08-04 14:29:02 +00:00
|
|
|
|
assert_equal 2, $CHILD_STATUS.exitstatus
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes lines, 'unknown option: --foobar'
|
2015-09-15 04:21:51 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_filter_exitstatus
|
|
|
|
|
# filter / streaming filter
|
2017-08-04 14:29:02 +00:00
|
|
|
|
['', '--no-sort'].each do |opts|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_includes `echo foo | #{FZF} -f foo #{opts}`, 'foo'
|
2017-08-04 14:29:02 +00:00
|
|
|
|
assert_equal 0, $CHILD_STATUS.exitstatus
|
2015-09-15 04:21:51 +00:00
|
|
|
|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_empty `echo foo | #{FZF} -f bar #{opts}`
|
2017-08-04 14:29:02 +00:00
|
|
|
|
assert_equal 1, $CHILD_STATUS.exitstatus
|
2015-09-15 04:21:51 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_exitstatus_empty
|
|
|
|
|
{ '99' => '0', '999' => '1' }.each do |query, status|
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{ [10]/100}, lines[-2] }
|
2015-09-15 04:21:51 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal "--#{status}--", lines.last }
|
2015-09-15 04:21:51 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-03 13:49:32 +00:00
|
|
|
|
def test_default_extended
|
|
|
|
|
assert_equal '100', `seq 100 | #{FZF} -f "1 00$"`.chomp
|
|
|
|
|
assert_equal '', `seq 100 | #{FZF} -f "1 00$" +x`.chomp
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_exact
|
|
|
|
|
assert_equal 4, `seq 123 | #{FZF} -f 13`.lines.length
|
|
|
|
|
assert_equal 2, `seq 123 | #{FZF} -f 13 -e`.lines.length
|
|
|
|
|
assert_equal 4, `seq 123 | #{FZF} -f 13 +e`.lines.length
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-09 16:50:41 +00:00
|
|
|
|
def test_or_operator
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[1 5 10], `seq 10 | #{FZF} -f "1 | 5"`.lines(chomp: true)
|
2015-11-09 16:50:41 +00:00
|
|
|
|
assert_equal %w[1 10 2 3 4 5 6 7 8 9],
|
2020-04-21 01:12:00 +00:00
|
|
|
|
`seq 10 | #{FZF} -f '1 | !1'`.lines(chomp: true)
|
2015-11-09 16:50:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-03-01 18:06:21 +00:00
|
|
|
|
def test_hscroll_off
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['=' * 10_000 + '0123456789'])
|
2016-03-01 18:06:21 +00:00
|
|
|
|
[0, 3, 6].each do |off|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 < #{tempname}", :Enter
|
2024-08-27 10:39:09 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-3]&.end_with?((0..off).to_a.join + '··') }
|
2016-03-01 18:06:21 +00:00
|
|
|
|
tmux.send_keys '9'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-3]&.end_with?('789') }
|
2016-03-01 18:06:21 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-04-23 18:30:51 +00:00
|
|
|
|
def test_partial_caching
|
|
|
|
|
tmux.send_keys 'seq 1000 | fzf -e', :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }
|
2016-04-23 18:30:51 +00:00
|
|
|
|
tmux.send_keys 11
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 19/1000', lines[-2] }
|
2016-04-23 18:30:51 +00:00
|
|
|
|
tmux.send_keys 'C-a', "'"
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 28/1000', lines[-2] }
|
2016-04-23 18:30:51 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-17 17:06:52 +00:00
|
|
|
|
def test_jump
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump'")}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys 'C-j'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '5 5', lines[-7] }
|
|
|
|
|
tmux.until { |lines| assert_equal ' 6', lines[-8] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys '5'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 5', lines[-7] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' >5', lines[-7] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys 'C-j'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '5>5', lines[-7] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys '2'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 2', lines[-4] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' >2', lines[-4] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys 'C-j'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '5>5', lines[-7] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
|
|
|
|
|
# Press any key other than jump labels to cancel jump
|
|
|
|
|
tmux.send_keys '6'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-3] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>>1', lines[-3] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[5 2 1], fzf_output_lines
|
2016-05-17 17:06:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_jump_accept
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump-accept'")}", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys 'C-j'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '5 5', lines[-7] }
|
2016-05-17 17:06:52 +00:00
|
|
|
|
tmux.send_keys '3'
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal '3', fzf_output
|
2016-05-17 17:06:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-04-10 11:11:47 +00:00
|
|
|
|
def test_jump_events
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump,jump:preview(echo jumped to {}),jump-cancel:preview(echo jump cancelled at {})'", :Enter
|
2024-04-10 11:11:47 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }
|
|
|
|
|
tmux.send_keys 'C-j'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-7], '5 5' }
|
|
|
|
|
tmux.send_keys '3'
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { _1.include?('jumped to 3') }) }
|
|
|
|
|
tmux.send_keys 'C-j'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-7], '5 5' }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { _1.include?('jump cancelled at 3') }) }
|
|
|
|
|
end
|
|
|
|
|
|
2020-02-17 01:19:03 +00:00
|
|
|
|
def test_pointer
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter
|
2020-02-17 01:19:03 +00:00
|
|
|
|
# Assert that specified pointer is displayed
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>> 1', lines[-3] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_pointer_with_jump
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '>>'", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
tmux.send_keys 'C-j'
|
|
|
|
|
# Correctly padded jump label should appear
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '5 5', lines[-7] }
|
|
|
|
|
tmux.until { |lines| assert_equal ' 6', lines[-8] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
tmux.send_keys '5'
|
|
|
|
|
# Assert that specified pointer is displayed
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>> 5', lines[-7] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_marker
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --multi --marker '>>'", :Enter
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
tmux.send_keys :BTab
|
|
|
|
|
# Assert that specified marker is displayed
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' >>1', lines[-3] }
|
2020-02-17 01:19:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-06-11 10:59:12 +00:00
|
|
|
|
def test_preview
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | sed s/^2$// | #{FZF} -m --preview 'sleep 0.2; echo {{}-{+}}' --bind ?:toggle-preview), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }
|
2016-06-15 04:03:42 +00:00
|
|
|
|
tmux.send_keys :Up
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {-} ' }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '555'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '?'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| refute_includes lines[1], ' {555-555} ' }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '?'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }
|
2016-06-15 04:03:42 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-2]&.start_with?(' 28/1000 ') }
|
2016-06-15 04:03:42 +00:00
|
|
|
|
tmux.send_keys 'foobar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| refute_includes lines[1], ' {55-55} ' }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {-1} ' }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {3-1 } ' }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {4-1 3} ' }
|
2017-01-27 07:38:42 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {5-1 3 4} ' }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-01-30 13:05:34 +00:00
|
|
|
|
def test_toggle_preview_without_default_preview_command
|
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --bind 'space:preview(echo [{}]),enter:toggle-preview' --preview-window up,border-double), :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.match_count
|
|
|
|
|
refute_includes lines[1], '║ [1]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# toggle-preview should do nothing
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '║ [1]' }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
refute_includes lines[1], '║ [1]'
|
|
|
|
|
refute_includes lines[1], '║ [2]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines, '> 3'
|
|
|
|
|
refute_includes lines[1], '║ [3]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# One-off preview action
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '║ [3]' }
|
|
|
|
|
|
|
|
|
|
# toggle-preview to hide it
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '║ [3]' }
|
|
|
|
|
|
|
|
|
|
# toggle-preview again does nothing
|
|
|
|
|
tmux.send_keys :Enter, :Up
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines, '> 4'
|
|
|
|
|
refute_includes lines[1], '║ [4]'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-31 08:33:53 +00:00
|
|
|
|
def test_show_and_hide_preview
|
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --preview-window hidden,border-bold --preview 'echo [{}]' --bind 'a:show-preview,b:hide-preview'), :Enter
|
|
|
|
|
|
|
|
|
|
# Hidden by default
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.match_count
|
|
|
|
|
refute_includes lines[1], '┃ [1]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Show
|
|
|
|
|
tmux.send_keys :a
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '┃ [1]' }
|
|
|
|
|
|
|
|
|
|
# Already shown
|
|
|
|
|
tmux.send_keys :a
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '┃ [2]' }
|
|
|
|
|
|
|
|
|
|
# Hide
|
|
|
|
|
tmux.send_keys :b
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines, '> 3'
|
|
|
|
|
refute_includes lines[1], '┃ [3]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Already hidden
|
|
|
|
|
tmux.send_keys :b
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines, '> 4'
|
|
|
|
|
refute_includes lines[1], '┃ [4]'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Show it again
|
|
|
|
|
tmux.send_keys :a
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '┃ [4]' }
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-11 10:59:12 +00:00
|
|
|
|
def test_preview_hidden
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '?'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_match(/ {1-1-1-[0-9]+}/, lines[-2]) }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '555'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_match(/ {555-555-1-[0-9]+}/, lines[-2]) }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
tmux.send_keys '?'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 555', lines[-1] }
|
2016-06-11 10:59:12 +00:00
|
|
|
|
end
|
2017-01-23 15:23:16 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_size_0
|
2023-01-07 02:21:52 +00:00
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0 --bind space:toggle-preview), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal ' 100/100', lines[1]
|
|
|
|
|
assert_equal '> 1', lines[2]
|
|
|
|
|
end
|
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
|
|
|
|
assert_equal %w[1], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
2023-01-07 02:21:52 +00:00
|
|
|
|
tmux.send_keys :Space, :Down, :Down
|
|
|
|
|
tmux.until { |lines| assert_equal '> 3', lines[4] }
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
2023-01-07 02:21:52 +00:00
|
|
|
|
assert_equal %w[1], File.readlines(tempname, chomp: true)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
end
|
2023-01-07 02:21:52 +00:00
|
|
|
|
tmux.send_keys :Space, :Down
|
|
|
|
|
tmux.until { |lines| assert_equal '> 4', lines[5] }
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
2023-01-07 02:21:52 +00:00
|
|
|
|
assert_equal %w[1 3 4], File.readlines(tempname, chomp: true)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
end
|
2017-01-23 15:23:16 +00:00
|
|
|
|
end
|
2017-03-04 05:26:47 +00:00
|
|
|
|
|
2023-01-30 12:39:18 +00:00
|
|
|
|
def test_preview_size_0_hidden
|
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0,hidden --bind space:toggle-preview), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys :Down, :Down
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 3' }
|
|
|
|
|
wait { refute_path_exists tempname }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
|
|
|
|
assert_equal %w[3], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
wait do
|
|
|
|
|
assert_equal %w[3 4], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space, :Down
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 5' }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 6' }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
wait do
|
|
|
|
|
assert_equal %w[3 4 6], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-09 16:40:22 +00:00
|
|
|
|
def test_preview_flags
|
|
|
|
|
tmux.send_keys %(seq 10 | sed 's/^/:: /; s/$/ /' |
|
2019-02-18 16:12:57 +00:00
|
|
|
|
#{FZF} --multi --preview 'echo {{2}/{s2}/{+2}/{+s2}/{q}/{n}/{+n}}'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 //0/0} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys '123'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {////123//} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys 'C-u', '1'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 /1/0/0} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {10/10 /1/1 /1/9/0} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {10/10 /1 10/1 10 /1/9/0 9} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys '2'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /12//0 9} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys '3'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /123//0 9} ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-10-27 14:50:12 +00:00
|
|
|
|
def test_preview_file
|
|
|
|
|
tmux.send_keys %[(echo foo bar; echo bar foo) | #{FZF} --multi --preview 'cat {+f} {+f2} {+nf} {+fn}' --print0], :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }
|
2019-10-27 14:50:12 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }
|
2019-10-27 14:50:12 +00:00
|
|
|
|
tmux.send_keys :BTab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo barbar foobarfoo0101 ' }
|
2019-10-27 14:50:12 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-06-09 16:40:22 +00:00
|
|
|
|
def test_preview_q_no_match
|
2022-12-30 00:57:10 +00:00
|
|
|
|
tmux.send_keys %(: | #{FZF} --preview 'echo foo {q} foo'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
2022-12-30 00:57:10 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo foo' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys 'bar'
|
2022-12-30 00:57:10 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo bar foo' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2022-12-30 00:57:10 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo foo' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-12-05 09:45:55 +00:00
|
|
|
|
def test_preview_q_no_match_with_initial_query
|
|
|
|
|
tmux.send_keys %(: | #{FZF} --preview 'echo foo {q}{q}' --query foo), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foofoo ' }
|
2018-12-05 09:45:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-03-04 05:26:47 +00:00
|
|
|
|
def test_no_clear
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 10 | #{fzf('--no-clear --inline-info --height 5')}", :Enter
|
2017-07-18 11:50:38 +00:00
|
|
|
|
prompt = '> < 10/10'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal prompt, lines[-1] }
|
2017-03-04 05:26:47 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[1], fzf_output_lines
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal prompt, lines[-1] }
|
2017-03-04 05:26:47 +00:00
|
|
|
|
end
|
2017-05-22 08:07:05 +00:00
|
|
|
|
|
2019-11-14 15:39:29 +00:00
|
|
|
|
def test_info_hidden
|
2024-04-03 15:05:55 +00:00
|
|
|
|
tmux.send_keys 'seq 10 | fzf --info=hidden --no-separator', :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-2] }
|
2019-11-14 15:39:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-01-24 08:40:08 +00:00
|
|
|
|
def test_info_inline_separator
|
|
|
|
|
tmux.send_keys 'seq 10 | fzf --info=inline:___ --no-separator', :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal '> ___10/10', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-30 09:41:53 +00:00
|
|
|
|
def test_change_first_last
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --bind change:first,alt-Z:last), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
2017-05-22 08:07:05 +00:00
|
|
|
|
tmux.send_keys :Up
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 2', lines[-4] }
|
2017-05-22 08:07:05 +00:00
|
|
|
|
tmux.send_keys 1
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-3] }
|
2017-05-22 08:07:05 +00:00
|
|
|
|
tmux.send_keys :Up
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 10', lines[-4] }
|
2017-05-22 08:07:05 +00:00
|
|
|
|
tmux.send_keys 1
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 11', lines[-3] }
|
2020-12-30 09:41:53 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-3] }
|
|
|
|
|
tmux.send_keys :Escape, 'Z'
|
|
|
|
|
tmux.until { |lines| assert_equal '> 1000', lines[0] }
|
2017-05-22 08:07:05 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
2017-07-27 16:39:25 +00:00
|
|
|
|
|
2022-12-26 16:01:06 +00:00
|
|
|
|
def test_pos
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:pos(3),b:pos(-3),c:pos(1),d:pos(-1),e:pos(0)' --preview 'echo {}/{}'), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.send_keys :a
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 3/3' }
|
|
|
|
|
tmux.send_keys :b
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 998/998' }
|
|
|
|
|
tmux.send_keys :c
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 1/1' }
|
|
|
|
|
tmux.send_keys :d
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 1000/1000' }
|
|
|
|
|
tmux.send_keys :e
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 1/1' }
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-27 10:54:46 +00:00
|
|
|
|
def test_put
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:put+put,b:put+put(ravo)' --preview 'echo {q}/{q}'), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.send_keys :a
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' aa/aa' }
|
|
|
|
|
tmux.send_keys :b
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' aabravo/aabravo' }
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 17:27:02 +00:00
|
|
|
|
def test_accept_non_empty
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
# fzf doesn't exit since there's no selection
|
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys '999'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/1000', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[999 999], fzf_output_lines
|
2017-12-01 17:27:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_accept_non_empty_with_multi_selection
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | #{fzf('-m --print-query --bind enter:accept-non-empty')}), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000 (1)', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/1000 (1)', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
# fzf will exit in this case even though there's no match for the current query
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[foo 1], fzf_output_lines
|
2017-12-01 17:27:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_accept_non_empty_with_empty_list
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys %(: | #{fzf('-q foo --print-query --bind enter:accept-non-empty')}), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/0', lines[-2] }
|
2017-12-01 17:27:02 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
# fzf will exit anyway since input list is empty
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[foo], fzf_output_lines
|
2017-12-01 17:27:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-12-10 06:59:45 +00:00
|
|
|
|
def test_accept_or_print_query_without_match
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
2023-12-10 07:04:30 +00:00
|
|
|
|
tmux.send_keys 99_999
|
2023-12-10 06:59:45 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[99999], fzf_output_lines
|
2023-12-10 06:59:45 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_accept_or_print_query_with_match
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.send_keys '^99$'
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[99], fzf_output_lines
|
2023-12-10 06:59:45 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_accept_or_print_query_with_multi_selection
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.send_keys :BTab, :BTab, :BTab
|
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.select_count }
|
2023-12-10 07:04:30 +00:00
|
|
|
|
tmux.send_keys 99_999
|
2023-12-10 06:59:45 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal %w[1 2 3], fzf_output_lines
|
2023-12-10 06:59:45 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-27 16:39:25 +00:00
|
|
|
|
def test_preview_update_on_select
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),
|
|
|
|
|
:Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
2017-07-27 16:39:25 +00:00
|
|
|
|
tmux.send_keys 'a'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?(' 1 2 3 4 5 ') }) }
|
2017-07-27 16:39:25 +00:00
|
|
|
|
tmux.send_keys 'a'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| lines.each { |line| refute_includes line, ' 1 2 3 4 5 ' } }
|
2017-07-27 16:39:25 +00:00
|
|
|
|
end
|
2017-08-09 14:25:32 +00:00
|
|
|
|
|
|
|
|
|
def test_escaped_meta_characters
|
2020-04-12 15:23:31 +00:00
|
|
|
|
input = [
|
|
|
|
|
'foo^bar',
|
|
|
|
|
'foo$bar',
|
|
|
|
|
'foo!bar',
|
|
|
|
|
"foo'bar",
|
|
|
|
|
'foo bar',
|
|
|
|
|
'bar foo'
|
|
|
|
|
]
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(input)
|
2020-04-12 15:23:31 +00:00
|
|
|
|
|
|
|
|
|
assert_equal input.length, `#{FZF} -f'foo bar' < #{tempname}`.lines.length
|
|
|
|
|
assert_equal input.length - 1, `#{FZF} -f'^foo bar$' < #{tempname}`.lines.length
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ['foo bar'], `#{FZF} -f'foo\\ bar' < #{tempname}`.lines(chomp: true)
|
|
|
|
|
assert_equal ['foo bar'], `#{FZF} -f'^foo\\ bar$' < #{tempname}`.lines(chomp: true)
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal input.length - 1, `#{FZF} -f'!^foo\\ bar$' < #{tempname}`.lines.length
|
2017-08-10 03:40:53 +00:00
|
|
|
|
end
|
2018-12-19 14:05:29 +00:00
|
|
|
|
|
|
|
|
|
def test_inverse_only_search_should_not_sort_the_result
|
|
|
|
|
# Filter
|
2020-04-12 15:23:31 +00:00
|
|
|
|
assert_equal %w[aaaaa b ccc],
|
2020-04-21 01:12:00 +00:00
|
|
|
|
`printf '%s\n' aaaaa b ccc BAD | #{FZF} -f '!bad'`.lines(chomp: true)
|
2018-12-19 14:05:29 +00:00
|
|
|
|
|
|
|
|
|
# Interactive
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys %(printf '%s\n' aaaaa b ccc BAD | #{FZF} -q '!bad'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 4, lines.item_count
|
|
|
|
|
assert_equal 3, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.until { |lines| assert_equal '> aaaaa', lines[-3] }
|
|
|
|
|
tmux.until { |lines| assert_equal ' b', lines[-4] }
|
|
|
|
|
tmux.until { |lines| assert_equal ' ccc', lines[-5] }
|
2018-12-19 14:05:29 +00:00
|
|
|
|
end
|
2018-12-22 02:52:18 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_correct_tab_width_after_ansi_reset_code
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(["\x1b[31m+\x1b[m\t\x1b[32mgreen"])
|
2018-12-22 02:52:18 +00:00
|
|
|
|
tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' + green ' }
|
2018-12-22 02:52:18 +00:00
|
|
|
|
end
|
2019-11-10 04:13:45 +00:00
|
|
|
|
|
2021-01-02 15:00:40 +00:00
|
|
|
|
def test_disabled
|
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --query 333 --disabled --bind a:enable-search,b:disable-search,c:toggle-search --preview 'echo {} {q}'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 1 333 ' }
|
2019-11-10 04:13:45 +00:00
|
|
|
|
tmux.send_keys 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 1 333foo ' }
|
2021-01-02 15:00:40 +00:00
|
|
|
|
|
|
|
|
|
# Already disabled, no change
|
|
|
|
|
tmux.send_keys 'b'
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
|
|
|
|
|
# Enable search
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace, :BSpace, :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 333 333 ' }
|
|
|
|
|
|
|
|
|
|
# Toggle search -> disabled again, but retains the previous result
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.send_keys 'foo'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 333 333foo ' }
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
|
|
|
|
|
# Enabled, no match
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' 333foo ' }
|
2019-11-10 04:13:45 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload
|
2024-02-15 13:27:32 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq $FZF_QUERY),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 998, lines.match_count }
|
2019-11-10 04:13:45 +00:00
|
|
|
|
tmux.send_keys 'a'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 98, lines.item_count
|
|
|
|
|
assert_equal 98, lines.match_count
|
|
|
|
|
end
|
2019-11-10 04:13:45 +00:00
|
|
|
|
tmux.send_keys 'b'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 198, lines.item_count
|
|
|
|
|
assert_equal 198, lines.match_count
|
|
|
|
|
end
|
2019-11-11 15:57:19 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 198/198 (1/2)', lines[-2] }
|
2019-11-10 04:13:45 +00:00
|
|
|
|
tmux.send_keys '555'
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1/553 (0/2)', lines[-2] }
|
2019-11-10 04:13:45 +00:00
|
|
|
|
end
|
2019-12-06 13:34:30 +00:00
|
|
|
|
|
|
|
|
|
def test_reload_even_when_theres_no_match
|
|
|
|
|
tmux.send_keys %(: | #{FZF} --bind 'space:reload(seq 10)'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.item_count }
|
2019-12-06 13:34:30 +00:00
|
|
|
|
tmux.send_keys :Space
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
2019-12-06 13:34:30 +00:00
|
|
|
|
end
|
2019-12-06 13:34:45 +00:00
|
|
|
|
|
2024-04-27 09:36:37 +00:00
|
|
|
|
def test_reload_should_terminate_standard_input_stream
|
2024-04-25 07:42:13 +00:00
|
|
|
|
tmux.send_keys %(ruby -e "STDOUT.sync = true; loop { puts 1; sleep 0.1 }" | fzf --bind 'start:reload(seq 100)'), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
end
|
|
|
|
|
|
2019-12-06 13:34:45 +00:00
|
|
|
|
def test_clear_list_when_header_lines_changed_due_to_reload
|
|
|
|
|
tmux.send_keys %(seq 10 | #{FZF} --header 0 --header-lines 3 --bind 'space:reload(seq 1)'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines, ' 9' }
|
2019-12-06 13:34:45 +00:00
|
|
|
|
tmux.send_keys :Space
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| refute_includes lines, ' 9' }
|
2019-12-06 13:34:45 +00:00
|
|
|
|
end
|
2019-12-07 05:44:24 +00:00
|
|
|
|
|
|
|
|
|
def test_clear_query
|
|
|
|
|
tmux.send_keys %(: | #{FZF} --query foo --bind space:clear-query), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_equal '> foo', lines.last }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
tmux.send_keys 'C-a', 'bar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> barfoo', lines.last }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
tmux.send_keys :Space
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines.last }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-22 13:01:00 +00:00
|
|
|
|
def test_change_and_transform_header
|
|
|
|
|
[
|
|
|
|
|
'space:change-header:$(seq 4)',
|
|
|
|
|
'space:transform-header:seq 4'
|
|
|
|
|
].each_with_index do |binding, i|
|
|
|
|
|
tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "#{binding}"), :Enter
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> 3
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
bar
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> 3
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
next unless i.zero?
|
|
|
|
|
|
|
|
|
|
teardown
|
|
|
|
|
setup
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_change_header
|
|
|
|
|
tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "space:change-header:$(seq 4)"), :Enter
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> 3
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
bar
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> 3
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-17 09:59:16 +00:00
|
|
|
|
def test_change_query
|
|
|
|
|
tmux.send_keys %(: | #{FZF} --query foo --bind space:change-query:foobar), :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_equal '> foo', lines.last }
|
|
|
|
|
tmux.send_keys :Space, 'baz'
|
|
|
|
|
tmux.until { |lines| assert_equal '> foobarbaz', lines.last }
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-27 15:05:31 +00:00
|
|
|
|
def test_transform_query
|
|
|
|
|
tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal '> bar', lines[-1] }
|
|
|
|
|
tmux.send_keys 'C-r'
|
|
|
|
|
tmux.until { |lines| assert_equal '> rab', lines[-1] }
|
|
|
|
|
tmux.send_keys 'C-u'
|
|
|
|
|
tmux.until { |lines| assert_equal '> RAB', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-31 00:27:11 +00:00
|
|
|
|
def test_transform_prompt
|
|
|
|
|
tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal '> bar', lines[-1] }
|
|
|
|
|
tmux.send_keys 'C-r'
|
|
|
|
|
tmux.until { |lines| assert_equal '> rab', lines[-1] }
|
|
|
|
|
tmux.send_keys 'C-u'
|
|
|
|
|
tmux.until { |lines| assert_equal '> RAB', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-25 14:43:46 +00:00
|
|
|
|
def test_transform
|
|
|
|
|
tmux.send_keys %{#{FZF} --bind 'focus:transform:echo "change-prompt({fzf:action})"'}, :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 'start', lines[-1] }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal 'up', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
|
2019-12-07 05:44:24 +00:00
|
|
|
|
def test_clear_selection
|
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 100/100 (1)', lines[-2] }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
tmux.send_keys 'foo'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/100 (1)', lines[-2] }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
tmux.send_keys :Space
|
2020-10-20 11:04:06 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 0/100 (0)', lines[-2] }
|
2019-12-07 05:44:24 +00:00
|
|
|
|
end
|
2020-02-27 17:38:32 +00:00
|
|
|
|
|
|
|
|
|
def test_backward_delete_char_eof
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --bind 'bs:backward-delete-char/eof'", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }
|
2020-02-27 17:38:32 +00:00
|
|
|
|
tmux.send_keys '11'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 11', lines[-1] }
|
2020-02-27 17:38:32 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 1', lines[-1] }
|
2020-02-27 17:38:32 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2020-02-27 17:38:32 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
|
|
|
|
|
2020-03-03 11:55:29 +00:00
|
|
|
|
def test_strip_xterm_osc_sequence
|
|
|
|
|
%W[\x07 \x1b\\].each do |esc|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines([%(printf $1"\e]4;3;rgb:aa/bb/cc#{esc} "$2)])
|
2020-03-03 11:55:29 +00:00
|
|
|
|
File.chmod(0o755, tempname)
|
|
|
|
|
tmux.prepare
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys \
|
2020-03-03 11:55:29 +00:00
|
|
|
|
%(echo foo bar | #{FZF} --preview '#{tempname} {2} {1}'), :Enter
|
2020-04-12 15:23:31 +00:00
|
|
|
|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines.any_include?('bar foo') }
|
2020-03-03 11:55:29 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-11 13:35:24 +00:00
|
|
|
|
|
|
|
|
|
def test_keep_right
|
2024-05-19 16:33:33 +00:00
|
|
|
|
tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right --no-multi-line", :Enter
|
2023-03-25 01:23:05 +00:00
|
|
|
|
tmux.until { |lines| assert lines.any_include?('9999␊10000') }
|
2020-03-11 13:35:24 +00:00
|
|
|
|
end
|
2020-06-07 14:07:03 +00:00
|
|
|
|
|
|
|
|
|
def test_backward_eof
|
|
|
|
|
tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter
|
|
|
|
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }
|
|
|
|
|
tmux.send_keys 'x'
|
|
|
|
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 0 }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| lines.item_count == 100 && lines.match_count == 100 }
|
|
|
|
|
end
|
2020-06-21 13:41:33 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_bindings_with_default_preview
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --preview 'echo [{}]' --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter
|
|
|
|
|
tmux.until { |lines| lines.item_count == 10 }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[1]' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[11]' }
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[1]' }
|
|
|
|
|
tmux.send_keys 'b'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[111]' }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[2]' }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_preview_bindings_without_default_preview
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter
|
|
|
|
|
tmux.until { |lines| lines.item_count == 10 }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '1' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[11]' }
|
|
|
|
|
tmux.send_keys 'c' # does nothing
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[11]' }
|
|
|
|
|
tmux.send_keys 'b'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[111]' }
|
|
|
|
|
tmux.send_keys 9
|
|
|
|
|
tmux.until { |lines| lines.match_count == 1 }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '2' }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[111]' }
|
|
|
|
|
end
|
2020-07-26 15:15:25 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_scroll_begin_constant
|
|
|
|
|
tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+123", :Enter
|
2020-10-23 10:54:45 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{1/1}, lines[-2] }
|
2020-07-26 15:15:25 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{123.*123/1000}, lines[1] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_preview_scroll_begin_expr
|
|
|
|
|
tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{3}", :Enter
|
2020-10-23 10:54:45 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{1/1}, lines[-2] }
|
2020-07-26 15:15:25 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{321.*321/1000}, lines[1] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_preview_scroll_begin_and_offset
|
2020-08-02 01:02:11 +00:00
|
|
|
|
['echo foo 123 321', 'echo foo :123: 321'].each do |input|
|
|
|
|
|
tmux.send_keys "#{input} | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter
|
2020-10-23 10:54:45 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{1/1}, lines[-2] }
|
2020-08-02 01:02:11 +00:00
|
|
|
|
tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
end
|
2020-07-26 15:15:25 +00:00
|
|
|
|
end
|
2020-07-28 04:06:57 +00:00
|
|
|
|
|
|
|
|
|
def test_normalized_match
|
|
|
|
|
echoes = '(echo a; echo á; echo A; echo Á;)'
|
|
|
|
|
assert_equal %w[a á A Á], `#{echoes} | #{FZF} -f a`.lines.map(&:chomp)
|
|
|
|
|
assert_equal %w[á Á], `#{echoes} | #{FZF} -f á`.lines.map(&:chomp)
|
|
|
|
|
assert_equal %w[A Á], `#{echoes} | #{FZF} -f A`.lines.map(&:chomp)
|
|
|
|
|
assert_equal %w[Á], `#{echoes} | #{FZF} -f Á`.lines.map(&:chomp)
|
|
|
|
|
end
|
2020-10-23 12:37:20 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_clear_screen
|
|
|
|
|
tmux.send_keys %{seq 100 | #{FZF} --preview 'for i in $(seq 300); do (( i % 200 == 0 )) && printf "\\033[2J"; echo "[$i]"; sleep 0.001; done'}, :Enter
|
|
|
|
|
tmux.until { |lines| lines.item_count == 100 }
|
|
|
|
|
tmux.until { |lines| lines[1]&.include?('[200]') }
|
|
|
|
|
end
|
2020-12-04 11:34:41 +00:00
|
|
|
|
|
|
|
|
|
def test_change_prompt
|
|
|
|
|
tmux.send_keys "#{FZF} --bind 'a:change-prompt(a> ),b:change-prompt:b> ' --query foo", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal '> foo', lines[-1] }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_equal 'a> foo', lines[-1] }
|
|
|
|
|
tmux.send_keys 'b'
|
2020-12-04 11:39:44 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'b> foo', lines[-1] }
|
2020-12-04 11:34:41 +00:00
|
|
|
|
end
|
2020-12-05 12:16:35 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_window_follow
|
2023-01-12 14:12:26 +00:00
|
|
|
|
file = Tempfile.new('fzf-follow')
|
|
|
|
|
file.sync = true
|
|
|
|
|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --preview 'echo start; tail -f "#{file.path}"' --preview-window follow --bind 'up:preview-up,down:preview-down,space:change-preview-window:follow|nofollow' --preview-window '~4'), :Enter
|
2023-01-12 14:12:26 +00:00
|
|
|
|
tmux.until { |lines| lines.item_count == 100 }
|
|
|
|
|
|
|
|
|
|
# Write to the temporary file, and check if the preview window is showing
|
|
|
|
|
# the last line of the file
|
2024-02-01 08:04:15 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], 'start' }
|
2023-01-12 14:12:26 +00:00
|
|
|
|
3.times { file.puts _1 } # header lines
|
|
|
|
|
1000.times { file.puts _1 }
|
2024-02-01 08:04:15 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '/1004' }
|
2023-01-12 14:12:26 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], '999' }
|
|
|
|
|
|
|
|
|
|
# Scroll the preview window and fzf should stop following the file content
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], '998' }
|
|
|
|
|
file.puts 'foo', 'bar'
|
|
|
|
|
tmux.until do |lines|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
assert_includes lines[1], '/1006'
|
2023-01-12 14:12:26 +00:00
|
|
|
|
assert_includes lines[-2], '998'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Scroll back to the bottom and fzf should start following the file again
|
|
|
|
|
%w[999 foo bar].each do |item|
|
|
|
|
|
wait do
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], item }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
file.puts 'baz'
|
|
|
|
|
tmux.until do |lines|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
assert_includes lines[1], '/1007'
|
2023-01-12 14:12:26 +00:00
|
|
|
|
assert_includes lines[-2], 'baz'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Scroll upwards to stop following
|
|
|
|
|
tmux.send_keys :Up
|
2023-01-12 14:24:39 +00:00
|
|
|
|
wait { assert_includes lines[-2], 'bar' }
|
2023-01-12 14:12:26 +00:00
|
|
|
|
file.puts 'aaa'
|
|
|
|
|
tmux.until do |lines|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
assert_includes lines[1], '/1008'
|
2023-01-12 14:12:26 +00:00
|
|
|
|
assert_includes lines[-2], 'bar'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Manually enable following
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], 'aaa' }
|
|
|
|
|
file.puts 'bbb'
|
|
|
|
|
tmux.until do |lines|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
assert_includes lines[1], '/1009'
|
2023-01-12 14:12:26 +00:00
|
|
|
|
assert_includes lines[-2], 'bbb'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Disable following
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
file.puts 'ccc', 'ddd'
|
|
|
|
|
tmux.until do |lines|
|
2024-02-01 08:04:15 +00:00
|
|
|
|
assert_includes lines[1], '/1011'
|
2023-01-12 14:12:26 +00:00
|
|
|
|
assert_includes lines[-2], 'bbb'
|
|
|
|
|
end
|
2023-01-12 14:37:23 +00:00
|
|
|
|
rescue StandardError
|
2023-01-12 14:12:26 +00:00
|
|
|
|
file.close
|
|
|
|
|
file.unlink
|
2020-12-05 12:16:35 +00:00
|
|
|
|
end
|
2021-02-01 14:14:21 +00:00
|
|
|
|
|
|
|
|
|
def test_toggle_preview_wrap
|
|
|
|
|
tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo wrapped; echo 2nd line' --bind ctrl-w:toggle-preview-wrap", :Enter
|
|
|
|
|
2.times do
|
|
|
|
|
tmux.until { |lines| assert_includes lines[2], '2nd line' }
|
|
|
|
|
tmux.send_keys 'C-w'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines[2], 'wrapped'
|
|
|
|
|
assert_includes lines[3], '2nd line'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys 'C-w'
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-02-01 15:08:54 +00:00
|
|
|
|
|
|
|
|
|
def test_close
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], 'foo' }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], 'foo' }
|
|
|
|
|
tmux.send_keys '10'
|
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.send_keys 'C-l', 'closed'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], 'closed' }
|
|
|
|
|
end
|
2021-02-25 12:14:15 +00:00
|
|
|
|
|
|
|
|
|
def test_select_deselect
|
|
|
|
|
tmux.send_keys "seq 3 | #{FZF} --multi --bind up:deselect+up,down:select+down", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.match_count }
|
|
|
|
|
tmux.send_keys :Tab
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.select_count }
|
|
|
|
|
tmux.send_keys :Down, :Down
|
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
|
|
|
|
tmux.send_keys :Tab
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
|
|
|
|
tmux.send_keys :Down, :Down
|
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
|
|
|
|
end
|
2021-02-28 12:01:03 +00:00
|
|
|
|
|
|
|
|
|
def test_interrupt_execute
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-l:execute:echo executing {}; sleep 100'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-l'
|
|
|
|
|
tmux.until { |lines| assert lines.any_include?('executing 1') }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys 99
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
end
|
2021-03-06 05:48:48 +00:00
|
|
|
|
|
|
|
|
|
def test_kill_default_command_on_abort
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['#!/usr/bin/env bash',
|
2021-03-06 05:48:48 +00:00
|
|
|
|
"echo 'Started'",
|
|
|
|
|
'while :; do sleep 1; done'])
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("chmod +x #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys FZF.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter
|
2021-03-06 05:48:48 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.send_keys 'C-l', 'closed'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], 'closed' }
|
2024-05-25 02:53:09 +00:00
|
|
|
|
wait { refute system("pgrep -f #{tempname}") }
|
2021-03-06 05:48:48 +00:00
|
|
|
|
ensure
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("pkill -9 -f #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_kill_default_command_on_accept
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['#!/usr/bin/env bash',
|
2021-03-06 05:48:48 +00:00
|
|
|
|
"echo 'Started'",
|
|
|
|
|
'while :; do sleep 1; done'])
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("chmod +x #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter
|
2021-03-06 05:48:48 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal 'Started', fzf_output
|
|
|
|
|
wait { refute system("pgrep -f #{tempname}") }
|
2021-03-06 05:48:48 +00:00
|
|
|
|
ensure
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("pkill -9 -f #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_kill_reload_command_on_abort
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['#!/usr/bin/env bash',
|
2021-03-06 05:48:48 +00:00
|
|
|
|
"echo 'Started'",
|
|
|
|
|
'while :; do sleep 1; done'])
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("chmod +x #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1 3 | #{FZF} --bind 'ctrl-r:reload(#{tempname})'", :Enter
|
2021-03-06 05:48:48 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-r'
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
tmux.send_keys 'C-l', 'closed'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], 'closed' }
|
2024-05-25 02:53:09 +00:00
|
|
|
|
wait { refute system("pgrep -f #{tempname}") }
|
2021-03-06 05:48:48 +00:00
|
|
|
|
ensure
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("pkill -9 -f #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_kill_reload_command_on_accept
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['#!/usr/bin/env bash',
|
2021-03-06 05:48:48 +00:00
|
|
|
|
"echo 'Started'",
|
|
|
|
|
'while :; do sleep 1; done'])
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("chmod +x #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
|
2024-05-25 02:53:09 +00:00
|
|
|
|
tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{tempname})'")}", :Enter
|
2021-03-06 05:48:48 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-r'
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
|
|
|
|
tmux.send_keys :Enter
|
2024-05-25 02:53:09 +00:00
|
|
|
|
assert_equal 'Started', fzf_output
|
|
|
|
|
wait { refute system("pgrep -f #{tempname}") }
|
2021-03-06 05:48:48 +00:00
|
|
|
|
ensure
|
2024-05-25 02:53:09 +00:00
|
|
|
|
system("pkill -9 -f #{tempname}")
|
2021-03-06 05:48:48 +00:00
|
|
|
|
end
|
2021-03-12 10:51:28 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_header
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind ctrl-k:preview-up+preview-up,ctrl-j:preview-down+preview-down+preview-down --preview 'seq 1000' --preview-window 'top:+{1}:~3'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
top5 = ->(lines) { lines.drop(1).take(5).map { |s| s[/[0-9]+/] } }
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines[1], '4/1000'
|
|
|
|
|
assert_equal(%w[1 2 3 4 5], top5[lines])
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys '55'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert_equal(%w[1 2 3 55 56], top5[lines])
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys 'C-J'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal(%w[1 2 3 58 59], top5[lines])
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 19, lines.match_count
|
|
|
|
|
assert_equal(%w[1 2 3 5 6], top5[lines])
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys 'C-K'
|
|
|
|
|
tmux.until { |lines| assert_equal(%w[1 2 3 4 5], top5[lines]) }
|
|
|
|
|
end
|
2021-05-22 04:13:55 +00:00
|
|
|
|
|
2022-04-04 12:54:22 +00:00
|
|
|
|
def test_unbind_rebind
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind 'c:clear-query,d:unbind(c,d),e:rebind(c,d)'", :Enter
|
2021-05-22 04:13:55 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys 'ab'
|
|
|
|
|
tmux.until { |lines| assert_equal '> ab', lines[-1] }
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
|
|
|
|
tmux.send_keys 'dabcd'
|
|
|
|
|
tmux.until { |lines| assert_equal '> abcd', lines[-1] }
|
2022-04-04 12:54:22 +00:00
|
|
|
|
tmux.send_keys 'ecabddc'
|
|
|
|
|
tmux.until { |lines| assert_equal '> abdc', lines[-1] }
|
2021-05-22 04:13:55 +00:00
|
|
|
|
end
|
2021-09-14 07:58:26 +00:00
|
|
|
|
|
|
|
|
|
def test_item_index_reset_on_reload
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --preview 'echo [[{n}]]' --bind 'up:last,down:first,space:reload:seq 100'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[[0]]' }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[[9]]' }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[[0]]' }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_includes lines[1], '[[0]]'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '[[99]]' }
|
|
|
|
|
end
|
2021-10-22 16:06:15 +00:00
|
|
|
|
|
|
|
|
|
def test_reload_should_update_preview
|
|
|
|
|
tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload:echo 4' --preview 'echo {}' --preview-window 'nohidden'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '1' }
|
|
|
|
|
tmux.send_keys 'C-t'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '4' }
|
2022-03-29 13:25:48 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_and_change_preview_should_update_preview
|
|
|
|
|
tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload(echo 4)+change-preview(echo {})'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.item_count }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '1' }
|
|
|
|
|
tmux.send_keys 'C-t'
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '4' }
|
2021-10-22 16:06:15 +00:00
|
|
|
|
end
|
2021-11-02 12:18:29 +00:00
|
|
|
|
|
2022-12-29 11:03:51 +00:00
|
|
|
|
def test_reload_sync
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind 'load:reload-sync(sleep 1; seq 1000)+unbind(load)'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys '00'
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
# After 1 second
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-27 08:25:56 +00:00
|
|
|
|
def test_reload_disabled_case1
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)'", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_disabled_case2
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)'", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_disabled_case3
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)+backward-delete-char'", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_disabled_case4
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)+backward-delete-char'", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_disabled_case5
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(echo xx; sleep 2; seq 1000)'", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 100, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 1001, lines.match_count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reload_disabled_case6
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --disabled --bind 'change:reload:sleep 0.5; seq {q}'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
|
|
|
|
tmux.send_keys '9'
|
|
|
|
|
tmux.until { |lines| assert_equal 9, lines.match_count }
|
|
|
|
|
tmux.send_keys '9'
|
|
|
|
|
tmux.until { |lines| assert_equal 99, lines.match_count }
|
|
|
|
|
|
2024-03-27 08:36:08 +00:00
|
|
|
|
# TODO: How do we verify if an intermediate empty list is not shown?
|
2024-03-27 08:25:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
2021-11-02 12:18:29 +00:00
|
|
|
|
def test_scroll_off
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.item_count }
|
|
|
|
|
height = tmux.until { |lines| lines }.first.to_i
|
|
|
|
|
tmux.send_keys :PgUp
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal height + 3, lines.first.to_i
|
|
|
|
|
assert_equal "> #{height}", lines[3].strip
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{height + 1}", lines[3].strip }
|
|
|
|
|
tmux.send_keys 'l'
|
|
|
|
|
tmux.until { |lines| assert_equal '> 1000', lines.first.strip }
|
|
|
|
|
tmux.send_keys :PgDn
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{1000 - height + 1}", lines.reverse[5].strip }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{1000 - height}", lines.reverse[5].strip }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_scroll_off_large
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.item_count }
|
|
|
|
|
height = tmux.until { |lines| lines }.first.to_i
|
|
|
|
|
tmux.send_keys :PgUp
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip }
|
|
|
|
|
tmux.send_keys :Down
|
|
|
|
|
tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }
|
|
|
|
|
end
|
2021-11-03 12:19:22 +00:00
|
|
|
|
|
|
|
|
|
def test_header_first
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> 4
|
|
|
|
|
997/997
|
|
|
|
|
>
|
|
|
|
|
3
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
foobar
|
|
|
|
|
OUTPUT
|
|
|
|
|
|
|
|
|
|
assert_equal expected.chomp, lines.reverse.take(7).reverse.join("\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_header_first_reverse
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first --reverse --inline-info", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
foobar
|
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
> < 997/997
|
|
|
|
|
> 4
|
|
|
|
|
OUTPUT
|
|
|
|
|
|
|
|
|
|
assert_equal expected.chomp, lines.take(6).join("\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-11-30 14:37:48 +00:00
|
|
|
|
|
|
|
|
|
def test_change_preview_window
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --preview 'echo [[{}]]' --preview-window border-none --bind '" \
|
|
|
|
|
'a:change-preview(echo __{}__),' \
|
|
|
|
|
'b:change-preview-window(down)+change-preview(echo =={}==)+change-preview-window(up),' \
|
|
|
|
|
'c:change-preview(),d:change-preview-window(hidden),' \
|
|
|
|
|
"e:preview(printf ::%${FZF_PREVIEW_COLUMNS}s{})+change-preview-window(up),f:change-preview-window(up,wrap)'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1000, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], '[[1]]' }
|
|
|
|
|
|
|
|
|
|
# change-preview action permanently changes the preview command set by --preview
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], '__1__' }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines[0], '__2__' }
|
|
|
|
|
|
|
|
|
|
# When multiple change-preview-window actions are bound to a single key,
|
|
|
|
|
# the last one wins and the updated options are immediately applied to the new preview
|
|
|
|
|
tmux.send_keys 'b'
|
|
|
|
|
tmux.until { |lines| assert_equal '==2==', lines[0] }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_equal '==3==', lines[0] }
|
|
|
|
|
|
|
|
|
|
# change-preview with an empty preview command closes the preview window
|
|
|
|
|
tmux.send_keys 'c'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[0], '==' }
|
|
|
|
|
|
|
|
|
|
# change-preview again to re-open the preview window
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_equal '__3__', lines[0] }
|
|
|
|
|
|
|
|
|
|
# Hide the preview window with hidden flag
|
|
|
|
|
tmux.send_keys 'd'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[0], '__3__' }
|
|
|
|
|
|
|
|
|
|
# One-off preview
|
|
|
|
|
tmux.send_keys 'e'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '::', lines[0]
|
|
|
|
|
refute_includes lines[1], '3'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Wrapped
|
|
|
|
|
tmux.send_keys 'f'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal '::', lines[0]
|
|
|
|
|
assert_equal ' 3', lines[1]
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-12-04 02:46:15 +00:00
|
|
|
|
|
2024-05-06 00:40:02 +00:00
|
|
|
|
def test_change_preview_window_should_not_reset_change_preview
|
|
|
|
|
tmux.send_keys "#{FZF} --preview-window up,border-none --bind 'start:change-preview(echo hello)' --bind 'enter:change-preview-window(border-left)'", :Enter
|
2024-05-06 04:59:16 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines, 'hello' }
|
2024-05-06 00:40:02 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2024-05-06 04:59:16 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines, '│ hello' }
|
2024-05-06 00:40:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-04 02:46:15 +00:00
|
|
|
|
def test_change_preview_window_rotate
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --preview-window left,border-none --preview 'echo hello' --bind '" \
|
|
|
|
|
"a:change-preview-window(right|down|up|hidden|)'", :Enter
|
2024-02-29 00:49:33 +00:00
|
|
|
|
tmux.until { |lines| assert(lines.any? { _1.include?('100/100') }) }
|
2021-12-04 02:46:15 +00:00
|
|
|
|
3.times do
|
|
|
|
|
tmux.until { |lines| lines[0].start_with?('hello') }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| lines[0].end_with?('hello') }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| lines[-1].start_with?('hello') }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_equal 'hello', lines[0] }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[0], 'hello' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-03-29 12:35:36 +00:00
|
|
|
|
|
2023-05-05 06:08:08 +00:00
|
|
|
|
def test_change_preview_window_rotate_hidden
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \
|
|
|
|
|
"a:change-preview-window(nohidden||down,1|)'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], '==1==' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[-2], '==1==' }
|
|
|
|
|
tmux.send_keys 'a'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_change_preview_window_rotate_hidden_down
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-2], '==1==' }
|
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.until { |lines| refute_includes lines[-2], '==1==' }
|
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-29 12:35:36 +00:00
|
|
|
|
def test_ellipsis
|
|
|
|
|
tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }
|
|
|
|
|
end
|
2022-09-07 16:01:22 +00:00
|
|
|
|
|
|
|
|
|
def assert_block(expected, lines)
|
|
|
|
|
cols = expected.lines.map(&:chomp).map(&:length).max
|
2024-05-26 16:20:56 +00:00
|
|
|
|
top = lines.take(expected.lines.length).map { _1[0, cols].rstrip + "\n" }.join
|
|
|
|
|
bottom = lines.reverse.take(expected.lines.length).reverse.map { _1[0, cols].rstrip + "\n" }.join
|
|
|
|
|
assert_includes [top, bottom], expected
|
2022-09-07 16:01:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_height_range_fit
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded', :Enter
|
2022-09-07 16:01:22 +00:00
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
╭──────────
|
|
|
|
|
│ 3
|
|
|
|
|
│ 2
|
|
|
|
|
│ > 1
|
|
|
|
|
│ > < 3/3
|
|
|
|
|
╰──────────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_height_range_fit_preview_above
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded --preview-window border-rounded --preview "seq {}" --preview-window up,60%', :Enter
|
2022-09-07 16:01:22 +00:00
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
╭──────────
|
|
|
|
|
│ ╭────────
|
|
|
|
|
│ │ 1
|
|
|
|
|
│ │
|
|
|
|
|
│ │
|
|
|
|
|
│ │
|
|
|
|
|
│ ╰────────
|
|
|
|
|
│ 3
|
|
|
|
|
│ 2
|
|
|
|
|
│ > 1
|
|
|
|
|
│ > < 3/3
|
|
|
|
|
╰──────────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_height_range_fit_preview_above_alternative
|
|
|
|
|
tmux.send_keys 'seq 3 | fzf --height ~100% --border=sharp --preview "seq {}" --preview-window up,40%,border-bottom --padding 1 --exit-0 --header hello --header-lines=2', :Enter
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
┌─────────
|
|
|
|
|
│
|
|
|
|
|
│ 1
|
|
|
|
|
│ 2
|
|
|
|
|
│ 3
|
|
|
|
|
│ ───────
|
|
|
|
|
│ > 3
|
|
|
|
|
│ 2
|
|
|
|
|
│ 1
|
|
|
|
|
│ hello
|
2022-10-31 01:56:24 +00:00
|
|
|
|
│ 1/1 ─
|
2022-09-07 16:01:22 +00:00
|
|
|
|
│ >
|
|
|
|
|
│
|
|
|
|
|
└─────────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_height_range_fit_preview_left
|
|
|
|
|
tmux.send_keys "seq 3 | fzf --height ~100% --border=vertical --preview 'seq {}' --preview-window left,5,border-right --padding 1 --exit-0 --header $'hello\\nworld' --header-lines=2", :Enter
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
│
|
2023-01-06 06:36:12 +00:00
|
|
|
|
│ 1 │ > 3
|
|
|
|
|
│ 2 │ 2
|
|
|
|
|
│ 3 │ 1
|
|
|
|
|
│ │ hello
|
|
|
|
|
│ │ world
|
|
|
|
|
│ │ 1/1 ─
|
|
|
|
|
│ │ >
|
2022-09-07 16:01:22 +00:00
|
|
|
|
│
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_height_range_overflow
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border rounded', :Enter
|
2022-09-07 16:01:22 +00:00
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
╭──────────────
|
|
|
|
|
│ 2
|
|
|
|
|
│ > 1
|
|
|
|
|
│ > < 100/100
|
|
|
|
|
╰──────────────
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
2022-10-26 15:33:05 +00:00
|
|
|
|
|
|
|
|
|
def test_start_event
|
2023-01-07 02:21:52 +00:00
|
|
|
|
tmux.send_keys 'seq 100 | fzf --multi --sync --preview-window hidden:border-none --bind "start:select-all+last+preview(echo welcome)"', :Enter
|
2022-10-26 15:33:05 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_match(/>100.*welcome/, lines[0])
|
|
|
|
|
assert_includes(lines[-2], '100/100 (100)')
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-10-31 01:56:24 +00:00
|
|
|
|
|
2023-01-23 07:22:25 +00:00
|
|
|
|
def test_focus_event
|
2023-05-17 01:55:12 +00:00
|
|
|
|
tmux.send_keys 'seq 100 | fzf --bind "focus:transform-prompt(echo [[{}]]),?:unbind(focus)"', :Enter
|
2023-01-23 07:22:25 +00:00
|
|
|
|
tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }
|
|
|
|
|
tmux.send_keys :X
|
|
|
|
|
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
|
2024-01-07 06:43:17 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }
|
|
|
|
|
tmux.send_keys :X
|
|
|
|
|
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
|
2023-05-17 01:55:12 +00:00
|
|
|
|
tmux.send_keys '?'
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
|
|
|
|
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }
|
2023-01-23 07:22:25 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-01-07 08:44:49 +00:00
|
|
|
|
def test_result_event
|
|
|
|
|
tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 11, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
|
|
|
|
tmux.send_keys '9'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 9' }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
|
|
|
|
end
|
|
|
|
|
|
2022-10-31 01:56:24 +00:00
|
|
|
|
def test_labels_center
|
2023-01-21 16:56:29 +00:00
|
|
|
|
tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─foobar─')
|
|
|
|
|
assert_includes(_1[1], '─barfoo─')
|
|
|
|
|
end
|
2023-01-21 16:56:29 +00:00
|
|
|
|
tmux.send_keys :space
|
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─foobarfoo─')
|
|
|
|
|
assert_includes(_1[1], '─barfoobar─')
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─fooxfoo─')
|
|
|
|
|
assert_includes(_1[1], '─barxbar─')
|
|
|
|
|
end
|
2022-10-31 01:56:24 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_labels_left
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2 --preview : --preview-label barfoo --preview-label-pos 2', :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '╭foobar─')
|
|
|
|
|
assert_includes(_1[1], '╭barfoo─')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_labels_right
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos -2 --preview : --preview-label barfoo --preview-label-pos -2', :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─foobar╮')
|
|
|
|
|
assert_includes(_1[1], '─barfoo╮')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_labels_bottom
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2:bottom --preview : --preview-label barfoo --preview-label-pos -2:bottom', :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[-1], '╰foobar─')
|
|
|
|
|
assert_includes(_1[-2], '─barfoo╯')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-29 07:14:08 +00:00
|
|
|
|
def test_labels_variables
|
|
|
|
|
tmux.send_keys ': | fzf --border --border-label foobar --preview "echo \$FZF_BORDER_LABEL // \$FZF_PREVIEW_LABEL" --preview-label barfoo --bind "space:change-border-label(barbaz)+change-preview-label(bazbar)+refresh-preview,enter:transform-border-label(echo 123)+transform-preview-label(echo 456)+refresh-preview"', :Enter
|
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─foobar─')
|
|
|
|
|
assert_includes(_1[1], '─barfoo─')
|
|
|
|
|
assert_includes(_1[2], ' foobar // barfoo ')
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─barbaz─')
|
|
|
|
|
assert_includes(_1[1], '─bazbar─')
|
|
|
|
|
assert_includes(_1[2], ' barbaz // bazbar ')
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until do
|
|
|
|
|
assert_includes(_1[0], '─123─')
|
|
|
|
|
assert_includes(_1[1], '─456─')
|
|
|
|
|
assert_includes(_1[2], ' 123 // 456 ')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-10 07:23:33 +00:00
|
|
|
|
def test_info_separator_unicode
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.send_keys 'seq 100 | fzf -q55', :Enter
|
|
|
|
|
tmux.until { assert_includes(_1[-2], ' 1/100 ─') }
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-10 07:23:33 +00:00
|
|
|
|
def test_info_separator_no_unicode
|
|
|
|
|
tmux.send_keys 'seq 100 | fzf -q55 --no-unicode', :Enter
|
|
|
|
|
tmux.until { assert_includes(_1[-2], ' 1/100 -') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_separator_repeat
|
|
|
|
|
tmux.send_keys 'seq 100 | fzf -q55 --separator _-', :Enter
|
|
|
|
|
tmux.until { assert_includes(_1[-2], ' 1/100 _-_-') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_separator_ansi_colors_and_tabs
|
|
|
|
|
tmux.send_keys "seq 100 | fzf -q55 --tabstop 4 --separator $'\\x1b[33ma\\tb'", :Enter
|
|
|
|
|
tmux.until { assert_includes(_1[-2], ' 1/100 a ba ba') }
|
|
|
|
|
end
|
|
|
|
|
|
2022-10-31 01:56:24 +00:00
|
|
|
|
def test_info_no_separator
|
2022-11-10 07:23:33 +00:00
|
|
|
|
tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter
|
2022-10-31 01:56:24 +00:00
|
|
|
|
tmux.until { assert(_1[-2] == ' 1/100') }
|
|
|
|
|
end
|
2022-12-10 15:59:34 +00:00
|
|
|
|
|
2023-06-10 15:04:24 +00:00
|
|
|
|
def test_info_right
|
|
|
|
|
tmux.send_keys "#{FZF} --info=right --separator x --bind 'start:reload:seq 100; sleep 10'", :Enter
|
|
|
|
|
tmux.until { assert_match(%r{xxx [⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, _1[-2]) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_inline_right
|
|
|
|
|
tmux.send_keys "#{FZF} --info=inline-right --bind 'start:reload:seq 100; sleep 10'", :Enter
|
|
|
|
|
tmux.until { assert_match(%r{[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, _1[-1]) }
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-03 02:56:54 +00:00
|
|
|
|
def test_info_inline_right_clearance
|
|
|
|
|
tmux.send_keys "seq 100000 | #{FZF} --info inline-right", :Enter
|
|
|
|
|
tmux.until { assert_match(%r{100000/100000}, _1[-1]) }
|
|
|
|
|
tmux.send_keys 'x'
|
|
|
|
|
tmux.until { assert_match(%r{ 0/100000}, _1[-1]) }
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-19 15:53:18 +00:00
|
|
|
|
def test_info_command
|
|
|
|
|
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"'), :Enter)
|
|
|
|
|
tmux.until { assert_match(%r{^ --1/10000/10000-- xx}, _1[-2]) }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { assert_match(%r{^ --2/10000/10000-- xx}, _1[-2]) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_command_inline
|
|
|
|
|
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline:xx), :Enter)
|
|
|
|
|
tmux.until { assert_match(%r{^> xx--1/10000/10000-- xx}, _1[-1]) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_command_right
|
|
|
|
|
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info right), :Enter)
|
|
|
|
|
tmux.until { assert_match(%r{xx --1/10000/10000-- *$}, _1[-2]) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_info_command_inline_right
|
|
|
|
|
tmux.send_keys(%(seq 10000 | #{FZF} --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline-right), :Enter)
|
|
|
|
|
tmux.until { assert_match(%r{ --1/10000/10000-- *$}, _1[-1]) }
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-10 15:59:34 +00:00
|
|
|
|
def test_prev_next_selected
|
|
|
|
|
tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
|
|
|
|
tmux.send_keys :BTab, :BTab, :Up, :BTab
|
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.select_count }
|
|
|
|
|
tmux.send_keys 'C-n'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>4' }
|
|
|
|
|
tmux.send_keys 'C-n'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>2' }
|
|
|
|
|
tmux.send_keys 'C-n'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>1' }
|
|
|
|
|
tmux.send_keys 'C-n'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>4' }
|
|
|
|
|
tmux.send_keys 'C-p'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>1' }
|
|
|
|
|
tmux.send_keys 'C-p'
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '>>2' }
|
|
|
|
|
end
|
2022-12-20 16:29:19 +00:00
|
|
|
|
|
|
|
|
|
def test_listen
|
2023-03-19 06:53:31 +00:00
|
|
|
|
{ '--listen 6266' => -> { URI('http://localhost:6266') },
|
2023-03-19 06:42:47 +00:00
|
|
|
|
"--listen --sync --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'" =>
|
2023-03-19 06:53:31 +00:00
|
|
|
|
-> { URI("http://localhost:#{File.read('/tmp/fzf-port').chomp}") } }.each do |opts, fn|
|
2023-03-19 06:42:47 +00:00
|
|
|
|
tmux.send_keys "seq 10 | fzf #{opts}", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
2023-09-03 07:30:35 +00:00
|
|
|
|
state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)
|
|
|
|
|
assert_equal 10, state[:totalCount]
|
|
|
|
|
assert_equal 10, state[:matchCount]
|
|
|
|
|
assert_empty state[:query]
|
|
|
|
|
assert_equal({ index: 0, text: '1' }, state[:current])
|
|
|
|
|
|
2023-03-19 06:42:47 +00:00
|
|
|
|
Net::HTTP.post(fn.call, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ')
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }
|
2023-09-03 07:30:35 +00:00
|
|
|
|
state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)
|
|
|
|
|
assert_equal 100, state[:totalCount]
|
|
|
|
|
assert_equal 0, state[:matchCount]
|
|
|
|
|
assert_equal 'yo', state[:query]
|
|
|
|
|
assert_nil state[:current]
|
|
|
|
|
|
2023-03-19 06:42:47 +00:00
|
|
|
|
teardown
|
|
|
|
|
setup
|
|
|
|
|
end
|
2022-12-20 16:29:19 +00:00
|
|
|
|
end
|
2023-01-07 02:21:52 +00:00
|
|
|
|
|
2023-07-20 14:42:09 +00:00
|
|
|
|
def test_listen_with_api_key
|
|
|
|
|
post_uri = URI('http://localhost:6266')
|
|
|
|
|
tmux.send_keys 'seq 10 | FZF_API_KEY=123abc fzf --listen 6266', :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
|
|
|
|
# Incorrect API Key
|
|
|
|
|
[nil, { 'x-api-key' => '' }, { 'x-api-key' => '124abc' }].each do |headers|
|
|
|
|
|
res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)
|
|
|
|
|
assert_equal '401', res.code
|
|
|
|
|
assert_equal 'Unauthorized', res.message
|
|
|
|
|
assert_equal "invalid api key\n", res.body
|
|
|
|
|
end
|
|
|
|
|
# Valid API Key
|
|
|
|
|
[{ 'x-api-key' => '123abc' }, { 'X-API-Key' => '123abc' }].each do |headers|
|
|
|
|
|
res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)
|
|
|
|
|
assert_equal '200', res.code
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-07 02:21:52 +00:00
|
|
|
|
def test_toggle_alternative_preview_window
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
|
|
|
|
tmux.until { |lines| refute_includes lines, '/1/1/' }
|
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '/1/1/' }
|
|
|
|
|
end
|
2023-02-11 11:21:10 +00:00
|
|
|
|
|
|
|
|
|
def test_become
|
2023-02-12 13:06:21 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter
|
2023-02-11 11:21:10 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
2023-02-12 13:06:21 +00:00
|
|
|
|
tmux.send_keys 999
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 99, lines.item_count }
|
2023-02-11 11:21:10 +00:00
|
|
|
|
end
|
2023-03-17 04:22:20 +00:00
|
|
|
|
|
|
|
|
|
def test_no_extra_newline_issue_3209
|
2024-02-01 07:25:53 +00:00
|
|
|
|
tmux.send_keys(%(seq 100 | #{FZF} --height 10 --preview-window up,wrap,border-rounded --preview 'printf "─%.0s" $(seq 1 "$((FZF_PREVIEW_COLUMNS - 5))"); printf $"\\e[7m%s\\e[0m" title; echo; echo something'), :Enter)
|
2023-03-17 04:22:20 +00:00
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
╭──────────
|
|
|
|
|
│ ─────────
|
|
|
|
|
│ something
|
|
|
|
|
│
|
|
|
|
|
╰──────────
|
|
|
|
|
3
|
|
|
|
|
2
|
|
|
|
|
> 1
|
|
|
|
|
100/100 ─
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
2023-03-29 11:36:09 +00:00
|
|
|
|
|
|
|
|
|
def test_track
|
2023-04-22 06:48:51 +00:00
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --query 555 --track --bind t:toggle-track", :Enter
|
2023-03-29 11:36:09 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert_includes lines, '> 555'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
index = tmux.until do |lines|
|
|
|
|
|
assert_equal 28, lines.match_count
|
|
|
|
|
assert_includes lines, '> 555'
|
|
|
|
|
end.index('> 555')
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 271, lines.match_count
|
|
|
|
|
assert_equal '> 555', lines[index]
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1000, lines.match_count
|
|
|
|
|
assert_equal '> 555', lines[index]
|
|
|
|
|
end
|
2023-04-22 06:48:51 +00:00
|
|
|
|
tmux.send_keys '555'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert_includes lines, '> 555'
|
|
|
|
|
assert_includes lines[-2], '+T'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys 't'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
refute_includes lines[-2], '+T'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 28, lines.match_count
|
|
|
|
|
assert_includes lines, '> 55'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 271, lines.match_count
|
|
|
|
|
assert_includes lines, '> 5'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys 't'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_includes lines[-2], '+T'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1000, lines.match_count
|
|
|
|
|
assert_includes lines, '> 5'
|
|
|
|
|
end
|
2023-03-29 11:36:09 +00:00
|
|
|
|
end
|
2023-04-01 08:16:02 +00:00
|
|
|
|
|
2023-04-22 14:39:35 +00:00
|
|
|
|
def test_track_action
|
|
|
|
|
tmux.send_keys "seq 1000 | #{FZF} --query 555 --bind t:track", :Enter
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert_includes lines, '> 555'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 28, lines.match_count
|
|
|
|
|
assert_includes lines, '> 55'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :t
|
|
|
|
|
tmux.until do |lines|
|
2024-03-28 11:42:01 +00:00
|
|
|
|
assert_includes lines[-2], '+t'
|
2023-04-22 14:39:35 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 271, lines.match_count
|
|
|
|
|
assert_includes lines, '> 55'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Automatically disabled when the tracking item is no longer visible
|
|
|
|
|
tmux.send_keys '4'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 28, lines.match_count
|
2024-03-28 11:42:01 +00:00
|
|
|
|
refute_includes lines[-2], '+t'
|
2023-04-22 14:39:35 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :BSpace
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 271, lines.match_count
|
|
|
|
|
assert_includes lines, '> 5'
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :t
|
|
|
|
|
tmux.until do |lines|
|
2024-03-28 11:42:01 +00:00
|
|
|
|
assert_includes lines[-2], '+t'
|
2023-04-22 14:39:35 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until do |lines|
|
2024-03-28 11:42:01 +00:00
|
|
|
|
refute_includes lines[-2], '+t'
|
2023-04-22 14:39:35 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-26 06:13:08 +00:00
|
|
|
|
def test_one_and_zero
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter
|
2023-04-01 08:16:02 +00:00
|
|
|
|
tmux.send_keys '1'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 2, lines.match_count
|
2023-04-01 08:29:13 +00:00
|
|
|
|
refute(lines.any? { _1.include?('only match') })
|
2023-04-26 06:13:08 +00:00
|
|
|
|
refute(lines.any? { _1.include?('no match') })
|
2023-04-01 08:16:02 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys '0'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
2023-04-01 08:29:13 +00:00
|
|
|
|
assert(lines.any? { _1.include?('only match') })
|
2023-04-01 08:16:02 +00:00
|
|
|
|
end
|
2023-04-26 06:13:08 +00:00
|
|
|
|
tmux.send_keys '0'
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 0, lines.match_count
|
|
|
|
|
assert(lines.any? { _1.include?('no match') })
|
|
|
|
|
end
|
2023-04-01 08:16:02 +00:00
|
|
|
|
end
|
2023-04-02 14:26:13 +00:00
|
|
|
|
|
|
|
|
|
def test_height_range_with_exit_0
|
|
|
|
|
tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 10, lines.item_count }
|
|
|
|
|
tmux.send_keys :c
|
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
end
|
2023-04-29 12:27:30 +00:00
|
|
|
|
|
|
|
|
|
def test_reload_and_change
|
|
|
|
|
tmux.send_keys "(echo foo; echo bar) | #{FZF} --bind 'load:reload-sync(sleep 60)+change-query(bar)'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
end
|
2023-05-01 04:53:34 +00:00
|
|
|
|
|
|
|
|
|
def test_reload_and_change_cache
|
|
|
|
|
tmux.send_keys "echo bar | #{FZF} --bind 'zero:change-header(foo)+reload(echo foo)+clear-query'", :Enter
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> bar
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
tmux.send_keys :z
|
|
|
|
|
expected = <<~OUTPUT
|
|
|
|
|
> foo
|
|
|
|
|
foo
|
|
|
|
|
1/1
|
|
|
|
|
>
|
|
|
|
|
OUTPUT
|
|
|
|
|
tmux.until { assert_block(expected, _1) }
|
|
|
|
|
end
|
2023-05-21 04:51:06 +00:00
|
|
|
|
|
2023-05-21 09:40:05 +00:00
|
|
|
|
def test_delete_with_modifiers
|
2024-02-01 08:04:15 +00:00
|
|
|
|
if ENV['GITHUB_ACTION']
|
|
|
|
|
# Expected: "[3]"
|
|
|
|
|
# Actual: "[]3;5~"
|
|
|
|
|
skip('CTRL-DELETE is not properly handled in GitHub Actions environment')
|
|
|
|
|
end
|
2023-05-21 09:40:05 +00:00
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-delete:up+up,shift-delete:down,focus:transform-prompt:echo [{}]'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
|
|
|
|
tmux.send_keys 'C-Delete'
|
|
|
|
|
tmux.until { |lines| assert_equal '[3]', lines[-1] }
|
|
|
|
|
tmux.send_keys 'S-Delete'
|
|
|
|
|
tmux.until { |lines| assert_equal '[2]', lines[-1] }
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-21 04:51:06 +00:00
|
|
|
|
def test_become_tty
|
|
|
|
|
tmux.send_keys "sleep 0.5 | #{FZF} --bind 'start:reload:ls' --bind 'load:become:tty'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '/dev/tty' }
|
|
|
|
|
end
|
2023-05-27 06:43:31 +00:00
|
|
|
|
|
|
|
|
|
def test_disabled_preview_update
|
|
|
|
|
tmux.send_keys "echo bar | #{FZF} --disabled --bind 'change:reload:echo foo' --preview 'echo [{q}-{}]'", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('[-bar]') }) }
|
|
|
|
|
tmux.send_keys :x
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('[x-foo]') }) }
|
|
|
|
|
end
|
2023-11-17 10:13:37 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_window_hidden_on_focus
|
|
|
|
|
tmux.send_keys "seq 3 | #{FZF} --preview 'echo {}' --bind focus:hide-preview", :Enter
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert_includes lines, '> 2' }
|
|
|
|
|
end
|
2024-04-27 09:56:23 +00:00
|
|
|
|
|
|
|
|
|
def test_fzf_pos
|
|
|
|
|
tmux.send_keys "seq 100 | #{FZF} --preview 'echo $FZF_POS / $FZF_MATCH_COUNT'", :Enter
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 100') }) }
|
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('2 / 100') }) }
|
|
|
|
|
tmux.send_keys '99'
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 1') }) }
|
|
|
|
|
tmux.send_keys '99'
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('0 / 0') }) }
|
|
|
|
|
end
|
2024-05-26 16:20:56 +00:00
|
|
|
|
|
|
|
|
|
def test_fzf_multi_line
|
|
|
|
|
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded], :Enter
|
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
│ ┃998
|
|
|
|
|
│ ┃999
|
|
|
|
|
│ ┃1000
|
|
|
|
|
│ ╹
|
|
|
|
|
│ ╻1
|
|
|
|
|
│ ╹2
|
|
|
|
|
│ >>0
|
|
|
|
|
│ 3/3 (3)
|
|
|
|
|
│ >
|
|
|
|
|
╰───────────
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
tmux.send_keys :Up, :Up
|
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
╭───────
|
|
|
|
|
│ >╻1
|
|
|
|
|
│ >┃2
|
|
|
|
|
│ >┃3
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
|
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
│ >┃
|
|
|
|
|
│
|
|
|
|
|
│ >
|
|
|
|
|
╰───
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_fzf_multi_line_reverse
|
|
|
|
|
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse], :Enter
|
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
╭───────────
|
|
|
|
|
│ >
|
|
|
|
|
│ 3/3 (3)
|
|
|
|
|
│ >>0
|
|
|
|
|
│ ╻1
|
|
|
|
|
│ ╹2
|
|
|
|
|
│ ╻1
|
|
|
|
|
│ ┃2
|
|
|
|
|
│ ┃3
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
end
|
2024-06-19 16:45:06 +00:00
|
|
|
|
|
|
|
|
|
def test_fzf_multi_line_no_pointer_and_marker
|
|
|
|
|
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse --pointer '' --marker '' --marker-multi-line ''], :Enter
|
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
╭───────────
|
|
|
|
|
│ >
|
|
|
|
|
│ 3/3 (3)
|
|
|
|
|
│ 0
|
|
|
|
|
│ 1
|
|
|
|
|
│ 2
|
|
|
|
|
│ 1
|
|
|
|
|
│ 2
|
|
|
|
|
│ 3
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
end
|
2024-06-24 08:05:53 +00:00
|
|
|
|
|
|
|
|
|
def test_start_on_reload
|
2024-06-25 08:10:22 +00:00
|
|
|
|
tmux.send_keys %(echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded' --bind space:change-header:), :Enter
|
2024-06-24 08:05:53 +00:00
|
|
|
|
tmux.until(timeout: 1) { |lines| assert_includes lines[-3], 'Loading' }
|
|
|
|
|
tmux.until(timeout: 1) { |lines| refute_includes lines[-4], 'foo' }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-3], 'Loaded' }
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-4], 'bar' }
|
2024-06-25 08:10:22 +00:00
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until { |lines| assert_includes lines[-3], 'bar' }
|
2024-06-24 08:05:53 +00:00
|
|
|
|
end
|
2024-08-16 10:20:30 +00:00
|
|
|
|
|
|
|
|
|
def test_boundary_match
|
|
|
|
|
# Underscore boundaries should be ranked lower
|
2024-08-17 09:23:42 +00:00
|
|
|
|
{
|
|
|
|
|
default: [' x '] + %w[/x/ [x] -x- -x_ _x- _x_],
|
|
|
|
|
path: ['/x/', ' x '] + %w[[x] -x- -x_ _x- _x_],
|
|
|
|
|
history: ['[x]', '-x-', ' x '] + %w[/x/ -x_ _x- _x_]
|
|
|
|
|
}.each do |scheme, expected|
|
|
|
|
|
result = `printf -- 'xxx\n-xx\nxx-\n_x_\n_x-\n-x_\n[x]\n-x-\n x \n/x/\n' | #{FZF} -f"'x'" --scheme=#{scheme}`.lines(chomp: true)
|
|
|
|
|
assert_equal expected, result
|
|
|
|
|
end
|
2024-08-16 10:20:30 +00:00
|
|
|
|
end
|
2024-09-12 09:22:07 +00:00
|
|
|
|
|
|
|
|
|
def test_preview_window_noinfo
|
|
|
|
|
# │ 1 ││
|
2024-09-12 13:04:19 +00:00
|
|
|
|
tmux.send_keys %(#{FZF} --preview 'seq 1000' --preview-window top,noinfo --scrollbar --bind space:change-preview-window:info), :Enter
|
2024-09-12 09:22:07 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines[1]&.start_with?('│ 1')
|
|
|
|
|
assert lines[1]&.end_with?(' ││')
|
|
|
|
|
end
|
2024-09-12 13:04:19 +00:00
|
|
|
|
tmux.send_keys :Space
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines[1]&.start_with?('│ 1')
|
|
|
|
|
assert lines[1]&.end_with?('1000││')
|
|
|
|
|
end
|
2024-09-12 09:22:07 +00:00
|
|
|
|
end
|
2024-10-01 10:15:17 +00:00
|
|
|
|
|
|
|
|
|
def test_gap
|
2024-10-01 10:45:53 +00:00
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --gap --border --reverse), :Enter
|
2024-10-01 10:15:17 +00:00
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
╭─────────────────
|
|
|
|
|
│ >
|
|
|
|
|
│ 100/100 ──────
|
|
|
|
|
│ > 1
|
|
|
|
|
│
|
|
|
|
|
│ 2
|
|
|
|
|
│
|
|
|
|
|
│ 3
|
|
|
|
|
│
|
|
|
|
|
│ 4
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_gap_2
|
2024-10-01 10:45:53 +00:00
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --gap=2 --border --reverse), :Enter
|
2024-10-01 10:15:17 +00:00
|
|
|
|
block = <<~BLOCK
|
|
|
|
|
╭─────────────────
|
|
|
|
|
│ >
|
|
|
|
|
│ 100/100 ──────
|
|
|
|
|
│ > 1
|
|
|
|
|
│
|
|
|
|
|
│
|
|
|
|
|
│ 2
|
|
|
|
|
│
|
|
|
|
|
│
|
|
|
|
|
│ 3
|
|
|
|
|
BLOCK
|
|
|
|
|
tmux.until { assert_block(block, _1) }
|
|
|
|
|
end
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
module TestShell
|
|
|
|
|
def setup
|
2020-04-12 15:23:31 +00:00
|
|
|
|
@tmux = Tmux.new(shell)
|
2020-02-28 09:47:13 +00:00
|
|
|
|
tmux.prepare
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
|
@tmux.kill
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def set_var(name, val)
|
2015-06-25 16:00:58 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys "export #{name}='#{val}'", :Enter
|
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def unset_var(name)
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys "unset #{name}", :Enter
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
def test_ctrl_t
|
2020-04-12 15:23:31 +00:00
|
|
|
|
set_var('FZF_CTRL_T_COMMAND', 'seq 100')
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'C-t'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 100, lines.item_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab, :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines.any_include?(' (3)') }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines.any_include?('1 2 3') }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'C-c'
|
2015-06-25 16:00:58 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-04-24 15:53:11 +00:00
|
|
|
|
def test_ctrl_t_unicode
|
2024-05-25 02:53:09 +00:00
|
|
|
|
writelines(['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])
|
2020-04-12 15:23:31 +00:00
|
|
|
|
set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'echo ', 'C-t'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.item_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'fzf-unicode'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys '1'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys '2'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_match(/echo .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines.join) }
|
2016-04-24 15:53:11 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'fzf-unicode 테스트1 fzf-unicode 테스트2', lines[-1] }
|
2016-04-24 15:53:11 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def test_alt_c
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys :Escape, :c
|
2020-04-21 01:12:00 +00:00
|
|
|
|
lines = tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2023-01-12 14:37:23 +00:00
|
|
|
|
expected = lines.reverse.find { |l| l.start_with?('> ') }[2..]
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys :pwd, :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-1]&.end_with?(expected) }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-07 15:11:46 +00:00
|
|
|
|
def test_alt_c_command
|
2020-04-12 15:23:31 +00:00
|
|
|
|
set_var('FZF_ALT_C_COMMAND', 'echo /tmp')
|
2015-11-07 15:11:46 +00:00
|
|
|
|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'cd /', :Enter
|
|
|
|
|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys :Escape, :c
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.item_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2015-11-07 15:11:46 +00:00
|
|
|
|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys :pwd, :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '/tmp', lines[-1] }
|
2015-11-07 15:11:46 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def test_ctrl_r
|
|
|
|
|
tmux.prepare
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys 'echo 1st', :Enter
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'echo 2nd', :Enter
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'echo 3d', :Enter
|
|
|
|
|
tmux.prepare
|
|
|
|
|
3.times do
|
|
|
|
|
tmux.send_keys 'echo 3rd', :Enter
|
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
2017-01-09 04:22:24 +00:00
|
|
|
|
tmux.send_keys 'echo 4th', :Enter
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'C-r'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2020-03-29 13:06:06 +00:00
|
|
|
|
tmux.send_keys 'e3d'
|
2020-03-29 12:26:52 +00:00
|
|
|
|
# Duplicates removed: 3d (1) + 3rd (1) => 2 matches
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
|
|
|
|
tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3d') }
|
2020-03-29 12:26:52 +00:00
|
|
|
|
tmux.send_keys 'C-r'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3rd') }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'echo 3rd', lines[-1] }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '3rd', lines[-1] }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
2017-01-09 04:22:24 +00:00
|
|
|
|
|
2020-02-28 11:06:38 +00:00
|
|
|
|
def test_ctrl_r_multiline
|
2024-05-19 02:26:32 +00:00
|
|
|
|
# NOTE: Current bash implementation shows an extra new line if there's
|
2024-05-19 16:33:33 +00:00
|
|
|
|
# only entry in the history
|
2024-05-19 02:26:32 +00:00
|
|
|
|
tmux.send_keys ':', :Enter
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter
|
2023-01-12 14:37:23 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'C-r'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '>', lines[-1] }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys 'foo bar'
|
2024-05-19 02:26:32 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-4]&.match?(/"foo/) } unless shell == :zsh
|
2023-03-25 01:23:05 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-3]&.match?(/bar"␊?/) }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2023-03-25 01:23:05 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-1]&.match?(/bar"␊?/) }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2023-01-12 14:37:23 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
2020-02-28 09:47:13 +00:00
|
|
|
|
def test_ctrl_r_abort
|
2020-04-17 17:34:38 +00:00
|
|
|
|
skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && `#{Shell.bash} --version`[/(?<= version )\d+/].to_i < 4
|
2020-02-29 02:54:05 +00:00
|
|
|
|
%w[foo ' "].each do |query|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys :Enter, query
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-1]&.start_with?(query) }
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.send_keys 'C-r'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal "> #{query}", lines[-1] }
|
2020-02-29 02:54:05 +00:00
|
|
|
|
tmux.send_keys 'C-g'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-1]&.start_with?(query) }
|
2020-02-29 02:54:05 +00:00
|
|
|
|
end
|
2020-02-28 09:47:13 +00:00
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-05-09 11:15:14 +00:00
|
|
|
|
module CompletionTest
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def test_file_completion
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.mkdir_p('/tmp/fzf-test')
|
|
|
|
|
FileUtils.mkdir_p('/tmp/fzf test')
|
|
|
|
|
(1..100).each { |i| FileUtils.touch("/tmp/fzf-test/#{i}") }
|
2020-10-23 10:54:45 +00:00
|
|
|
|
['no~such~user', '/tmp/fzf test/foobar'].each do |f|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.touch(File.expand_path(f))
|
2015-05-11 16:40:44 +00:00
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'cat /tmp/fzf-test/10**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2015-12-28 15:00:20 +00:00
|
|
|
|
tmux.send_keys ' !d'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2017-01-20 19:17:51 +00:00
|
|
|
|
tmux.until(true) do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal 'cat /tmp/fzf-test/10 /tmp/fzf-test/100', lines[-1]
|
2015-04-13 17:00:50 +00:00
|
|
|
|
end
|
2015-05-09 17:35:00 +00:00
|
|
|
|
|
|
|
|
|
# ~USERNAME**<TAB>
|
2021-03-07 09:05:39 +00:00
|
|
|
|
user = `whoami`.chomp
|
2015-05-09 17:35:00 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2020-10-23 10:54:45 +00:00
|
|
|
|
tmux.send_keys "cat ~#{user}**", :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2020-10-23 10:54:45 +00:00
|
|
|
|
tmux.send_keys "/#{user}"
|
|
|
|
|
tmux.until { |lines| assert(lines.any? { |l| l.end_with?("/#{user}") }) }
|
2015-05-09 17:35:00 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2017-01-20 19:17:51 +00:00
|
|
|
|
tmux.until(true) do |lines|
|
2020-10-23 10:54:45 +00:00
|
|
|
|
assert_match %r{cat .*/#{user}}, lines[-1]
|
2015-05-09 17:54:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# ~INVALID_USERNAME**<TAB>
|
|
|
|
|
tmux.send_keys 'C-u'
|
2017-08-04 14:29:02 +00:00
|
|
|
|
tmux.send_keys 'cat ~such**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert lines.any_include?('no~such~user') }
|
2015-05-09 17:54:22 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_equal 'cat no~such~user', lines[-1] }
|
2015-05-11 16:40:44 +00:00
|
|
|
|
|
|
|
|
|
# /tmp/fzf\ test**<TAB>
|
|
|
|
|
tmux.send_keys 'C-u'
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'cat /tmp/fzf\ test/**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'foobar$'
|
2024-03-29 07:15:53 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert lines.any_include?('> /tmp/fzf test/foobar')
|
|
|
|
|
end
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_equal 'cat /tmp/fzf\ test/foobar', lines[-1] }
|
2015-12-28 15:00:20 +00:00
|
|
|
|
|
|
|
|
|
# Should include hidden files
|
2020-04-12 15:23:31 +00:00
|
|
|
|
(1..100).each { |i| FileUtils.touch("/tmp/fzf-test/.hidden-#{i}") }
|
2015-12-28 15:00:20 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'cat /tmp/fzf-test/hidden**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) do |lines|
|
|
|
|
|
assert_equal 100, lines.match_count
|
|
|
|
|
assert lines.any_include?('/tmp/fzf-test/.hidden-')
|
|
|
|
|
end
|
2016-03-06 03:46:28 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2015-05-09 20:01:52 +00:00
|
|
|
|
ensure
|
2015-05-20 10:47:48 +00:00
|
|
|
|
['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.rm_rf(File.expand_path(f))
|
2015-05-11 16:40:44 +00:00
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-12-29 04:02:16 +00:00
|
|
|
|
def test_file_completion_root
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'ls /**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2015-12-29 04:02:16 +00:00
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def test_dir_completion
|
2017-01-07 16:30:31 +00:00
|
|
|
|
(1..100).each do |idx|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.mkdir_p("/tmp/fzf-test/d#{idx}")
|
2017-01-07 16:30:31 +00:00
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.touch('/tmp/fzf-test/d55/xxx')
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'cd /tmp/fzf-test/**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab # Tab does not work here
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys 55
|
2024-04-19 13:40:38 +00:00
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert_includes lines, '> 55'
|
|
|
|
|
assert_includes lines, '> /tmp/fzf-test/d55'
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }
|
2015-03-04 03:59:23 +00:00
|
|
|
|
tmux.send_keys :xx
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }
|
2015-03-04 04:13:11 +00:00
|
|
|
|
|
2015-05-09 11:15:14 +00:00
|
|
|
|
# Should not match regular files (bash-only)
|
2020-10-23 11:44:04 +00:00
|
|
|
|
if instance_of?(TestBash)
|
2015-05-09 11:15:14 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }
|
2015-05-09 11:15:14 +00:00
|
|
|
|
end
|
2015-03-04 04:13:11 +00:00
|
|
|
|
|
|
|
|
|
# Fail back to plusdirs
|
|
|
|
|
tmux.send_keys :BSpace, :BSpace, :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55', lines[-1] }
|
2015-03-04 04:13:11 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_process_completion
|
|
|
|
|
tmux.send_keys 'sleep 12345 &', :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
lines = tmux.until { |lines| assert lines[-1]&.start_with?('[1] ') }
|
|
|
|
|
pid = lines[-1]&.split&.last
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'C-L'
|
2022-07-21 13:16:19 +00:00
|
|
|
|
tmux.send_keys 'kill **', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys 'sleep12345'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines.any_include?('sleep 12345') }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_equal "kill #{pid}", lines[-1] }
|
2015-05-10 02:21:21 +00:00
|
|
|
|
ensure
|
2017-08-04 14:29:02 +00:00
|
|
|
|
if pid
|
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
Process.kill('KILL', pid.to_i)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
2016-02-16 03:32:05 +00:00
|
|
|
|
|
|
|
|
|
def test_custom_completion
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'ls /tmp/**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 11, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab, :Tab, :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 3, lines.select_count }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_equal 'ls /tmp 1 2', lines[-1] }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_unset_completion
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
|
|
|
|
|
# Using tmux
|
2017-02-04 13:49:17 +00:00
|
|
|
|
tmux.send_keys 'unset FZFFOOBR**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
# FZF_TMUX=1
|
2016-02-16 03:32:05 +00:00
|
|
|
|
new_shell
|
2020-03-31 13:18:09 +00:00
|
|
|
|
tmux.focus
|
|
|
|
|
tmux.send_keys 'unset FZFFOOBR**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }
|
2016-02-16 03:32:05 +00:00
|
|
|
|
end
|
2016-04-24 15:53:11 +00:00
|
|
|
|
|
|
|
|
|
def test_file_completion_unicode
|
2020-04-12 15:23:31 +00:00
|
|
|
|
FileUtils.mkdir_p('/tmp/fzf-test')
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.paste "cd /tmp/fzf-test; echo test3 > $'fzf-unicode \\355\\205\\214\\354\\212\\244\\355\\212\\2701'; echo test4 > $'fzf-unicode \\355\\205\\214\\354\\212\\244\\355\\212\\2702'"
|
2016-04-24 15:53:11 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'cat fzf-unicode**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
2016-07-10 06:44:44 +00:00
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys '1'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
2016-07-10 06:44:44 +00:00
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :BSpace
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.match_count }
|
2016-07-10 06:44:44 +00:00
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys '2'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.select_count }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 2, lines.select_count }
|
2016-07-10 06:44:44 +00:00
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until(true) { |lines| assert_match(/cat .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines[-1]) }
|
2016-04-24 15:53:11 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2023-01-12 14:37:23 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[test3 test4], lines[-2..] }
|
2016-04-24 15:53:11 +00:00
|
|
|
|
end
|
2020-03-11 09:29:39 +00:00
|
|
|
|
|
|
|
|
|
def test_custom_completion_api
|
2020-03-11 10:42:17 +00:00
|
|
|
|
tmux.send_keys 'eval "_fzf$(declare -f _comprun)"', :Enter
|
2020-03-11 09:29:39 +00:00
|
|
|
|
%w[f g].each do |command|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys "#{command} b**", :Tab
|
|
|
|
|
tmux.until do |lines|
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal 2, lines.item_count
|
|
|
|
|
assert_equal 1, lines.match_count
|
|
|
|
|
assert lines.any_include?("prompt-#{command}")
|
|
|
|
|
assert lines.any_include?("preview-#{command}-bar")
|
2020-03-11 09:29:39 +00:00
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal "#{command} #{command}barbar", lines[-1] }
|
2020-03-11 09:29:39 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
|
|
|
|
end
|
2020-03-11 10:42:17 +00:00
|
|
|
|
ensure
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'unset -f _fzf_comprun', :Enter
|
2020-03-11 09:29:39 +00:00
|
|
|
|
end
|
2023-09-17 15:15:04 +00:00
|
|
|
|
|
|
|
|
|
def test_ssh_completion
|
|
|
|
|
(1..5).each { |i| FileUtils.touch("/tmp/fzf-test-ssh-#{i}") }
|
|
|
|
|
|
|
|
|
|
tmux.send_keys 'ssh jg@localhost**', :Tab
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines.match_count >= 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| assert lines.any_include?('ssh jg@localhost') }
|
|
|
|
|
tmux.send_keys ' -i /tmp/fzf-test-ssh**', :Tab
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines.match_count >= 5
|
|
|
|
|
assert_equal 0, lines.select_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Tab, :Tab, :Tab
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert_equal 3, lines.select_count
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys :Enter
|
|
|
|
|
tmux.until { |lines| assert lines.any_include?('ssh jg@localhost -i /tmp/fzf-test-ssh-') }
|
|
|
|
|
|
|
|
|
|
tmux.send_keys 'localhost**', :Tab
|
|
|
|
|
tmux.until do |lines|
|
|
|
|
|
assert lines.match_count >= 1
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-05-09 11:15:14 +00:00
|
|
|
|
class TestBash < TestBase
|
|
|
|
|
include TestShell
|
|
|
|
|
include CompletionTest
|
|
|
|
|
|
2020-02-28 09:47:13 +00:00
|
|
|
|
def shell
|
|
|
|
|
:bash
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-09 11:15:14 +00:00
|
|
|
|
def new_shell
|
2015-06-14 14:44:42 +00:00
|
|
|
|
tmux.prepare
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter
|
2015-05-09 11:15:14 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-02 18:06:10 +00:00
|
|
|
|
def test_dynamic_completion_loader
|
|
|
|
|
tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'
|
|
|
|
|
tmux.paste '_completion_loader() { complete -o default fake; }'
|
|
|
|
|
tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'
|
|
|
|
|
tmux.send_keys 'fake /tmp/foo**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2017-12-02 18:06:10 +00:00
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'fake /tmp/foo'
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys :Tab, 'C-u'
|
2017-12-02 18:06:10 +00:00
|
|
|
|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys 'fake /tmp/foo**', :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_operator lines.match_count, :>, 0 }
|
2017-12-02 18:06:10 +00:00
|
|
|
|
end
|
2015-05-09 11:15:14 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
class TestZsh < TestBase
|
|
|
|
|
include TestShell
|
2015-05-09 11:15:14 +00:00
|
|
|
|
include CompletionTest
|
2015-02-28 18:00:36 +00:00
|
|
|
|
|
2020-02-28 09:47:13 +00:00
|
|
|
|
def shell
|
|
|
|
|
:zsh
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def new_shell
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
2020-04-12 15:30:43 +00:00
|
|
|
|
|
|
|
|
|
def test_complete_quoted_command
|
|
|
|
|
tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter
|
|
|
|
|
['unset', '\unset', "'unset'"].each do |command|
|
|
|
|
|
tmux.prepare
|
|
|
|
|
tmux.send_keys "#{command} FZFFOOBR**", :Tab
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
2020-04-12 15:30:43 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal "#{command} FZFFOOBAR", lines[-1] }
|
2020-04-12 15:30:43 +00:00
|
|
|
|
tmux.send_keys 'C-c'
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class TestFish < TestBase
|
|
|
|
|
include TestShell
|
|
|
|
|
|
2020-02-28 09:47:13 +00:00
|
|
|
|
def shell
|
|
|
|
|
:fish
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-28 18:00:36 +00:00
|
|
|
|
def new_shell
|
2023-01-01 05:48:14 +00:00
|
|
|
|
tmux.send_keys 'env FZF_TMUX=1 FZF_DEFAULT_OPTS=--no-scrollbar fish', :Enter
|
2015-02-28 18:00:36 +00:00
|
|
|
|
tmux.send_keys 'function fish_prompt; end; clear', :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_empty lines }
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def set_var(name, val)
|
2015-06-25 16:00:58 +00:00
|
|
|
|
tmux.prepare
|
2015-07-13 10:24:22 +00:00
|
|
|
|
tmux.send_keys "set -g #{name} '#{val}'", :Enter
|
2015-06-25 16:00:58 +00:00
|
|
|
|
tmux.prepare
|
|
|
|
|
end
|
2015-02-28 18:00:36 +00:00
|
|
|
|
end
|
2020-02-28 06:38:39 +00:00
|
|
|
|
|
|
|
|
|
__END__
|
2022-10-16 08:15:19 +00:00
|
|
|
|
set -u
|
2020-10-23 10:54:45 +00:00
|
|
|
|
PS1= PROMPT_COMMAND= HISTFILE= HISTSIZE=100
|
|
|
|
|
unset <%= UNSETS.join(' ') %>
|
|
|
|
|
unset $(env | sed -n /^_fzf_orig/s/=.*//p)
|
|
|
|
|
unset $(declare -F | sed -n "/_fzf/s/.*-f //p")
|
|
|
|
|
|
2024-05-19 02:26:32 +00:00
|
|
|
|
export FZF_DEFAULT_OPTS="--no-scrollbar --pointer '>' --marker '>'"
|
2023-01-01 05:48:14 +00:00
|
|
|
|
|
2020-02-28 06:38:39 +00:00
|
|
|
|
# Setup fzf
|
|
|
|
|
# ---------
|
|
|
|
|
if [[ ! "$PATH" == *<%= BASE %>/bin* ]]; then
|
|
|
|
|
export PATH="${PATH:+${PATH}:}<%= BASE %>/bin"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Auto-completion
|
|
|
|
|
# ---------------
|
|
|
|
|
[[ $- == *i* ]] && source "<%= BASE %>/shell/completion.<%= __method__ %>" 2> /dev/null
|
|
|
|
|
|
|
|
|
|
# Key bindings
|
|
|
|
|
# ------------
|
|
|
|
|
source "<%= BASE %>/shell/key-bindings.<%= __method__ %>"
|
|
|
|
|
|
2020-03-11 09:29:39 +00:00
|
|
|
|
# Old API
|
|
|
|
|
_fzf_complete_f() {
|
2020-03-23 23:58:22 +00:00
|
|
|
|
_fzf_complete "+m --multi --prompt \"prompt-f> \"" "$@" < <(
|
2020-03-11 09:29:39 +00:00
|
|
|
|
echo foo
|
|
|
|
|
echo bar
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# New API
|
|
|
|
|
_fzf_complete_g() {
|
2020-03-23 23:58:22 +00:00
|
|
|
|
_fzf_complete +m --multi --prompt "prompt-g> " -- "$@" < <(
|
2020-03-11 09:29:39 +00:00
|
|
|
|
echo foo
|
|
|
|
|
echo bar
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_fzf_complete_f_post() {
|
|
|
|
|
awk '{print "f" $0 $0}'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_fzf_complete_g_post() {
|
|
|
|
|
awk '{print "g" $0 $0}'
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-16 08:15:19 +00:00
|
|
|
|
[ -n "${BASH-}" ] && complete -F _fzf_complete_f -o default -o bashdefault f
|
|
|
|
|
[ -n "${BASH-}" ] && complete -F _fzf_complete_g -o default -o bashdefault g
|
2020-03-11 09:29:39 +00:00
|
|
|
|
|
2020-03-11 10:42:17 +00:00
|
|
|
|
_comprun() {
|
2020-03-11 09:29:39 +00:00
|
|
|
|
local command=$1
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
|
|
case "$command" in
|
|
|
|
|
f) fzf "$@" --preview 'echo preview-f-{}' ;;
|
|
|
|
|
g) fzf "$@" --preview 'echo preview-g-{}' ;;
|
|
|
|
|
*) fzf "$@" ;;
|
|
|
|
|
esac
|
|
|
|
|
}
|