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'
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
fish_history
|
|
|
|
|
].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)
|
|
|
|
|
FZF = "FZF_DEFAULT_OPTS= FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf"
|
2015-03-28 12:37:37 +00:00
|
|
|
|
|
2015-04-25 01:39:04 +00:00
|
|
|
|
def wait
|
|
|
|
|
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
|
|
|
|
|
raise if Time.now - since > DEFAULT_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
|
2020-02-28 06:38:39 +00:00
|
|
|
|
UNSETS.map { |v| v + '= ' }.join + '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
|
|
|
|
|
|
2020-03-31 13:18:09 +00:00
|
|
|
|
def until(refresh = false)
|
2015-02-28 18:00:36 +00:00
|
|
|
|
lines = nil
|
2015-05-09 18:25:14 +00:00
|
|
|
|
begin
|
|
|
|
|
wait 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
|
2015-01-24 04:25:11 +00:00
|
|
|
|
TEMPNAME = '/tmp/output'
|
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
|
|
|
|
|
2015-06-13 17:44:22 +00:00
|
|
|
|
def tempname
|
2016-01-13 15:41:02 +00:00
|
|
|
|
@temp_suffix ||= 0
|
2015-06-13 17:44:22 +00:00
|
|
|
|
[TEMPNAME,
|
2020-04-21 01:12:00 +00:00
|
|
|
|
caller_locations.map(&:label).find { |l| l.start_with?('test_') },
|
2020-04-12 15:23:31 +00:00
|
|
|
|
@temp_suffix].join('-')
|
2015-06-13 17:44:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-04 14:29:02 +00:00
|
|
|
|
def writelines(path, lines)
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(path) while File.exist?(path)
|
2020-04-21 01:12:00 +00:00
|
|
|
|
File.open(path, 'w') { |f| f.puts lines }
|
2017-01-07 16:30:31 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-25 01:39:04 +00:00
|
|
|
|
def readonce
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait { assert_path_exists tempname }
|
2015-06-13 17:44:22 +00:00
|
|
|
|
File.read(tempname)
|
2015-04-25 01:39:04 +00:00
|
|
|
|
ensure
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(tempname) while File.exist?(tempname)
|
2016-01-13 15:41:02 +00:00
|
|
|
|
@temp_suffix += 1
|
2015-06-17 17:09:03 +00:00
|
|
|
|
tmux.prepare
|
2015-01-16 19:55:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-29 08:37:35 +00:00
|
|
|
|
def fzf(*opts)
|
2015-06-13 17:44:22 +00:00
|
|
|
|
fzf!(*opts) + " > #{tempname}.tmp; mv #{tempname}.tmp #{tempname}"
|
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
|
|
|
|
|
@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
|
2016-04-16 05:02:43 +00:00
|
|
|
|
assert_equal '3910', readonce.chomp
|
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
|
2015-01-24 04:25:11 +00:00
|
|
|
|
assert_equal 'hello', readonce.chomp
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' [Command failed: false]', lines[-2] }
|
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'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[3 2 5 6 8 7], readonce.lines(chomp: true)
|
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
|
|
|
|
|
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal [' 1st 2nd 3rd/', ' first second third/'], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal [' 1st 2nd 3rd/'], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines, ' 100/100' }
|
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
|
2015-01-24 04:25:11 +00:00
|
|
|
|
assert_equal '100', readonce.chomp
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[5555 55], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[555555], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[5 5 50 51], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[가나다], readonce.lines(chomp: true)
|
2015-01-24 04:26:33 +00:00
|
|
|
|
end
|
2015-02-18 03:07:54 +00:00
|
|
|
|
|
|
|
|
|
def test_sync
|
2020-04-12 15:23:31 +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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[9090], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[1000 999 998], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[99 999 998], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[1000 900 800], readonce.lines(chomp: true)
|
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|
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.send_keys "seq 1 100 | #{fzf(:expect, 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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal [expected, '55'], readonce.lines(chomp: true)
|
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
|
|
|
|
|
|
|
|
|
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[55 alt-z 55], readonce.lines(chomp: true)
|
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'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[55 z 55], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal ['55', '', '55'], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[111 11], readonce.lines(chomp: true)
|
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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, %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-
|
|
|
|
|
]
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, 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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, [
|
|
|
|
|
'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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, [
|
|
|
|
|
'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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, [
|
|
|
|
|
'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)
|
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
|
|
|
|
|
]
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, 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
|
|
|
|
|
|
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
|
2020-02-28 11:06:38 +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'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[4 5 6 9], readonce.lines(chomp: true)
|
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'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[print-my-query], readonce.lines(chomp: true)
|
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],
|
2020-04-21 01:12:00 +00:00
|
|
|
|
readonce.lines(chomp: true)
|
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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(history_file)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
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
|
2020-04-12 15:23:31 +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
|
|
|
|
|
assert_equal input[1..-1], File.readlines(history_file, chomp: true)
|
|
|
|
|
end
|
2015-06-13 15:43:44 +00:00
|
|
|
|
|
|
|
|
|
# Update history entries (not changed on disk)
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(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'
|
2020-02-28 11:06:38 +00:00
|
|
|
|
opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"]
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, %w[foo'bar foo"bar foo$bar])
|
2020-04-17 17:34:38 +00:00
|
|
|
|
tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal ' 3/3', lines[-2] }
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
|
|
|
|
tmux.send_keys :Escape, :a
|
2015-06-14 03:25:08 +00:00
|
|
|
|
tmux.send_keys :Up
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :b
|
|
|
|
|
tmux.send_keys :Escape, :b
|
2015-06-14 03:25:08 +00:00
|
|
|
|
tmux.send_keys :Up
|
|
|
|
|
tmux.send_keys :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] }
|
2016-05-10 16:40:49 +00:00
|
|
|
|
tmux.send_keys :Escape, :a
|
|
|
|
|
tmux.send_keys :Escape, :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[
|
2020-04-17 17:34:38 +00:00
|
|
|
|
/foo'bar/ /foo'bar/
|
|
|
|
|
/foo"barfoo"bar/ /foo"barfoo"bar/
|
|
|
|
|
/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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
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'
|
2020-04-17 17:34:38 +00:00
|
|
|
|
opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})"]
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, %w[foo'bar foo"bar foo$bar foobar])
|
|
|
|
|
tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
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'
|
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ['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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
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'
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname,
|
2020-04-17 17:34:38 +00:00
|
|
|
|
['#!/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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(output)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
2016-02-02 19:46:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-16 14:14:57 +00:00
|
|
|
|
def test_cycle
|
2020-04-12 15:23:31 +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
|
2016-04-16 05:02:43 +00:00
|
|
|
|
assert_equal '50', readonce.chomp
|
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
|
2016-04-16 05:02:43 +00:00
|
|
|
|
assert_equal '50', readonce.chomp
|
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
|
|
|
|
|
assert_equal '50', readonce.chomp
|
|
|
|
|
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
|
|
|
|
|
assert_equal '', readonce.chomp
|
|
|
|
|
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
|
|
|
|
|
assert_equal '6', readonce.chomp
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-15 10:04:53 +00:00
|
|
|
|
def test_header
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
|
|
|
|
|
2016-05-12 15:44:27 +00:00
|
|
|
|
def test_cancel
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, %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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ['hello world ', 'byebye'])
|
|
|
|
|
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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye'])
|
|
|
|
|
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 "
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, [src, 'byebye'])
|
|
|
|
|
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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ['=' * 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
|
2020-04-21 01:12:00 +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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[5 2 1], readonce.lines(chomp: true)
|
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'
|
|
|
|
|
assert_equal '3', readonce.chomp
|
|
|
|
|
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
|
2020-04-17 17:34:38 +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
|
2020-04-17 17:34:38 +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
|
|
|
|
|
|
|
|
|
|
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
|
2017-08-04 14:29:02 +00:00
|
|
|
|
begin
|
2020-04-12 15:23:31 +00:00
|
|
|
|
File.unlink(tempname)
|
|
|
|
|
rescue StandardError
|
2017-08-04 14:29:02 +00:00
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0), :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
|
2017-01-23 15:23:16 +00:00
|
|
|
|
tmux.send_keys :Down
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 2', lines[3] }
|
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
|
|
|
|
assert_equal %w[1 2], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
2017-01-23 15:23:16 +00:00
|
|
|
|
tmux.send_keys :Down
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal '> 3', lines[4] }
|
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
|
|
|
|
assert_equal %w[1 2 3], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
2017-01-23 15:23:16 +00:00
|
|
|
|
end
|
2017-03-04 05:26:47 +00:00
|
|
|
|
|
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
|
|
|
|
|
tmux.send_keys %(: | #{FZF} --preview 'echo foo {q}'), :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
|
|
|
|
tmux.until { |lines| refute_includes lines[1], ' foo ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys 'bar'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_includes lines[1], ' foo bar ' }
|
2018-06-09 16:40:22 +00:00
|
|
|
|
tmux.send_keys 'C-u'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| refute_includes lines[1], ' 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
|
2017-07-18 11:50:38 +00:00
|
|
|
|
tmux.send_keys "seq 10 | fzf --no-clear --inline-info --height 5 > #{tempname}", :Enter
|
|
|
|
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
wait do
|
|
|
|
|
assert_path_exists tempname
|
|
|
|
|
assert_equal %w[1], File.readlines(tempname, chomp: true)
|
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
tmux.send_keys 'seq 10 | fzf --info=hidden', :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
|
|
|
|
|
|
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
|
|
|
|
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[999 999], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[foo 1], readonce.lines(chomp: true)
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
assert_equal %w[foo], readonce.lines(chomp: true)
|
2017-12-01 17:27:02 +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'
|
|
|
|
|
]
|
|
|
|
|
writelines(tempname, input)
|
|
|
|
|
|
|
|
|
|
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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ["\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
|
2019-11-11 15:57:19 +00:00
|
|
|
|
tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq {q}),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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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
|
2020-04-12 15:23:31 +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|
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, [%(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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right", :Enter
|
2020-04-21 01:12:00 +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
|
|
|
|
|
tmux.send_keys "#{FZF} --preview 'seq 1000 | nl' --preview-window down:noborder:follow", :Enter
|
|
|
|
|
tmux.until { |lines| assert_equal '1000 1000', lines[-1].strip }
|
|
|
|
|
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
|
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
|
2020-04-12 15:23:31 +00:00
|
|
|
|
writelines(tempname, ['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])
|
|
|
|
|
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 }
|
|
|
|
|
expected = lines.reverse.find { |l| l.start_with?('> ') }[2..-1]
|
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
|
|
|
|
|
tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[foo bar], lines[-2..-1] }
|
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'
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-3]&.end_with?('bar"') }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert lines[-1]&.end_with?('bar"') }
|
2020-02-28 11:06:38 +00:00
|
|
|
|
tmux.send_keys :Enter
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[foo bar], lines[-2..-1] }
|
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>
|
2020-10-23 10:54:45 +00:00
|
|
|
|
user = ENV['USER']
|
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$'
|
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 :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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
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'
|
|
|
|
|
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
|
2020-04-21 01:12:00 +00:00
|
|
|
|
tmux.until { |lines| assert_equal %w[test3 test4], lines[-2..-1] }
|
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
|
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
|
2017-01-07 16:30:31 +00:00
|
|
|
|
tmux.send_keys 'env FZF_TMUX=1 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__
|
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")
|
|
|
|
|
|
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}'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ -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 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
|
|
|
|
|
}
|