Split integration test file (#4205)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by GitHub · parent 04017c2 · Browse files · 20 files·+4790 added−4687 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+4790 added−4687 removed
- tests:+4716 added−4679 removed
- other:+74 added−8 removed
Provenance
- Commit
0237bf0- Tree
d32061f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
04017c2
20 files changed+4790 added−4687 removed
modified:.github/workflows/linux.yml+4 added-4 removed
28 unmodified lines29303132333334353637383939404142424344454647484828 unmodified lines
- name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: 3.1.0 ruby-version: 3.4.1
- name: Install packages run: sudo apt-get install --yes zsh fish tmux
- name: Install Ruby gems run: sudo gem install --no-document minitest:5.25.1 rubocop:1.65.0 rubocop-minitest:0.35.1 rubocop-performance:1.21.1 run: bundle install
- name: Rubocop run: rubocop --require rubocop-minitest --require rubocop-performance run: make lint
- name: Unit test run: make test
- name: Integration test run: make install && ./install --all && tmux new-session -d && ruby test/test_go.rb --verbose run: make install && ./install --all && tmux new-session -d && ruby test/runner.rb --verboseadded:test/lib/common.rb+240 added
1+# frozen_string_literal: true2+3+require 'bundler/setup'4+require 'minitest/autorun'5+require 'fileutils'6+require 'English'7+require 'shellwords'8+require 'erb'9+require 'tempfile'10+require 'net/http'11+require 'json'12+13+TEMPLATE = File.read(File.expand_path('common.sh', __dir__))14+UNSETS = %w[15+ FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS16+ FZF_TMUX FZF_TMUX_OPTS17+ FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS18+ FZF_ALT_C_COMMAND19+ FZF_ALT_C_OPTS FZF_CTRL_R_OPTS20+ FZF_API_KEY21+].freeze22+DEFAULT_TIMEOUT = 1023+24+FILE = File.expand_path(__FILE__)25+BASE = File.expand_path('../..', __dir__)26+Dir.chdir(BASE)27+FZF = "FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer \\> --marker \\>\" FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf".freeze28+29+def wait(timeout = DEFAULT_TIMEOUT)30+ since = Time.now31+ begin32+ yield or raise Minitest::Assertion, 'Assertion failure'33+ rescue Minitest::Assertion34+ raise if Time.now - since > timeout35+36+ sleep(0.05)37+ retry38+ end39+end40+41+class Shell42+ class << self43+ def bash44+ @bash ||=45+ begin46+ bashrc = '/tmp/fzf.bash'47+ File.open(bashrc, 'w') do |f|48+ f.puts ERB.new(TEMPLATE).result(binding)49+ end50+51+ "bash --rcfile #{bashrc}"52+ end53+ end54+55+ def zsh56+ @zsh ||=57+ begin58+ zdotdir = '/tmp/fzf-zsh'59+ FileUtils.rm_rf(zdotdir)60+ FileUtils.mkdir_p(zdotdir)61+ File.open("#{zdotdir}/.zshrc", 'w') do |f|62+ f.puts ERB.new(TEMPLATE).result(binding)63+ end64+ "ZDOTDIR=#{zdotdir} zsh"65+ end66+ end67+68+ def fish69+ "unset #{UNSETS.join(' ')}; rm -f ~/.local/share/fish/fzf_test_history; FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer '>' --marker '>'\" fish_history=fzf_test fish"70+ end71+ end72+end73+74+class Tmux75+ attr_reader :win76+77+ def initialize(shell = :bash)78+ @win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first79+ go(%W[set-window-option -t #{@win} pane-base-index 0])80+ return unless shell == :fish81+82+ send_keys 'function fish_prompt; end; clear', :Enter83+ self.until(&:empty?)84+ end85+86+ def kill87+ go(%W[kill-window -t #{win}])88+ end89+90+ def focus91+ go(%W[select-window -t #{win}])92+ end93+94+ def send_keys(*args)95+ go(%W[send-keys -t #{win}] + args.map(&:to_s))96+ end97+98+ def paste(str)99+ system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')100+ end101+102+ def capture103+ go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse104+ end105+106+ def until(refresh = false, timeout: DEFAULT_TIMEOUT)107+ lines = nil108+ begin109+ wait(timeout) do110+ lines = capture111+ class << lines112+ def counts113+ lazy114+ .map { |l| l.scan(%r{^. ([0-9]+)/([0-9]+)( \(([0-9]+)\))?}) }115+ .reject(&:empty?)116+ .first&.first&.map(&:to_i)&.values_at(0, 1, 3) || [0, 0, 0]117+ end118+119+ def match_count120+ counts[0]121+ end122+123+ def item_count124+ counts[1]125+ end126+127+ def select_count128+ counts[2]129+ end130+131+ def any_include?(val)132+ method = val.is_a?(Regexp) ? :match : :include?133+ find { |line| line.send(method, val) }134+ end135+ end136+ yield(lines).tap do |ok|137+ send_keys 'C-l' if refresh && !ok138+ end139+ end140+ rescue Minitest::Assertion141+ puts $ERROR_INFO.backtrace142+ puts '>' * 80143+ puts lines144+ puts '<' * 80145+ raise146+ end147+ lines148+ end149+150+ def prepare151+ tries = 0152+ begin153+ self.until(true) do |lines|154+ message = "Prepare[#{tries}]"155+ send_keys ' ', 'C-u', :Enter, message, :Left, :Right156+ lines[-1] == message157+ end158+ rescue Minitest::Assertion159+ (tries += 1) < 5 ? retry : raise160+ end161+ send_keys 'C-u', 'C-l'162+ end163+164+ private165+166+ def go(args)167+ IO.popen(%w[tmux] + args) { |io| io.readlines(chomp: true) }168+ end169+end170+171+class TestBase < Minitest::Test172+ TEMPNAME = Dir::Tmpname.create(%w[fzf]) {}173+ FIFONAME = Dir::Tmpname.create(%w[fzf-fifo]) {}174+175+ def writelines(lines)176+ File.write(TEMPNAME, lines.join("\n"))177+ end178+179+ def tempname180+ TEMPNAME181+ end182+183+ def fzf_output184+ @thread.join.value.chomp.tap { @thread = nil }185+ end186+187+ def fzf_output_lines188+ fzf_output.lines(chomp: true)189+ end190+191+ def setup192+ File.mkfifo(FIFONAME)193+ end194+195+ def teardown196+ FileUtils.rm_f([TEMPNAME, FIFONAME])197+ end198+199+ alias assert_equal_org assert_equal200+ def assert_equal(expected, actual)201+ # Ignore info separator202+ actual = actual&.sub(/\s*─+$/, '') if actual.is_a?(String) && actual&.match?(%r{\d+/\d+})203+ assert_equal_org(expected, actual)204+ end205+206+ # Run fzf with its output piped to a fifo207+ def fzf(*opts)208+ raise 'fzf_output not taken' if @thread209+210+ @thread = Thread.new { File.read(FIFONAME) }211+ fzf!(*opts) + " > #{FIFONAME.shellescape}"212+ end213+214+ def fzf!(*opts)215+ opts = opts.filter_map do |o|216+ case o217+ when Symbol218+ o = o.to_s219+ o.length > 1 ? "--#{o.tr('_', '-')}" : "-#{o}"220+ when String, Numeric221+ o.to_s222+ end223+ end224+ "#{FZF} #{opts.join(' ')}"225+ end226+end227+228+class TestInteractive < TestBase229+ attr_reader :tmux230+231+ def setup232+ super233+ @tmux = Tmux.new234+ end235+236+ def teardown237+ super238+ @tmux.kill239+ end240+endadded:test/lib/common.sh+59 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859set -uPS1= PROMPT_COMMAND= HISTFILE= HISTSIZE=100unset <%= UNSETS.join(' ') %>unset $(env | sed -n /^_fzf_orig/s/=.*//p)unset $(declare -F | sed -n "/_fzf/s/.*-f //p")
export FZF_DEFAULT_OPTS="--no-scrollbar --pointer '>' --marker '>'"
# 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__ %>"
# Old API_fzf_complete_f() { _fzf_complete "+m --multi --prompt \"prompt-f> \"" "$@" < <( echo foo echo bar )}
# New API_fzf_complete_g() { _fzf_complete +m --multi --prompt "prompt-g> " -- "$@" < <( 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
_comprun() { local command=$1 shift
case "$command" in f) fzf "$@" --preview 'echo preview-f-{}' ;; g) fzf "$@" --preview 'echo preview-g-{}' ;; *) fzf "$@" ;; esac}added:test/vim/fzf.vader+175 added
1+Execute (Setup):2+ let g:dir = fnamemodify(g:vader_file, ':p:h')3+ unlet! g:fzf_layout g:fzf_action g:fzf_history_dir4+ Log 'Test directory: ' . g:dir5+ Save &acd6+7+Execute (fzf#run with dir option):8+ let cwd = getcwd()9+ let result = fzf#run({ 'source': 'git ls-files', 'options': '--filter=vdr', 'dir': g:dir })10+ AssertEqual ['fzf.vader'], result11+ AssertEqual 0, haslocaldir()12+ AssertEqual getcwd(), cwd13+14+ execute 'lcd' fnameescape(cwd)15+ let result = sort(fzf#run({ 'source': 'git ls-files', 'options': '--filter e', 'dir': g:dir }))16+ AssertEqual ['fzf.vader'], result17+ AssertEqual 1, haslocaldir()18+ AssertEqual getcwd(), cwd19+20+Execute (fzf#run with Funcref command):21+ let g:ret = []22+ function! g:FzfTest(e)23+ call add(g:ret, a:e)24+ endfunction25+ let result = sort(fzf#run({ 'source': 'git ls-files', 'sink': function('g:FzfTest'), 'options': '--filter e', 'dir': g:dir }))26+ AssertEqual ['fzf.vader'], result27+ AssertEqual ['fzf.vader'], sort(g:ret)28+29+Execute (fzf#run with string source):30+ let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))31+ AssertEqual ['hi'], result32+33+Execute (fzf#run with list source):34+ let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f e' }))35+ AssertEqual ['hello'], result36+ let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f o' }))37+ AssertEqual ['hello', 'world'], result38+39+Execute (fzf#run with string source):40+ let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))41+ AssertEqual ['hi'], result42+43+Execute (fzf#run with dir option and noautochdir):44+ set noacd45+ let cwd = getcwd()46+ call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})47+ " No change in working directory48+ AssertEqual cwd, getcwd()49+50+ call fzf#run({'source': ['/foobar'], 'sink': 'tabe', 'dir': '/tmp', 'options': '-1'})51+ AssertEqual cwd, getcwd()52+ tabclose53+ AssertEqual cwd, getcwd()54+55+Execute (Incomplete fzf#run with dir option and autochdir):56+ set acd57+ let cwd = getcwd()58+ call fzf#run({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'})59+ " No change in working directory even if &acd is set60+ AssertEqual cwd, getcwd()61+62+Execute (FIXME: fzf#run with dir option and autochdir):63+ set acd64+ call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})65+ " Working directory changed due to &acd66+ AssertEqual '/foobar', expand('%')67+ AssertEqual '/', getcwd()68+69+Execute (fzf#run with dir option and autochdir when final cwd is same as dir):70+ set acd71+ cd /tmp72+ call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'})73+ " Working directory changed due to &acd74+ AssertEqual '/', getcwd()75+76+Execute (fzf#wrap):77+ AssertThrows fzf#wrap({'foo': 'bar'})78+79+ let opts = fzf#wrap('foobar')80+ Log opts81+ AssertEqual 0.9, opts.window.width82+ Assert opts.options =~ '--expect='83+ Assert !has_key(opts, 'sink')84+ Assert has_key(opts, 'sink*')85+86+ let opts = fzf#wrap('foobar', {}, 0)87+ Log opts88+ AssertEqual 0.9, opts.window.width89+90+ let opts = fzf#wrap('foobar', {}, 1)91+ Log opts92+ Assert !has_key(opts, 'window')93+94+ let opts = fzf#wrap('foobar', {'down': '50%'})95+ Log opts96+ AssertEqual '50%', opts.down97+98+ let opts = fzf#wrap('foobar', {'down': '50%'}, 1)99+ Log opts100+ Assert !has_key(opts, 'down')101+102+ let opts = fzf#wrap('foobar', {'sink': 'e'})103+ Log opts104+ AssertEqual 'e', opts.sink105+ Assert !has_key(opts, 'sink*')106+107+ let opts = fzf#wrap('foobar', {'options': '--reverse'})108+ Log opts109+ Assert opts.options =~ '--expect='110+ Assert opts.options =~ '--reverse'111+112+ let g:fzf_layout = {'window': 'enew'}113+ let opts = fzf#wrap('foobar')114+ Log opts115+ AssertEqual 'enew', opts.window116+117+ let opts = fzf#wrap('foobar', {}, 1)118+ Log opts119+ Assert !has_key(opts, 'window')120+121+ let opts = fzf#wrap('foobar', {'right': '50%'})122+ Log opts123+ Assert !has_key(opts, 'window')124+ AssertEqual '50%', opts.right125+126+ let opts = fzf#wrap('foobar', {'right': '50%'}, 1)127+ Log opts128+ Assert !has_key(opts, 'window')129+ Assert !has_key(opts, 'right')130+131+ let g:fzf_action = {'a': 'tabe'}132+ let opts = fzf#wrap('foobar')133+ Log opts134+ Assert opts.options =~ '--expect=a'135+ Assert !has_key(opts, 'sink')136+ Assert has_key(opts, 'sink*')137+138+ let opts = fzf#wrap('foobar', {'sink': 'e'})139+ Log opts140+ AssertEqual 'e', opts.sink141+ Assert !has_key(opts, 'sink*')142+143+ let g:fzf_history_dir = '/tmp'144+ let opts = fzf#wrap('foobar', {'options': '--color light'})145+ Log opts146+ Assert opts.options =~ "--history '/tmp/foobar'"147+ Assert opts.options =~ '--color light'148+149+ let g:fzf_colors = { 'fg': ['fg', 'Error'] }150+ let opts = fzf#wrap({})151+ Assert opts.options =~ '--color=fg:'152+153+Execute (fzf#shellescape with sh):154+ AssertEqual '''''', fzf#shellescape('', 'sh')155+ AssertEqual '''\''', fzf#shellescape('\', 'sh')156+ AssertEqual '''""''', fzf#shellescape('""', 'sh')157+ AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')158+ AssertEqual '''\\\"\\\''', fzf#shellescape('\\\"\\\', 'sh')159+ AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')160+161+Execute (fzf#shellescape with cmd.exe):162+ AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')163+ AssertEqual '^"\\^"', fzf#shellescape('\', 'cmd.exe')164+ AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')165+ AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')166+ AssertEqual '^"\\\\\\\^"\\\\\\^"', fzf#shellescape('\\\"\\\', 'cmd.exe')167+ AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')168+169+ AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')170+ AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe')171+ AssertEqual '^"%%USERPROFILE%%^"', fzf#shellescape('%USERPROFILE%', 'cmd.exe')172+173+Execute (Cleanup):174+ unlet g:dir175+ Restoredeleted:test/fzf.vader-175 removed
1-Execute (Setup):2- let g:dir = fnamemodify(g:vader_file, ':p:h')3- unlet! g:fzf_layout g:fzf_action g:fzf_history_dir4- Log 'Test directory: ' . g:dir5- Save &acd6-7-Execute (fzf#run with dir option):8- let cwd = getcwd()9- let result = fzf#run({ 'source': 'git ls-files', 'options': '--filter=vdr', 'dir': g:dir })10- AssertEqual ['fzf.vader'], result11- AssertEqual 0, haslocaldir()12- AssertEqual getcwd(), cwd13-14- execute 'lcd' fnameescape(cwd)15- let result = sort(fzf#run({ 'source': 'git ls-files', 'options': '--filter e', 'dir': g:dir }))16- AssertEqual ['fzf.vader', 'test_go.rb'], result17- AssertEqual 1, haslocaldir()18- AssertEqual getcwd(), cwd19-20-Execute (fzf#run with Funcref command):21- let g:ret = []22- function! g:FzfTest(e)23- call add(g:ret, a:e)24- endfunction25- let result = sort(fzf#run({ 'source': 'git ls-files', 'sink': function('g:FzfTest'), 'options': '--filter e', 'dir': g:dir }))26- AssertEqual ['fzf.vader', 'test_go.rb'], result27- AssertEqual ['fzf.vader', 'test_go.rb'], sort(g:ret)28-29-Execute (fzf#run with string source):30- let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))31- AssertEqual ['hi'], result32-33-Execute (fzf#run with list source):34- let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f e' }))35- AssertEqual ['hello'], result36- let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f o' }))37- AssertEqual ['hello', 'world'], result38-39-Execute (fzf#run with string source):40- let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))41- AssertEqual ['hi'], result42-43-Execute (fzf#run with dir option and noautochdir):44- set noacd45- let cwd = getcwd()46- call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})47- " No change in working directory48- AssertEqual cwd, getcwd()49-50- call fzf#run({'source': ['/foobar'], 'sink': 'tabe', 'dir': '/tmp', 'options': '-1'})51- AssertEqual cwd, getcwd()52- tabclose53- AssertEqual cwd, getcwd()54-55-Execute (Incomplete fzf#run with dir option and autochdir):56- set acd57- let cwd = getcwd()58- call fzf#run({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'})59- " No change in working directory even if &acd is set60- AssertEqual cwd, getcwd()61-62-Execute (FIXME: fzf#run with dir option and autochdir):63- set acd64- call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})65- " Working directory changed due to &acd66- AssertEqual '/foobar', expand('%')67- AssertEqual '/', getcwd()68-69-Execute (fzf#run with dir option and autochdir when final cwd is same as dir):70- set acd71- cd /tmp72- call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'})73- " Working directory changed due to &acd74- AssertEqual '/', getcwd()75-76-Execute (fzf#wrap):77- AssertThrows fzf#wrap({'foo': 'bar'})78-79- let opts = fzf#wrap('foobar')80- Log opts81- AssertEqual '~40%', opts.down82- Assert opts.options =~ '--expect='83- Assert !has_key(opts, 'sink')84- Assert has_key(opts, 'sink*')85-86- let opts = fzf#wrap('foobar', {}, 0)87- Log opts88- AssertEqual '~40%', opts.down89-90- let opts = fzf#wrap('foobar', {}, 1)91- Log opts92- Assert !has_key(opts, 'down')93-94- let opts = fzf#wrap('foobar', {'down': '50%'})95- Log opts96- AssertEqual '50%', opts.down97-98- let opts = fzf#wrap('foobar', {'down': '50%'}, 1)99- Log opts100- Assert !has_key(opts, 'down')101-102- let opts = fzf#wrap('foobar', {'sink': 'e'})103- Log opts104- AssertEqual 'e', opts.sink105- Assert !has_key(opts, 'sink*')106-107- let opts = fzf#wrap('foobar', {'options': '--reverse'})108- Log opts109- Assert opts.options =~ '--expect='110- Assert opts.options =~ '--reverse'111-112- let g:fzf_layout = {'window': 'enew'}113- let opts = fzf#wrap('foobar')114- Log opts115- AssertEqual 'enew', opts.window116-117- let opts = fzf#wrap('foobar', {}, 1)118- Log opts119- Assert !has_key(opts, 'window')120-121- let opts = fzf#wrap('foobar', {'right': '50%'})122- Log opts123- Assert !has_key(opts, 'window')124- AssertEqual '50%', opts.right125-126- let opts = fzf#wrap('foobar', {'right': '50%'}, 1)127- Log opts128- Assert !has_key(opts, 'window')129- Assert !has_key(opts, 'right')130-131- let g:fzf_action = {'a': 'tabe'}132- let opts = fzf#wrap('foobar')133- Log opts134- Assert opts.options =~ '--expect=a'135- Assert !has_key(opts, 'sink')136- Assert has_key(opts, 'sink*')137-138- let opts = fzf#wrap('foobar', {'sink': 'e'})139- Log opts140- AssertEqual 'e', opts.sink141- Assert !has_key(opts, 'sink*')142-143- let g:fzf_history_dir = '/tmp'144- let opts = fzf#wrap('foobar', {'options': '--color light'})145- Log opts146- Assert opts.options =~ "--history '/tmp/foobar'"147- Assert opts.options =~ '--color light'148-149- let g:fzf_colors = { 'fg': ['fg', 'Error'] }150- let opts = fzf#wrap({})151- Assert opts.options =~ '^--color=fg:'152-153-Execute (fzf#shellescape with sh):154- AssertEqual '''''', fzf#shellescape('', 'sh')155- AssertEqual '''\''', fzf#shellescape('\', 'sh')156- AssertEqual '''""''', fzf#shellescape('""', 'sh')157- AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')158- AssertEqual '''\\\"\\\''', fzf#shellescape('\\\"\\\', 'sh')159- AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')160-161-Execute (fzf#shellescape with cmd.exe):162- AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')163- AssertEqual '^"\\^"', fzf#shellescape('\', 'cmd.exe')164- AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')165- AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')166- AssertEqual '^"\\\\\\\^"\\\\\\^"', fzf#shellescape('\\\"\\\', 'cmd.exe')167- AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')168-169- AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')170- AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe')171- AssertEqual '^"%%USERPROFILE%%^"', fzf#shellescape('%USERPROFILE%', 'cmd.exe')172-173-Execute (Cleanup):174- unlet g:dir175- Restoreadded:test/runner.rb+5 added
1+# frozen_string_literal: true2+3+Dir[File.join(__dir__, 'test_*.rb')].each { require it }4+5+require 'minitest/autorun'added:test/test_core.rb+1588 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Testing basic features of fzf6+class TestCore < TestInteractive7+ def test_fzf_default_command8+ tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter9+ tmux.until { |lines| assert_equal '> hello', lines[-3] }10+11+ tmux.send_keys :Enter12+ assert_equal 'hello', fzf_output13+ end14+15+ def test_fzf_default_command_failure16+ tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter17+ tmux.until { |lines| assert_includes lines[-2], ' [Command failed: false] ─' }18+ tmux.send_keys :Enter19+ end20+21+ def test_key_bindings22+ tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter23+ tmux.until { |lines| assert_equal '> foo bar foo-bar', lines.last }24+25+ # CTRL-A26+ tmux.send_keys 'C-A', '('27+ tmux.until { |lines| assert_equal '> (foo bar foo-bar', lines.last }28+29+ # META-F30+ tmux.send_keys :Escape, :f, ')'31+ tmux.until { |lines| assert_equal '> (foo) bar foo-bar', lines.last }32+33+ # CTRL-B34+ tmux.send_keys 'C-B', 'var'35+ tmux.until { |lines| assert_equal '> (foovar) bar foo-bar', lines.last }36+37+ # Left, CTRL-D38+ tmux.send_keys :Left, :Left, 'C-D'39+ tmux.until { |lines| assert_equal '> (foovr) bar foo-bar', lines.last }40+41+ # META-BS42+ tmux.send_keys :Escape, :BSpace43+ tmux.until { |lines| assert_equal '> (r) bar foo-bar', lines.last }44+45+ # CTRL-Y46+ tmux.send_keys 'C-Y', 'C-Y'47+ tmux.until { |lines| assert_equal '> (foovfoovr) bar foo-bar', lines.last }48+49+ # META-B50+ tmux.send_keys :Escape, :b, :Space, :Space51+ tmux.until { |lines| assert_equal '> ( foovfoovr) bar foo-bar', lines.last }52+53+ # CTRL-F / Right54+ tmux.send_keys 'C-F', :Right, '/'55+ tmux.until { |lines| assert_equal '> ( fo/ovfoovr) bar foo-bar', lines.last }56+57+ # CTRL-H / BS58+ tmux.send_keys 'C-H', :BSpace59+ tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-bar', lines.last }60+61+ # CTRL-E62+ tmux.send_keys 'C-E', 'baz'63+ tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }64+65+ # CTRL-U66+ tmux.send_keys 'C-U'67+ tmux.until { |lines| assert_equal '>', lines.last }68+69+ # CTRL-Y70+ tmux.send_keys 'C-Y'71+ tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }72+73+ # CTRL-W74+ tmux.send_keys 'C-W', 'bar-foo'75+ tmux.until { |lines| assert_equal '> ( fovfoovr) bar bar-foo', lines.last }76+77+ # META-D78+ tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, 'C-A', 'C-Y'79+ tmux.until { |lines| assert_equal '> bar( fovfoovr) bar -foo', lines.last }80+81+ # CTRL-M82+ tmux.send_keys 'C-M'83+ tmux.until { |lines| refute_equal '>', lines.last }84+ end85+86+ def test_file_word87+ tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter88+ tmux.until { |lines| assert_equal '> --/foo bar/foo-bar/baz', lines.last }89+90+ tmux.send_keys :Escape, :b91+ tmux.send_keys :Escape, :b92+ tmux.send_keys :Escape, :b93+ tmux.send_keys :Escape, :d94+ tmux.send_keys :Escape, :f95+ tmux.send_keys :Escape, :BSpace96+ tmux.until { |lines| assert_equal '> --///baz', lines.last }97+ end98+99+ def test_multi_order100+ tmux.send_keys "seq 1 10 | #{fzf(:multi)}", :Enter101+ tmux.until { |lines| assert_equal '>', lines.last }102+103+ tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2104+ 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6105+ :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7106+ tmux.until { |lines| assert_equal ' 10/10 (6)', lines[-2] }107+ tmux.send_keys 'C-M'108+ assert_equal %w[3 2 5 6 8 7], fzf_output_lines109+ end110+111+ def test_multi_max112+ tmux.send_keys "seq 1 10 | #{FZF} -m 3 --bind A:select-all,T:toggle-all --preview 'echo [{+}]/{}'", :Enter113+114+ tmux.until { |lines| assert_equal 10, lines.item_count }115+116+ tmux.send_keys '1'117+ tmux.until do |lines|118+ assert_includes lines[1], ' [1]/1 '119+ assert lines[-2]&.start_with?(' 2/10 ')120+ end121+122+ tmux.send_keys 'A'123+ tmux.until do |lines|124+ assert_includes lines[1], ' [1 10]/1 '125+ assert lines[-2]&.start_with?(' 2/10 (2/3)')126+ end127+128+ tmux.send_keys :BSpace129+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }130+131+ tmux.send_keys 'T'132+ tmux.until do |lines|133+ assert_includes lines[1], ' [2 3 4]/1 '134+ assert lines[-2]&.start_with?(' 10/10 (3/3)')135+ end136+137+ %w[T A].each do |key|138+ tmux.send_keys key139+ tmux.until do |lines|140+ assert_includes lines[1], ' [1 5 6]/1 '141+ assert lines[-2]&.start_with?(' 10/10 (3/3)')142+ end143+ end144+145+ tmux.send_keys :BTab146+ tmux.until do |lines|147+ assert_includes lines[1], ' [5 6]/2 '148+ assert lines[-2]&.start_with?(' 10/10 (2/3)')149+ end150+151+ [:BTab, :BTab, 'A'].each do |key|152+ tmux.send_keys key153+ tmux.until do |lines|154+ assert_includes lines[1], ' [5 6 2]/3 '155+ assert lines[-2]&.start_with?(' 10/10 (3/3)')156+ end157+ end158+159+ tmux.send_keys '2'160+ tmux.until { |lines| assert lines[-2]&.start_with?(' 1/10 (3/3)') }161+162+ tmux.send_keys 'T'163+ tmux.until do |lines|164+ assert_includes lines[1], ' [5 6]/2 '165+ assert lines[-2]&.start_with?(' 1/10 (2/3)')166+ end167+168+ tmux.send_keys :BSpace169+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }170+171+ tmux.send_keys 'A'172+ tmux.until do |lines|173+ assert_includes lines[1], ' [5 6 1]/1 '174+ assert lines[-2]&.start_with?(' 10/10 (3/3)')175+ end176+ end177+178+ def test_multi_action179+ tmux.send_keys "seq 10 | #{FZF} --bind 'a:change-multi,b:change-multi(3),c:change-multi(xxx),d:change-multi(0)'", :Enter180+ tmux.until { |lines| assert_equal 10, lines.item_count }181+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 ') }182+ tmux.send_keys 'a'183+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0)') }184+ tmux.send_keys 'b'185+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0/3)') }186+ tmux.send_keys :BTab187+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (1/3)') }188+ tmux.send_keys 'c'189+ tmux.send_keys :BTab190+ tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }191+ tmux.send_keys 'd'192+ tmux.until do |lines|193+ assert lines[-2]&.start_with?(' 10/10 ') && !lines[-2]&.include?('(')194+ end195+ end196+197+ def test_with_nth198+ [true, false].each do |multi|199+ tmux.send_keys "(echo ' 1st 2nd 3rd/';200+ echo ' first second third/') |201+ #{fzf(multi && :multi, :x, :nth, 2, :with_nth, '2,-1,1')}",202+ :Enter203+ tmux.until { |lines| assert_equal multi ? ' 2/2 (0)' : ' 2/2', lines[-2] }204+205+ # Transformed list206+ lines = tmux.capture207+ assert_equal ' second third/first', lines[-4]208+ assert_equal '> 2nd 3rd/1st', lines[-3]209+210+ # However, the output must not be transformed211+ if multi212+ tmux.send_keys :BTab, :BTab213+ tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }214+ tmux.send_keys :Enter215+ assert_equal [' 1st 2nd 3rd/', ' first second third/'], fzf_output_lines216+ else217+ tmux.send_keys '^', '3'218+ tmux.until { |lines| assert_equal ' 1/2', lines[-2] }219+ tmux.send_keys :Enter220+ assert_equal [' 1st 2nd 3rd/'], fzf_output_lines221+ end222+ end223+ end224+225+ def test_scroll226+ [true, false].each do |rev|227+ tmux.send_keys "seq 1 100 | #{fzf(rev && :reverse)}", :Enter228+ tmux.until { |lines| assert_equal ' 100/100', lines[rev ? 1 : -2] }229+ tmux.send_keys(*Array.new(110) { rev ? :Down : :Up })230+ tmux.until { |lines| assert_includes lines, '> 100' }231+ tmux.send_keys :Enter232+ assert_equal '100', fzf_output233+ end234+ end235+236+ def test_select_1237+ tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter238+ assert_equal %w[5555 55], fzf_output_lines239+ end240+241+ def test_exit_0242+ tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter243+ assert_equal %w[555555], fzf_output_lines244+ end245+246+ def test_select_1_exit_0_fail247+ [:'0', :'1', %i[1 0]].each do |opt|248+ tmux.send_keys "seq 1 100 | #{fzf(:print_query, :multi, :q, 5, *opt)}", :Enter249+ tmux.until { |lines| assert_equal '> 5', lines.last }250+ tmux.send_keys :BTab, :BTab, :BTab251+ tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }252+ tmux.send_keys :Enter253+ assert_equal %w[5 5 50 51], fzf_output_lines254+ end255+ end256+257+ def test_query_unicode258+ tmux.paste "(echo abc; echo $'\\352\\260\\200\\353\\202\\230\\353\\213\\244') | #{fzf(:query, "$'\\352\\260\\200\\353\\213\\244'")}"259+ tmux.until { |lines| assert_equal ' 1/2', lines[-2] }260+ tmux.send_keys :Enter261+ assert_equal %w[가나다], fzf_output_lines262+ end263+264+ def test_sync265+ tmux.send_keys "seq 1 100 | #{FZF} --multi | awk '{print $1 $1}' | #{fzf(:sync)}", :Enter266+ tmux.until { |lines| assert_equal '>', lines[-1] }267+ tmux.send_keys 9268+ tmux.until { |lines| assert_equal ' 19/100 (0)', lines[-2] }269+ tmux.send_keys :BTab, :BTab, :BTab270+ tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }271+ tmux.send_keys :Enter272+ tmux.until { |lines| assert_equal '>', lines[-1] }273+ tmux.send_keys 'C-K', :Enter274+ assert_equal %w[9090], fzf_output_lines275+ end276+277+ def test_tac278+ tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter279+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }280+ tmux.send_keys :BTab, :BTab, :BTab281+ tmux.until { |lines| assert_equal ' 1000/1000 (3)', lines[-2] }282+ tmux.send_keys :Enter283+ assert_equal %w[1000 999 998], fzf_output_lines284+ end285+286+ def test_tac_sort287+ tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter288+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }289+ tmux.send_keys '99'290+ tmux.until { |lines| assert_equal ' 28/1000 (0)', lines[-2] }291+ tmux.send_keys :BTab, :BTab, :BTab292+ tmux.until { |lines| assert_equal ' 28/1000 (3)', lines[-2] }293+ tmux.send_keys :Enter294+ assert_equal %w[99 999 998], fzf_output_lines295+ end296+297+ def test_tac_nosort298+ tmux.send_keys "seq 1 1000 | #{fzf(:tac, :no_sort, :multi)}", :Enter299+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }300+ tmux.send_keys '00'301+ tmux.until { |lines| assert_equal ' 10/1000 (0)', lines[-2] }302+ tmux.send_keys :BTab, :BTab, :BTab303+ tmux.until { |lines| assert_equal ' 10/1000 (3)', lines[-2] }304+ tmux.send_keys :Enter305+ assert_equal %w[1000 900 800], fzf_output_lines306+ end307+308+ def test_expect309+ test = lambda do |key, feed, expected = key|310+ tmux.send_keys "seq 1 100 | #{fzf(:expect, key, :prompt, "[#{key}]")}", :Enter311+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }312+ tmux.send_keys '55'313+ tmux.until { |lines| assert_equal ' 1/100', lines[-2] }314+ tmux.send_keys(*feed)315+ tmux.prepare316+ assert_equal [expected, '55'], fzf_output_lines317+ end318+ test.call('ctrl-t', 'C-T')319+ test.call('ctrl-t', 'Enter', '')320+ test.call('alt-c', %i[Escape c])321+ test.call('f1', 'f1')322+ test.call('f2', 'f2')323+ test.call('f3', 'f3')324+ test.call('f2,f4', 'f2', 'f2')325+ test.call('f2,f4', 'f4', 'f4')326+ test.call('alt-/', %i[Escape /])327+ %w[f5 f6 f7 f8 f9 f10].each do |key|328+ test.call('f5,f6,f7,f8,f9,f10', key, key)329+ end330+ test.call('@', '@')331+ end332+333+ def test_expect_with_bound_actions334+ tmux.send_keys "seq 1 100 | #{fzf('--query 1 --print-query --expect z --bind z:up+up')}", :Enter335+ tmux.until { |lines| assert_equal 20, lines.match_count }336+ tmux.send_keys('z')337+ assert_equal %w[1 z 1], fzf_output_lines338+ end339+340+ def test_expect_print_query341+ tmux.send_keys "seq 1 100 | #{fzf('--expect=alt-z', :print_query)}", :Enter342+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }343+ tmux.send_keys '55'344+ tmux.until { |lines| assert_equal ' 1/100', lines[-2] }345+ tmux.send_keys :Escape, :z346+ assert_equal %w[55 alt-z 55], fzf_output_lines347+ end348+349+ def test_expect_printable_character_print_query350+ tmux.send_keys "seq 1 100 | #{fzf('--expect=z --print-query')}", :Enter351+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }352+ tmux.send_keys '55'353+ tmux.until { |lines| assert_equal ' 1/100', lines[-2] }354+ tmux.send_keys 'z'355+ assert_equal %w[55 z 55], fzf_output_lines356+ end357+358+ def test_expect_print_query_select_1359+ tmux.send_keys "seq 1 100 | #{fzf('-q55 -1 --expect=alt-z --print-query')}", :Enter360+ assert_equal ['55', '', '55'], fzf_output_lines361+ end362+363+ def test_toggle_sort364+ ['--toggle-sort=ctrl-r', '--bind=ctrl-r:toggle-sort'].each do |opt|365+ tmux.send_keys "seq 1 111 | #{fzf("-m +s --tac #{opt} -q11")}", :Enter366+ tmux.until { |lines| assert_equal '> 111', lines[-3] }367+ tmux.send_keys :Tab368+ tmux.until { |lines| assert_equal ' 4/111 -S (1)', lines[-2] }369+ tmux.send_keys 'C-R'370+ tmux.until { |lines| assert_equal '> 11', lines[-3] }371+ tmux.send_keys :Tab372+ tmux.until { |lines| assert_equal ' 4/111 +S (2)', lines[-2] }373+ tmux.send_keys :Enter374+ assert_equal %w[111 11], fzf_output_lines375+ end376+ end377+378+ def test_invalid_cache379+ tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter380+ tmux.until { |lines| assert_equal ' 2/3', lines[-2] }381+ tmux.send_keys :BSpace382+ tmux.until { |lines| assert_equal ' 3/3', lines[-2] }383+ tmux.send_keys :D384+ tmux.until { |lines| assert_equal ' 1/3', lines[-2] }385+ tmux.send_keys :Enter386+ end387+388+ def test_invalid_cache_query_type389+ command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{FZF}]390+391+ # Suffix match392+ tmux.send_keys command, :Enter393+ tmux.until { |lines| assert_equal 104, lines.match_count }394+ tmux.send_keys 'foo$'395+ tmux.until { |lines| assert_equal 1, lines.match_count }396+ tmux.send_keys 'bar'397+ tmux.until { |lines| assert_equal 1, lines.match_count }398+ tmux.send_keys :Enter399+400+ # Prefix match401+ tmux.prepare402+ tmux.send_keys command, :Enter403+ tmux.until { |lines| assert_equal 104, lines.match_count }404+ tmux.send_keys '^bar'405+ tmux.until { |lines| assert_equal 1, lines.match_count }406+ tmux.send_keys 'C-a', 'foo'407+ tmux.until { |lines| assert_equal 1, lines.match_count }408+ tmux.send_keys :Enter409+410+ # Exact match411+ tmux.prepare412+ tmux.send_keys command, :Enter413+ tmux.until { |lines| assert_equal 104, lines.match_count }414+ tmux.send_keys "'12"415+ tmux.until { |lines| assert_equal 1, lines.match_count }416+ tmux.send_keys 'C-a', 'foo'417+ tmux.until { |lines| assert_equal 1, lines.match_count }418+ end419+420+ def test_bind421+ tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:accept,u:up,T:toggle-up,t:toggle')}", :Enter422+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }423+ tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j'424+ assert_equal %w[4 5 6 9], fzf_output_lines425+ end426+427+ def test_bind_print_query428+ tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:print-query')}", :Enter429+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }430+ tmux.send_keys 'print-my-query', 'C-j'431+ assert_equal %w[print-my-query], fzf_output_lines432+ end433+434+ def test_bind_replace_query435+ tmux.send_keys "seq 1 1000 | #{fzf('--print-query --bind=ctrl-j:replace-query')}", :Enter436+ tmux.send_keys '1'437+ tmux.until { |lines| assert_equal ' 272/1000', lines[-2] }438+ tmux.send_keys 'C-k', 'C-j'439+ tmux.until { |lines| assert_equal ' 29/1000', lines[-2] }440+ tmux.until { |lines| assert_equal '> 10', lines[-1] }441+ end442+443+ def test_select_all_deselect_all_toggle_all444+ tmux.send_keys "seq 100 | #{fzf('--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi')}", :Enter445+ tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }446+ tmux.send_keys :BTab, :BTab, :BTab447+ tmux.until { |lines| assert_equal ' 100/100 (3)', lines[-2] }448+ tmux.send_keys 'C-t'449+ tmux.until { |lines| assert_equal ' 100/100 (97)', lines[-2] }450+ tmux.send_keys 'C-a'451+ tmux.until { |lines| assert_equal ' 100/100 (100)', lines[-2] }452+ tmux.send_keys :Tab, :Tab453+ tmux.until { |lines| assert_equal ' 100/100 (98)', lines[-2] }454+ tmux.send_keys '100'455+ tmux.until { |lines| assert_equal 1, lines.match_count }456+ tmux.send_keys 'C-d'457+ tmux.until { |lines| assert_equal ' 1/100 (97)', lines[-2] }458+ tmux.send_keys 'C-u'459+ tmux.until { |lines| assert_equal 100, lines.match_count }460+ tmux.send_keys 'C-d'461+ tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }462+ tmux.send_keys :BTab, :BTab463+ tmux.until { |lines| assert_equal ' 100/100 (2)', lines[-2] }464+ tmux.send_keys 0465+ tmux.until { |lines| assert_equal ' 10/100 (2)', lines[-2] }466+ tmux.send_keys 'C-a'467+ tmux.until { |lines| assert_equal ' 10/100 (12)', lines[-2] }468+ tmux.send_keys :Enter469+ assert_equal %w[1 2 10 20 30 40 50 60 70 80 90 100],470+ fzf_output_lines471+ end472+473+ def test_history474+ history_file = '/tmp/fzf-test-history'475+476+ # History with limited number of entries477+ FileUtils.rm_f(history_file)478+ opts = "--history=#{history_file} --history-size=4"479+ input = %w[00 11 22 33 44]480+ input.each do |keys|481+ tmux.prepare482+ tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter483+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }484+ tmux.send_keys keys485+ tmux.until { |lines| assert_equal ' 1/100', lines[-2] }486+ tmux.send_keys :Enter487+ end488+ wait do489+ assert_path_exists history_file490+ assert_equal input[1..], File.readlines(history_file, chomp: true)491+ end492+493+ # Update history entries (not changed on disk)494+ tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter495+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }496+ tmux.send_keys 'C-p'497+ tmux.until { |lines| assert_equal '> 44', lines[-1] }498+ tmux.send_keys 'C-p'499+ tmux.until { |lines| assert_equal '> 33', lines[-1] }500+ tmux.send_keys :BSpace501+ tmux.until { |lines| assert_equal '> 3', lines[-1] }502+ tmux.send_keys 1503+ tmux.until { |lines| assert_equal '> 31', lines[-1] }504+ tmux.send_keys 'C-p'505+ tmux.until { |lines| assert_equal '> 22', lines[-1] }506+ tmux.send_keys 'C-n'507+ tmux.until { |lines| assert_equal '> 31', lines[-1] }508+ tmux.send_keys 0509+ tmux.until { |lines| assert_equal '> 310', lines[-1] }510+ tmux.send_keys :Enter511+ wait do512+ assert_path_exists history_file513+ assert_equal %w[22 33 44 310], File.readlines(history_file, chomp: true)514+ end515+516+ # Respect --bind option517+ tmux.send_keys "seq 100 | #{FZF} #{opts} --bind ctrl-p:next-history,ctrl-n:previous-history", :Enter518+ tmux.until { |lines| assert_equal ' 100/100', lines[-2] }519+ tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'520+ tmux.until { |lines| assert_equal '> 33', lines[-1] }521+ tmux.send_keys :Enter522+ ensure523+ FileUtils.rm_f(history_file)524+ end525+526+ def test_cycle527+ tmux.send_keys "seq 8 | #{FZF} --cycle", :Enter528+ tmux.until { |lines| assert_equal ' 8/8', lines[-2] }529+ tmux.send_keys :Down530+ tmux.until { |lines| assert_equal '> 8', lines[-10] }531+ tmux.send_keys :Down532+ tmux.until { |lines| assert_equal '> 7', lines[-9] }533+ tmux.send_keys :Up534+ tmux.until { |lines| assert_equal '> 8', lines[-10] }535+ tmux.send_keys :PgUp536+ tmux.until { |lines| assert_equal '> 8', lines[-10] }537+ tmux.send_keys :Up538+ tmux.until { |lines| assert_equal '> 1', lines[-3] }539+ tmux.send_keys :PgDn540+ tmux.until { |lines| assert_equal '> 1', lines[-3] }541+ tmux.send_keys :Down542+ tmux.until { |lines| assert_equal '> 8', lines[-10] }543+ end544+545+ def test_header_lines546+ tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5')}", :Enter547+ 2.times do548+ tmux.until do |lines|549+ assert_equal ' 18/90', lines[-2]550+ assert_equal ' 1', lines[-3]551+ assert_equal ' 2', lines[-4]552+ assert_equal '> 50', lines[-13]553+ end554+ tmux.send_keys :Down555+ end556+ tmux.send_keys :Enter557+ assert_equal '50', fzf_output558+ end559+560+ def test_header_lines_reverse561+ tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --reverse')}", :Enter562+ 2.times do563+ tmux.until do |lines|564+ assert_equal ' 18/90', lines[1]565+ assert_equal ' 1', lines[2]566+ assert_equal ' 2', lines[3]567+ assert_equal '> 50', lines[12]568+ end569+ tmux.send_keys :Up570+ end571+ tmux.send_keys :Enter572+ assert_equal '50', fzf_output573+ end574+575+ def test_header_lines_reverse_list576+ tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --layout=reverse-list')}", :Enter577+ 2.times do578+ tmux.until do |lines|579+ assert_equal '> 50', lines[0]580+ assert_equal ' 2', lines[-4]581+ assert_equal ' 1', lines[-3]582+ assert_equal ' 18/90', lines[-2]583+ end584+ tmux.send_keys :Up585+ end586+ tmux.send_keys :Enter587+ assert_equal '50', fzf_output588+ end589+590+ def test_header_lines_overflow591+ tmux.send_keys "seq 100 | #{fzf('--header-lines=200')}", :Enter592+ tmux.until do |lines|593+ assert_equal ' 0/0', lines[-2]594+ assert_equal ' 1', lines[-3]595+ end596+ tmux.send_keys :Enter597+ assert_equal '', fzf_output598+ end599+600+ def test_header_lines_with_nth601+ tmux.send_keys "seq 100 | #{fzf('--header-lines 5 --with-nth 1,1,1,1,1')}", :Enter602+ tmux.until do |lines|603+ assert_equal ' 95/95', lines[-2]604+ assert_equal ' 11111', lines[-3]605+ assert_equal ' 55555', lines[-7]606+ assert_equal '> 66666', lines[-8]607+ end608+ tmux.send_keys :Enter609+ assert_equal '6', fzf_output610+ end611+612+ def test_header613+ tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})"], :Enter614+ header = File.readlines(FILE, chomp: true).take(5)615+ tmux.until do |lines|616+ assert_equal ' 100/100', lines[-2]617+ assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]618+ assert_equal '> 1', lines[-8]619+ end620+ end621+622+ def test_header_reverse623+ tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --reverse], :Enter624+ header = File.readlines(FILE, chomp: true).take(5)625+ tmux.until do |lines|626+ assert_equal ' 100/100', lines[1]627+ assert_equal header.map { |line| " #{line}".rstrip }, lines[2..6]628+ assert_equal '> 1', lines[7]629+ end630+ end631+632+ def test_header_reverse_list633+ tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --layout=reverse-list], :Enter634+ header = File.readlines(FILE, chomp: true).take(5)635+ tmux.until do |lines|636+ assert_equal ' 100/100', lines[-2]637+ assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]638+ assert_equal '> 1', lines[0]639+ end640+ end641+642+ def test_header_and_header_lines643+ tmux.send_keys %[seq 100 | #{FZF} --header-lines 10 --header "$(head -5 #{FILE})"], :Enter644+ header = File.readlines(FILE, chomp: true).take(5)645+ tmux.until do |lines|646+ assert_equal ' 90/90', lines[-2]647+ assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]648+ assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]649+ end650+ end651+652+ def test_header_and_header_lines_reverse653+ tmux.send_keys %[seq 100 | #{FZF} --reverse --header-lines 10 --header "$(head -5 #{FILE})"], :Enter654+ header = File.readlines(FILE, chomp: true).take(5)655+ tmux.until do |lines|656+ assert_equal ' 90/90', lines[1]657+ assert_equal header.map { |line| " #{line}".rstrip }, lines[2...7]658+ assert_equal (' 1'..' 10').to_a, lines[7...17]659+ end660+ end661+662+ def test_header_and_header_lines_reverse_list663+ tmux.send_keys %[seq 100 | #{FZF} --layout=reverse-list --header-lines 10 --header "$(head -5 #{FILE})"], :Enter664+ header = File.readlines(FILE, chomp: true).take(5)665+ tmux.until do |lines|666+ assert_equal ' 90/90', lines[-2]667+ assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]668+ assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]669+ end670+ end671+672+ def test_cancel673+ tmux.send_keys "seq 10 | #{FZF} --bind 2:cancel", :Enter674+ tmux.until { |lines| assert_equal ' 10/10', lines[-2] }675+ tmux.send_keys '123'676+ tmux.until do |lines|677+ assert_equal '> 3', lines[-1]678+ assert_equal ' 1/10', lines[-2]679+ end680+ tmux.send_keys 'C-y', 'C-y'681+ tmux.until { |lines| assert_equal '> 311', lines[-1] }682+ tmux.send_keys 2683+ tmux.until { |lines| assert_equal '>', lines[-1] }684+ tmux.send_keys 2685+ tmux.prepare686+ end687+688+ def test_margin689+ tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3", :Enter690+ tmux.until do |lines|691+ assert_equal '', lines[4]692+ assert_equal ' y', lines[5]693+ end694+ tmux.send_keys :Enter695+ end696+697+ def test_margin_reverse698+ tmux.send_keys "seq 1000 | #{FZF} --margin 7,5 --reverse", :Enter699+ tmux.until { |lines| assert_equal ' 1000/1000', lines[1 + 7] }700+ tmux.send_keys :Enter701+ end702+703+ def test_margin_reverse_list704+ tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3 --layout=reverse-list", :Enter705+ tmux.until do |lines|706+ assert_equal '', lines[4]707+ assert_equal ' > y', lines[5]708+ end709+ tmux.send_keys :Enter710+ end711+712+ def test_tabstop713+ writelines(%W[f\too\tba\tr\tbaz\tbarfooq\tux])714+ {715+ 1 => '> f oo ba r baz barfooq ux',716+ 2 => '> f oo ba r baz barfooq ux',717+ 3 => '> f oo ba r baz barfooq ux',718+ 4 => '> f oo ba r baz barfooq ux',719+ 5 => '> f oo ba r baz barfooq ux',720+ 6 => '> f oo ba r baz barfooq ux',721+ 7 => '> f oo ba r baz barfooq ux',722+ 8 => '> f oo ba r baz barfooq ux',723+ 9 => '> f oo ba r baz barfooq ux'724+ }.each do |ts, exp|725+ tmux.prepare726+ tmux.send_keys %(cat #{tempname} | fzf --tabstop=#{ts}), :Enter727+ tmux.until(true) do |lines|728+ assert_equal exp, lines[-3]729+ end730+ tmux.send_keys :Enter731+ end732+ end733+734+ def test_exit_0_exit_code735+ `echo foo | #{FZF} -q bar -0`736+ assert_equal 1, $CHILD_STATUS.exitstatus737+ end738+739+ def test_invalid_option740+ lines = `#{FZF} --foobar 2>&1`741+ assert_equal 2, $CHILD_STATUS.exitstatus742+ assert_includes lines, 'unknown option: --foobar'743+ end744+745+ def test_exitstatus_empty746+ { '99' => '0', '999' => '1' }.each do |query, status|747+ tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter748+ tmux.until { |lines| assert_match %r{ [10]/100}, lines[-2] }749+ tmux.send_keys :Enter750+ tmux.until { |lines| assert_equal "--#{status}--", lines.last }751+ end752+ end753+754+ def test_hscroll_off755+ writelines([('=' * 10_000) + '0123456789'])756+ [0, 3, 6].each do |off|757+ tmux.prepare758+ tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 --bind space:toggle-hscroll < #{tempname}", :Enter759+ tmux.until { |lines| assert lines[-3]&.end_with?((0..off).to_a.join + '··') }760+ tmux.send_keys '9'761+ tmux.until { |lines| assert lines[-3]&.end_with?('789') }762+ tmux.send_keys :Space763+ tmux.until { |lines| assert lines[-3]&.end_with?('=··') }764+ tmux.send_keys :Space765+ tmux.until { |lines| assert lines[-3]&.end_with?('789') }766+ tmux.send_keys :Enter767+ end768+ end769+770+ def test_partial_caching771+ tmux.send_keys 'seq 1000 | fzf -e', :Enter772+ tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }773+ tmux.send_keys 11774+ tmux.until { |lines| assert_equal ' 19/1000', lines[-2] }775+ tmux.send_keys 'C-a', "'"776+ tmux.until { |lines| assert_equal ' 28/1000', lines[-2] }777+ tmux.send_keys :Enter778+ end779+780+ def test_jump781+ tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump'")}", :Enter782+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }783+ tmux.send_keys 'C-j'784+ tmux.until { |lines| assert_equal '5 5', lines[-7] }785+ tmux.until { |lines| assert_equal ' 6', lines[-8] }786+ tmux.send_keys '5'787+ tmux.until { |lines| assert_equal '> 5', lines[-7] }788+ tmux.send_keys :Tab789+ tmux.until { |lines| assert_equal ' >5', lines[-7] }790+ tmux.send_keys 'C-j'791+ tmux.until { |lines| assert_equal '5>5', lines[-7] }792+ tmux.send_keys '2'793+ tmux.until { |lines| assert_equal '> 2', lines[-4] }794+ tmux.send_keys :Tab795+ tmux.until { |lines| assert_equal ' >2', lines[-4] }796+ tmux.send_keys 'C-j'797+ tmux.until { |lines| assert_equal '5>5', lines[-7] }798+799+ # Press any key other than jump labels to cancel jump800+ tmux.send_keys '6'801+ tmux.until { |lines| assert_equal '> 1', lines[-3] }802+ tmux.send_keys :Tab803+ tmux.until { |lines| assert_equal '>>1', lines[-3] }804+ tmux.send_keys :Enter805+ assert_equal %w[5 2 1], fzf_output_lines806+ end807+808+ def test_jump_accept809+ tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump-accept'")}", :Enter810+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }811+ tmux.send_keys 'C-j'812+ tmux.until { |lines| assert_equal '5 5', lines[-7] }813+ tmux.send_keys '3'814+ assert_equal '3', fzf_output815+ end816+817+ def test_jump_events818+ tmux.send_keys "seq 1000 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump,jump:preview(echo jumped to {}),jump-cancel:preview(echo jump cancelled at {})'", :Enter819+ tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }820+ tmux.send_keys 'C-j'821+ tmux.until { |lines| assert_includes lines[-7], '5 5' }822+ tmux.send_keys '3'823+ tmux.until { |lines| assert(lines.any? { it.include?('jumped to 3') }) }824+ tmux.send_keys 'C-j'825+ tmux.until { |lines| assert_includes lines[-7], '5 5' }826+ tmux.send_keys 'C-c'827+ tmux.until { |lines| assert(lines.any? { it.include?('jump cancelled at 3') }) }828+ end829+830+ def test_pointer831+ tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter832+ # Assert that specified pointer is displayed833+ tmux.until { |lines| assert_equal '>> 1', lines[-3] }834+ end835+836+ def test_pointer_with_jump837+ tmux.send_keys "seq 10 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '>>'", :Enter838+ tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }839+ tmux.send_keys 'C-j'840+ # Correctly padded jump label should appear841+ tmux.until { |lines| assert_equal '5 5', lines[-7] }842+ tmux.until { |lines| assert_equal ' 6', lines[-8] }843+ tmux.send_keys '5'844+ # Assert that specified pointer is displayed845+ tmux.until { |lines| assert_equal '>> 5', lines[-7] }846+ end847+848+ def test_marker849+ tmux.send_keys "seq 10 | #{FZF} --multi --marker '>>'", :Enter850+ tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }851+ tmux.send_keys :BTab852+ # Assert that specified marker is displayed853+ tmux.until { |lines| assert_equal ' >>1', lines[-3] }854+ end855+856+ def test_no_clear857+ tmux.send_keys "seq 10 | #{fzf('--no-clear --inline-info --height 5')}", :Enter858+ prompt = '> < 10/10'859+ tmux.until { |lines| assert_equal prompt, lines[-1] }860+ tmux.send_keys :Enter861+ assert_equal %w[1], fzf_output_lines862+ tmux.until { |lines| assert_equal prompt, lines[-1] }863+ end864+865+ def test_info_hidden866+ tmux.send_keys 'seq 10 | fzf --info=hidden --no-separator', :Enter867+ tmux.until { |lines| assert_equal '> 1', lines[-2] }868+ end869+870+ def test_info_inline_separator871+ tmux.send_keys 'seq 10 | fzf --info=inline:___ --no-separator', :Enter872+ tmux.until { |lines| assert_equal '> ___10/10', lines[-1] }873+ end874+875+ def test_change_first_last876+ tmux.send_keys %(seq 1000 | #{FZF} --bind change:first,alt-Z:last), :Enter877+ tmux.until { |lines| assert_equal 1000, lines.match_count }878+ tmux.send_keys :Up879+ tmux.until { |lines| assert_equal '> 2', lines[-4] }880+ tmux.send_keys 1881+ tmux.until { |lines| assert_equal '> 1', lines[-3] }882+ tmux.send_keys :Up883+ tmux.until { |lines| assert_equal '> 10', lines[-4] }884+ tmux.send_keys 1885+ tmux.until { |lines| assert_equal '> 11', lines[-3] }886+ tmux.send_keys 'C-u'887+ tmux.until { |lines| assert_equal '> 1', lines[-3] }888+ tmux.send_keys :Escape, 'Z'889+ tmux.until { |lines| assert_equal '> 1000', lines[0] }890+ tmux.send_keys :Enter891+ end892+893+ def test_pos894+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:pos(3),b:pos(-3),c:pos(1),d:pos(-1),e:pos(0)' --preview 'echo {}/{}'), :Enter895+ tmux.until { |lines| assert_equal 1000, lines.match_count }896+ tmux.send_keys :a897+ tmux.until { |lines| assert_includes lines[1], ' 3/3' }898+ tmux.send_keys :b899+ tmux.until { |lines| assert_includes lines[1], ' 998/998' }900+ tmux.send_keys :c901+ tmux.until { |lines| assert_includes lines[1], ' 1/1' }902+ tmux.send_keys :d903+ tmux.until { |lines| assert_includes lines[1], ' 1000/1000' }904+ tmux.send_keys :e905+ tmux.until { |lines| assert_includes lines[1], ' 1/1' }906+ end907+908+ def test_put909+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:put+put,b:put+put(ravo)' --preview 'echo {q}/{q}'), :Enter910+ tmux.until { |lines| assert_equal 1000, lines.match_count }911+ tmux.send_keys :a912+ tmux.until { |lines| assert_includes lines[1], ' aa/aa' }913+ tmux.send_keys :b914+ tmux.until { |lines| assert_includes lines[1], ' aabravo/aabravo' }915+ end916+917+ def test_accept_non_empty918+ tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter919+ tmux.until { |lines| assert_equal 1000, lines.match_count }920+ tmux.send_keys 'foo'921+ tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }922+ # fzf doesn't exit since there's no selection923+ tmux.send_keys :Enter924+ tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }925+ tmux.send_keys 'C-u'926+ tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }927+ tmux.send_keys '999'928+ tmux.until { |lines| assert_equal ' 1/1000', lines[-2] }929+ tmux.send_keys :Enter930+ assert_equal %w[999 999], fzf_output_lines931+ end932+933+ def test_accept_non_empty_with_multi_selection934+ tmux.send_keys %(seq 1000 | #{fzf('-m --print-query --bind enter:accept-non-empty')}), :Enter935+ tmux.until { |lines| assert_equal 1000, lines.match_count }936+ tmux.send_keys :Tab937+ tmux.until { |lines| assert_equal ' 1000/1000 (1)', lines[-2] }938+ tmux.send_keys 'foo'939+ tmux.until { |lines| assert_equal ' 0/1000 (1)', lines[-2] }940+ # fzf will exit in this case even though there's no match for the current query941+ tmux.send_keys :Enter942+ assert_equal %w[foo 1], fzf_output_lines943+ end944+945+ def test_accept_non_empty_with_empty_list946+ tmux.send_keys %(: | #{fzf('-q foo --print-query --bind enter:accept-non-empty')}), :Enter947+ tmux.until { |lines| assert_equal ' 0/0', lines[-2] }948+ tmux.send_keys :Enter949+ # fzf will exit anyway since input list is empty950+ assert_equal %w[foo], fzf_output_lines951+ end952+953+ def test_accept_or_print_query_without_match954+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter955+ tmux.until { |lines| assert_equal 1000, lines.match_count }956+ tmux.send_keys 99_999957+ tmux.until { |lines| assert_equal 0, lines.match_count }958+ tmux.send_keys :Enter959+ assert_equal %w[99999], fzf_output_lines960+ end961+962+ def test_accept_or_print_query_with_match963+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter964+ tmux.until { |lines| assert_equal 1000, lines.match_count }965+ tmux.send_keys '^99$'966+ tmux.until { |lines| assert_equal 1, lines.match_count }967+ tmux.send_keys :Enter968+ assert_equal %w[99], fzf_output_lines969+ end970+971+ def test_accept_or_print_query_with_multi_selection972+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter973+ tmux.until { |lines| assert_equal 1000, lines.match_count }974+ tmux.send_keys :BTab, :BTab, :BTab975+ tmux.until { |lines| assert_equal 3, lines.select_count }976+ tmux.send_keys 99_999977+ tmux.until { |lines| assert_equal 0, lines.match_count }978+ tmux.send_keys :Enter979+ assert_equal %w[1 2 3], fzf_output_lines980+ end981+982+ def test_inverse_only_search_should_not_sort_the_result983+ # Filter984+ assert_equal %w[aaaaa b ccc],985+ `printf '%s\n' aaaaa b ccc BAD | #{FZF} -f '!bad'`.lines(chomp: true)986+987+ # Interactive988+ tmux.send_keys %(printf '%s\n' aaaaa b ccc BAD | #{FZF} -q '!bad'), :Enter989+ tmux.until do |lines|990+ assert_equal 4, lines.item_count991+ assert_equal 3, lines.match_count992+ end993+ tmux.until { |lines| assert_equal '> aaaaa', lines[-3] }994+ tmux.until { |lines| assert_equal ' b', lines[-4] }995+ tmux.until { |lines| assert_equal ' ccc', lines[-5] }996+ end997+998+ def test_disabled999+ tmux.send_keys %(seq 1000 | #{FZF} --query 333 --disabled --bind a:enable-search,b:disable-search,c:toggle-search --preview 'echo {} {q}'), :Enter1000+ tmux.until { |lines| assert_equal 1000, lines.match_count }1001+ tmux.until { |lines| assert_includes lines[1], ' 1 333 ' }1002+ tmux.send_keys 'foo'1003+ tmux.until { |lines| assert_equal 1000, lines.match_count }1004+ tmux.until { |lines| assert_includes lines[1], ' 1 333foo ' }1005+1006+ # Already disabled, no change1007+ tmux.send_keys 'b'1008+ tmux.until { |lines| assert_equal 1000, lines.match_count }1009+1010+ # Enable search1011+ tmux.send_keys 'a'1012+ tmux.until { |lines| assert_equal 0, lines.match_count }1013+ tmux.send_keys :BSpace, :BSpace, :BSpace1014+ tmux.until { |lines| assert_equal 1, lines.match_count }1015+ tmux.until { |lines| assert_includes lines[1], ' 333 333 ' }1016+1017+ # Toggle search -> disabled again, but retains the previous result1018+ tmux.send_keys 'c'1019+ tmux.send_keys 'foo'1020+ tmux.until { |lines| assert_includes lines[1], ' 333 333foo ' }1021+ tmux.until { |lines| assert_equal 1, lines.match_count }1022+1023+ # Enabled, no match1024+ tmux.send_keys 'c'1025+ tmux.until { |lines| assert_equal 0, lines.match_count }1026+ tmux.until { |lines| assert_includes lines[1], ' 333foo ' }1027+ end1028+1029+ def test_clear_query1030+ tmux.send_keys %(: | #{FZF} --query foo --bind space:clear-query), :Enter1031+ tmux.until { |lines| assert_equal 0, lines.item_count }1032+ tmux.until { |lines| assert_equal '> foo', lines.last }1033+ tmux.send_keys 'C-a', 'bar'1034+ tmux.until { |lines| assert_equal '> barfoo', lines.last }1035+ tmux.send_keys :Space1036+ tmux.until { |lines| assert_equal '>', lines.last }1037+ end1038+1039+ def test_change_query1040+ tmux.send_keys %(: | #{FZF} --query foo --bind space:change-query:foobar), :Enter1041+ tmux.until { |lines| assert_equal 0, lines.item_count }1042+ tmux.until { |lines| assert_equal '> foo', lines.last }1043+ tmux.send_keys :Space, 'baz'1044+ tmux.until { |lines| assert_equal '> foobarbaz', lines.last }1045+ end1046+1047+ def test_transform_query1048+ tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter1049+ tmux.until { |lines| assert_equal '> bar', lines[-1] }1050+ tmux.send_keys 'C-r'1051+ tmux.until { |lines| assert_equal '> rab', lines[-1] }1052+ tmux.send_keys 'C-u'1053+ tmux.until { |lines| assert_equal '> RAB', lines[-1] }1054+ end1055+1056+ def test_transform_prompt1057+ tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter1058+ tmux.until { |lines| assert_equal '> bar', lines[-1] }1059+ tmux.send_keys 'C-r'1060+ tmux.until { |lines| assert_equal '> rab', lines[-1] }1061+ tmux.send_keys 'C-u'1062+ tmux.until { |lines| assert_equal '> RAB', lines[-1] }1063+ end1064+1065+ def test_transform1066+ tmux.send_keys %{#{FZF} --bind 'focus:transform:echo "change-prompt({fzf:action})"'}, :Enter1067+ tmux.until { |lines| assert_equal 'start', lines[-1] }1068+ tmux.send_keys :Up1069+ tmux.until { |lines| assert_equal 'up', lines[-1] }1070+ end1071+1072+ def test_clear_selection1073+ tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter1074+ tmux.until { |lines| assert_equal 100, lines.match_count }1075+ tmux.send_keys :Tab1076+ tmux.until { |lines| assert_equal ' 100/100 (1)', lines[-2] }1077+ tmux.send_keys 'foo'1078+ tmux.until { |lines| assert_equal ' 0/100 (1)', lines[-2] }1079+ tmux.send_keys :Space1080+ tmux.until { |lines| assert_equal ' 0/100 (0)', lines[-2] }1081+ end1082+1083+ def test_backward_delete_char_eof1084+ tmux.send_keys "seq 1000 | #{FZF} --bind 'bs:backward-delete-char/eof'", :Enter1085+ tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }1086+ tmux.send_keys '11'1087+ tmux.until { |lines| assert_equal '> 11', lines[-1] }1088+ tmux.send_keys :BSpace1089+ tmux.until { |lines| assert_equal '> 1', lines[-1] }1090+ tmux.send_keys :BSpace1091+ tmux.until { |lines| assert_equal '>', lines[-1] }1092+ tmux.send_keys :BSpace1093+ tmux.prepare1094+ end1095+1096+ def test_strip_xterm_osc_sequence1097+ %W[\x07 \x1b\\].each do |esc|1098+ writelines([%(printf $1"\e]4;3;rgb:aa/bb/cc#{esc} "$2)])1099+ File.chmod(0o755, tempname)1100+ tmux.prepare1101+ tmux.send_keys \1102+ %(echo foo bar | #{FZF} --preview '#{tempname} {2} {1}'), :Enter1103+1104+ tmux.until { |lines| assert lines.any_include?('bar foo') }1105+ tmux.send_keys :Enter1106+ end1107+ end1108+1109+ def test_keep_right1110+ tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right --no-multi-line --bind space:toggle-multi-line", :Enter1111+ tmux.until { |lines| assert lines.any_include?('9999␊10000') }1112+ tmux.send_keys :Space1113+ tmux.until { |lines| assert lines.any_include?('> 1') }1114+ tmux.send_keys :Space1115+ tmux.until { |lines| assert lines.any_include?('9999␊10000') }1116+ end1117+1118+ def test_backward_eof1119+ tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter1120+ tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }1121+ tmux.send_keys 'x'1122+ tmux.until { |lines| lines.item_count == 1 && lines.match_count == 0 }1123+ tmux.send_keys :BSpace1124+ tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }1125+ tmux.send_keys :BSpace1126+ tmux.until { |lines| lines.item_count == 100 && lines.match_count == 100 }1127+ end1128+1129+ def test_change_prompt1130+ tmux.send_keys "#{FZF} --bind 'a:change-prompt(a> ),b:change-prompt:b> ' --query foo", :Enter1131+ tmux.until { |lines| assert_equal '> foo', lines[-1] }1132+ tmux.send_keys 'a'1133+ tmux.until { |lines| assert_equal 'a> foo', lines[-1] }1134+ tmux.send_keys 'b'1135+ tmux.until { |lines| assert_equal 'b> foo', lines[-1] }1136+ end1137+1138+ def test_select_deselect1139+ tmux.send_keys "seq 3 | #{FZF} --multi --bind up:deselect+up,down:select+down", :Enter1140+ tmux.until { |lines| assert_equal 3, lines.match_count }1141+ tmux.send_keys :Tab1142+ tmux.until { |lines| assert_equal 1, lines.select_count }1143+ tmux.send_keys :Up1144+ tmux.until { |lines| assert_equal 0, lines.select_count }1145+ tmux.send_keys :Down, :Down1146+ tmux.until { |lines| assert_equal 2, lines.select_count }1147+ tmux.send_keys :Tab1148+ tmux.until { |lines| assert_equal 1, lines.select_count }1149+ tmux.send_keys :Down, :Down1150+ tmux.until { |lines| assert_equal 2, lines.select_count }1151+ tmux.send_keys :Up1152+ tmux.until { |lines| assert_equal 1, lines.select_count }1153+ tmux.send_keys :Down1154+ tmux.until { |lines| assert_equal 1, lines.select_count }1155+ tmux.send_keys :Down1156+ tmux.until { |lines| assert_equal 2, lines.select_count }1157+ end1158+1159+ def test_unbind_rebind1160+ tmux.send_keys "seq 100 | #{FZF} --bind 'c:clear-query,d:unbind(c,d),e:rebind(c,d)'", :Enter1161+ tmux.until { |lines| assert_equal 100, lines.item_count }1162+ tmux.send_keys 'ab'1163+ tmux.until { |lines| assert_equal '> ab', lines[-1] }1164+ tmux.send_keys 'c'1165+ tmux.until { |lines| assert_equal '>', lines[-1] }1166+ tmux.send_keys 'dabcd'1167+ tmux.until { |lines| assert_equal '> abcd', lines[-1] }1168+ tmux.send_keys 'ecabddc'1169+ tmux.until { |lines| assert_equal '> abdc', lines[-1] }1170+ end1171+1172+ def test_scroll_off1173+ tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter1174+ tmux.until { |lines| assert_equal 1000, lines.item_count }1175+ height = tmux.until { |lines| lines }.first.to_i1176+ tmux.send_keys :PgUp1177+ tmux.until do |lines|1178+ assert_equal height + 3, lines.first.to_i1179+ assert_equal "> #{height}", lines[3].strip1180+ end1181+ tmux.send_keys :Up1182+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[3].strip }1183+ tmux.send_keys 'l'1184+ tmux.until { |lines| assert_equal '> 1000', lines.first.strip }1185+ tmux.send_keys :PgDn1186+ tmux.until { |lines| assert_equal "> #{1000 - height + 1}", lines.reverse[5].strip }1187+ tmux.send_keys :Down1188+ tmux.until { |lines| assert_equal "> #{1000 - height}", lines.reverse[5].strip }1189+ end1190+1191+ def test_scroll_off_large1192+ tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter1193+ tmux.until { |lines| assert_equal 1000, lines.item_count }1194+ height = tmux.until { |lines| lines }.first.to_i1195+ tmux.send_keys :PgUp1196+ tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip }1197+ tmux.send_keys :Up1198+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }1199+ tmux.send_keys :Up1200+ tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip }1201+ tmux.send_keys :Down1202+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }1203+ end1204+1205+ def test_ellipsis1206+ tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter1207+ tmux.until { |lines| assert_equal 1, lines.match_count }1208+ tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }1209+ end1210+1211+ def test_start_event1212+ tmux.send_keys 'seq 100 | fzf --multi --sync --preview-window hidden:border-none --bind "start:select-all+last+preview(echo welcome)"', :Enter1213+ tmux.until do |lines|1214+ assert_match(/>100.*welcome/, lines[0])1215+ assert_includes(lines[-2], '100/100 (100)')1216+ end1217+ end1218+1219+ def test_focus_event1220+ tmux.send_keys 'seq 100 | fzf --bind "focus:transform-prompt(echo [[{}]]),?:unbind(focus)"', :Enter1221+ tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }1222+ tmux.send_keys :Up1223+ tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }1224+ tmux.send_keys :X1225+ tmux.until { |lines| assert_includes(lines[-1], '[[]]') }1226+ tmux.send_keys :BSpace1227+ tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }1228+ tmux.send_keys :X1229+ tmux.until { |lines| assert_includes(lines[-1], '[[]]') }1230+ tmux.send_keys '?'1231+ tmux.send_keys :BSpace1232+ tmux.until { |lines| assert_equal 100, lines.match_count }1233+ tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }1234+ end1235+1236+ def test_result_event1237+ tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter1238+ tmux.until { |lines| assert_equal 11, lines.item_count }1239+ tmux.until { |lines| assert_includes lines, '> 1' }1240+ tmux.send_keys '9'1241+ tmux.until { |lines| assert_includes lines, '> 9' }1242+ tmux.send_keys :BSpace1243+ tmux.until { |lines| assert_includes lines, '> 1' }1244+ end1245+1246+ def test_labels_center1247+ tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter1248+ tmux.until do1249+ assert_includes(it[0], '─foobar─')1250+ assert_includes(it[1], '─barfoo─')1251+ end1252+ tmux.send_keys :space1253+ tmux.until do1254+ assert_includes(it[0], '─foobarfoo─')1255+ assert_includes(it[1], '─barfoobar─')1256+ end1257+ tmux.send_keys :Enter1258+ tmux.until do1259+ assert_includes(it[0], '─fooxfoo─')1260+ assert_includes(it[1], '─barxbar─')1261+ end1262+ end1263+1264+ def test_labels_left1265+ tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2 --preview : --preview-label barfoo --preview-label-pos 2', :Enter1266+ tmux.until do1267+ assert_includes(it[0], '╭foobar─')1268+ assert_includes(it[1], '╭barfoo─')1269+ end1270+ end1271+1272+ def test_labels_right1273+ tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos -2 --preview : --preview-label barfoo --preview-label-pos -2', :Enter1274+ tmux.until do1275+ assert_includes(it[0], '─foobar╮')1276+ assert_includes(it[1], '─barfoo╮')1277+ end1278+ end1279+1280+ def test_labels_bottom1281+ tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2:bottom --preview : --preview-label barfoo --preview-label-pos -2:bottom', :Enter1282+ tmux.until do1283+ assert_includes(it[-1], '╰foobar─')1284+ assert_includes(it[-2], '─barfoo╯')1285+ end1286+ end1287+1288+ def test_labels_variables1289+ tmux.send_keys ': | fzf --border --border-label foobar --preview "echo \$FZF_BORDER_LABEL // \$FZF_PREVIEW_LABEL" --preview-label barfoo --bind "space:change-border-label(barbaz)+change-preview-label(bazbar)+refresh-preview,enter:transform-border-label(echo 123)+transform-preview-label(echo 456)+refresh-preview"', :Enter1290+ tmux.until do1291+ assert_includes(it[0], '─foobar─')1292+ assert_includes(it[1], '─barfoo─')1293+ assert_includes(it[2], ' foobar // barfoo ')1294+ end1295+ tmux.send_keys :Space1296+ tmux.until do1297+ assert_includes(it[0], '─barbaz─')1298+ assert_includes(it[1], '─bazbar─')1299+ assert_includes(it[2], ' barbaz // bazbar ')1300+ end1301+ tmux.send_keys :Enter1302+ tmux.until do1303+ assert_includes(it[0], '─123─')1304+ assert_includes(it[1], '─456─')1305+ assert_includes(it[2], ' 123 // 456 ')1306+ end1307+ end1308+1309+ def test_info_separator_unicode1310+ tmux.send_keys 'seq 100 | fzf -q55', :Enter1311+ tmux.until { assert_includes(it[-2], ' 1/100 ─') }1312+ end1313+1314+ def test_info_separator_no_unicode1315+ tmux.send_keys 'seq 100 | fzf -q55 --no-unicode', :Enter1316+ tmux.until { assert_includes(it[-2], ' 1/100 -') }1317+ end1318+1319+ def test_info_separator_repeat1320+ tmux.send_keys 'seq 100 | fzf -q55 --separator _-', :Enter1321+ tmux.until { assert_includes(it[-2], ' 1/100 _-_-') }1322+ end1323+1324+ def test_info_separator_ansi_colors_and_tabs1325+ tmux.send_keys "seq 100 | fzf -q55 --tabstop 4 --separator $'\\x1b[33ma\\tb'", :Enter1326+ tmux.until { assert_includes(it[-2], ' 1/100 a ba ba') }1327+ end1328+1329+ def test_info_no_separator1330+ tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter1331+ tmux.until { assert_operator(it[-2], :==, ' 1/100') }1332+ end1333+1334+ def test_info_right1335+ tmux.send_keys "#{FZF} --info=right --separator x --bind 'start:reload:seq 100; sleep 10'", :Enter1336+ tmux.until { assert_match(%r{xxx [⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, it[-2]) }1337+ end1338+1339+ def test_info_inline_right1340+ tmux.send_keys "#{FZF} --info=inline-right --bind 'start:reload:seq 100; sleep 10'", :Enter1341+ tmux.until { assert_match(%r{[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, it[-1]) }1342+ end1343+1344+ def test_info_inline_right_clearance1345+ tmux.send_keys "seq 100000 | #{FZF} --info inline-right", :Enter1346+ tmux.until { assert_match(%r{100000/100000}, it[-1]) }1347+ tmux.send_keys 'x'1348+ tmux.until { assert_match(%r{ 0/100000}, it[-1]) }1349+ end1350+1351+ def test_info_command1352+ tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"'), :Enter)1353+ tmux.until { assert_match(%r{^ --1/10000/10000-- xx}, it[-2]) }1354+ tmux.send_keys :Up1355+ tmux.until { assert_match(%r{^ --2/10000/10000-- xx}, it[-2]) }1356+ end1357+1358+ def test_info_command_inline1359+ tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline:xx), :Enter)1360+ tmux.until { assert_match(%r{^> xx--1/10000/10000-- xx}, it[-1]) }1361+ end1362+1363+ def test_info_command_right1364+ tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info right), :Enter)1365+ tmux.until { assert_match(%r{xx --1/10000/10000-- *$}, it[-2]) }1366+ end1367+1368+ def test_info_command_inline_right1369+ tmux.send_keys(%(seq 10000 | #{FZF} --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline-right), :Enter)1370+ tmux.until { assert_match(%r{ --1/10000/10000-- *$}, it[-1]) }1371+ end1372+1373+ def test_info_command_and_focus1374+ tmux.send_keys(%(seq 100 | #{FZF} --separator x --info-command 'echo $FZF_POS' --bind focus:clear-query), :Enter)1375+ tmux.until { assert_match(/^ 1 xx/, it[-2]) }1376+ tmux.send_keys :Up1377+ tmux.until { assert_match(/^ 2 xx/, it[-2]) }1378+ end1379+1380+ def test_prev_next_selected1381+ tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter1382+ tmux.until { |lines| assert_equal 10, lines.item_count }1383+ tmux.send_keys :BTab, :BTab, :Up, :BTab1384+ tmux.until { |lines| assert_equal 3, lines.select_count }1385+ tmux.send_keys 'C-n'1386+ tmux.until { |lines| assert_includes lines, '>>4' }1387+ tmux.send_keys 'C-n'1388+ tmux.until { |lines| assert_includes lines, '>>2' }1389+ tmux.send_keys 'C-n'1390+ tmux.until { |lines| assert_includes lines, '>>1' }1391+ tmux.send_keys 'C-n'1392+ tmux.until { |lines| assert_includes lines, '>>4' }1393+ tmux.send_keys 'C-p'1394+ tmux.until { |lines| assert_includes lines, '>>1' }1395+ tmux.send_keys 'C-p'1396+ tmux.until { |lines| assert_includes lines, '>>2' }1397+ end1398+1399+ def test_track1400+ tmux.send_keys "seq 1000 | #{FZF} --query 555 --track --bind t:toggle-track", :Enter1401+ tmux.until do |lines|1402+ assert_equal 1, lines.match_count1403+ assert_includes lines, '> 555'1404+ end1405+ tmux.send_keys :BSpace1406+ index = tmux.until do |lines|1407+ assert_equal 28, lines.match_count1408+ assert_includes lines, '> 555'1409+ end.index('> 555')1410+ tmux.send_keys :BSpace1411+ tmux.until do |lines|1412+ assert_equal 271, lines.match_count1413+ assert_equal '> 555', lines[index]1414+ end1415+ tmux.send_keys :BSpace1416+ tmux.until do |lines|1417+ assert_equal 1000, lines.match_count1418+ assert_equal '> 555', lines[index]1419+ end1420+ tmux.send_keys '555'1421+ tmux.until do |lines|1422+ assert_equal 1, lines.match_count1423+ assert_includes lines, '> 555'1424+ assert_includes lines[-2], '+T'1425+ end1426+ tmux.send_keys 't'1427+ tmux.until do |lines|1428+ refute_includes lines[-2], '+T'1429+ end1430+ tmux.send_keys :BSpace1431+ tmux.until do |lines|1432+ assert_equal 28, lines.match_count1433+ assert_includes lines, '> 55'1434+ end1435+ tmux.send_keys :BSpace1436+ tmux.until do |lines|1437+ assert_equal 271, lines.match_count1438+ assert_includes lines, '> 5'1439+ end1440+ tmux.send_keys 't'1441+ tmux.until do |lines|1442+ assert_includes lines[-2], '+T'1443+ end1444+ tmux.send_keys :BSpace1445+ tmux.until do |lines|1446+ assert_equal 1000, lines.match_count1447+ assert_includes lines, '> 5'1448+ end1449+ end1450+1451+ def test_track_action1452+ tmux.send_keys "seq 1000 | #{FZF} --query 555 --bind t:track", :Enter1453+ tmux.until do |lines|1454+ assert_equal 1, lines.match_count1455+ assert_includes lines, '> 555'1456+ end1457+ tmux.send_keys :BSpace1458+ tmux.until do |lines|1459+ assert_equal 28, lines.match_count1460+ assert_includes lines, '> 55'1461+ end1462+ tmux.send_keys :t1463+ tmux.until do |lines|1464+ assert_includes lines[-2], '+t'1465+ end1466+ tmux.send_keys :BSpace1467+ tmux.until do |lines|1468+ assert_equal 271, lines.match_count1469+ assert_includes lines, '> 55'1470+ end1471+1472+ # Automatically disabled when the tracking item is no longer visible1473+ tmux.send_keys '4'1474+ tmux.until do |lines|1475+ assert_equal 28, lines.match_count1476+ refute_includes lines[-2], '+t'1477+ end1478+ tmux.send_keys :BSpace1479+ tmux.until do |lines|1480+ assert_equal 271, lines.match_count1481+ assert_includes lines, '> 5'1482+ end1483+ tmux.send_keys :t1484+ tmux.until do |lines|1485+ assert_includes lines[-2], '+t'1486+ end1487+ tmux.send_keys :Up1488+ tmux.until do |lines|1489+ refute_includes lines[-2], '+t'1490+ end1491+ end1492+1493+ def test_one_and_zero1494+ tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter1495+ tmux.send_keys '1'1496+ tmux.until do |lines|1497+ assert_equal 2, lines.match_count1498+ refute(lines.any? { it.include?('only match') })1499+ refute(lines.any? { it.include?('no match') })1500+ end1501+ tmux.send_keys '0'1502+ tmux.until do |lines|1503+ assert_equal 1, lines.match_count1504+ assert(lines.any? { it.include?('only match') })1505+ end1506+ tmux.send_keys '0'1507+ tmux.until do |lines|1508+ assert_equal 0, lines.match_count1509+ assert(lines.any? { it.include?('no match') })1510+ end1511+ end1512+1513+ def test_height_range_with_exit_01514+ tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter1515+ tmux.until { |lines| assert_equal 10, lines.item_count }1516+ tmux.send_keys :c1517+ tmux.until { |lines| assert_equal 0, lines.match_count }1518+ end1519+1520+ def test_delete_with_modifiers1521+ if ENV['GITHUB_ACTION']1522+ # Expected: "[3]"1523+ # Actual: "[]3;5~"1524+ skip('CTRL-DELETE is not properly handled in GitHub Actions environment')1525+ end1526+ tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-delete:up+up,shift-delete:down,focus:transform-prompt:echo [{}]'", :Enter1527+ tmux.until { |lines| assert_equal 100, lines.item_count }1528+ tmux.send_keys 'C-Delete'1529+ tmux.until { |lines| assert_equal '[3]', lines[-1] }1530+ tmux.send_keys 'S-Delete'1531+ tmux.until { |lines| assert_equal '[2]', lines[-1] }1532+ end1533+1534+ def test_fzf_pos1535+ tmux.send_keys "seq 100 | #{FZF} --preview 'echo $FZF_POS / $FZF_MATCH_COUNT'", :Enter1536+ tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 100') }) }1537+ tmux.send_keys :Up1538+ tmux.until { |lines| assert(lines.any? { |line| line.include?('2 / 100') }) }1539+ tmux.send_keys '99'1540+ tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 1') }) }1541+ tmux.send_keys '99'1542+ tmux.until { |lines| assert(lines.any? { |line| line.include?('0 / 0') }) }1543+ end1544+1545+ def test_change_nth1546+ input = [1547+ *[''] * 1000,1548+ 'foo bar bar bar bar',1549+ 'foo foo bar bar bar',1550+ 'foo foo foo bar bar',1551+ 'foo foo foo foo bar',1552+ *[''] * 10001553+ ]1554+ writelines(input)1555+ nths = '1,2..4,-1,-3..,..2'1556+ tmux.send_keys %(#{FZF} -qfoo -n#{nths} --bind 'space:change-nth(2|3|4|5|),result:transform-prompt:echo "[$FZF_NTH] "' < #{tempname}), :Enter1557+1558+ tmux.until do |lines|1559+ assert lines.any_include?("[#{nths}] foo")1560+ assert_equal 4, lines.match_count1561+ end1562+ tmux.send_keys :Space1563+ tmux.until do |lines|1564+ assert lines.any_include?('[2] foo')1565+ assert_equal 3, lines.match_count1566+ end1567+ tmux.send_keys :Space1568+ tmux.until do |lines|1569+ assert lines.any_include?('[3] foo')1570+ assert_equal 2, lines.match_count1571+ end1572+ tmux.send_keys :Space1573+ tmux.until do |lines|1574+ assert lines.any_include?('[4] foo')1575+ assert_equal 1, lines.match_count1576+ end1577+ tmux.send_keys :Space1578+ tmux.until do |lines|1579+ assert lines.any_include?('[5] foo')1580+ assert_equal 0, lines.match_count1581+ end1582+ tmux.send_keys :Space1583+ tmux.until do |lines|1584+ assert lines.any_include?("[#{nths}] foo")1585+ assert_equal 4, lines.match_count1586+ end1587+ end1588+endadded:test/test_exec.rb+417 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Process execution: execute, become, reload6+class TestExec < TestInteractive7+ def test_execute8+ output = '/tmp/fzf-test-execute'9+ opts = %[--bind "alt-a:execute(echo /{}/ >> #{output})+change-header(alt-a),alt-b:execute[echo /{}{}/ >> #{output}]+change-header(alt-b),C:execute(echo /{}{}{}/ >> #{output})+change-header(C)"]10+ writelines(%w[foo'bar foo"bar foo$bar])11+ tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter12+ tmux.until { |lines| assert_equal 3, lines.item_count }13+14+ ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }15+ tmux.send_keys :Escape, :a16+ ready.call('alt-a')17+ tmux.send_keys :Escape, :b18+ ready.call('alt-b')19+20+ tmux.send_keys :Up21+ tmux.send_keys :Escape, :a22+ ready.call('alt-a')23+ tmux.send_keys :Escape, :b24+ ready.call('alt-b')25+26+ tmux.send_keys :Up27+ tmux.send_keys :C28+ ready.call('C')29+30+ tmux.send_keys 'barfoo'31+ tmux.until { |lines| assert_equal ' 0/3', lines[-2] }32+33+ tmux.send_keys :Escape, :a34+ ready.call('alt-a')35+ tmux.send_keys :Escape, :b36+ ready.call('alt-b')37+38+ wait do39+ assert_path_exists output40+ assert_equal %w[41+ /foo'bar/ /foo'barfoo'bar/42+ /foo"bar/ /foo"barfoo"bar/43+ /foo$barfoo$barfoo$bar/44+ ], File.readlines(output, chomp: true)45+ end46+ ensure47+ FileUtils.rm_f(output)48+ end49+50+ def test_execute_multi51+ output = '/tmp/fzf-test-execute-multi'52+ opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})+change-header(alt-a),alt-b:change-header(alt-b)"]53+ writelines(%w[foo'bar foo"bar foo$bar foobar])54+ tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter55+ ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }56+57+ tmux.until { |lines| assert_equal ' 4/4 (0)', lines[-2] }58+ tmux.send_keys :Escape, :a59+ ready.call('alt-a')60+ tmux.send_keys :Escape, :b61+ ready.call('alt-b')62+63+ tmux.send_keys :BTab, :BTab, :BTab64+ tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }65+ tmux.send_keys :Escape, :a66+ ready.call('alt-a')67+ tmux.send_keys :Escape, :b68+ ready.call('alt-b')69+70+ tmux.send_keys :Tab, :Tab71+ tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }72+ tmux.send_keys :Escape, :a73+ ready.call('alt-a')74+ wait do75+ assert_path_exists output76+ assert_equal [77+ %(foo'bar/foo'bar),78+ %(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar),79+ %(foo'bar foo"bar foobar/foo'bar foo"bar foobar)80+ ], File.readlines(output, chomp: true)81+ end82+ ensure83+ FileUtils.rm_f(output)84+ end85+86+ def test_execute_plus_flag87+ output = tempname + '.tmp'88+ FileUtils.rm_f(output)89+ writelines(['foo bar', '123 456'])90+91+ tmux.send_keys "cat #{tempname} | #{FZF} --multi --bind 'x:execute-silent(echo {+}/{}/{+2}/{2} >> #{output})'", :Enter92+93+ tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }94+ tmux.send_keys 'xy'95+ tmux.until { |lines| assert_equal ' 0/2 (0)', lines[-2] }96+ tmux.send_keys :BSpace97+ tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }98+99+ tmux.send_keys :Up100+ tmux.send_keys :Tab101+ tmux.send_keys 'xy'102+ tmux.until { |lines| assert_equal ' 0/2 (1)', lines[-2] }103+ tmux.send_keys :BSpace104+ tmux.until { |lines| assert_equal ' 2/2 (1)', lines[-2] }105+106+ tmux.send_keys :Tab107+ tmux.send_keys 'xy'108+ tmux.until { |lines| assert_equal ' 0/2 (2)', lines[-2] }109+ tmux.send_keys :BSpace110+ tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }111+112+ wait do113+ assert_path_exists output114+ assert_equal [115+ %(foo bar/foo bar/bar/bar),116+ %(123 456/foo bar/456/bar),117+ %(123 456 foo bar/foo bar/456 bar/bar)118+ ], File.readlines(output, chomp: true)119+ end120+ rescue StandardError121+ FileUtils.rm_f(output)122+ end123+124+ def test_execute_shell125+ # Custom script to use as $SHELL126+ output = tempname + '.out'127+ FileUtils.rm_f(output)128+ writelines(['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"])129+ system("chmod +x #{tempname}")130+131+ tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter132+ tmux.until { |lines| assert_equal ' 1/1', lines[-2] }133+ tmux.send_keys :Enter134+ tmux.until { |lines| assert_equal ' 1/1', lines[-2] }135+ wait do136+ assert_path_exists output137+ assert_equal ["-c / 'foo'bar"], File.readlines(output, chomp: true)138+ end139+ ensure140+ FileUtils.rm_f(output)141+ end142+143+ def test_interrupt_execute144+ tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-l:execute:echo executing {}; sleep 100'", :Enter145+ tmux.until { |lines| assert_equal 100, lines.item_count }146+ tmux.send_keys 'C-l'147+ tmux.until { |lines| assert lines.any_include?('executing 1') }148+ tmux.send_keys 'C-c'149+ tmux.until { |lines| assert_equal 100, lines.item_count }150+ tmux.send_keys 99151+ tmux.until { |lines| assert_equal 1, lines.match_count }152+ end153+154+ def test_kill_default_command_on_abort155+ writelines(['#!/usr/bin/env bash',156+ "echo 'Started'",157+ 'while :; do sleep 1; done'])158+ system("chmod +x #{tempname}")159+160+ tmux.send_keys FZF.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter161+ tmux.until { |lines| assert_equal 1, lines.item_count }162+ tmux.send_keys 'C-c'163+ tmux.send_keys 'C-l', 'closed'164+ tmux.until { |lines| assert_includes lines[0], 'closed' }165+ wait { refute system("pgrep -f #{tempname}") }166+ ensure167+ system("pkill -9 -f #{tempname}")168+ end169+170+ def test_kill_default_command_on_accept171+ writelines(['#!/usr/bin/env bash',172+ "echo 'Started'",173+ 'while :; do sleep 1; done'])174+ system("chmod +x #{tempname}")175+176+ tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter177+ tmux.until { |lines| assert_equal 1, lines.match_count }178+ tmux.send_keys :Enter179+ assert_equal 'Started', fzf_output180+ wait { refute system("pgrep -f #{tempname}") }181+ ensure182+ system("pkill -9 -f #{tempname}")183+ end184+185+ def test_kill_reload_command_on_abort186+ writelines(['#!/usr/bin/env bash',187+ "echo 'Started'",188+ 'while :; do sleep 1; done'])189+ system("chmod +x #{tempname}")190+191+ tmux.send_keys "seq 1 3 | #{FZF} --bind 'ctrl-r:reload(#{tempname})'", :Enter192+ tmux.until { |lines| assert_equal 3, lines.item_count }193+ tmux.send_keys 'C-r'194+ tmux.until { |lines| assert_equal 1, lines.item_count }195+ tmux.send_keys 'C-c'196+ tmux.send_keys 'C-l', 'closed'197+ tmux.until { |lines| assert_includes lines[0], 'closed' }198+ wait { refute system("pgrep -f #{tempname}") }199+ ensure200+ system("pkill -9 -f #{tempname}")201+ end202+203+ def test_kill_reload_command_on_accept204+ writelines(['#!/usr/bin/env bash',205+ "echo 'Started'",206+ 'while :; do sleep 1; done'])207+ system("chmod +x #{tempname}")208+209+ tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{tempname})'")}", :Enter210+ tmux.until { |lines| assert_equal 3, lines.item_count }211+ tmux.send_keys 'C-r'212+ tmux.until { |lines| assert_equal 1, lines.item_count }213+ tmux.send_keys :Enter214+ assert_equal 'Started', fzf_output215+ wait { refute system("pgrep -f #{tempname}") }216+ ensure217+ system("pkill -9 -f #{tempname}")218+ end219+220+ def test_reload221+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq $FZF_QUERY),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter222+ tmux.until { |lines| assert_equal 998, lines.match_count }223+ tmux.send_keys 'a'224+ tmux.until do |lines|225+ assert_equal 98, lines.item_count226+ assert_equal 98, lines.match_count227+ end228+ tmux.send_keys 'b'229+ tmux.until do |lines|230+ assert_equal 198, lines.item_count231+ assert_equal 198, lines.match_count232+ end233+ tmux.send_keys :Tab234+ tmux.until { |lines| assert_equal ' 198/198 (1/2)', lines[-2] }235+ tmux.send_keys '555'236+ tmux.until { |lines| assert_equal ' 1/553 (0/2)', lines[-2] }237+ end238+239+ def test_reload_even_when_theres_no_match240+ tmux.send_keys %(: | #{FZF} --bind 'space:reload(seq 10)'), :Enter241+ tmux.until { |lines| assert_equal 0, lines.item_count }242+ tmux.send_keys :Space243+ tmux.until { |lines| assert_equal 10, lines.item_count }244+ end245+246+ def test_reload_should_terminate_standard_input_stream247+ tmux.send_keys %(ruby -e "STDOUT.sync = true; loop { puts 1; sleep 0.1 }" | fzf --bind 'start:reload(seq 100)'), :Enter248+ tmux.until { |lines| assert_equal 100, lines.item_count }249+ end250+251+ def test_clear_list_when_header_lines_changed_due_to_reload252+ tmux.send_keys %(seq 10 | #{FZF} --header 0 --header-lines 3 --bind 'space:reload(seq 1)'), :Enter253+ tmux.until { |lines| assert_includes lines, ' 9' }254+ tmux.send_keys :Space255+ tmux.until { |lines| refute_includes lines, ' 9' }256+ end257+258+ def test_item_index_reset_on_reload259+ tmux.send_keys "seq 10 | #{FZF} --preview 'echo [[{n}]]' --bind 'up:last,down:first,space:reload:seq 100'", :Enter260+ tmux.until { |lines| assert_includes lines[1], '[[0]]' }261+ tmux.send_keys :Up262+ tmux.until { |lines| assert_includes lines[1], '[[9]]' }263+ tmux.send_keys :Down264+ tmux.until { |lines| assert_includes lines[1], '[[0]]' }265+ tmux.send_keys :Space266+ tmux.until do |lines|267+ assert_equal 100, lines.item_count268+ assert_includes lines[1], '[[0]]'269+ end270+ tmux.send_keys :Up271+ tmux.until { |lines| assert_includes lines[1], '[[99]]' }272+ end273+274+ def test_reload_should_update_preview275+ tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload:echo 4' --preview 'echo {}' --preview-window 'nohidden'", :Enter276+ tmux.until { |lines| assert_includes lines[1], '1' }277+ tmux.send_keys 'C-t'278+ tmux.until { |lines| assert_includes lines[1], '4' }279+ end280+281+ def test_reload_and_change_preview_should_update_preview282+ tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload(echo 4)+change-preview(echo {})'", :Enter283+ tmux.until { |lines| assert_equal 3, lines.item_count }284+ tmux.until { |lines| refute_includes lines[1], '1' }285+ tmux.send_keys 'C-t'286+ tmux.until { |lines| assert_equal 1, lines.item_count }287+ tmux.until { |lines| assert_includes lines[1], '4' }288+ end289+290+ def test_reload_sync291+ tmux.send_keys "seq 100 | #{FZF} --bind 'load:reload-sync(sleep 1; seq 1000)+unbind(load)'", :Enter292+ tmux.until { |lines| assert_equal 100, lines.item_count }293+ tmux.send_keys '00'294+ tmux.until { |lines| assert_equal 1, lines.match_count }295+ # After 1 second296+ tmux.until { |lines| assert_equal 10, lines.match_count }297+ end298+299+ def test_reload_disabled_case1300+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)'", :Enter301+ tmux.until do |lines|302+ assert_equal 100, lines.item_count303+ assert_equal 1, lines.match_count304+ end305+ tmux.send_keys :Space306+ tmux.until { |lines| assert_equal 1, lines.match_count }307+ tmux.send_keys :BSpace308+ tmux.until { |lines| assert_equal 0, lines.match_count }309+ tmux.until { |lines| assert_equal 1000, lines.match_count }310+ end311+312+ def test_reload_disabled_case2313+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)'", :Enter314+ tmux.until do |lines|315+ assert_equal 100, lines.item_count316+ assert_equal 1, lines.match_count317+ end318+ tmux.send_keys :Space319+ tmux.until { |lines| assert_equal 1, lines.match_count }320+ tmux.send_keys :BSpace321+ tmux.until { |lines| assert_equal 1, lines.match_count }322+ tmux.until { |lines| assert_equal 1000, lines.match_count }323+ end324+325+ def test_reload_disabled_case3326+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)+backward-delete-char'", :Enter327+ tmux.until do |lines|328+ assert_equal 100, lines.item_count329+ assert_equal 1, lines.match_count330+ end331+ tmux.send_keys :Space332+ tmux.until { |lines| assert_equal 1, lines.match_count }333+ tmux.send_keys :BSpace334+ tmux.until { |lines| assert_equal 0, lines.match_count }335+ tmux.until { |lines| assert_equal 1000, lines.match_count }336+ end337+338+ def test_reload_disabled_case4339+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)+backward-delete-char'", :Enter340+ tmux.until do |lines|341+ assert_equal 100, lines.item_count342+ assert_equal 1, lines.match_count343+ end344+ tmux.send_keys :Space345+ tmux.until { |lines| assert_equal 1, lines.match_count }346+ tmux.send_keys :BSpace347+ tmux.until { |lines| assert_equal 1, lines.match_count }348+ tmux.until { |lines| assert_equal 1000, lines.match_count }349+ end350+351+ def test_reload_disabled_case5352+ tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(echo xx; sleep 2; seq 1000)'", :Enter353+ tmux.until do |lines|354+ assert_equal 100, lines.item_count355+ assert_equal 1, lines.match_count356+ end357+ tmux.send_keys :Space358+ tmux.until do |lines|359+ assert_equal 1, lines.item_count360+ assert_equal 1, lines.match_count361+ end362+ tmux.send_keys :BSpace363+ tmux.until { |lines| assert_equal 1001, lines.match_count }364+ end365+366+ def test_reload_disabled_case6367+ tmux.send_keys "seq 1000 | #{FZF} --disabled --bind 'change:reload:sleep 0.5; seq {q}'", :Enter368+ tmux.until { |lines| assert_equal 1000, lines.match_count }369+ tmux.send_keys '9'370+ tmux.until { |lines| assert_equal 9, lines.match_count }371+ tmux.send_keys '9'372+ tmux.until { |lines| assert_equal 99, lines.match_count }373+374+ # TODO: How do we verify if an intermediate empty list is not shown?375+ end376+377+ def test_reload_and_change378+ tmux.send_keys "(echo foo; echo bar) | #{FZF} --bind 'load:reload-sync(sleep 60)+change-query(bar)'", :Enter379+ tmux.until { |lines| assert_equal 1, lines.match_count }380+ end381+382+ def test_become_tty383+ tmux.send_keys "sleep 0.5 | #{FZF} --bind 'start:reload:ls' --bind 'load:become:tty'", :Enter384+ tmux.until { |lines| assert_includes lines, '/dev/tty' }385+ end386+387+ def test_disabled_preview_update388+ tmux.send_keys "echo bar | #{FZF} --disabled --bind 'change:reload:echo foo' --preview 'echo [{q}-{}]'", :Enter389+ tmux.until { |lines| assert_equal 1, lines.match_count }390+ tmux.until { |lines| assert(lines.any? { |line| line.include?('[-bar]') }) }391+ tmux.send_keys :x392+ tmux.until { |lines| assert(lines.any? { |line| line.include?('[x-foo]') }) }393+ end394+395+ def test_start_on_reload396+ tmux.send_keys %(echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded' --bind space:change-header:), :Enter397+ tmux.until(timeout: 1) { |lines| assert_includes lines[-3], 'Loading' }398+ tmux.until(timeout: 1) { |lines| refute_includes lines[-4], 'foo' }399+ tmux.until { |lines| assert_includes lines[-3], 'Loaded' }400+ tmux.until { |lines| assert_includes lines[-4], 'bar' }401+ tmux.send_keys :Space402+ tmux.until { |lines| assert_includes lines[-3], 'bar' }403+ end404+405+ def test_become406+ tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter407+ tmux.until { |lines| assert_equal 100, lines.item_count }408+ tmux.send_keys 999409+ tmux.until { |lines| assert_equal 0, lines.match_count }410+ tmux.send_keys :Enter411+ tmux.until { |lines| assert_equal 0, lines.match_count }412+ tmux.send_keys :BSpace413+ tmux.until { |lines| assert_equal 1, lines.match_count }414+ tmux.send_keys :Enter415+ tmux.until { |lines| assert_equal 99, lines.item_count }416+ end417+endadded:test/test_filter.rb+302 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Non-interactive tests6+class TestFilter < TestBase7+ def test_default_extended8+ assert_equal '100', `seq 100 | #{FZF} -f "1 00$"`.chomp9+ assert_equal '', `seq 100 | #{FZF} -f "1 00$" +x`.chomp10+ end11+12+ def test_exact13+ assert_equal 4, `seq 123 | #{FZF} -f 13`.lines.length14+ assert_equal 2, `seq 123 | #{FZF} -f 13 -e`.lines.length15+ assert_equal 4, `seq 123 | #{FZF} -f 13 +e`.lines.length16+ end17+18+ def test_or_operator19+ assert_equal %w[1 5 10], `seq 10 | #{FZF} -f "1 | 5"`.lines(chomp: true)20+ assert_equal %w[1 10 2 3 4 5 6 7 8 9],21+ `seq 10 | #{FZF} -f '1 | !1'`.lines(chomp: true)22+ end23+24+ def test_smart_case_for_each_term25+ assert_equal 1, `echo Foo bar | #{FZF} -x -f "foo Fbar" | wc -l`.to_i26+ end27+28+ def test_filter_exitstatus29+ # filter / streaming filter30+ ['', '--no-sort'].each do |opts|31+ assert_includes `echo foo | #{FZF} -f foo #{opts}`, 'foo'32+ assert_equal 0, $CHILD_STATUS.exitstatus33+34+ assert_empty `echo foo | #{FZF} -f bar #{opts}`35+ assert_equal 1, $CHILD_STATUS.exitstatus36+ end37+ end38+39+ def test_long_line40+ data = '.' * 256 * 102441+ File.open(tempname, 'w') do |f|42+ f << data43+ end44+ assert_equal data, `#{FZF} -f . < #{tempname}`.chomp45+ end46+47+ def test_read048+ lines = `find .`.lines(chomp: true)49+ assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp50+ assert_equal \51+ lines.last,52+ `find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp53+ end54+55+ def test_with_nth_basic56+ writelines(['hello world ', 'byebye'])57+ assert_equal \58+ 'hello world ',59+ `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 < #{tempname}`.chomp60+ end61+62+ def test_with_nth_ansi63+ writelines(["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye'])64+ assert_equal \65+ 'hello world ',66+ `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi < #{tempname}`.chomp67+ end68+69+ def test_with_nth_no_ansi70+ src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "71+ writelines([src, 'byebye'])72+ assert_equal \73+ src,74+ `#{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi < #{tempname}`.chomp75+ end76+77+ def test_escaped_meta_characters78+ input = [79+ 'foo^bar',80+ 'foo$bar',81+ 'foo!bar',82+ "foo'bar",83+ 'foo bar',84+ 'bar foo'85+ ]86+ writelines(input)87+88+ assert_equal input.length, `#{FZF} -f'foo bar' < #{tempname}`.lines.length89+ assert_equal input.length - 1, `#{FZF} -f'^foo bar$' < #{tempname}`.lines.length90+ assert_equal ['foo bar'], `#{FZF} -f'foo\\ bar' < #{tempname}`.lines(chomp: true)91+ assert_equal ['foo bar'], `#{FZF} -f'^foo\\ bar$' < #{tempname}`.lines(chomp: true)92+ assert_equal input.length - 1, `#{FZF} -f'!^foo\\ bar$' < #{tempname}`.lines.length93+ end94+95+ def test_normalized_match96+ echoes = '(echo a; echo á; echo A; echo Á;)'97+ assert_equal %w[a á A Á], `#{echoes} | #{FZF} -f a`.lines.map(&:chomp)98+ assert_equal %w[á Á], `#{echoes} | #{FZF} -f á`.lines.map(&:chomp)99+ assert_equal %w[A Á], `#{echoes} | #{FZF} -f A`.lines.map(&:chomp)100+ assert_equal %w[Á], `#{echoes} | #{FZF} -f Á`.lines.map(&:chomp)101+ end102+103+ def test_unicode_case104+ writelines(%w[строКА1 СТРОКА2 строка3 Строка4])105+ assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.lines(chomp: true)106+ assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.lines(chomp: true)107+ end108+109+ def test_tiebreak110+ input = %w[111+ --foobar--------112+ -----foobar---113+ ----foobar--114+ -------foobar-115+ ]116+ writelines(input)117+118+ assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.lines(chomp: true)119+120+ by_length = %w[121+ ----foobar--122+ -----foobar---123+ -------foobar-124+ --foobar--------125+ ]126+ assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.lines(chomp: true)127+ assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.lines(chomp: true)128+129+ by_begin = %w[130+ --foobar--------131+ ----foobar--132+ -----foobar---133+ -------foobar-134+ ]135+ assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.lines(chomp: true)136+ assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.lines(chomp: true)137+138+ assert_equal %w[139+ -------foobar-140+ ----foobar--141+ -----foobar---142+ --foobar--------143+ ], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.lines(chomp: true)144+145+ assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.lines(chomp: true)146+ end147+148+ def test_tiebreak_index_begin149+ writelines([150+ 'xoxxxxxoxx',151+ 'xoxxxxxox',152+ 'xxoxxxoxx',153+ 'xxxoxoxxx',154+ 'xxxxoxox',155+ ' xxoxoxxx'156+ ])157+158+ assert_equal [159+ 'xxxxoxox',160+ ' xxoxoxxx',161+ 'xxxoxoxxx',162+ 'xxoxxxoxx',163+ 'xoxxxxxox',164+ 'xoxxxxxoxx'165+ ], `#{FZF} -foo < #{tempname}`.lines(chomp: true)166+167+ assert_equal [168+ 'xxxoxoxxx',169+ 'xxxxoxox',170+ ' xxoxoxxx',171+ 'xxoxxxoxx',172+ 'xoxxxxxoxx',173+ 'xoxxxxxox'174+ ], `#{FZF} -foo --tiebreak=index < #{tempname}`.lines(chomp: true)175+176+ # Note that --tiebreak=begin is now based on the first occurrence of the177+ # first character on the pattern178+ assert_equal [179+ ' xxoxoxxx',180+ 'xxxoxoxxx',181+ 'xxxxoxox',182+ 'xxoxxxoxx',183+ 'xoxxxxxoxx',184+ 'xoxxxxxox'185+ ], `#{FZF} -foo --tiebreak=begin < #{tempname}`.lines(chomp: true)186+187+ assert_equal [188+ ' xxoxoxxx',189+ 'xxxoxoxxx',190+ 'xxxxoxox',191+ 'xxoxxxoxx',192+ 'xoxxxxxox',193+ 'xoxxxxxoxx'194+ ], `#{FZF} -foo --tiebreak=begin,length < #{tempname}`.lines(chomp: true)195+ end196+197+ def test_tiebreak_begin_algo_v2198+ writelines(['baz foo bar',199+ 'foo bar baz'])200+ assert_equal [201+ 'foo bar baz',202+ 'baz foo bar'203+ ], `#{FZF} -fbar --tiebreak=begin --algo=v2 < #{tempname}`.lines(chomp: true)204+ end205+206+ def test_tiebreak_end207+ writelines(['xoxxxxxxxx',208+ 'xxoxxxxxxx',209+ 'xxxoxxxxxx',210+ 'xxxxoxxxx',211+ 'xxxxxoxxx',212+ ' xxxxoxxx'])213+214+ assert_equal [215+ ' xxxxoxxx',216+ 'xxxxoxxxx',217+ 'xxxxxoxxx',218+ 'xoxxxxxxxx',219+ 'xxoxxxxxxx',220+ 'xxxoxxxxxx'221+ ], `#{FZF} -fo < #{tempname}`.lines(chomp: true)222+223+ assert_equal [224+ 'xxxxxoxxx',225+ ' xxxxoxxx',226+ 'xxxxoxxxx',227+ 'xxxoxxxxxx',228+ 'xxoxxxxxxx',229+ 'xoxxxxxxxx'230+ ], `#{FZF} -fo --tiebreak=end < #{tempname}`.lines(chomp: true)231+232+ assert_equal [233+ 'xxxxxoxxx',234+ ' xxxxoxxx',235+ 'xxxxoxxxx',236+ 'xxxoxxxxxx',237+ 'xxoxxxxxxx',238+ 'xoxxxxxxxx'239+ ], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)240+241+ writelines(['/bar/baz', '/foo/bar/baz'])242+ assert_equal [243+ '/foo/bar/baz',244+ '/bar/baz'245+ ], `#{FZF} -fbaz --tiebreak=end < #{tempname}`.lines(chomp: true)246+ end247+248+ def test_tiebreak_length_with_nth249+ input = %w[250+ 1:hell251+ 123:hello252+ 12345:he253+ 1234567:h254+ ]255+ writelines(input)256+257+ output = %w[258+ 1:hell259+ 12345:he260+ 123:hello261+ 1234567:h262+ ]263+ assert_equal output, `#{FZF} -fh < #{tempname}`.lines(chomp: true)264+265+ # Since 0.16.8, --nth doesn't affect --tiebreak266+ assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.lines(chomp: true)267+ end268+269+ def test_tiebreak_chunk270+ writelines(['1 foobarbaz ba',271+ '2 foobar baz',272+ '3 foo barbaz'])273+274+ assert_equal [275+ '3 foo barbaz',276+ '2 foobar baz',277+ '1 foobarbaz ba'278+ ], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true)279+280+ assert_equal [281+ '1 foobarbaz ba',282+ '2 foobar baz',283+ '3 foo barbaz'284+ ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)285+286+ assert_equal [287+ '3 foo barbaz'288+ ], `#{FZF} -f'!foobar' --tiebreak=chunk < #{tempname}`.lines(chomp: true)289+ end290+291+ def test_boundary_match292+ # Underscore boundaries should be ranked lower293+ {294+ default: [' x '] + %w[/x/ [x] -x- -x_ _x- _x_],295+ path: ['/x/', ' x '] + %w[[x] -x- -x_ _x- _x_],296+ history: ['[x]', '-x-', ' x '] + %w[/x/ -x_ _x- _x_]297+ }.each do |scheme, expected|298+ result = `printf -- 'xxx\n-xx\nxx-\n_x_\n_x-\n-x_\n[x]\n-x-\n x \n/x/\n' | #{FZF} -f"'x'" --scheme=#{scheme}`.lines(chomp: true)299+ assert_equal expected, result300+ end301+ end302+enddeleted:test/test_go.rb-4504 removed
1-#!/usr/bin/env ruby2-# frozen_string_literal: true3-4-require 'minitest/autorun'5-require 'fileutils'6-require 'English'7-require 'shellwords'8-require 'erb'9-require 'tempfile'10-require 'net/http'11-require 'json'12-13-TEMPLATE = DATA.read14-UNSETS = %w[15- FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS16- FZF_TMUX FZF_TMUX_OPTS17- FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS18- FZF_ALT_C_COMMAND19- FZF_ALT_C_OPTS FZF_CTRL_R_OPTS20- FZF_API_KEY21-].freeze22-DEFAULT_TIMEOUT = 1023-24-FILE = File.expand_path(__FILE__)25-BASE = File.expand_path('..', __dir__)26-Dir.chdir(BASE)27-FZF = "FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer \\> --marker \\>\" FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf"28-29-def wait(timeout = DEFAULT_TIMEOUT)30- since = Time.now31- begin32- yield or raise Minitest::Assertion, 'Assertion failure'33- rescue Minitest::Assertion34- raise if Time.now - since > timeout35-36- sleep(0.05)37- retry38- end39-end40-41-class Shell42- class << self43- def bash44- @bash ||=45- begin46- bashrc = '/tmp/fzf.bash'47- File.open(bashrc, 'w') do |f|48- f.puts ERB.new(TEMPLATE).result(binding)49- end50-51- "bash --rcfile #{bashrc}"52- end53- end54-55- def zsh56- @zsh ||=57- begin58- zdotdir = '/tmp/fzf-zsh'59- FileUtils.rm_rf(zdotdir)60- FileUtils.mkdir_p(zdotdir)61- File.open("#{zdotdir}/.zshrc", 'w') do |f|62- f.puts ERB.new(TEMPLATE).result(binding)63- end64- "ZDOTDIR=#{zdotdir} zsh"65- end66- end67-68- def fish69- "unset #{UNSETS.join(' ')}; rm -f ~/.local/share/fish/fzf_test_history; FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer '>' --marker '>'\" fish_history=fzf_test fish"70- end71- end72-end73-74-class Tmux75- attr_reader :win76-77- def initialize(shell = :bash)78- @win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first79- go(%W[set-window-option -t #{@win} pane-base-index 0])80- return unless shell == :fish81-82- send_keys 'function fish_prompt; end; clear', :Enter83- self.until(&:empty?)84- end85-86- def kill87- go(%W[kill-window -t #{win}])88- end89-90- def focus91- go(%W[select-window -t #{win}])92- end93-94- def send_keys(*args)95- go(%W[send-keys -t #{win}] + args.map(&:to_s))96- end97-98- def paste(str)99- system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')100- end101-102- def capture103- go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse104- end105-106- def until(refresh = false, timeout: DEFAULT_TIMEOUT)107- lines = nil108- begin109- wait(timeout) do110- lines = capture111- class << lines112- def counts113- lazy114- .map { |l| l.scan(%r{^. ([0-9]+)/([0-9]+)( \(([0-9]+)\))?}) }115- .reject(&:empty?)116- .first&.first&.map(&:to_i)&.values_at(0, 1, 3) || [0, 0, 0]117- end118-119- def match_count120- counts[0]121- end122-123- def item_count124- counts[1]125- end126-127- def select_count128- counts[2]129- end130-131- def any_include?(val)132- method = val.is_a?(Regexp) ? :match : :include?133- find { |line| line.send(method, val) }134- end135- end136- yield(lines).tap do |ok|137- send_keys 'C-l' if refresh && !ok138- end139- end140- rescue Minitest::Assertion141- puts $ERROR_INFO.backtrace142- puts '>' * 80143- puts lines144- puts '<' * 80145- raise146- end147- lines148- end149-150- def prepare151- tries = 0152- begin153- self.until(true) do |lines|154- message = "Prepare[#{tries}]"155- send_keys ' ', 'C-u', :Enter, message, :Left, :Right156- lines[-1] == message157- end158- rescue Minitest::Assertion159- (tries += 1) < 5 ? retry : raise160- end161- send_keys 'C-u', 'C-l'162- end163-164- private165-166- def go(args)167- IO.popen(%w[tmux] + args) { |io| io.readlines(chomp: true) }168- end169-end170-171-class TestBase < Minitest::Test172- TEMPNAME = Dir::Tmpname.create(%w[fzf]) {}173- FIFONAME = Dir::Tmpname.create(%w[fzf-fifo]) {}174-175- attr_reader :tmux176-177- def writelines(lines)178- File.write(TEMPNAME, lines.join("\n"))179- end180-181- def tempname182- TEMPNAME183- end184-185- def fzf_output186- @thread.join.value.chomp.tap { @thread = nil }187- end188-189- def fzf_output_lines190- fzf_output.lines(chomp: true)191- end192-193- def setup194- FileUtils.rm_f([TEMPNAME, FIFONAME])195- File.mkfifo(FIFONAME)196- end197-198- def teardown199- FileUtils.rm_f([TEMPNAME, FIFONAME])200- end201-202- alias assert_equal_org assert_equal203- def assert_equal(expected, actual)204- # Ignore info separator205- actual = actual&.sub(/\s*─+$/, '') if actual.is_a?(String) && actual&.match?(%r{\d+/\d+})206- assert_equal_org(expected, actual)207- end208-209- # Run fzf with its output piped to a fifo210- def fzf(*opts)211- raise 'fzf_output not taken' if @thread212-213- @thread = Thread.new { File.read(FIFONAME) }214- fzf!(*opts) + " > #{FIFONAME}"215- end216-217- def fzf!(*opts)218- opts = opts.map do |o|219- case o220- when Symbol221- o = o.to_s222- o.length > 1 ? "--#{o.tr('_', '-')}" : "-#{o}"223- when String, Numeric224- o.to_s225- end226- end.compact227- "#{FZF} #{opts.join(' ')}"228- end229-end230-231-class TestGoFZF < TestBase232- def setup233- super234- @tmux = Tmux.new235- end236-237- def teardown238- super239- @tmux.kill240- end241-242- def test_vanilla243- tmux.send_keys "seq 1 100000 | #{fzf}", :Enter244- tmux.until do |lines|245- assert_equal '>', lines.last246- assert_equal ' 100000/100000', lines[-2]247- end248- lines = tmux.capture249- assert_equal ' 2', lines[-4]250- assert_equal '> 1', lines[-3]251- assert_equal ' 100000/100000', lines[-2]252- assert_equal '>', lines[-1]253-254- # Testing basic key bindings255- tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'256- tmux.until do |lines|257- assert_equal '> 3910', lines[-4]258- assert_equal ' 391', lines[-3]259- assert_equal ' 856/100000', lines[-2]260- assert_equal '> 391', lines[-1]261- end262-263- tmux.send_keys :Enter264- assert_equal '3910', fzf_output265- end266-267- def test_fzf_default_command268- tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter269- tmux.until { |lines| assert_equal '> hello', lines[-3] }270-271- tmux.send_keys :Enter272- assert_equal 'hello', fzf_output273- end274-275- def test_fzf_default_command_failure276- tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter277- tmux.until { |lines| assert_includes lines[-2], ' [Command failed: false] ─' }278- tmux.send_keys :Enter279- end280-281- def test_key_bindings282- tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter283- tmux.until { |lines| assert_equal '> foo bar foo-bar', lines.last }284-285- # CTRL-A286- tmux.send_keys 'C-A', '('287- tmux.until { |lines| assert_equal '> (foo bar foo-bar', lines.last }288-289- # META-F290- tmux.send_keys :Escape, :f, ')'291- tmux.until { |lines| assert_equal '> (foo) bar foo-bar', lines.last }292-293- # CTRL-B294- tmux.send_keys 'C-B', 'var'295- tmux.until { |lines| assert_equal '> (foovar) bar foo-bar', lines.last }296-297- # Left, CTRL-D298- tmux.send_keys :Left, :Left, 'C-D'299- tmux.until { |lines| assert_equal '> (foovr) bar foo-bar', lines.last }300-301- # META-BS302- tmux.send_keys :Escape, :BSpace303- tmux.until { |lines| assert_equal '> (r) bar foo-bar', lines.last }304-305- # CTRL-Y306- tmux.send_keys 'C-Y', 'C-Y'307- tmux.until { |lines| assert_equal '> (foovfoovr) bar foo-bar', lines.last }308-309- # META-B310- tmux.send_keys :Escape, :b, :Space, :Space311- tmux.until { |lines| assert_equal '> ( foovfoovr) bar foo-bar', lines.last }312-313- # CTRL-F / Right314- tmux.send_keys 'C-F', :Right, '/'315- tmux.until { |lines| assert_equal '> ( fo/ovfoovr) bar foo-bar', lines.last }316-317- # CTRL-H / BS318- tmux.send_keys 'C-H', :BSpace319- tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-bar', lines.last }320-321- # CTRL-E322- tmux.send_keys 'C-E', 'baz'323- tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }324-325- # CTRL-U326- tmux.send_keys 'C-U'327- tmux.until { |lines| assert_equal '>', lines.last }328-329- # CTRL-Y330- tmux.send_keys 'C-Y'331- tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last }332-333- # CTRL-W334- tmux.send_keys 'C-W', 'bar-foo'335- tmux.until { |lines| assert_equal '> ( fovfoovr) bar bar-foo', lines.last }336-337- # META-D338- tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, 'C-A', 'C-Y'339- tmux.until { |lines| assert_equal '> bar( fovfoovr) bar -foo', lines.last }340-341- # CTRL-M342- tmux.send_keys 'C-M'343- tmux.until { |lines| refute_equal '>', lines.last }344- end345-346- def test_file_word347- tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter348- tmux.until { |lines| assert_equal '> --/foo bar/foo-bar/baz', lines.last }349-350- tmux.send_keys :Escape, :b351- tmux.send_keys :Escape, :b352- tmux.send_keys :Escape, :b353- tmux.send_keys :Escape, :d354- tmux.send_keys :Escape, :f355- tmux.send_keys :Escape, :BSpace356- tmux.until { |lines| assert_equal '> --///baz', lines.last }357- end358-359- def test_multi_order360- tmux.send_keys "seq 1 10 | #{fzf(:multi)}", :Enter361- tmux.until { |lines| assert_equal '>', lines.last }362-363- tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2364- 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6365- :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7366- tmux.until { |lines| assert_equal ' 10/10 (6)', lines[-2] }367- tmux.send_keys 'C-M'368- assert_equal %w[3 2 5 6 8 7], fzf_output_lines369- end370-371- def test_multi_max372- tmux.send_keys "seq 1 10 | #{FZF} -m 3 --bind A:select-all,T:toggle-all --preview 'echo [{+}]/{}'", :Enter373-374- tmux.until { |lines| assert_equal 10, lines.item_count }375-376- tmux.send_keys '1'377- tmux.until do |lines|378- assert_includes lines[1], ' [1]/1 '379- assert lines[-2]&.start_with?(' 2/10 ')380- end381-382- tmux.send_keys 'A'383- tmux.until do |lines|384- assert_includes lines[1], ' [1 10]/1 '385- assert lines[-2]&.start_with?(' 2/10 (2/3)')386- end387-388- tmux.send_keys :BSpace389- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }390-391- tmux.send_keys 'T'392- tmux.until do |lines|393- assert_includes lines[1], ' [2 3 4]/1 '394- assert lines[-2]&.start_with?(' 10/10 (3/3)')395- end396-397- %w[T A].each do |key|398- tmux.send_keys key399- tmux.until do |lines|400- assert_includes lines[1], ' [1 5 6]/1 '401- assert lines[-2]&.start_with?(' 10/10 (3/3)')402- end403- end404-405- tmux.send_keys :BTab406- tmux.until do |lines|407- assert_includes lines[1], ' [5 6]/2 '408- assert lines[-2]&.start_with?(' 10/10 (2/3)')409- end410-411- [:BTab, :BTab, 'A'].each do |key|412- tmux.send_keys key413- tmux.until do |lines|414- assert_includes lines[1], ' [5 6 2]/3 '415- assert lines[-2]&.start_with?(' 10/10 (3/3)')416- end417- end418-419- tmux.send_keys '2'420- tmux.until { |lines| assert lines[-2]&.start_with?(' 1/10 (3/3)') }421-422- tmux.send_keys 'T'423- tmux.until do |lines|424- assert_includes lines[1], ' [5 6]/2 '425- assert lines[-2]&.start_with?(' 1/10 (2/3)')426- end427-428- tmux.send_keys :BSpace429- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }430-431- tmux.send_keys 'A'432- tmux.until do |lines|433- assert_includes lines[1], ' [5 6 1]/1 '434- assert lines[-2]&.start_with?(' 10/10 (3/3)')435- end436- end437-438- def test_multi_action439- tmux.send_keys "seq 10 | #{FZF} --bind 'a:change-multi,b:change-multi(3),c:change-multi(xxx),d:change-multi(0)'", :Enter440- tmux.until { |lines| assert_equal 10, lines.item_count }441- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 ') }442- tmux.send_keys 'a'443- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0)') }444- tmux.send_keys 'b'445- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0/3)') }446- tmux.send_keys :BTab447- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (1/3)') }448- tmux.send_keys 'c'449- tmux.send_keys :BTab450- tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') }451- tmux.send_keys 'd'452- tmux.until do |lines|453- assert lines[-2]&.start_with?(' 10/10 ') && !lines[-2]&.include?('(')454- end455- end456-457- def test_with_nth458- [true, false].each do |multi|459- tmux.send_keys "(echo ' 1st 2nd 3rd/';460- echo ' first second third/') |461- #{fzf(multi && :multi, :x, :nth, 2, :with_nth, '2,-1,1')}",462- :Enter463- tmux.until { |lines| assert_equal multi ? ' 2/2 (0)' : ' 2/2', lines[-2] }464-465- # Transformed list466- lines = tmux.capture467- assert_equal ' second third/first', lines[-4]468- assert_equal '> 2nd 3rd/1st', lines[-3]469-470- # However, the output must not be transformed471- if multi472- tmux.send_keys :BTab, :BTab473- tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }474- tmux.send_keys :Enter475- assert_equal [' 1st 2nd 3rd/', ' first second third/'], fzf_output_lines476- else477- tmux.send_keys '^', '3'478- tmux.until { |lines| assert_equal ' 1/2', lines[-2] }479- tmux.send_keys :Enter480- assert_equal [' 1st 2nd 3rd/'], fzf_output_lines481- end482- end483- end484-485- def test_scroll486- [true, false].each do |rev|487- tmux.send_keys "seq 1 100 | #{fzf(rev && :reverse)}", :Enter488- tmux.until { |lines| assert_equal ' 100/100', lines[rev ? 1 : -2] }489- tmux.send_keys(*Array.new(110) { rev ? :Down : :Up })490- tmux.until { |lines| assert_includes lines, '> 100' }491- tmux.send_keys :Enter492- assert_equal '100', fzf_output493- end494- end495-496- def test_select_1497- tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter498- assert_equal %w[5555 55], fzf_output_lines499- end500-501- def test_exit_0502- tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter503- assert_equal %w[555555], fzf_output_lines504- end505-506- def test_select_1_exit_0_fail507- [:'0', :'1', %i[1 0]].each do |opt|508- tmux.send_keys "seq 1 100 | #{fzf(:print_query, :multi, :q, 5, *opt)}", :Enter509- tmux.until { |lines| assert_equal '> 5', lines.last }510- tmux.send_keys :BTab, :BTab, :BTab511- tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }512- tmux.send_keys :Enter513- assert_equal %w[5 5 50 51], fzf_output_lines514- end515- end516-517- def test_query_unicode518- tmux.paste "(echo abc; echo $'\\352\\260\\200\\353\\202\\230\\353\\213\\244') | #{fzf(:query, "$'\\352\\260\\200\\353\\213\\244'")}"519- tmux.until { |lines| assert_equal ' 1/2', lines[-2] }520- tmux.send_keys :Enter521- assert_equal %w[가나다], fzf_output_lines522- end523-524- def test_sync525- tmux.send_keys "seq 1 100 | #{FZF} --multi | awk '{print $1 $1}' | #{fzf(:sync)}", :Enter526- tmux.until { |lines| assert_equal '>', lines[-1] }527- tmux.send_keys 9528- tmux.until { |lines| assert_equal ' 19/100 (0)', lines[-2] }529- tmux.send_keys :BTab, :BTab, :BTab530- tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] }531- tmux.send_keys :Enter532- tmux.until { |lines| assert_equal '>', lines[-1] }533- tmux.send_keys 'C-K', :Enter534- assert_equal %w[9090], fzf_output_lines535- end536-537- def test_tac538- tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter539- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }540- tmux.send_keys :BTab, :BTab, :BTab541- tmux.until { |lines| assert_equal ' 1000/1000 (3)', lines[-2] }542- tmux.send_keys :Enter543- assert_equal %w[1000 999 998], fzf_output_lines544- end545-546- def test_tac_sort547- tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter548- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }549- tmux.send_keys '99'550- tmux.until { |lines| assert_equal ' 28/1000 (0)', lines[-2] }551- tmux.send_keys :BTab, :BTab, :BTab552- tmux.until { |lines| assert_equal ' 28/1000 (3)', lines[-2] }553- tmux.send_keys :Enter554- assert_equal %w[99 999 998], fzf_output_lines555- end556-557- def test_tac_nosort558- tmux.send_keys "seq 1 1000 | #{fzf(:tac, :no_sort, :multi)}", :Enter559- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }560- tmux.send_keys '00'561- tmux.until { |lines| assert_equal ' 10/1000 (0)', lines[-2] }562- tmux.send_keys :BTab, :BTab, :BTab563- tmux.until { |lines| assert_equal ' 10/1000 (3)', lines[-2] }564- tmux.send_keys :Enter565- assert_equal %w[1000 900 800], fzf_output_lines566- end567-568- def test_expect569- test = lambda do |key, feed, expected = key|570- tmux.send_keys "seq 1 100 | #{fzf(:expect, key, :prompt, "[#{key}]")}", :Enter571- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }572- tmux.send_keys '55'573- tmux.until { |lines| assert_equal ' 1/100', lines[-2] }574- tmux.send_keys(*feed)575- tmux.prepare576- assert_equal [expected, '55'], fzf_output_lines577- end578- test.call('ctrl-t', 'C-T')579- test.call('ctrl-t', 'Enter', '')580- test.call('alt-c', %i[Escape c])581- test.call('f1', 'f1')582- test.call('f2', 'f2')583- test.call('f3', 'f3')584- test.call('f2,f4', 'f2', 'f2')585- test.call('f2,f4', 'f4', 'f4')586- test.call('alt-/', %i[Escape /])587- %w[f5 f6 f7 f8 f9 f10].each do |key|588- test.call('f5,f6,f7,f8,f9,f10', key, key)589- end590- test.call('@', '@')591- end592-593- def test_expect_with_bound_actions594- tmux.send_keys "seq 1 100 | #{fzf('--query 1 --print-query --expect z --bind z:up+up')}", :Enter595- tmux.until { |lines| assert_equal 20, lines.match_count }596- tmux.send_keys('z')597- assert_equal %w[1 z 1], fzf_output_lines598- end599-600- def test_expect_print_query601- tmux.send_keys "seq 1 100 | #{fzf('--expect=alt-z', :print_query)}", :Enter602- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }603- tmux.send_keys '55'604- tmux.until { |lines| assert_equal ' 1/100', lines[-2] }605- tmux.send_keys :Escape, :z606- assert_equal %w[55 alt-z 55], fzf_output_lines607- end608-609- def test_expect_printable_character_print_query610- tmux.send_keys "seq 1 100 | #{fzf('--expect=z --print-query')}", :Enter611- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }612- tmux.send_keys '55'613- tmux.until { |lines| assert_equal ' 1/100', lines[-2] }614- tmux.send_keys 'z'615- assert_equal %w[55 z 55], fzf_output_lines616- end617-618- def test_expect_print_query_select_1619- tmux.send_keys "seq 1 100 | #{fzf('-q55 -1 --expect=alt-z --print-query')}", :Enter620- assert_equal ['55', '', '55'], fzf_output_lines621- end622-623- def test_toggle_sort624- ['--toggle-sort=ctrl-r', '--bind=ctrl-r:toggle-sort'].each do |opt|625- tmux.send_keys "seq 1 111 | #{fzf("-m +s --tac #{opt} -q11")}", :Enter626- tmux.until { |lines| assert_equal '> 111', lines[-3] }627- tmux.send_keys :Tab628- tmux.until { |lines| assert_equal ' 4/111 -S (1)', lines[-2] }629- tmux.send_keys 'C-R'630- tmux.until { |lines| assert_equal '> 11', lines[-3] }631- tmux.send_keys :Tab632- tmux.until { |lines| assert_equal ' 4/111 +S (2)', lines[-2] }633- tmux.send_keys :Enter634- assert_equal %w[111 11], fzf_output_lines635- end636- end637-638- def test_unicode_case639- writelines(%w[строКА1 СТРОКА2 строка3 Строка4])640- assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.lines(chomp: true)641- assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.lines(chomp: true)642- end643-644- def test_tiebreak645- input = %w[646- --foobar--------647- -----foobar---648- ----foobar--649- -------foobar-650- ]651- writelines(input)652-653- assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.lines(chomp: true)654-655- by_length = %w[656- ----foobar--657- -----foobar---658- -------foobar-659- --foobar--------660- ]661- assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.lines(chomp: true)662- assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.lines(chomp: true)663-664- by_begin = %w[665- --foobar--------666- ----foobar--667- -----foobar---668- -------foobar-669- ]670- assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.lines(chomp: true)671- assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.lines(chomp: true)672-673- assert_equal %w[674- -------foobar-675- ----foobar--676- -----foobar---677- --foobar--------678- ], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.lines(chomp: true)679-680- assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.lines(chomp: true)681- end682-683- def test_tiebreak_index_begin684- writelines([685- 'xoxxxxxoxx',686- 'xoxxxxxox',687- 'xxoxxxoxx',688- 'xxxoxoxxx',689- 'xxxxoxox',690- ' xxoxoxxx'691- ])692-693- assert_equal [694- 'xxxxoxox',695- ' xxoxoxxx',696- 'xxxoxoxxx',697- 'xxoxxxoxx',698- 'xoxxxxxox',699- 'xoxxxxxoxx'700- ], `#{FZF} -foo < #{tempname}`.lines(chomp: true)701-702- assert_equal [703- 'xxxoxoxxx',704- 'xxxxoxox',705- ' xxoxoxxx',706- 'xxoxxxoxx',707- 'xoxxxxxoxx',708- 'xoxxxxxox'709- ], `#{FZF} -foo --tiebreak=index < #{tempname}`.lines(chomp: true)710-711- # Note that --tiebreak=begin is now based on the first occurrence of the712- # first character on the pattern713- assert_equal [714- ' xxoxoxxx',715- 'xxxoxoxxx',716- 'xxxxoxox',717- 'xxoxxxoxx',718- 'xoxxxxxoxx',719- 'xoxxxxxox'720- ], `#{FZF} -foo --tiebreak=begin < #{tempname}`.lines(chomp: true)721-722- assert_equal [723- ' xxoxoxxx',724- 'xxxoxoxxx',725- 'xxxxoxox',726- 'xxoxxxoxx',727- 'xoxxxxxox',728- 'xoxxxxxoxx'729- ], `#{FZF} -foo --tiebreak=begin,length < #{tempname}`.lines(chomp: true)730- end731-732- def test_tiebreak_begin_algo_v2733- writelines(['baz foo bar',734- 'foo bar baz'])735- assert_equal [736- 'foo bar baz',737- 'baz foo bar'738- ], `#{FZF} -fbar --tiebreak=begin --algo=v2 < #{tempname}`.lines(chomp: true)739- end740-741- def test_tiebreak_end742- writelines(['xoxxxxxxxx',743- 'xxoxxxxxxx',744- 'xxxoxxxxxx',745- 'xxxxoxxxx',746- 'xxxxxoxxx',747- ' xxxxoxxx'])748-749- assert_equal [750- ' xxxxoxxx',751- 'xxxxoxxxx',752- 'xxxxxoxxx',753- 'xoxxxxxxxx',754- 'xxoxxxxxxx',755- 'xxxoxxxxxx'756- ], `#{FZF} -fo < #{tempname}`.lines(chomp: true)757-758- assert_equal [759- 'xxxxxoxxx',760- ' xxxxoxxx',761- 'xxxxoxxxx',762- 'xxxoxxxxxx',763- 'xxoxxxxxxx',764- 'xoxxxxxxxx'765- ], `#{FZF} -fo --tiebreak=end < #{tempname}`.lines(chomp: true)766-767- assert_equal [768- 'xxxxxoxxx',769- ' xxxxoxxx',770- 'xxxxoxxxx',771- 'xxxoxxxxxx',772- 'xxoxxxxxxx',773- 'xoxxxxxxxx'774- ], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)775-776- writelines(['/bar/baz', '/foo/bar/baz'])777- assert_equal [778- '/foo/bar/baz',779- '/bar/baz'780- ], `#{FZF} -fbaz --tiebreak=end < #{tempname}`.lines(chomp: true)781- end782-783- def test_tiebreak_length_with_nth784- input = %w[785- 1:hell786- 123:hello787- 12345:he788- 1234567:h789- ]790- writelines(input)791-792- output = %w[793- 1:hell794- 12345:he795- 123:hello796- 1234567:h797- ]798- assert_equal output, `#{FZF} -fh < #{tempname}`.lines(chomp: true)799-800- # Since 0.16.8, --nth doesn't affect --tiebreak801- assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.lines(chomp: true)802- end803-804- def test_tiebreak_chunk805- writelines(['1 foobarbaz ba',806- '2 foobar baz',807- '3 foo barbaz'])808-809- assert_equal [810- '3 foo barbaz',811- '2 foobar baz',812- '1 foobarbaz ba'813- ], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true)814-815- assert_equal [816- '1 foobarbaz ba',817- '2 foobar baz',818- '3 foo barbaz'819- ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)820-821- assert_equal [822- '3 foo barbaz'823- ], `#{FZF} -f'!foobar' --tiebreak=chunk < #{tempname}`.lines(chomp: true)824- end825-826- def test_invalid_cache827- tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter828- tmux.until { |lines| assert_equal ' 2/3', lines[-2] }829- tmux.send_keys :BSpace830- tmux.until { |lines| assert_equal ' 3/3', lines[-2] }831- tmux.send_keys :D832- tmux.until { |lines| assert_equal ' 1/3', lines[-2] }833- tmux.send_keys :Enter834- end835-836- def test_invalid_cache_query_type837- command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{FZF}]838-839- # Suffix match840- tmux.send_keys command, :Enter841- tmux.until { |lines| assert_equal 104, lines.match_count }842- tmux.send_keys 'foo$'843- tmux.until { |lines| assert_equal 1, lines.match_count }844- tmux.send_keys 'bar'845- tmux.until { |lines| assert_equal 1, lines.match_count }846- tmux.send_keys :Enter847-848- # Prefix match849- tmux.prepare850- tmux.send_keys command, :Enter851- tmux.until { |lines| assert_equal 104, lines.match_count }852- tmux.send_keys '^bar'853- tmux.until { |lines| assert_equal 1, lines.match_count }854- tmux.send_keys 'C-a', 'foo'855- tmux.until { |lines| assert_equal 1, lines.match_count }856- tmux.send_keys :Enter857-858- # Exact match859- tmux.prepare860- tmux.send_keys command, :Enter861- tmux.until { |lines| assert_equal 104, lines.match_count }862- tmux.send_keys "'12"863- tmux.until { |lines| assert_equal 1, lines.match_count }864- tmux.send_keys 'C-a', 'foo'865- tmux.until { |lines| assert_equal 1, lines.match_count }866- end867-868- def test_smart_case_for_each_term869- assert_equal 1, `echo Foo bar | #{FZF} -x -f "foo Fbar" | wc -l`.to_i870- end871-872- def test_bind873- tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:accept,u:up,T:toggle-up,t:toggle')}", :Enter874- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }875- tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j'876- assert_equal %w[4 5 6 9], fzf_output_lines877- end878-879- def test_bind_print_query880- tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:print-query')}", :Enter881- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }882- tmux.send_keys 'print-my-query', 'C-j'883- assert_equal %w[print-my-query], fzf_output_lines884- end885-886- def test_bind_replace_query887- tmux.send_keys "seq 1 1000 | #{fzf('--print-query --bind=ctrl-j:replace-query')}", :Enter888- tmux.send_keys '1'889- tmux.until { |lines| assert_equal ' 272/1000', lines[-2] }890- tmux.send_keys 'C-k', 'C-j'891- tmux.until { |lines| assert_equal ' 29/1000', lines[-2] }892- tmux.until { |lines| assert_equal '> 10', lines[-1] }893- end894-895- def test_long_line896- data = '.' * 256 * 1024897- File.open(tempname, 'w') do |f|898- f << data899- end900- assert_equal data, `#{FZF} -f . < #{tempname}`.chomp901- end902-903- def test_read0904- lines = `find .`.lines(chomp: true)905- assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp906- assert_equal \907- lines.last,908- `find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp909- end910-911- def test_select_all_deselect_all_toggle_all912- tmux.send_keys "seq 100 | #{fzf('--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi')}", :Enter913- tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }914- tmux.send_keys :BTab, :BTab, :BTab915- tmux.until { |lines| assert_equal ' 100/100 (3)', lines[-2] }916- tmux.send_keys 'C-t'917- tmux.until { |lines| assert_equal ' 100/100 (97)', lines[-2] }918- tmux.send_keys 'C-a'919- tmux.until { |lines| assert_equal ' 100/100 (100)', lines[-2] }920- tmux.send_keys :Tab, :Tab921- tmux.until { |lines| assert_equal ' 100/100 (98)', lines[-2] }922- tmux.send_keys '100'923- tmux.until { |lines| assert_equal 1, lines.match_count }924- tmux.send_keys 'C-d'925- tmux.until { |lines| assert_equal ' 1/100 (97)', lines[-2] }926- tmux.send_keys 'C-u'927- tmux.until { |lines| assert_equal 100, lines.match_count }928- tmux.send_keys 'C-d'929- tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] }930- tmux.send_keys :BTab, :BTab931- tmux.until { |lines| assert_equal ' 100/100 (2)', lines[-2] }932- tmux.send_keys 0933- tmux.until { |lines| assert_equal ' 10/100 (2)', lines[-2] }934- tmux.send_keys 'C-a'935- tmux.until { |lines| assert_equal ' 10/100 (12)', lines[-2] }936- tmux.send_keys :Enter937- assert_equal %w[1 2 10 20 30 40 50 60 70 80 90 100],938- fzf_output_lines939- end940-941- def test_history942- history_file = '/tmp/fzf-test-history'943-944- # History with limited number of entries945- FileUtils.rm_f(history_file)946- opts = "--history=#{history_file} --history-size=4"947- input = %w[00 11 22 33 44]948- input.each do |keys|949- tmux.prepare950- tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter951- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }952- tmux.send_keys keys953- tmux.until { |lines| assert_equal ' 1/100', lines[-2] }954- tmux.send_keys :Enter955- end956- wait do957- assert_path_exists history_file958- assert_equal input[1..], File.readlines(history_file, chomp: true)959- end960-961- # Update history entries (not changed on disk)962- tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter963- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }964- tmux.send_keys 'C-p'965- tmux.until { |lines| assert_equal '> 44', lines[-1] }966- tmux.send_keys 'C-p'967- tmux.until { |lines| assert_equal '> 33', lines[-1] }968- tmux.send_keys :BSpace969- tmux.until { |lines| assert_equal '> 3', lines[-1] }970- tmux.send_keys 1971- tmux.until { |lines| assert_equal '> 31', lines[-1] }972- tmux.send_keys 'C-p'973- tmux.until { |lines| assert_equal '> 22', lines[-1] }974- tmux.send_keys 'C-n'975- tmux.until { |lines| assert_equal '> 31', lines[-1] }976- tmux.send_keys 0977- tmux.until { |lines| assert_equal '> 310', lines[-1] }978- tmux.send_keys :Enter979- wait do980- assert_path_exists history_file981- assert_equal %w[22 33 44 310], File.readlines(history_file, chomp: true)982- end983-984- # Respect --bind option985- tmux.send_keys "seq 100 | #{FZF} #{opts} --bind ctrl-p:next-history,ctrl-n:previous-history", :Enter986- tmux.until { |lines| assert_equal ' 100/100', lines[-2] }987- tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'988- tmux.until { |lines| assert_equal '> 33', lines[-1] }989- tmux.send_keys :Enter990- ensure991- FileUtils.rm_f(history_file)992- end993-994- def test_execute995- output = '/tmp/fzf-test-execute'996- opts = %[--bind "alt-a:execute(echo /{}/ >> #{output})+change-header(alt-a),alt-b:execute[echo /{}{}/ >> #{output}]+change-header(alt-b),C:execute(echo /{}{}{}/ >> #{output})+change-header(C)"]997- writelines(%w[foo'bar foo"bar foo$bar])998- tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter999- tmux.until { |lines| assert_equal 3, lines.item_count }1000-1001- ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }1002- tmux.send_keys :Escape, :a1003- ready.call('alt-a')1004- tmux.send_keys :Escape, :b1005- ready.call('alt-b')1006-1007- tmux.send_keys :Up1008- tmux.send_keys :Escape, :a1009- ready.call('alt-a')1010- tmux.send_keys :Escape, :b1011- ready.call('alt-b')1012-1013- tmux.send_keys :Up1014- tmux.send_keys :C1015- ready.call('C')1016-1017- tmux.send_keys 'barfoo'1018- tmux.until { |lines| assert_equal ' 0/3', lines[-2] }1019-1020- tmux.send_keys :Escape, :a1021- ready.call('alt-a')1022- tmux.send_keys :Escape, :b1023- ready.call('alt-b')1024-1025- wait do1026- assert_path_exists output1027- assert_equal %w[1028- /foo'bar/ /foo'barfoo'bar/1029- /foo"bar/ /foo"barfoo"bar/1030- /foo$barfoo$barfoo$bar/1031- ], File.readlines(output, chomp: true)1032- end1033- ensure1034- FileUtils.rm_f(output)1035- end1036-1037- def test_execute_multi1038- output = '/tmp/fzf-test-execute-multi'1039- opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})+change-header(alt-a),alt-b:change-header(alt-b)"]1040- writelines(%w[foo'bar foo"bar foo$bar foobar])1041- tmux.send_keys "cat #{tempname} | #{FZF} #{opts}", :Enter1042- ready = ->(s) { tmux.until { |lines| assert_includes lines[-3], s } }1043-1044- tmux.until { |lines| assert_equal ' 4/4 (0)', lines[-2] }1045- tmux.send_keys :Escape, :a1046- ready.call('alt-a')1047- tmux.send_keys :Escape, :b1048- ready.call('alt-b')1049-1050- tmux.send_keys :BTab, :BTab, :BTab1051- tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }1052- tmux.send_keys :Escape, :a1053- ready.call('alt-a')1054- tmux.send_keys :Escape, :b1055- ready.call('alt-b')1056-1057- tmux.send_keys :Tab, :Tab1058- tmux.until { |lines| assert_equal ' 4/4 (3)', lines[-2] }1059- tmux.send_keys :Escape, :a1060- ready.call('alt-a')1061- wait do1062- assert_path_exists output1063- assert_equal [1064- %(foo'bar/foo'bar),1065- %(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar),1066- %(foo'bar foo"bar foobar/foo'bar foo"bar foobar)1067- ], File.readlines(output, chomp: true)1068- end1069- ensure1070- FileUtils.rm_f(output)1071- end1072-1073- def test_execute_plus_flag1074- output = tempname + '.tmp'1075- FileUtils.rm_f(output)1076- writelines(['foo bar', '123 456'])1077-1078- tmux.send_keys "cat #{tempname} | #{FZF} --multi --bind 'x:execute-silent(echo {+}/{}/{+2}/{2} >> #{output})'", :Enter1079-1080- tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }1081- tmux.send_keys 'xy'1082- tmux.until { |lines| assert_equal ' 0/2 (0)', lines[-2] }1083- tmux.send_keys :BSpace1084- tmux.until { |lines| assert_equal ' 2/2 (0)', lines[-2] }1085-1086- tmux.send_keys :Up1087- tmux.send_keys :Tab1088- tmux.send_keys 'xy'1089- tmux.until { |lines| assert_equal ' 0/2 (1)', lines[-2] }1090- tmux.send_keys :BSpace1091- tmux.until { |lines| assert_equal ' 2/2 (1)', lines[-2] }1092-1093- tmux.send_keys :Tab1094- tmux.send_keys 'xy'1095- tmux.until { |lines| assert_equal ' 0/2 (2)', lines[-2] }1096- tmux.send_keys :BSpace1097- tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] }1098-1099- wait do1100- assert_path_exists output1101- assert_equal [1102- %(foo bar/foo bar/bar/bar),1103- %(123 456/foo bar/456/bar),1104- %(123 456 foo bar/foo bar/456 bar/bar)1105- ], File.readlines(output, chomp: true)1106- end1107- rescue StandardError1108- FileUtils.rm_f(output)1109- end1110-1111- def test_execute_shell1112- # Custom script to use as $SHELL1113- output = tempname + '.out'1114- FileUtils.rm_f(output)1115- writelines(['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"])1116- system("chmod +x #{tempname}")1117-1118- tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter1119- tmux.until { |lines| assert_equal ' 1/1', lines[-2] }1120- tmux.send_keys :Enter1121- tmux.until { |lines| assert_equal ' 1/1', lines[-2] }1122- wait do1123- assert_path_exists output1124- assert_equal ["-c / 'foo'bar"], File.readlines(output, chomp: true)1125- end1126- ensure1127- FileUtils.rm_f(output)1128- end1129-1130- def test_cycle1131- tmux.send_keys "seq 8 | #{FZF} --cycle", :Enter1132- tmux.until { |lines| assert_equal ' 8/8', lines[-2] }1133- tmux.send_keys :Down1134- tmux.until { |lines| assert_equal '> 8', lines[-10] }1135- tmux.send_keys :Down1136- tmux.until { |lines| assert_equal '> 7', lines[-9] }1137- tmux.send_keys :Up1138- tmux.until { |lines| assert_equal '> 8', lines[-10] }1139- tmux.send_keys :PgUp1140- tmux.until { |lines| assert_equal '> 8', lines[-10] }1141- tmux.send_keys :Up1142- tmux.until { |lines| assert_equal '> 1', lines[-3] }1143- tmux.send_keys :PgDn1144- tmux.until { |lines| assert_equal '> 1', lines[-3] }1145- tmux.send_keys :Down1146- tmux.until { |lines| assert_equal '> 8', lines[-10] }1147- end1148-1149- def test_header_lines1150- tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5')}", :Enter1151- 2.times do1152- tmux.until do |lines|1153- assert_equal ' 18/90', lines[-2]1154- assert_equal ' 1', lines[-3]1155- assert_equal ' 2', lines[-4]1156- assert_equal '> 50', lines[-13]1157- end1158- tmux.send_keys :Down1159- end1160- tmux.send_keys :Enter1161- assert_equal '50', fzf_output1162- end1163-1164- def test_header_lines_reverse1165- tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --reverse')}", :Enter1166- 2.times do1167- tmux.until do |lines|1168- assert_equal ' 18/90', lines[1]1169- assert_equal ' 1', lines[2]1170- assert_equal ' 2', lines[3]1171- assert_equal '> 50', lines[12]1172- end1173- tmux.send_keys :Up1174- end1175- tmux.send_keys :Enter1176- assert_equal '50', fzf_output1177- end1178-1179- def test_header_lines_reverse_list1180- tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --layout=reverse-list')}", :Enter1181- 2.times do1182- tmux.until do |lines|1183- assert_equal '> 50', lines[0]1184- assert_equal ' 2', lines[-4]1185- assert_equal ' 1', lines[-3]1186- assert_equal ' 18/90', lines[-2]1187- end1188- tmux.send_keys :Up1189- end1190- tmux.send_keys :Enter1191- assert_equal '50', fzf_output1192- end1193-1194- def test_header_lines_overflow1195- tmux.send_keys "seq 100 | #{fzf('--header-lines=200')}", :Enter1196- tmux.until do |lines|1197- assert_equal ' 0/0', lines[-2]1198- assert_equal ' 1', lines[-3]1199- end1200- tmux.send_keys :Enter1201- assert_equal '', fzf_output1202- end1203-1204- def test_header_lines_with_nth1205- tmux.send_keys "seq 100 | #{fzf('--header-lines 5 --with-nth 1,1,1,1,1')}", :Enter1206- tmux.until do |lines|1207- assert_equal ' 95/95', lines[-2]1208- assert_equal ' 11111', lines[-3]1209- assert_equal ' 55555', lines[-7]1210- assert_equal '> 66666', lines[-8]1211- end1212- tmux.send_keys :Enter1213- assert_equal '6', fzf_output1214- end1215-1216- def test_header1217- tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})"], :Enter1218- header = File.readlines(FILE, chomp: true).take(5)1219- tmux.until do |lines|1220- assert_equal ' 100/100', lines[-2]1221- assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]1222- assert_equal '> 1', lines[-8]1223- end1224- end1225-1226- def test_header_reverse1227- tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --reverse], :Enter1228- header = File.readlines(FILE, chomp: true).take(5)1229- tmux.until do |lines|1230- assert_equal ' 100/100', lines[1]1231- assert_equal header.map { |line| " #{line}".rstrip }, lines[2..6]1232- assert_equal '> 1', lines[7]1233- end1234- end1235-1236- def test_header_reverse_list1237- tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --layout=reverse-list], :Enter1238- header = File.readlines(FILE, chomp: true).take(5)1239- tmux.until do |lines|1240- assert_equal ' 100/100', lines[-2]1241- assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3]1242- assert_equal '> 1', lines[0]1243- end1244- end1245-1246- def test_header_and_header_lines1247- tmux.send_keys %[seq 100 | #{FZF} --header-lines 10 --header "$(head -5 #{FILE})"], :Enter1248- header = File.readlines(FILE, chomp: true).take(5)1249- tmux.until do |lines|1250- assert_equal ' 90/90', lines[-2]1251- assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]1252- assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]1253- end1254- end1255-1256- def test_header_and_header_lines_reverse1257- tmux.send_keys %[seq 100 | #{FZF} --reverse --header-lines 10 --header "$(head -5 #{FILE})"], :Enter1258- header = File.readlines(FILE, chomp: true).take(5)1259- tmux.until do |lines|1260- assert_equal ' 90/90', lines[1]1261- assert_equal header.map { |line| " #{line}".rstrip }, lines[2...7]1262- assert_equal (' 1'..' 10').to_a, lines[7...17]1263- end1264- end1265-1266- def test_header_and_header_lines_reverse_list1267- tmux.send_keys %[seq 100 | #{FZF} --layout=reverse-list --header-lines 10 --header "$(head -5 #{FILE})"], :Enter1268- header = File.readlines(FILE, chomp: true).take(5)1269- tmux.until do |lines|1270- assert_equal ' 90/90', lines[-2]1271- assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2]1272- assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7]1273- end1274- end1275-1276- def test_toggle_header1277- tmux.send_keys "seq 4 | #{FZF} --header-lines 2 --header foo --bind space:toggle-header --header-first --height 10 --border rounded", :Enter1278- before = <<~OUTPUT1279- ╭───────1280- │1281- │ 41282- │ > 31283- │ 2/21284- │ >1285- │ 21286- │ 11287- │ foo1288- ╰───────1289- OUTPUT1290- tmux.until { assert_block(before, _1) }1291- tmux.send_keys :Space1292- after = <<~OUTPUT1293- ╭───────1294- │1295- │1296- │1297- │1298- │ 41299- │ > 31300- │ 2/21301- │ >1302- ╰───────1303- OUTPUT1304- tmux.until { assert_block(after, _1) }1305- tmux.send_keys :Space1306- tmux.until { assert_block(before, _1) }1307- end1308-1309- def test_cancel1310- tmux.send_keys "seq 10 | #{FZF} --bind 2:cancel", :Enter1311- tmux.until { |lines| assert_equal ' 10/10', lines[-2] }1312- tmux.send_keys '123'1313- tmux.until do |lines|1314- assert_equal '> 3', lines[-1]1315- assert_equal ' 1/10', lines[-2]1316- end1317- tmux.send_keys 'C-y', 'C-y'1318- tmux.until { |lines| assert_equal '> 311', lines[-1] }1319- tmux.send_keys 21320- tmux.until { |lines| assert_equal '>', lines[-1] }1321- tmux.send_keys 21322- tmux.prepare1323- end1324-1325- def test_margin1326- tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3", :Enter1327- tmux.until do |lines|1328- assert_equal '', lines[4]1329- assert_equal ' y', lines[5]1330- end1331- tmux.send_keys :Enter1332- end1333-1334- def test_margin_reverse1335- tmux.send_keys "seq 1000 | #{FZF} --margin 7,5 --reverse", :Enter1336- tmux.until { |lines| assert_equal ' 1000/1000', lines[1 + 7] }1337- tmux.send_keys :Enter1338- end1339-1340- def test_margin_reverse_list1341- tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3 --layout=reverse-list", :Enter1342- tmux.until do |lines|1343- assert_equal '', lines[4]1344- assert_equal ' > y', lines[5]1345- end1346- tmux.send_keys :Enter1347- end1348-1349- def test_tabstop1350- writelines(%W[f\too\tba\tr\tbaz\tbarfooq\tux])1351- {1352- 1 => '> f oo ba r baz barfooq ux',1353- 2 => '> f oo ba r baz barfooq ux',1354- 3 => '> f oo ba r baz barfooq ux',1355- 4 => '> f oo ba r baz barfooq ux',1356- 5 => '> f oo ba r baz barfooq ux',1357- 6 => '> f oo ba r baz barfooq ux',1358- 7 => '> f oo ba r baz barfooq ux',1359- 8 => '> f oo ba r baz barfooq ux',1360- 9 => '> f oo ba r baz barfooq ux'1361- }.each do |ts, exp|1362- tmux.prepare1363- tmux.send_keys %(cat #{tempname} | fzf --tabstop=#{ts}), :Enter1364- tmux.until(true) do |lines|1365- assert_equal exp, lines[-3]1366- end1367- tmux.send_keys :Enter1368- end1369- end1370-1371- def test_with_nth_basic1372- writelines(['hello world ', 'byebye'])1373- assert_equal \1374- 'hello world ',1375- `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 < #{tempname}`.chomp1376- end1377-1378- def test_with_nth_ansi1379- writelines(["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye'])1380- assert_equal \1381- 'hello world ',1382- `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi < #{tempname}`.chomp1383- end1384-1385- def test_with_nth_no_ansi1386- src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "1387- writelines([src, 'byebye'])1388- assert_equal \1389- src,1390- `#{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi < #{tempname}`.chomp1391- end1392-1393- def test_exit_0_exit_code1394- `echo foo | #{FZF} -q bar -0`1395- assert_equal 1, $CHILD_STATUS.exitstatus1396- end1397-1398- def test_invalid_option1399- lines = `#{FZF} --foobar 2>&1`1400- assert_equal 2, $CHILD_STATUS.exitstatus1401- assert_includes lines, 'unknown option: --foobar'1402- end1403-1404- def test_filter_exitstatus1405- # filter / streaming filter1406- ['', '--no-sort'].each do |opts|1407- assert_includes `echo foo | #{FZF} -f foo #{opts}`, 'foo'1408- assert_equal 0, $CHILD_STATUS.exitstatus1409-1410- assert_empty `echo foo | #{FZF} -f bar #{opts}`1411- assert_equal 1, $CHILD_STATUS.exitstatus1412- end1413- end1414-1415- def test_exitstatus_empty1416- { '99' => '0', '999' => '1' }.each do |query, status|1417- tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter1418- tmux.until { |lines| assert_match %r{ [10]/100}, lines[-2] }1419- tmux.send_keys :Enter1420- tmux.until { |lines| assert_equal "--#{status}--", lines.last }1421- end1422- end1423-1424- def test_default_extended1425- assert_equal '100', `seq 100 | #{FZF} -f "1 00$"`.chomp1426- assert_equal '', `seq 100 | #{FZF} -f "1 00$" +x`.chomp1427- end1428-1429- def test_exact1430- assert_equal 4, `seq 123 | #{FZF} -f 13`.lines.length1431- assert_equal 2, `seq 123 | #{FZF} -f 13 -e`.lines.length1432- assert_equal 4, `seq 123 | #{FZF} -f 13 +e`.lines.length1433- end1434-1435- def test_or_operator1436- assert_equal %w[1 5 10], `seq 10 | #{FZF} -f "1 | 5"`.lines(chomp: true)1437- assert_equal %w[1 10 2 3 4 5 6 7 8 9],1438- `seq 10 | #{FZF} -f '1 | !1'`.lines(chomp: true)1439- end1440-1441- def test_hscroll_off1442- writelines(['=' * 10_000 + '0123456789'])1443- [0, 3, 6].each do |off|1444- tmux.prepare1445- tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 --bind space:toggle-hscroll < #{tempname}", :Enter1446- tmux.until { |lines| assert lines[-3]&.end_with?((0..off).to_a.join + '··') }1447- tmux.send_keys '9'1448- tmux.until { |lines| assert lines[-3]&.end_with?('789') }1449- tmux.send_keys :Space1450- tmux.until { |lines| assert lines[-3]&.end_with?('=··') }1451- tmux.send_keys :Space1452- tmux.until { |lines| assert lines[-3]&.end_with?('789') }1453- tmux.send_keys :Enter1454- end1455- end1456-1457- def test_partial_caching1458- tmux.send_keys 'seq 1000 | fzf -e', :Enter1459- tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }1460- tmux.send_keys 111461- tmux.until { |lines| assert_equal ' 19/1000', lines[-2] }1462- tmux.send_keys 'C-a', "'"1463- tmux.until { |lines| assert_equal ' 28/1000', lines[-2] }1464- tmux.send_keys :Enter1465- end1466-1467- def test_jump1468- tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump'")}", :Enter1469- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }1470- tmux.send_keys 'C-j'1471- tmux.until { |lines| assert_equal '5 5', lines[-7] }1472- tmux.until { |lines| assert_equal ' 6', lines[-8] }1473- tmux.send_keys '5'1474- tmux.until { |lines| assert_equal '> 5', lines[-7] }1475- tmux.send_keys :Tab1476- tmux.until { |lines| assert_equal ' >5', lines[-7] }1477- tmux.send_keys 'C-j'1478- tmux.until { |lines| assert_equal '5>5', lines[-7] }1479- tmux.send_keys '2'1480- tmux.until { |lines| assert_equal '> 2', lines[-4] }1481- tmux.send_keys :Tab1482- tmux.until { |lines| assert_equal ' >2', lines[-4] }1483- tmux.send_keys 'C-j'1484- tmux.until { |lines| assert_equal '5>5', lines[-7] }1485-1486- # Press any key other than jump labels to cancel jump1487- tmux.send_keys '6'1488- tmux.until { |lines| assert_equal '> 1', lines[-3] }1489- tmux.send_keys :Tab1490- tmux.until { |lines| assert_equal '>>1', lines[-3] }1491- tmux.send_keys :Enter1492- assert_equal %w[5 2 1], fzf_output_lines1493- end1494-1495- def test_jump_accept1496- tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump-accept'")}", :Enter1497- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }1498- tmux.send_keys 'C-j'1499- tmux.until { |lines| assert_equal '5 5', lines[-7] }1500- tmux.send_keys '3'1501- assert_equal '3', fzf_output1502- end1503-1504- def test_jump_events1505- tmux.send_keys "seq 1000 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump,jump:preview(echo jumped to {}),jump-cancel:preview(echo jump cancelled at {})'", :Enter1506- tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }1507- tmux.send_keys 'C-j'1508- tmux.until { |lines| assert_includes lines[-7], '5 5' }1509- tmux.send_keys '3'1510- tmux.until { |lines| assert(lines.any? { _1.include?('jumped to 3') }) }1511- tmux.send_keys 'C-j'1512- tmux.until { |lines| assert_includes lines[-7], '5 5' }1513- tmux.send_keys 'C-c'1514- tmux.until { |lines| assert(lines.any? { _1.include?('jump cancelled at 3') }) }1515- end1516-1517- def test_pointer1518- tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter1519- # Assert that specified pointer is displayed1520- tmux.until { |lines| assert_equal '>> 1', lines[-3] }1521- end1522-1523- def test_pointer_with_jump1524- tmux.send_keys "seq 10 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '>>'", :Enter1525- tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }1526- tmux.send_keys 'C-j'1527- # Correctly padded jump label should appear1528- tmux.until { |lines| assert_equal '5 5', lines[-7] }1529- tmux.until { |lines| assert_equal ' 6', lines[-8] }1530- tmux.send_keys '5'1531- # Assert that specified pointer is displayed1532- tmux.until { |lines| assert_equal '>> 5', lines[-7] }1533- end1534-1535- def test_marker1536- tmux.send_keys "seq 10 | #{FZF} --multi --marker '>>'", :Enter1537- tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] }1538- tmux.send_keys :BTab1539- # Assert that specified marker is displayed1540- tmux.until { |lines| assert_equal ' >>1', lines[-3] }1541- end1542-1543- def test_preview1544- tmux.send_keys %(seq 1000 | sed s/^2$// | #{FZF} -m --preview 'sleep 0.2; echo {{}-{+}}' --bind ?:toggle-preview), :Enter1545- tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }1546- tmux.send_keys :Up1547- tmux.until { |lines| assert_includes lines[1], ' {-} ' }1548- tmux.send_keys '555'1549- tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }1550- tmux.send_keys '?'1551- tmux.until { |lines| refute_includes lines[1], ' {555-555} ' }1552- tmux.send_keys '?'1553- tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }1554- tmux.send_keys :BSpace1555- tmux.until { |lines| assert lines[-2]&.start_with?(' 28/1000 ') }1556- tmux.send_keys 'foobar'1557- tmux.until { |lines| refute_includes lines[1], ' {55-55} ' }1558- tmux.send_keys 'C-u'1559- tmux.until { |lines| assert_equal 1000, lines.match_count }1560- tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }1561- tmux.send_keys :BTab1562- tmux.until { |lines| assert_includes lines[1], ' {-1} ' }1563- tmux.send_keys :BTab1564- tmux.until { |lines| assert_includes lines[1], ' {3-1 } ' }1565- tmux.send_keys :BTab1566- tmux.until { |lines| assert_includes lines[1], ' {4-1 3} ' }1567- tmux.send_keys :BTab1568- tmux.until { |lines| assert_includes lines[1], ' {5-1 3 4} ' }1569- end1570-1571- def test_toggle_preview_without_default_preview_command1572- tmux.send_keys %(seq 100 | #{FZF} --bind 'space:preview(echo [{}]),enter:toggle-preview' --preview-window up,border-double), :Enter1573- tmux.until do |lines|1574- assert_equal 100, lines.match_count1575- refute_includes lines[1], '║ [1]'1576- end1577-1578- # toggle-preview should do nothing1579- tmux.send_keys :Enter1580- tmux.until { |lines| refute_includes lines[1], '║ [1]' }1581- tmux.send_keys :Up1582- tmux.until do |lines|1583- refute_includes lines[1], '║ [1]'1584- refute_includes lines[1], '║ [2]'1585- end1586-1587- tmux.send_keys :Up1588- tmux.until do |lines|1589- assert_includes lines, '> 3'1590- refute_includes lines[1], '║ [3]'1591- end1592-1593- # One-off preview action1594- tmux.send_keys :Space1595- tmux.until { |lines| assert_includes lines[1], '║ [3]' }1596-1597- # toggle-preview to hide it1598- tmux.send_keys :Enter1599- tmux.until { |lines| refute_includes lines[1], '║ [3]' }1600-1601- # toggle-preview again does nothing1602- tmux.send_keys :Enter, :Up1603- tmux.until do |lines|1604- assert_includes lines, '> 4'1605- refute_includes lines[1], '║ [4]'1606- end1607- end1608-1609- def test_show_and_hide_preview1610- tmux.send_keys %(seq 100 | #{FZF} --preview-window hidden,border-bold --preview 'echo [{}]' --bind 'a:show-preview,b:hide-preview'), :Enter1611-1612- # Hidden by default1613- tmux.until do |lines|1614- assert_equal 100, lines.match_count1615- refute_includes lines[1], '┃ [1]'1616- end1617-1618- # Show1619- tmux.send_keys :a1620- tmux.until { |lines| assert_includes lines[1], '┃ [1]' }1621-1622- # Already shown1623- tmux.send_keys :a1624- tmux.send_keys :Up1625- tmux.until { |lines| assert_includes lines[1], '┃ [2]' }1626-1627- # Hide1628- tmux.send_keys :b1629- tmux.send_keys :Up1630- tmux.until do |lines|1631- assert_includes lines, '> 3'1632- refute_includes lines[1], '┃ [3]'1633- end1634-1635- # Already hidden1636- tmux.send_keys :b1637- tmux.send_keys :Up1638- tmux.until do |lines|1639- assert_includes lines, '> 4'1640- refute_includes lines[1], '┃ [4]'1641- end1642-1643- # Show it again1644- tmux.send_keys :a1645- tmux.until { |lines| assert_includes lines[1], '┃ [4]' }1646- end1647-1648- def test_preview_hidden1649- tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1650- tmux.until { |lines| assert_equal '>', lines[-1] }1651- tmux.send_keys '?'1652- tmux.until { |lines| assert_match(/ {1-1-1-[0-9]+}/, lines[-2]) }1653- tmux.send_keys '555'1654- tmux.until { |lines| assert_match(/ {555-555-1-[0-9]+}/, lines[-2]) }1655- tmux.send_keys '?'1656- tmux.until { |lines| assert_equal '> 555', lines[-1] }1657- end1658-1659- def test_preview_size_01660- tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0 --bind space:toggle-preview), :Enter1661- tmux.until do |lines|1662- assert_equal 100, lines.item_count1663- assert_equal ' 100/100', lines[1]1664- assert_equal '> 1', lines[2]1665- end1666- wait do1667- assert_path_exists tempname1668- assert_equal %w[1], File.readlines(tempname, chomp: true)1669- end1670- tmux.send_keys :Space, :Down, :Down1671- tmux.until { |lines| assert_equal '> 3', lines[4] }1672- wait do1673- assert_path_exists tempname1674- assert_equal %w[1], File.readlines(tempname, chomp: true)1675- end1676- tmux.send_keys :Space, :Down1677- tmux.until { |lines| assert_equal '> 4', lines[5] }1678- wait do1679- assert_path_exists tempname1680- assert_equal %w[1 3 4], File.readlines(tempname, chomp: true)1681- end1682- end1683-1684- def test_preview_size_0_hidden1685- tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0,hidden --bind space:toggle-preview), :Enter1686- tmux.until { |lines| assert_equal 100, lines.item_count }1687- tmux.send_keys :Down, :Down1688- tmux.until { |lines| assert_includes lines, '> 3' }1689- wait { refute_path_exists tempname }1690- tmux.send_keys :Space1691- wait do1692- assert_path_exists tempname1693- assert_equal %w[3], File.readlines(tempname, chomp: true)1694- end1695- tmux.send_keys :Down1696- wait do1697- assert_equal %w[3 4], File.readlines(tempname, chomp: true)1698- end1699- tmux.send_keys :Space, :Down1700- tmux.until { |lines| assert_includes lines, '> 5' }1701- tmux.send_keys :Down1702- tmux.until { |lines| assert_includes lines, '> 6' }1703- tmux.send_keys :Space1704- wait do1705- assert_equal %w[3 4 6], File.readlines(tempname, chomp: true)1706- end1707- end1708-1709- def test_preview_flags1710- tmux.send_keys %(seq 10 | sed 's/^/:: /; s/$/ /' |1711- #{FZF} --multi --preview 'echo {{2}/{s2}/{+2}/{+s2}/{q}/{n}/{+n}}'), :Enter1712- tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 //0/0} ' }1713- tmux.send_keys '123'1714- tmux.until { |lines| assert_includes lines[1], ' {////123//} ' }1715- tmux.send_keys 'C-u', '1'1716- tmux.until { |lines| assert_equal 2, lines.match_count }1717- tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 /1/0/0} ' }1718- tmux.send_keys :BTab1719- tmux.until { |lines| assert_includes lines[1], ' {10/10 /1/1 /1/9/0} ' }1720- tmux.send_keys :BTab1721- tmux.until { |lines| assert_includes lines[1], ' {10/10 /1 10/1 10 /1/9/0 9} ' }1722- tmux.send_keys '2'1723- tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /12//0 9} ' }1724- tmux.send_keys '3'1725- tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /123//0 9} ' }1726- end1727-1728- def test_preview_file1729- tmux.send_keys %[(echo foo bar; echo bar foo) | #{FZF} --multi --preview 'cat {+f} {+f2} {+nf} {+fn}' --print0], :Enter1730- tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }1731- tmux.send_keys :BTab1732- tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }1733- tmux.send_keys :BTab1734- tmux.until { |lines| assert_includes lines[1], ' foo barbar foobarfoo0101 ' }1735- end1736-1737- def test_preview_q_no_match1738- tmux.send_keys %(: | #{FZF} --preview 'echo foo {q} foo'), :Enter1739- tmux.until { |lines| assert_equal 0, lines.match_count }1740- tmux.until { |lines| assert_includes lines[1], ' foo foo' }1741- tmux.send_keys 'bar'1742- tmux.until { |lines| assert_includes lines[1], ' foo bar foo' }1743- tmux.send_keys 'C-u'1744- tmux.until { |lines| assert_includes lines[1], ' foo foo' }1745- end1746-1747- def test_preview_q_no_match_with_initial_query1748- tmux.send_keys %(: | #{FZF} --preview 'echo foo {q}{q}' --query foo), :Enter1749- tmux.until { |lines| assert_equal 0, lines.match_count }1750- tmux.until { |lines| assert_includes lines[1], ' foofoo ' }1751- end1752-1753- def test_no_clear1754- tmux.send_keys "seq 10 | #{fzf('--no-clear --inline-info --height 5')}", :Enter1755- prompt = '> < 10/10'1756- tmux.until { |lines| assert_equal prompt, lines[-1] }1757- tmux.send_keys :Enter1758- assert_equal %w[1], fzf_output_lines1759- tmux.until { |lines| assert_equal prompt, lines[-1] }1760- end1761-1762- def test_info_hidden1763- tmux.send_keys 'seq 10 | fzf --info=hidden --no-separator', :Enter1764- tmux.until { |lines| assert_equal '> 1', lines[-2] }1765- end1766-1767- def test_info_inline_separator1768- tmux.send_keys 'seq 10 | fzf --info=inline:___ --no-separator', :Enter1769- tmux.until { |lines| assert_equal '> ___10/10', lines[-1] }1770- end1771-1772- def test_change_first_last1773- tmux.send_keys %(seq 1000 | #{FZF} --bind change:first,alt-Z:last), :Enter1774- tmux.until { |lines| assert_equal 1000, lines.match_count }1775- tmux.send_keys :Up1776- tmux.until { |lines| assert_equal '> 2', lines[-4] }1777- tmux.send_keys 11778- tmux.until { |lines| assert_equal '> 1', lines[-3] }1779- tmux.send_keys :Up1780- tmux.until { |lines| assert_equal '> 10', lines[-4] }1781- tmux.send_keys 11782- tmux.until { |lines| assert_equal '> 11', lines[-3] }1783- tmux.send_keys 'C-u'1784- tmux.until { |lines| assert_equal '> 1', lines[-3] }1785- tmux.send_keys :Escape, 'Z'1786- tmux.until { |lines| assert_equal '> 1000', lines[0] }1787- tmux.send_keys :Enter1788- end1789-1790- def test_pos1791- tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:pos(3),b:pos(-3),c:pos(1),d:pos(-1),e:pos(0)' --preview 'echo {}/{}'), :Enter1792- tmux.until { |lines| assert_equal 1000, lines.match_count }1793- tmux.send_keys :a1794- tmux.until { |lines| assert_includes lines[1], ' 3/3' }1795- tmux.send_keys :b1796- tmux.until { |lines| assert_includes lines[1], ' 998/998' }1797- tmux.send_keys :c1798- tmux.until { |lines| assert_includes lines[1], ' 1/1' }1799- tmux.send_keys :d1800- tmux.until { |lines| assert_includes lines[1], ' 1000/1000' }1801- tmux.send_keys :e1802- tmux.until { |lines| assert_includes lines[1], ' 1/1' }1803- end1804-1805- def test_put1806- tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:put+put,b:put+put(ravo)' --preview 'echo {q}/{q}'), :Enter1807- tmux.until { |lines| assert_equal 1000, lines.match_count }1808- tmux.send_keys :a1809- tmux.until { |lines| assert_includes lines[1], ' aa/aa' }1810- tmux.send_keys :b1811- tmux.until { |lines| assert_includes lines[1], ' aabravo/aabravo' }1812- end1813-1814- def test_accept_non_empty1815- tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter1816- tmux.until { |lines| assert_equal 1000, lines.match_count }1817- tmux.send_keys 'foo'1818- tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }1819- # fzf doesn't exit since there's no selection1820- tmux.send_keys :Enter1821- tmux.until { |lines| assert_equal ' 0/1000', lines[-2] }1822- tmux.send_keys 'C-u'1823- tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }1824- tmux.send_keys '999'1825- tmux.until { |lines| assert_equal ' 1/1000', lines[-2] }1826- tmux.send_keys :Enter1827- assert_equal %w[999 999], fzf_output_lines1828- end1829-1830- def test_accept_non_empty_with_multi_selection1831- tmux.send_keys %(seq 1000 | #{fzf('-m --print-query --bind enter:accept-non-empty')}), :Enter1832- tmux.until { |lines| assert_equal 1000, lines.match_count }1833- tmux.send_keys :Tab1834- tmux.until { |lines| assert_equal ' 1000/1000 (1)', lines[-2] }1835- tmux.send_keys 'foo'1836- tmux.until { |lines| assert_equal ' 0/1000 (1)', lines[-2] }1837- # fzf will exit in this case even though there's no match for the current query1838- tmux.send_keys :Enter1839- assert_equal %w[foo 1], fzf_output_lines1840- end1841-1842- def test_accept_non_empty_with_empty_list1843- tmux.send_keys %(: | #{fzf('-q foo --print-query --bind enter:accept-non-empty')}), :Enter1844- tmux.until { |lines| assert_equal ' 0/0', lines[-2] }1845- tmux.send_keys :Enter1846- # fzf will exit anyway since input list is empty1847- assert_equal %w[foo], fzf_output_lines1848- end1849-1850- def test_accept_or_print_query_without_match1851- tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter1852- tmux.until { |lines| assert_equal 1000, lines.match_count }1853- tmux.send_keys 99_9991854- tmux.until { |lines| assert_equal 0, lines.match_count }1855- tmux.send_keys :Enter1856- assert_equal %w[99999], fzf_output_lines1857- end1858-1859- def test_accept_or_print_query_with_match1860- tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter1861- tmux.until { |lines| assert_equal 1000, lines.match_count }1862- tmux.send_keys '^99$'1863- tmux.until { |lines| assert_equal 1, lines.match_count }1864- tmux.send_keys :Enter1865- assert_equal %w[99], fzf_output_lines1866- end1867-1868- def test_accept_or_print_query_with_multi_selection1869- tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter1870- tmux.until { |lines| assert_equal 1000, lines.match_count }1871- tmux.send_keys :BTab, :BTab, :BTab1872- tmux.until { |lines| assert_equal 3, lines.select_count }1873- tmux.send_keys 99_9991874- tmux.until { |lines| assert_equal 0, lines.match_count }1875- tmux.send_keys :Enter1876- assert_equal %w[1 2 3], fzf_output_lines1877- end1878-1879- def test_preview_update_on_select1880- tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),1881- :Enter1882- tmux.until { |lines| assert_equal 10, lines.item_count }1883- tmux.send_keys 'a'1884- tmux.until { |lines| assert(lines.any? { |line| line.include?(' 1 2 3 4 5 ') }) }1885- tmux.send_keys 'a'1886- tmux.until { |lines| lines.each { |line| refute_includes line, ' 1 2 3 4 5 ' } }1887- end1888-1889- def test_escaped_meta_characters1890- input = [1891- 'foo^bar',1892- 'foo$bar',1893- 'foo!bar',1894- "foo'bar",1895- 'foo bar',1896- 'bar foo'1897- ]1898- writelines(input)1899-1900- assert_equal input.length, `#{FZF} -f'foo bar' < #{tempname}`.lines.length1901- assert_equal input.length - 1, `#{FZF} -f'^foo bar$' < #{tempname}`.lines.length1902- assert_equal ['foo bar'], `#{FZF} -f'foo\\ bar' < #{tempname}`.lines(chomp: true)1903- assert_equal ['foo bar'], `#{FZF} -f'^foo\\ bar$' < #{tempname}`.lines(chomp: true)1904- assert_equal input.length - 1, `#{FZF} -f'!^foo\\ bar$' < #{tempname}`.lines.length1905- end1906-1907- def test_inverse_only_search_should_not_sort_the_result1908- # Filter1909- assert_equal %w[aaaaa b ccc],1910- `printf '%s\n' aaaaa b ccc BAD | #{FZF} -f '!bad'`.lines(chomp: true)1911-1912- # Interactive1913- tmux.send_keys %(printf '%s\n' aaaaa b ccc BAD | #{FZF} -q '!bad'), :Enter1914- tmux.until do |lines|1915- assert_equal 4, lines.item_count1916- assert_equal 3, lines.match_count1917- end1918- tmux.until { |lines| assert_equal '> aaaaa', lines[-3] }1919- tmux.until { |lines| assert_equal ' b', lines[-4] }1920- tmux.until { |lines| assert_equal ' ccc', lines[-5] }1921- end1922-1923- def test_preview_correct_tab_width_after_ansi_reset_code1924- writelines(["\x1b[31m+\x1b[m\t\x1b[32mgreen"])1925- tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter1926- tmux.until { |lines| assert_includes lines[1], ' + green ' }1927- end1928-1929- def test_disabled1930- tmux.send_keys %(seq 1000 | #{FZF} --query 333 --disabled --bind a:enable-search,b:disable-search,c:toggle-search --preview 'echo {} {q}'), :Enter1931- tmux.until { |lines| assert_equal 1000, lines.match_count }1932- tmux.until { |lines| assert_includes lines[1], ' 1 333 ' }1933- tmux.send_keys 'foo'1934- tmux.until { |lines| assert_equal 1000, lines.match_count }1935- tmux.until { |lines| assert_includes lines[1], ' 1 333foo ' }1936-1937- # Already disabled, no change1938- tmux.send_keys 'b'1939- tmux.until { |lines| assert_equal 1000, lines.match_count }1940-1941- # Enable search1942- tmux.send_keys 'a'1943- tmux.until { |lines| assert_equal 0, lines.match_count }1944- tmux.send_keys :BSpace, :BSpace, :BSpace1945- tmux.until { |lines| assert_equal 1, lines.match_count }1946- tmux.until { |lines| assert_includes lines[1], ' 333 333 ' }1947-1948- # Toggle search -> disabled again, but retains the previous result1949- tmux.send_keys 'c'1950- tmux.send_keys 'foo'1951- tmux.until { |lines| assert_includes lines[1], ' 333 333foo ' }1952- tmux.until { |lines| assert_equal 1, lines.match_count }1953-1954- # Enabled, no match1955- tmux.send_keys 'c'1956- tmux.until { |lines| assert_equal 0, lines.match_count }1957- tmux.until { |lines| assert_includes lines[1], ' 333foo ' }1958- end1959-1960- def test_reload1961- tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq $FZF_QUERY),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter1962- tmux.until { |lines| assert_equal 998, lines.match_count }1963- tmux.send_keys 'a'1964- tmux.until do |lines|1965- assert_equal 98, lines.item_count1966- assert_equal 98, lines.match_count1967- end1968- tmux.send_keys 'b'1969- tmux.until do |lines|1970- assert_equal 198, lines.item_count1971- assert_equal 198, lines.match_count1972- end1973- tmux.send_keys :Tab1974- tmux.until { |lines| assert_equal ' 198/198 (1/2)', lines[-2] }1975- tmux.send_keys '555'1976- tmux.until { |lines| assert_equal ' 1/553 (0/2)', lines[-2] }1977- end1978-1979- def test_reload_even_when_theres_no_match1980- tmux.send_keys %(: | #{FZF} --bind 'space:reload(seq 10)'), :Enter1981- tmux.until { |lines| assert_equal 0, lines.item_count }1982- tmux.send_keys :Space1983- tmux.until { |lines| assert_equal 10, lines.item_count }1984- end1985-1986- def test_reload_should_terminate_standard_input_stream1987- tmux.send_keys %(ruby -e "STDOUT.sync = true; loop { puts 1; sleep 0.1 }" | fzf --bind 'start:reload(seq 100)'), :Enter1988- tmux.until { |lines| assert_equal 100, lines.item_count }1989- end1990-1991- def test_clear_list_when_header_lines_changed_due_to_reload1992- tmux.send_keys %(seq 10 | #{FZF} --header 0 --header-lines 3 --bind 'space:reload(seq 1)'), :Enter1993- tmux.until { |lines| assert_includes lines, ' 9' }1994- tmux.send_keys :Space1995- tmux.until { |lines| refute_includes lines, ' 9' }1996- end1997-1998- def test_clear_query1999- tmux.send_keys %(: | #{FZF} --query foo --bind space:clear-query), :Enter2000- tmux.until { |lines| assert_equal 0, lines.item_count }2001- tmux.until { |lines| assert_equal '> foo', lines.last }2002- tmux.send_keys 'C-a', 'bar'2003- tmux.until { |lines| assert_equal '> barfoo', lines.last }2004- tmux.send_keys :Space2005- tmux.until { |lines| assert_equal '>', lines.last }2006- end2007-2008- def test_change_and_transform_header2009- [2010- 'space:change-header:$(seq 4)',2011- 'space:transform-header:seq 4'2012- ].each_with_index do |binding, i|2013- tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "#{binding}"), :Enter2014- expected = <<~OUTPUT2015- > 32016- 22017- 12018- bar2019- 1/12020- >2021- OUTPUT2022- tmux.until { assert_block(expected, _1) }2023- tmux.send_keys :Space2024- expected = <<~OUTPUT2025- > 32026- 22027- 12028- 12029- 22030- 32031- 42032- 1/12033- >2034- OUTPUT2035- tmux.until { assert_block(expected, _1) }2036- next unless i.zero?2037-2038- teardown2039- setup2040- end2041- end2042-2043- def test_change_header2044- tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "space:change-header:$(seq 4)"), :Enter2045- expected = <<~OUTPUT2046- > 32047- 22048- 12049- bar2050- 1/12051- >2052- OUTPUT2053- tmux.until { assert_block(expected, _1) }2054- tmux.send_keys :Space2055- expected = <<~OUTPUT2056- > 32057- 22058- 12059- 12060- 22061- 32062- 42063- 1/12064- >2065- OUTPUT2066- tmux.until { assert_block(expected, _1) }2067- end2068-2069- def test_change_query2070- tmux.send_keys %(: | #{FZF} --query foo --bind space:change-query:foobar), :Enter2071- tmux.until { |lines| assert_equal 0, lines.item_count }2072- tmux.until { |lines| assert_equal '> foo', lines.last }2073- tmux.send_keys :Space, 'baz'2074- tmux.until { |lines| assert_equal '> foobarbaz', lines.last }2075- end2076-2077- def test_transform_query2078- tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter2079- tmux.until { |lines| assert_equal '> bar', lines[-1] }2080- tmux.send_keys 'C-r'2081- tmux.until { |lines| assert_equal '> rab', lines[-1] }2082- tmux.send_keys 'C-u'2083- tmux.until { |lines| assert_equal '> RAB', lines[-1] }2084- end2085-2086- def test_transform_prompt2087- tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter2088- tmux.until { |lines| assert_equal '> bar', lines[-1] }2089- tmux.send_keys 'C-r'2090- tmux.until { |lines| assert_equal '> rab', lines[-1] }2091- tmux.send_keys 'C-u'2092- tmux.until { |lines| assert_equal '> RAB', lines[-1] }2093- end2094-2095- def test_transform2096- tmux.send_keys %{#{FZF} --bind 'focus:transform:echo "change-prompt({fzf:action})"'}, :Enter2097- tmux.until { |lines| assert_equal 'start', lines[-1] }2098- tmux.send_keys :Up2099- tmux.until { |lines| assert_equal 'up', lines[-1] }2100- end2101-2102- def test_clear_selection2103- tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter2104- tmux.until { |lines| assert_equal 100, lines.match_count }2105- tmux.send_keys :Tab2106- tmux.until { |lines| assert_equal ' 100/100 (1)', lines[-2] }2107- tmux.send_keys 'foo'2108- tmux.until { |lines| assert_equal ' 0/100 (1)', lines[-2] }2109- tmux.send_keys :Space2110- tmux.until { |lines| assert_equal ' 0/100 (0)', lines[-2] }2111- end2112-2113- def test_backward_delete_char_eof2114- tmux.send_keys "seq 1000 | #{FZF} --bind 'bs:backward-delete-char/eof'", :Enter2115- tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] }2116- tmux.send_keys '11'2117- tmux.until { |lines| assert_equal '> 11', lines[-1] }2118- tmux.send_keys :BSpace2119- tmux.until { |lines| assert_equal '> 1', lines[-1] }2120- tmux.send_keys :BSpace2121- tmux.until { |lines| assert_equal '>', lines[-1] }2122- tmux.send_keys :BSpace2123- tmux.prepare2124- end2125-2126- def test_strip_xterm_osc_sequence2127- %W[\x07 \x1b\\].each do |esc|2128- writelines([%(printf $1"\e]4;3;rgb:aa/bb/cc#{esc} "$2)])2129- File.chmod(0o755, tempname)2130- tmux.prepare2131- tmux.send_keys \2132- %(echo foo bar | #{FZF} --preview '#{tempname} {2} {1}'), :Enter2133-2134- tmux.until { |lines| assert lines.any_include?('bar foo') }2135- tmux.send_keys :Enter2136- end2137- end2138-2139- def test_keep_right2140- tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right --no-multi-line --bind space:toggle-multi-line", :Enter2141- tmux.until { |lines| assert lines.any_include?('9999␊10000') }2142- tmux.send_keys :Space2143- tmux.until { |lines| assert lines.any_include?('> 1') }2144- tmux.send_keys :Space2145- tmux.until { |lines| assert lines.any_include?('9999␊10000') }2146- end2147-2148- def test_backward_eof2149- tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter2150- tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }2151- tmux.send_keys 'x'2152- tmux.until { |lines| lines.item_count == 1 && lines.match_count == 0 }2153- tmux.send_keys :BSpace2154- tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }2155- tmux.send_keys :BSpace2156- tmux.until { |lines| lines.item_count == 100 && lines.match_count == 100 }2157- end2158-2159- def test_preview_bindings_with_default_preview2160- tmux.send_keys "seq 10 | #{FZF} --preview 'echo [{}]' --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter2161- tmux.until { |lines| lines.item_count == 10 }2162- tmux.until { |lines| assert_includes lines[1], '[1]' }2163- tmux.send_keys 'a'2164- tmux.until { |lines| assert_includes lines[1], '[11]' }2165- tmux.send_keys 'c'2166- tmux.until { |lines| assert_includes lines[1], '[1]' }2167- tmux.send_keys 'b'2168- tmux.until { |lines| assert_includes lines[1], '[111]' }2169- tmux.send_keys :Up2170- tmux.until { |lines| assert_includes lines[1], '[2]' }2171- end2172-2173- def test_preview_bindings_without_default_preview2174- tmux.send_keys "seq 10 | #{FZF} --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter2175- tmux.until { |lines| lines.item_count == 10 }2176- tmux.until { |lines| refute_includes lines[1], '1' }2177- tmux.send_keys 'a'2178- tmux.until { |lines| assert_includes lines[1], '[11]' }2179- tmux.send_keys 'c' # does nothing2180- tmux.until { |lines| assert_includes lines[1], '[11]' }2181- tmux.send_keys 'b'2182- tmux.until { |lines| assert_includes lines[1], '[111]' }2183- tmux.send_keys 92184- tmux.until { |lines| lines.match_count == 1 }2185- tmux.until { |lines| refute_includes lines[1], '2' }2186- tmux.until { |lines| assert_includes lines[1], '[111]' }2187- end2188-2189- def test_preview_scroll_begin_constant2190- tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+123", :Enter2191- tmux.until { |lines| assert_match %r{1/1}, lines[-2] }2192- tmux.until { |lines| assert_match %r{123.*123/1000}, lines[1] }2193- end2194-2195- def test_preview_scroll_begin_expr2196- tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{3}", :Enter2197- tmux.until { |lines| assert_match %r{1/1}, lines[-2] }2198- tmux.until { |lines| assert_match %r{321.*321/1000}, lines[1] }2199- end2200-2201- def test_preview_scroll_begin_and_offset2202- ['echo foo 123 321', 'echo foo :123: 321'].each do |input|2203- tmux.send_keys "#{input} | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter2204- tmux.until { |lines| assert_match %r{1/1}, lines[-2] }2205- tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] }2206- tmux.send_keys 'C-c'2207- end2208- end2209-2210- def test_normalized_match2211- echoes = '(echo a; echo á; echo A; echo Á;)'2212- assert_equal %w[a á A Á], `#{echoes} | #{FZF} -f a`.lines.map(&:chomp)2213- assert_equal %w[á Á], `#{echoes} | #{FZF} -f á`.lines.map(&:chomp)2214- assert_equal %w[A Á], `#{echoes} | #{FZF} -f A`.lines.map(&:chomp)2215- assert_equal %w[Á], `#{echoes} | #{FZF} -f Á`.lines.map(&:chomp)2216- end2217-2218- def test_preview_clear_screen2219- 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'}, :Enter2220- tmux.until { |lines| lines.item_count == 100 }2221- tmux.until { |lines| lines[1]&.include?('[200]') }2222- end2223-2224- def test_change_prompt2225- tmux.send_keys "#{FZF} --bind 'a:change-prompt(a> ),b:change-prompt:b> ' --query foo", :Enter2226- tmux.until { |lines| assert_equal '> foo', lines[-1] }2227- tmux.send_keys 'a'2228- tmux.until { |lines| assert_equal 'a> foo', lines[-1] }2229- tmux.send_keys 'b'2230- tmux.until { |lines| assert_equal 'b> foo', lines[-1] }2231- end2232-2233- def test_preview_window_follow2234- file = Tempfile.new('fzf-follow')2235- file.sync = true2236-2237- tmux.send_keys %(seq 100 | #{FZF} --preview 'echo start; tail -f "#{file.path}"' --preview-window follow --bind 'up:preview-up,down:preview-down,space:change-preview-window:follow|nofollow' --preview-window '~4'), :Enter2238- tmux.until { |lines| lines.item_count == 100 }2239-2240- # Write to the temporary file, and check if the preview window is showing2241- # the last line of the file2242- tmux.until { |lines| assert_includes lines[1], 'start' }2243- 3.times { file.puts _1 } # header lines2244- 1000.times { file.puts _1 }2245- tmux.until { |lines| assert_includes lines[1], '/1004' }2246- tmux.until { |lines| assert_includes lines[-2], '999' }2247-2248- # Scroll the preview window and fzf should stop following the file content2249- tmux.send_keys :Up2250- tmux.until { |lines| assert_includes lines[-2], '998' }2251- file.puts 'foo', 'bar'2252- tmux.until do |lines|2253- assert_includes lines[1], '/1006'2254- assert_includes lines[-2], '998'2255- end2256-2257- # Scroll back to the bottom and fzf should start following the file again2258- %w[999 foo bar].each do |item|2259- wait do2260- tmux.send_keys :Down2261- tmux.until { |lines| assert_includes lines[-2], item }2262- end2263- end2264- file.puts 'baz'2265- tmux.until do |lines|2266- assert_includes lines[1], '/1007'2267- assert_includes lines[-2], 'baz'2268- end2269-2270- # Scroll upwards to stop following2271- tmux.send_keys :Up2272- wait { assert_includes lines[-2], 'bar' }2273- file.puts 'aaa'2274- tmux.until do |lines|2275- assert_includes lines[1], '/1008'2276- assert_includes lines[-2], 'bar'2277- end2278-2279- # Manually enable following2280- tmux.send_keys :Space2281- tmux.until { |lines| assert_includes lines[-2], 'aaa' }2282- file.puts 'bbb'2283- tmux.until do |lines|2284- assert_includes lines[1], '/1009'2285- assert_includes lines[-2], 'bbb'2286- end2287-2288- # Disable following2289- tmux.send_keys :Space2290- file.puts 'ccc', 'ddd'2291- tmux.until do |lines|2292- assert_includes lines[1], '/1011'2293- assert_includes lines[-2], 'bbb'2294- end2295- rescue StandardError2296- file.close2297- file.unlink2298- end2299-2300- def test_toggle_preview_wrap2301- 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", :Enter2302- 2.times do2303- tmux.until { |lines| assert_includes lines[2], '2nd line' }2304- tmux.send_keys 'C-w'2305- tmux.until do |lines|2306- assert_includes lines[2], 'wrapped'2307- assert_includes lines[3], '2nd line'2308- end2309- tmux.send_keys 'C-w'2310- end2311- end2312-2313- def test_close2314- tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter2315- tmux.until { |lines| assert_equal 100, lines.match_count }2316- tmux.until { |lines| assert_includes lines[1], 'foo' }2317- tmux.send_keys 'C-c'2318- tmux.until { |lines| refute_includes lines[1], 'foo' }2319- tmux.send_keys '10'2320- tmux.until { |lines| assert_equal 2, lines.match_count }2321- tmux.send_keys 'C-c'2322- tmux.send_keys 'C-l', 'closed'2323- tmux.until { |lines| assert_includes lines[0], 'closed' }2324- end2325-2326- def test_select_deselect2327- tmux.send_keys "seq 3 | #{FZF} --multi --bind up:deselect+up,down:select+down", :Enter2328- tmux.until { |lines| assert_equal 3, lines.match_count }2329- tmux.send_keys :Tab2330- tmux.until { |lines| assert_equal 1, lines.select_count }2331- tmux.send_keys :Up2332- tmux.until { |lines| assert_equal 0, lines.select_count }2333- tmux.send_keys :Down, :Down2334- tmux.until { |lines| assert_equal 2, lines.select_count }2335- tmux.send_keys :Tab2336- tmux.until { |lines| assert_equal 1, lines.select_count }2337- tmux.send_keys :Down, :Down2338- tmux.until { |lines| assert_equal 2, lines.select_count }2339- tmux.send_keys :Up2340- tmux.until { |lines| assert_equal 1, lines.select_count }2341- tmux.send_keys :Down2342- tmux.until { |lines| assert_equal 1, lines.select_count }2343- tmux.send_keys :Down2344- tmux.until { |lines| assert_equal 2, lines.select_count }2345- end2346-2347- def test_interrupt_execute2348- tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-l:execute:echo executing {}; sleep 100'", :Enter2349- tmux.until { |lines| assert_equal 100, lines.item_count }2350- tmux.send_keys 'C-l'2351- tmux.until { |lines| assert lines.any_include?('executing 1') }2352- tmux.send_keys 'C-c'2353- tmux.until { |lines| assert_equal 100, lines.item_count }2354- tmux.send_keys 992355- tmux.until { |lines| assert_equal 1, lines.match_count }2356- end2357-2358- def test_kill_default_command_on_abort2359- writelines(['#!/usr/bin/env bash',2360- "echo 'Started'",2361- 'while :; do sleep 1; done'])2362- system("chmod +x #{tempname}")2363-2364- tmux.send_keys FZF.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter2365- tmux.until { |lines| assert_equal 1, lines.item_count }2366- tmux.send_keys 'C-c'2367- tmux.send_keys 'C-l', 'closed'2368- tmux.until { |lines| assert_includes lines[0], 'closed' }2369- wait { refute system("pgrep -f #{tempname}") }2370- ensure2371- system("pkill -9 -f #{tempname}")2372- end2373-2374- def test_kill_default_command_on_accept2375- writelines(['#!/usr/bin/env bash',2376- "echo 'Started'",2377- 'while :; do sleep 1; done'])2378- system("chmod +x #{tempname}")2379-2380- tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND=#{tempname}"), :Enter2381- tmux.until { |lines| assert_equal 1, lines.item_count }2382- tmux.send_keys :Enter2383- assert_equal 'Started', fzf_output2384- wait { refute system("pgrep -f #{tempname}") }2385- ensure2386- system("pkill -9 -f #{tempname}")2387- end2388-2389- def test_kill_reload_command_on_abort2390- writelines(['#!/usr/bin/env bash',2391- "echo 'Started'",2392- 'while :; do sleep 1; done'])2393- system("chmod +x #{tempname}")2394-2395- tmux.send_keys "seq 1 3 | #{FZF} --bind 'ctrl-r:reload(#{tempname})'", :Enter2396- tmux.until { |lines| assert_equal 3, lines.item_count }2397- tmux.send_keys 'C-r'2398- tmux.until { |lines| assert_equal 1, lines.item_count }2399- tmux.send_keys 'C-c'2400- tmux.send_keys 'C-l', 'closed'2401- tmux.until { |lines| assert_includes lines[0], 'closed' }2402- wait { refute system("pgrep -f #{tempname}") }2403- ensure2404- system("pkill -9 -f #{tempname}")2405- end2406-2407- def test_kill_reload_command_on_accept2408- writelines(['#!/usr/bin/env bash',2409- "echo 'Started'",2410- 'while :; do sleep 1; done'])2411- system("chmod +x #{tempname}")2412-2413- tmux.send_keys "seq 1 3 | #{fzf("--bind 'ctrl-r:reload(#{tempname})'")}", :Enter2414- tmux.until { |lines| assert_equal 3, lines.item_count }2415- tmux.send_keys 'C-r'2416- tmux.until { |lines| assert_equal 1, lines.item_count }2417- tmux.send_keys :Enter2418- assert_equal 'Started', fzf_output2419- wait { refute system("pgrep -f #{tempname}") }2420- ensure2421- system("pkill -9 -f #{tempname}")2422- end2423-2424- def test_preview_header2425- tmux.send_keys "seq 100 | #{FZF} --bind ctrl-k:preview-up+preview-up,ctrl-j:preview-down+preview-down+preview-down --preview 'seq 1000' --preview-window 'top:+{1}:~3'", :Enter2426- tmux.until { |lines| assert_equal 100, lines.item_count }2427- top5 = ->(lines) { lines.drop(1).take(5).map { |s| s[/[0-9]+/] } }2428- tmux.until do |lines|2429- assert_includes lines[1], '4/1000'2430- assert_equal(%w[1 2 3 4 5], top5[lines])2431- end2432- tmux.send_keys '55'2433- tmux.until do |lines|2434- assert_equal 1, lines.match_count2435- assert_equal(%w[1 2 3 55 56], top5[lines])2436- end2437- tmux.send_keys 'C-J'2438- tmux.until do |lines|2439- assert_equal(%w[1 2 3 58 59], top5[lines])2440- end2441- tmux.send_keys :BSpace2442- tmux.until do |lines|2443- assert_equal 19, lines.match_count2444- assert_equal(%w[1 2 3 5 6], top5[lines])2445- end2446- tmux.send_keys 'C-K'2447- tmux.until { |lines| assert_equal(%w[1 2 3 4 5], top5[lines]) }2448- end2449-2450- def test_unbind_rebind2451- tmux.send_keys "seq 100 | #{FZF} --bind 'c:clear-query,d:unbind(c,d),e:rebind(c,d)'", :Enter2452- tmux.until { |lines| assert_equal 100, lines.item_count }2453- tmux.send_keys 'ab'2454- tmux.until { |lines| assert_equal '> ab', lines[-1] }2455- tmux.send_keys 'c'2456- tmux.until { |lines| assert_equal '>', lines[-1] }2457- tmux.send_keys 'dabcd'2458- tmux.until { |lines| assert_equal '> abcd', lines[-1] }2459- tmux.send_keys 'ecabddc'2460- tmux.until { |lines| assert_equal '> abdc', lines[-1] }2461- end2462-2463- def test_item_index_reset_on_reload2464- tmux.send_keys "seq 10 | #{FZF} --preview 'echo [[{n}]]' --bind 'up:last,down:first,space:reload:seq 100'", :Enter2465- tmux.until { |lines| assert_includes lines[1], '[[0]]' }2466- tmux.send_keys :Up2467- tmux.until { |lines| assert_includes lines[1], '[[9]]' }2468- tmux.send_keys :Down2469- tmux.until { |lines| assert_includes lines[1], '[[0]]' }2470- tmux.send_keys :Space2471- tmux.until do |lines|2472- assert_equal 100, lines.item_count2473- assert_includes lines[1], '[[0]]'2474- end2475- tmux.send_keys :Up2476- tmux.until { |lines| assert_includes lines[1], '[[99]]' }2477- end2478-2479- def test_reload_should_update_preview2480- tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload:echo 4' --preview 'echo {}' --preview-window 'nohidden'", :Enter2481- tmux.until { |lines| assert_includes lines[1], '1' }2482- tmux.send_keys 'C-t'2483- tmux.until { |lines| assert_includes lines[1], '4' }2484- end2485-2486- def test_reload_and_change_preview_should_update_preview2487- tmux.send_keys "seq 3 | #{FZF} --bind 'ctrl-t:reload(echo 4)+change-preview(echo {})'", :Enter2488- tmux.until { |lines| assert_equal 3, lines.item_count }2489- tmux.until { |lines| refute_includes lines[1], '1' }2490- tmux.send_keys 'C-t'2491- tmux.until { |lines| assert_equal 1, lines.item_count }2492- tmux.until { |lines| assert_includes lines[1], '4' }2493- end2494-2495- def test_reload_sync2496- tmux.send_keys "seq 100 | #{FZF} --bind 'load:reload-sync(sleep 1; seq 1000)+unbind(load)'", :Enter2497- tmux.until { |lines| assert_equal 100, lines.item_count }2498- tmux.send_keys '00'2499- tmux.until { |lines| assert_equal 1, lines.match_count }2500- # After 1 second2501- tmux.until { |lines| assert_equal 10, lines.match_count }2502- end2503-2504- def test_reload_disabled_case12505- tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)'", :Enter2506- tmux.until do |lines|2507- assert_equal 100, lines.item_count2508- assert_equal 1, lines.match_count2509- end2510- tmux.send_keys :Space2511- tmux.until { |lines| assert_equal 1, lines.match_count }2512- tmux.send_keys :BSpace2513- tmux.until { |lines| assert_equal 0, lines.match_count }2514- tmux.until { |lines| assert_equal 1000, lines.match_count }2515- end2516-2517- def test_reload_disabled_case22518- tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)'", :Enter2519- tmux.until do |lines|2520- assert_equal 100, lines.item_count2521- assert_equal 1, lines.match_count2522- end2523- tmux.send_keys :Space2524- tmux.until { |lines| assert_equal 1, lines.match_count }2525- tmux.send_keys :BSpace2526- tmux.until { |lines| assert_equal 1, lines.match_count }2527- tmux.until { |lines| assert_equal 1000, lines.match_count }2528- end2529-2530- def test_reload_disabled_case32531- tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(sleep 2; seq 1000)+backward-delete-char'", :Enter2532- tmux.until do |lines|2533- assert_equal 100, lines.item_count2534- assert_equal 1, lines.match_count2535- end2536- tmux.send_keys :Space2537- tmux.until { |lines| assert_equal 1, lines.match_count }2538- tmux.send_keys :BSpace2539- tmux.until { |lines| assert_equal 0, lines.match_count }2540- tmux.until { |lines| assert_equal 1000, lines.match_count }2541- end2542-2543- def test_reload_disabled_case42544- tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload-sync(sleep 2; seq 1000)+backward-delete-char'", :Enter2545- tmux.until do |lines|2546- assert_equal 100, lines.item_count2547- assert_equal 1, lines.match_count2548- end2549- tmux.send_keys :Space2550- tmux.until { |lines| assert_equal 1, lines.match_count }2551- tmux.send_keys :BSpace2552- tmux.until { |lines| assert_equal 1, lines.match_count }2553- tmux.until { |lines| assert_equal 1000, lines.match_count }2554- end2555-2556- def test_reload_disabled_case52557- tmux.send_keys "seq 100 | #{FZF} --query 99 --bind 'space:disable-search+reload(echo xx; sleep 2; seq 1000)'", :Enter2558- tmux.until do |lines|2559- assert_equal 100, lines.item_count2560- assert_equal 1, lines.match_count2561- end2562- tmux.send_keys :Space2563- tmux.until do |lines|2564- assert_equal 1, lines.item_count2565- assert_equal 1, lines.match_count2566- end2567- tmux.send_keys :BSpace2568- tmux.until { |lines| assert_equal 1001, lines.match_count }2569- end2570-2571- def test_reload_disabled_case62572- tmux.send_keys "seq 1000 | #{FZF} --disabled --bind 'change:reload:sleep 0.5; seq {q}'", :Enter2573- tmux.until { |lines| assert_equal 1000, lines.match_count }2574- tmux.send_keys '9'2575- tmux.until { |lines| assert_equal 9, lines.match_count }2576- tmux.send_keys '9'2577- tmux.until { |lines| assert_equal 99, lines.match_count }2578-2579- # TODO: How do we verify if an intermediate empty list is not shown?2580- end2581-2582- def test_scroll_off2583- tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter2584- tmux.until { |lines| assert_equal 1000, lines.item_count }2585- height = tmux.until { |lines| lines }.first.to_i2586- tmux.send_keys :PgUp2587- tmux.until do |lines|2588- assert_equal height + 3, lines.first.to_i2589- assert_equal "> #{height}", lines[3].strip2590- end2591- tmux.send_keys :Up2592- tmux.until { |lines| assert_equal "> #{height + 1}", lines[3].strip }2593- tmux.send_keys 'l'2594- tmux.until { |lines| assert_equal '> 1000', lines.first.strip }2595- tmux.send_keys :PgDn2596- tmux.until { |lines| assert_equal "> #{1000 - height + 1}", lines.reverse[5].strip }2597- tmux.send_keys :Down2598- tmux.until { |lines| assert_equal "> #{1000 - height}", lines.reverse[5].strip }2599- end2600-2601- def test_scroll_off_large2602- tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter2603- tmux.until { |lines| assert_equal 1000, lines.item_count }2604- height = tmux.until { |lines| lines }.first.to_i2605- tmux.send_keys :PgUp2606- tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip }2607- tmux.send_keys :Up2608- tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }2609- tmux.send_keys :Up2610- tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip }2611- tmux.send_keys :Down2612- tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }2613- end2614-2615- def test_header_first2616- tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first", :Enter2617- tmux.until do |lines|2618- expected = <<~OUTPUT2619- > 42620- 997/9972621- >2622- 32623- 22624- 12625- foobar2626- OUTPUT2627-2628- assert_equal expected.chomp, lines.reverse.take(7).reverse.join("\n")2629- end2630- end2631-2632- def test_header_first_reverse2633- tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first --reverse --inline-info", :Enter2634- tmux.until do |lines|2635- expected = <<~OUTPUT2636- foobar2637- 12638- 22639- 32640- > < 997/9972641- > 42642- OUTPUT2643-2644- assert_equal expected.chomp, lines.take(6).join("\n")2645- end2646- end2647-2648- def test_change_preview_window2649- tmux.send_keys "seq 1000 | #{FZF} --preview 'echo [[{}]]' --no-preview-border --bind '" \2650- 'a:change-preview(echo __{}__),' \2651- 'b:change-preview-window(down)+change-preview(echo =={}==)+change-preview-window(up),' \2652- 'c:change-preview(),d:change-preview-window(hidden),' \2653- "e:preview(printf ::%${FZF_PREVIEW_COLUMNS}s{})+change-preview-window(up),f:change-preview-window(up,wrap)'", :Enter2654- tmux.until { |lines| assert_equal 1000, lines.item_count }2655- tmux.until { |lines| assert_includes lines[0], '[[1]]' }2656-2657- # change-preview action permanently changes the preview command set by --preview2658- tmux.send_keys 'a'2659- tmux.until { |lines| assert_includes lines[0], '__1__' }2660- tmux.send_keys :Up2661- tmux.until { |lines| assert_includes lines[0], '__2__' }2662-2663- # When multiple change-preview-window actions are bound to a single key,2664- # the last one wins and the updated options are immediately applied to the new preview2665- tmux.send_keys 'b'2666- tmux.until { |lines| assert_equal '==2==', lines[0] }2667- tmux.send_keys :Up2668- tmux.until { |lines| assert_equal '==3==', lines[0] }2669-2670- # change-preview with an empty preview command closes the preview window2671- tmux.send_keys 'c'2672- tmux.until { |lines| refute_includes lines[0], '==' }2673-2674- # change-preview again to re-open the preview window2675- tmux.send_keys 'a'2676- tmux.until { |lines| assert_equal '__3__', lines[0] }2677-2678- # Hide the preview window with hidden flag2679- tmux.send_keys 'd'2680- tmux.until { |lines| refute_includes lines[0], '__3__' }2681-2682- # One-off preview2683- tmux.send_keys 'e'2684- tmux.until do |lines|2685- assert_equal '::', lines[0]2686- refute_includes lines[1], '3'2687- end2688-2689- # Wrapped2690- tmux.send_keys 'f'2691- tmux.until do |lines|2692- assert_equal '::', lines[0]2693- assert_equal ' 3', lines[1]2694- end2695- end2696-2697- def test_change_preview_window_should_not_reset_change_preview2698- tmux.send_keys "#{FZF} --preview-window up,border-none --bind 'start:change-preview(echo hello)' --bind 'enter:change-preview-window(border-left)'", :Enter2699- tmux.until { |lines| assert_includes lines, 'hello' }2700- tmux.send_keys :Enter2701- tmux.until { |lines| assert_includes lines, '│ hello' }2702- end2703-2704- def test_change_preview_window_rotate2705- tmux.send_keys "seq 100 | #{FZF} --preview-window left,border-none --preview 'echo hello' --bind '" \2706- "a:change-preview-window(right|down|up|hidden|)'", :Enter2707- tmux.until { |lines| assert(lines.any? { _1.include?('100/100') }) }2708- 3.times do2709- tmux.until { |lines| lines[0].start_with?('hello') }2710- tmux.send_keys 'a'2711- tmux.until { |lines| lines[0].end_with?('hello') }2712- tmux.send_keys 'a'2713- tmux.until { |lines| lines[-1].start_with?('hello') }2714- tmux.send_keys 'a'2715- tmux.until { |lines| assert_equal 'hello', lines[0] }2716- tmux.send_keys 'a'2717- tmux.until { |lines| refute_includes lines[0], 'hello' }2718- tmux.send_keys 'a'2719- end2720- end2721-2722- def test_change_preview_window_rotate_hidden2723- tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \2724- "a:change-preview-window(nohidden||down,1|)'", :Enter2725- tmux.until { |lines| assert_equal 100, lines.match_count }2726- tmux.until { |lines| refute_includes lines[1], '==1==' }2727- tmux.send_keys 'a'2728- tmux.until { |lines| assert_includes lines[1], '==1==' }2729- tmux.send_keys 'a'2730- tmux.until { |lines| refute_includes lines[1], '==1==' }2731- tmux.send_keys 'a'2732- tmux.until { |lines| assert_includes lines[-2], '==1==' }2733- tmux.send_keys 'a'2734- tmux.until { |lines| refute_includes lines[-2], '==1==' }2735- tmux.send_keys 'a'2736- tmux.until { |lines| assert_includes lines[1], '==1==' }2737- end2738-2739- def test_change_preview_window_rotate_hidden_down2740- tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter2741- tmux.until { |lines| assert_equal 100, lines.match_count }2742- tmux.until { |lines| refute_includes lines[1], '==1==' }2743- tmux.send_keys '?'2744- tmux.until { |lines| assert_includes lines[1], '==1==' }2745- tmux.send_keys '?'2746- tmux.until { |lines| refute_includes lines[1], '==1==' }2747- tmux.send_keys '?'2748- tmux.until { |lines| assert_includes lines[-2], '==1==' }2749- tmux.send_keys '?'2750- tmux.until { |lines| refute_includes lines[-2], '==1==' }2751- tmux.send_keys '?'2752- tmux.until { |lines| assert_includes lines[1], '==1==' }2753- end2754-2755- def test_ellipsis2756- tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter2757- tmux.until { |lines| assert_equal 1, lines.match_count }2758- tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }2759- end2760-2761- def assert_block(expected, lines)2762- cols = expected.lines.map(&:chomp).map(&:length).max2763- top = lines.take(expected.lines.length).map { _1[0, cols].rstrip + "\n" }.join2764- bottom = lines.reverse.take(expected.lines.length).reverse.map { _1[0, cols].rstrip + "\n" }.join2765- assert_includes [top, bottom], expected2766- end2767-2768- def test_height_range_fit2769- tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded', :Enter2770- expected = <<~OUTPUT2771- ╭──────────2772- │ 32773- │ 22774- │ > 12775- │ > < 3/32776- ╰──────────2777- OUTPUT2778- tmux.until { assert_block(expected, _1) }2779- end2780-2781- def test_height_range_fit_preview_above2782- tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded --preview-window border-rounded --preview "seq {}" --preview-window up,60%', :Enter2783- expected = <<~OUTPUT2784- ╭──────────2785- │ ╭────────2786- │ │ 12787- │ │2788- │ │2789- │ │2790- │ ╰────────2791- │ 32792- │ 22793- │ > 12794- │ > < 3/32795- ╰──────────2796- OUTPUT2797- tmux.until { assert_block(expected, _1) }2798- end2799-2800- def test_height_range_fit_preview_above_alternative2801- tmux.send_keys 'seq 3 | fzf --height ~100% --border=sharp --preview "seq {}" --preview-window up,40%,border-bottom --padding 1 --exit-0 --header hello --header-lines=2', :Enter2802- expected = <<~OUTPUT2803- ┌─────────2804- │2805- │ 12806- │ 22807- │ 32808- │ ───────2809- │ > 32810- │ 22811- │ 12812- │ hello2813- │ 1/1 ─2814- │ >2815- │2816- └─────────2817- OUTPUT2818- tmux.until { assert_block(expected, _1) }2819- end2820-2821- def test_height_range_fit_preview_left2822- tmux.send_keys "seq 3 | fzf --height ~100% --border=vertical --preview 'seq {}' --preview-window left,5,border-right --padding 1 --exit-0 --header $'hello\\nworld' --header-lines=2", :Enter2823- expected = <<~OUTPUT2824- │2825- │ 1 │ > 32826- │ 2 │ 22827- │ 3 │ 12828- │ │ hello2829- │ │ world2830- │ │ 1/1 ─2831- │ │ >2832- │2833- OUTPUT2834- tmux.until { assert_block(expected, _1) }2835- end2836-2837- def test_height_range_overflow2838- tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border rounded', :Enter2839- expected = <<~OUTPUT2840- ╭──────────────2841- │ 22842- │ > 12843- │ > < 100/1002844- ╰──────────────2845- OUTPUT2846- tmux.until { assert_block(expected, _1) }2847- end2848-2849- def test_start_event2850- tmux.send_keys 'seq 100 | fzf --multi --sync --preview-window hidden:border-none --bind "start:select-all+last+preview(echo welcome)"', :Enter2851- tmux.until do |lines|2852- assert_match(/>100.*welcome/, lines[0])2853- assert_includes(lines[-2], '100/100 (100)')2854- end2855- end2856-2857- def test_focus_event2858- tmux.send_keys 'seq 100 | fzf --bind "focus:transform-prompt(echo [[{}]]),?:unbind(focus)"', :Enter2859- tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }2860- tmux.send_keys :Up2861- tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }2862- tmux.send_keys :X2863- tmux.until { |lines| assert_includes(lines[-1], '[[]]') }2864- tmux.send_keys :BSpace2865- tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }2866- tmux.send_keys :X2867- tmux.until { |lines| assert_includes(lines[-1], '[[]]') }2868- tmux.send_keys '?'2869- tmux.send_keys :BSpace2870- tmux.until { |lines| assert_equal 100, lines.match_count }2871- tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }2872- end2873-2874- def test_result_event2875- tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter2876- tmux.until { |lines| assert_equal 11, lines.item_count }2877- tmux.until { |lines| assert_includes lines, '> 1' }2878- tmux.send_keys '9'2879- tmux.until { |lines| assert_includes lines, '> 9' }2880- tmux.send_keys :BSpace2881- tmux.until { |lines| assert_includes lines, '> 1' }2882- end2883-2884- def test_labels_center2885- tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter2886- tmux.until do2887- assert_includes(_1[0], '─foobar─')2888- assert_includes(_1[1], '─barfoo─')2889- end2890- tmux.send_keys :space2891- tmux.until do2892- assert_includes(_1[0], '─foobarfoo─')2893- assert_includes(_1[1], '─barfoobar─')2894- end2895- tmux.send_keys :Enter2896- tmux.until do2897- assert_includes(_1[0], '─fooxfoo─')2898- assert_includes(_1[1], '─barxbar─')2899- end2900- end2901-2902- def test_labels_left2903- tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2 --preview : --preview-label barfoo --preview-label-pos 2', :Enter2904- tmux.until do2905- assert_includes(_1[0], '╭foobar─')2906- assert_includes(_1[1], '╭barfoo─')2907- end2908- end2909-2910- def test_labels_right2911- tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos -2 --preview : --preview-label barfoo --preview-label-pos -2', :Enter2912- tmux.until do2913- assert_includes(_1[0], '─foobar╮')2914- assert_includes(_1[1], '─barfoo╮')2915- end2916- end2917-2918- def test_labels_bottom2919- tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2:bottom --preview : --preview-label barfoo --preview-label-pos -2:bottom', :Enter2920- tmux.until do2921- assert_includes(_1[-1], '╰foobar─')2922- assert_includes(_1[-2], '─barfoo╯')2923- end2924- end2925-2926- def test_labels_variables2927- tmux.send_keys ': | fzf --border --border-label foobar --preview "echo \$FZF_BORDER_LABEL // \$FZF_PREVIEW_LABEL" --preview-label barfoo --bind "space:change-border-label(barbaz)+change-preview-label(bazbar)+refresh-preview,enter:transform-border-label(echo 123)+transform-preview-label(echo 456)+refresh-preview"', :Enter2928- tmux.until do2929- assert_includes(_1[0], '─foobar─')2930- assert_includes(_1[1], '─barfoo─')2931- assert_includes(_1[2], ' foobar // barfoo ')2932- end2933- tmux.send_keys :Space2934- tmux.until do2935- assert_includes(_1[0], '─barbaz─')2936- assert_includes(_1[1], '─bazbar─')2937- assert_includes(_1[2], ' barbaz // bazbar ')2938- end2939- tmux.send_keys :Enter2940- tmux.until do2941- assert_includes(_1[0], '─123─')2942- assert_includes(_1[1], '─456─')2943- assert_includes(_1[2], ' 123 // 456 ')2944- end2945- end2946-2947- def test_info_separator_unicode2948- tmux.send_keys 'seq 100 | fzf -q55', :Enter2949- tmux.until { assert_includes(_1[-2], ' 1/100 ─') }2950- end2951-2952- def test_info_separator_no_unicode2953- tmux.send_keys 'seq 100 | fzf -q55 --no-unicode', :Enter2954- tmux.until { assert_includes(_1[-2], ' 1/100 -') }2955- end2956-2957- def test_info_separator_repeat2958- tmux.send_keys 'seq 100 | fzf -q55 --separator _-', :Enter2959- tmux.until { assert_includes(_1[-2], ' 1/100 _-_-') }2960- end2961-2962- def test_info_separator_ansi_colors_and_tabs2963- tmux.send_keys "seq 100 | fzf -q55 --tabstop 4 --separator $'\\x1b[33ma\\tb'", :Enter2964- tmux.until { assert_includes(_1[-2], ' 1/100 a ba ba') }2965- end2966-2967- def test_info_no_separator2968- tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter2969- tmux.until { assert(_1[-2] == ' 1/100') }2970- end2971-2972- def test_info_right2973- tmux.send_keys "#{FZF} --info=right --separator x --bind 'start:reload:seq 100; sleep 10'", :Enter2974- tmux.until { assert_match(%r{xxx [⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, _1[-2]) }2975- end2976-2977- def test_info_inline_right2978- tmux.send_keys "#{FZF} --info=inline-right --bind 'start:reload:seq 100; sleep 10'", :Enter2979- tmux.until { assert_match(%r{[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, _1[-1]) }2980- end2981-2982- def test_info_inline_right_clearance2983- tmux.send_keys "seq 100000 | #{FZF} --info inline-right", :Enter2984- tmux.until { assert_match(%r{100000/100000}, _1[-1]) }2985- tmux.send_keys 'x'2986- tmux.until { assert_match(%r{ 0/100000}, _1[-1]) }2987- end2988-2989- def test_info_command2990- tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"'), :Enter)2991- tmux.until { assert_match(%r{^ --1/10000/10000-- xx}, _1[-2]) }2992- tmux.send_keys :Up2993- tmux.until { assert_match(%r{^ --2/10000/10000-- xx}, _1[-2]) }2994- end2995-2996- def test_info_command_inline2997- tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline:xx), :Enter)2998- tmux.until { assert_match(%r{^> xx--1/10000/10000-- xx}, _1[-1]) }2999- end3000-3001- def test_info_command_right3002- tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info right), :Enter)3003- tmux.until { assert_match(%r{xx --1/10000/10000-- *$}, _1[-2]) }3004- end3005-3006- def test_info_command_inline_right3007- tmux.send_keys(%(seq 10000 | #{FZF} --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline-right), :Enter)3008- tmux.until { assert_match(%r{ --1/10000/10000-- *$}, _1[-1]) }3009- end3010-3011- def test_info_command_and_focus3012- tmux.send_keys(%(seq 100 | #{FZF} --separator x --info-command 'echo $FZF_POS' --bind focus:clear-query), :Enter)3013- tmux.until { assert_match(/^ 1 xx/, _1[-2]) }3014- tmux.send_keys :Up3015- tmux.until { assert_match(/^ 2 xx/, _1[-2]) }3016- end3017-3018- def test_prev_next_selected3019- tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter3020- tmux.until { |lines| assert_equal 10, lines.item_count }3021- tmux.send_keys :BTab, :BTab, :Up, :BTab3022- tmux.until { |lines| assert_equal 3, lines.select_count }3023- tmux.send_keys 'C-n'3024- tmux.until { |lines| assert_includes lines, '>>4' }3025- tmux.send_keys 'C-n'3026- tmux.until { |lines| assert_includes lines, '>>2' }3027- tmux.send_keys 'C-n'3028- tmux.until { |lines| assert_includes lines, '>>1' }3029- tmux.send_keys 'C-n'3030- tmux.until { |lines| assert_includes lines, '>>4' }3031- tmux.send_keys 'C-p'3032- tmux.until { |lines| assert_includes lines, '>>1' }3033- tmux.send_keys 'C-p'3034- tmux.until { |lines| assert_includes lines, '>>2' }3035- end3036-3037- def test_listen3038- { '--listen 6266' => -> { URI('http://localhost:6266') },3039- "--listen --sync --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'" =>3040- -> { URI("http://localhost:#{File.read('/tmp/fzf-port').chomp}") } }.each do |opts, fn|3041- tmux.send_keys "seq 10 | fzf #{opts}", :Enter3042- tmux.until { |lines| assert_equal 10, lines.item_count }3043- state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)3044- assert_equal 10, state[:totalCount]3045- assert_equal 10, state[:matchCount]3046- assert_empty state[:query]3047- assert_equal({ index: 0, text: '1' }, state[:current])3048-3049- Net::HTTP.post(fn.call, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ')3050- tmux.until { |lines| assert_equal 100, lines.item_count }3051- tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }3052- state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)3053- assert_equal 100, state[:totalCount]3054- assert_equal 0, state[:matchCount]3055- assert_equal 'yo', state[:query]3056- assert_nil state[:current]3057-3058- teardown3059- setup3060- end3061- end3062-3063- def test_listen_with_api_key3064- post_uri = URI('http://localhost:6266')3065- tmux.send_keys 'seq 10 | FZF_API_KEY=123abc fzf --listen 6266', :Enter3066- tmux.until { |lines| assert_equal 10, lines.item_count }3067- # Incorrect API Key3068- [nil, { 'x-api-key' => '' }, { 'x-api-key' => '124abc' }].each do |headers|3069- res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)3070- assert_equal '401', res.code3071- assert_equal 'Unauthorized', res.message3072- assert_equal "invalid api key\n", res.body3073- end3074- # Valid API Key3075- [{ 'x-api-key' => '123abc' }, { 'X-API-Key' => '123abc' }].each do |headers|3076- res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)3077- assert_equal '200', res.code3078- tmux.until { |lines| assert_equal 100, lines.item_count }3079- tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }3080- end3081- end3082-3083- def test_toggle_alternative_preview_window3084- tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter3085- tmux.until { |lines| assert_equal 10, lines.item_count }3086- tmux.until { |lines| refute_includes lines, '/1/1/' }3087- tmux.send_keys :Space3088- tmux.until { |lines| assert_includes lines, '/1/1/' }3089- end3090-3091- def test_alternative_preview_window_opts3092- tmux.send_keys "seq 10 | #{FZF} --preview-window '~5,2,+0,<100000(~0,+100,wrap,noinfo)' --preview 'seq 1000'", :Enter3093- tmux.until { |lines| assert_equal 10, lines.item_count }3094- tmux.until do |lines|3095- assert_equal ['╭────╮', '│ 10 │', '│ 0 │', '│ 10 │', '│ 1 │'], lines.take(5).map(&:strip)3096- end3097- end3098-3099- def test_preview_window_width_exception3100- tmux.send_keys "seq 10 | #{FZF} --scrollbar --preview-window border-left --border --preview 'seq 1000'", :Enter3101- tmux.until do |lines|3102- assert lines[1]&.end_with?(' 1/1000││')3103- end3104- end3105-3106- def test_become3107- tmux.send_keys "seq 100 | #{FZF} --bind 'enter:become:seq {} | #{FZF}'", :Enter3108- tmux.until { |lines| assert_equal 100, lines.item_count }3109- tmux.send_keys 9993110- tmux.until { |lines| assert_equal 0, lines.match_count }3111- tmux.send_keys :Enter3112- tmux.until { |lines| assert_equal 0, lines.match_count }3113- tmux.send_keys :BSpace3114- tmux.until { |lines| assert_equal 1, lines.match_count }3115- tmux.send_keys :Enter3116- tmux.until { |lines| assert_equal 99, lines.item_count }3117- end3118-3119- def test_no_extra_newline_issue_32093120- tmux.send_keys(%(seq 100 | #{FZF} --height 10 --preview-window up,wrap,border-rounded --preview 'printf "─%.0s" $(seq 1 "$((FZF_PREVIEW_COLUMNS - 5))"); printf $"\\e[7m%s\\e[0m" title; echo; echo something'), :Enter)3121- expected = <<~OUTPUT3122- ╭──────────3123- │ ─────────3124- │ something3125- │3126- ╰──────────3127- 33128- 23129- > 13130- 100/100 ─3131- >3132- OUTPUT3133- tmux.until { assert_block(expected, _1) }3134- end3135-3136- def test_track3137- tmux.send_keys "seq 1000 | #{FZF} --query 555 --track --bind t:toggle-track", :Enter3138- tmux.until do |lines|3139- assert_equal 1, lines.match_count3140- assert_includes lines, '> 555'3141- end3142- tmux.send_keys :BSpace3143- index = tmux.until do |lines|3144- assert_equal 28, lines.match_count3145- assert_includes lines, '> 555'3146- end.index('> 555')3147- tmux.send_keys :BSpace3148- tmux.until do |lines|3149- assert_equal 271, lines.match_count3150- assert_equal '> 555', lines[index]3151- end3152- tmux.send_keys :BSpace3153- tmux.until do |lines|3154- assert_equal 1000, lines.match_count3155- assert_equal '> 555', lines[index]3156- end3157- tmux.send_keys '555'3158- tmux.until do |lines|3159- assert_equal 1, lines.match_count3160- assert_includes lines, '> 555'3161- assert_includes lines[-2], '+T'3162- end3163- tmux.send_keys 't'3164- tmux.until do |lines|3165- refute_includes lines[-2], '+T'3166- end3167- tmux.send_keys :BSpace3168- tmux.until do |lines|3169- assert_equal 28, lines.match_count3170- assert_includes lines, '> 55'3171- end3172- tmux.send_keys :BSpace3173- tmux.until do |lines|3174- assert_equal 271, lines.match_count3175- assert_includes lines, '> 5'3176- end3177- tmux.send_keys 't'3178- tmux.until do |lines|3179- assert_includes lines[-2], '+T'3180- end3181- tmux.send_keys :BSpace3182- tmux.until do |lines|3183- assert_equal 1000, lines.match_count3184- assert_includes lines, '> 5'3185- end3186- end3187-3188- def test_track_action3189- tmux.send_keys "seq 1000 | #{FZF} --query 555 --bind t:track", :Enter3190- tmux.until do |lines|3191- assert_equal 1, lines.match_count3192- assert_includes lines, '> 555'3193- end3194- tmux.send_keys :BSpace3195- tmux.until do |lines|3196- assert_equal 28, lines.match_count3197- assert_includes lines, '> 55'3198- end3199- tmux.send_keys :t3200- tmux.until do |lines|3201- assert_includes lines[-2], '+t'3202- end3203- tmux.send_keys :BSpace3204- tmux.until do |lines|3205- assert_equal 271, lines.match_count3206- assert_includes lines, '> 55'3207- end3208-3209- # Automatically disabled when the tracking item is no longer visible3210- tmux.send_keys '4'3211- tmux.until do |lines|3212- assert_equal 28, lines.match_count3213- refute_includes lines[-2], '+t'3214- end3215- tmux.send_keys :BSpace3216- tmux.until do |lines|3217- assert_equal 271, lines.match_count3218- assert_includes lines, '> 5'3219- end3220- tmux.send_keys :t3221- tmux.until do |lines|3222- assert_includes lines[-2], '+t'3223- end3224- tmux.send_keys :Up3225- tmux.until do |lines|3226- refute_includes lines[-2], '+t'3227- end3228- end3229-3230- def test_one_and_zero3231- tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter3232- tmux.send_keys '1'3233- tmux.until do |lines|3234- assert_equal 2, lines.match_count3235- refute(lines.any? { _1.include?('only match') })3236- refute(lines.any? { _1.include?('no match') })3237- end3238- tmux.send_keys '0'3239- tmux.until do |lines|3240- assert_equal 1, lines.match_count3241- assert(lines.any? { _1.include?('only match') })3242- end3243- tmux.send_keys '0'3244- tmux.until do |lines|3245- assert_equal 0, lines.match_count3246- assert(lines.any? { _1.include?('no match') })3247- end3248- end3249-3250- def test_height_range_with_exit_03251- tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter3252- tmux.until { |lines| assert_equal 10, lines.item_count }3253- tmux.send_keys :c3254- tmux.until { |lines| assert_equal 0, lines.match_count }3255- end3256-3257- def test_reload_and_change3258- tmux.send_keys "(echo foo; echo bar) | #{FZF} --bind 'load:reload-sync(sleep 60)+change-query(bar)'", :Enter3259- tmux.until { |lines| assert_equal 1, lines.match_count }3260- end3261-3262- def test_reload_and_change_cache3263- tmux.send_keys "echo bar | #{FZF} --bind 'zero:change-header(foo)+reload(echo foo)+clear-query'", :Enter3264- expected = <<~OUTPUT3265- > bar3266- 1/13267- >3268- OUTPUT3269- tmux.until { assert_block(expected, _1) }3270- tmux.send_keys :z3271- expected = <<~OUTPUT3272- > foo3273- foo3274- 1/13275- >3276- OUTPUT3277- tmux.until { assert_block(expected, _1) }3278- end3279-3280- def test_delete_with_modifiers3281- if ENV['GITHUB_ACTION']3282- # Expected: "[3]"3283- # Actual: "[]3;5~"3284- skip('CTRL-DELETE is not properly handled in GitHub Actions environment')3285- end3286- tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-delete:up+up,shift-delete:down,focus:transform-prompt:echo [{}]'", :Enter3287- tmux.until { |lines| assert_equal 100, lines.item_count }3288- tmux.send_keys 'C-Delete'3289- tmux.until { |lines| assert_equal '[3]', lines[-1] }3290- tmux.send_keys 'S-Delete'3291- tmux.until { |lines| assert_equal '[2]', lines[-1] }3292- end3293-3294- def test_become_tty3295- tmux.send_keys "sleep 0.5 | #{FZF} --bind 'start:reload:ls' --bind 'load:become:tty'", :Enter3296- tmux.until { |lines| assert_includes lines, '/dev/tty' }3297- end3298-3299- def test_disabled_preview_update3300- tmux.send_keys "echo bar | #{FZF} --disabled --bind 'change:reload:echo foo' --preview 'echo [{q}-{}]'", :Enter3301- tmux.until { |lines| assert_equal 1, lines.match_count }3302- tmux.until { |lines| assert(lines.any? { |line| line.include?('[-bar]') }) }3303- tmux.send_keys :x3304- tmux.until { |lines| assert(lines.any? { |line| line.include?('[x-foo]') }) }3305- end3306-3307- def test_preview_window_hidden_on_focus3308- tmux.send_keys "seq 3 | #{FZF} --preview 'echo {}' --bind focus:hide-preview", :Enter3309- tmux.until { |lines| assert_includes lines, '> 1' }3310- tmux.send_keys :Up3311- tmux.until { |lines| assert_includes lines, '> 2' }3312- end3313-3314- def test_fzf_pos3315- tmux.send_keys "seq 100 | #{FZF} --preview 'echo $FZF_POS / $FZF_MATCH_COUNT'", :Enter3316- tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 100') }) }3317- tmux.send_keys :Up3318- tmux.until { |lines| assert(lines.any? { |line| line.include?('2 / 100') }) }3319- tmux.send_keys '99'3320- tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 1') }) }3321- tmux.send_keys '99'3322- tmux.until { |lines| assert(lines.any? { |line| line.include?('0 / 0') }) }3323- end3324-3325- def test_fzf_multi_line3326- tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded], :Enter3327- block = <<~BLOCK3328- │ ┃9983329- │ ┃9993330- │ ┃10003331- │ ╹3332- │ ╻13333- │ ╹23334- │ >>03335- │ 3/3 (3)3336- │ >3337- ╰───────────3338- BLOCK3339- tmux.until { assert_block(block, _1) }3340- tmux.send_keys :Up, :Up3341- block = <<~BLOCK3342- ╭───────3343- │ >╻13344- │ >┃23345- │ >┃33346- BLOCK3347- tmux.until { assert_block(block, _1) }3348-3349- block = <<~BLOCK3350- │ >┃3351- │3352- │ >3353- ╰───3354- BLOCK3355- tmux.until { assert_block(block, _1) }3356- end3357-3358- def test_fzf_multi_line_reverse3359- tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse], :Enter3360- block = <<~BLOCK3361- ╭───────────3362- │ >3363- │ 3/3 (3)3364- │ >>03365- │ ╻13366- │ ╹23367- │ ╻13368- │ ┃23369- │ ┃33370- BLOCK3371- tmux.until { assert_block(block, _1) }3372- end3373-3374- def test_fzf_multi_line_no_pointer_and_marker3375- tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse --pointer '' --marker '' --marker-multi-line ''], :Enter3376- block = <<~BLOCK3377- ╭───────────3378- │ >3379- │ 3/3 (3)3380- │ 03381- │ 13382- │ 23383- │ 13384- │ 23385- │ 33386- BLOCK3387- tmux.until { assert_block(block, _1) }3388- end3389-3390- def test_start_on_reload3391- tmux.send_keys %(echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded' --bind space:change-header:), :Enter3392- tmux.until(timeout: 1) { |lines| assert_includes lines[-3], 'Loading' }3393- tmux.until(timeout: 1) { |lines| refute_includes lines[-4], 'foo' }3394- tmux.until { |lines| assert_includes lines[-3], 'Loaded' }3395- tmux.until { |lines| assert_includes lines[-4], 'bar' }3396- tmux.send_keys :Space3397- tmux.until { |lines| assert_includes lines[-3], 'bar' }3398- end3399-3400- def test_boundary_match3401- # Underscore boundaries should be ranked lower3402- {3403- default: [' x '] + %w[/x/ [x] -x- -x_ _x- _x_],3404- path: ['/x/', ' x '] + %w[[x] -x- -x_ _x- _x_],3405- history: ['[x]', '-x-', ' x '] + %w[/x/ -x_ _x- _x_]3406- }.each do |scheme, expected|3407- result = `printf -- 'xxx\n-xx\nxx-\n_x_\n_x-\n-x_\n[x]\n-x-\n x \n/x/\n' | #{FZF} -f"'x'" --scheme=#{scheme}`.lines(chomp: true)3408- assert_equal expected, result3409- end3410- end3411-3412- def test_preview_window_noinfo3413- # │ 1 ││3414- tmux.send_keys %(#{FZF} --preview 'seq 1000' --preview-window top,noinfo --scrollbar --bind space:change-preview-window:info), :Enter3415- tmux.until do |lines|3416- assert lines[1]&.start_with?('│ 1')3417- assert lines[1]&.end_with?(' ││')3418- end3419- tmux.send_keys :Space3420- tmux.until do |lines|3421- assert lines[1]&.start_with?('│ 1')3422- assert lines[1]&.end_with?('1000││')3423- end3424- end3425-3426- def test_gap3427- tmux.send_keys %(seq 100 | #{FZF} --gap --border --reverse), :Enter3428- block = <<~BLOCK3429- ╭─────────────────3430- │ >3431- │ 100/100 ──────3432- │ > 13433- │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈3434- │ 23435- │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈3436- │ 33437- │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈3438- │ 43439- BLOCK3440- tmux.until { assert_block(block, _1) }3441- end3442-3443- def test_gap_23444- tmux.send_keys %(seq 100 | #{FZF} --gap=2 --gap-line xyz --border --reverse), :Enter3445- block = <<~BLOCK3446- ╭─────────────────3447- │ >3448- │ 100/100 ──────3449- │ > 13450- │3451- │ xyzxyzxyzxyzxy3452- │ 23453- │3454- │ xyzxyzxyzxyzxy3455- │ 33456- BLOCK3457- tmux.until { assert_block(block, _1) }3458- end3459-3460- def test_list_border_and_label3461- tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --query 1 --padding 1,2), :Enter3462- block = <<~BLOCK3463- │ ║ 113464- │ ║ > 103465- │ ║ 33466- │ ║ 23467- │ ║ 13468- │ ║ 19/97 ─3469- │ ║ > 13470- │ ╚list══════3471- │3472- ╰──────────────3473- BLOCK3474- tmux.until { assert_block(block, _1) }3475- end3476-3477- def test_input_border_and_label3478- tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2), :Enter3479- block = <<~BLOCK3480- │ 113481- │ > 103482- │ 33483- │ 23484- │ 13485- │ ┏input━━━━━3486- │ ┃ 19/973487- │ ┃ > 13488- │ ┗━━━━━━━━━━3489- │3490- ╰──────────────3491- BLOCK3492- tmux.until { assert_block(block, _1) }3493- end3494-3495- def test_input_border_and_label_header_first3496- tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 --header-first), :Enter3497- block = <<~BLOCK3498- │ 113499- │ > 103500- │ ┏input━━━━━3501- │ ┃ 19/973502- │ ┃ > 13503- │ ┗━━━━━━━━━━3504- │ 33505- │ 23506- │ 13507- │3508- ╰──────────────3509- BLOCK3510- tmux.until { assert_block(block, _1) }3511- end3512-3513- def test_list_input_border_and_label3514- tmux.send_keys %(3515- seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \3516- --bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \3517- --bind 'space:change-input-label( input )+change-list-label( list )'3518- ).strip, :Enter3519- block = <<~BLOCK3520- │ ║ 113521- │ ║ > 103522- │ ╚LIST══════3523- │ 33524- │ 23525- │ 13526- │ ┏INPUT━━━━━3527- │ ┃ 19/973528- │ ┃ > 13529- │ ┗━━━━━━━━━━3530- │3531- ╰──────────────3532- BLOCK3533- tmux.until { assert_block(block, _1) }3534- tmux.send_keys :Space3535- block = <<~BLOCK3536- │ ║ 113537- │ ║ > 103538- │ ╚ list ════3539- │ 33540- │ 23541- │ 13542- │ ┏ input ━━━3543- │ ┃ 19/973544- │ ┃ > 13545- │ ┗━━━━━━━━━━3546- │3547- ╰──────────────3548- BLOCK3549- tmux.until { assert_block(block, _1) }3550- end3551-3552- def test_list_input_border_and_label_header_first3553- tmux.send_keys %(3554- seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \3555- --bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \3556- --bind 'space:change-input-label( input )+change-list-label( list )' --header-first3557- ).strip, :Enter3558- block = <<~BLOCK3559- │ ║ 113560- │ ║ > 103561- │ ╚LIST══════3562- │ ┏INPUT━━━━━3563- │ ┃ 19/973564- │ ┃ > 13565- │ ┗━━━━━━━━━━3566- │ 33567- │ 23568- │ 13569- │3570- ╰──────────────3571- BLOCK3572- tmux.until { assert_block(block, _1) }3573- tmux.send_keys :Space3574- block = <<~BLOCK3575- │ ║ 113576- │ ║ > 103577- │ ╚ list ════3578- │ ┏ input ━━━3579- │ ┃ 19/973580- │ ┃ > 13581- │ ┗━━━━━━━━━━3582- │ 33583- │ 23584- │ 13585- │3586- ╰──────────────3587- BLOCK3588- tmux.until { assert_block(block, _1) }3589- end3590-3591- def test_header_border_and_label3592- tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter3593- block = <<~BLOCK3594- │ 123595- │ 113596- │ > 103597- │ ┌────────3598- │ │ 33599- │ │ 23600- │ │ 13601- │ └header──3602- │ 19/97 ─3603- │ > 13604- │3605- ╰────────────3606- BLOCK3607- tmux.until { assert_block(block, _1) }3608- end3609-3610- def test_header_border_toggle3611- tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()'), :Enter3612- block1 = <<~BLOCK3613- │ 53614- │ 43615- │ 33616- │ 23617- │ > 13618- │ 100/100 ─3619- │ >3620- ╰────────────3621- BLOCK3622- tmux.until { assert_block(block1, _1) }3623-3624- tmux.send_keys :Space3625- block2 = <<~BLOCK3626- │ 33627- │ 23628- │ > 13629- ╰────────────3630- ╭────────────3631- │ hello3632- ╰────────────3633- 100/100 ─3634- >3635- BLOCK3636- tmux.until { assert_block(block2, _1) }3637-3638- tmux.send_keys :Enter3639- tmux.until { assert_block(block1, _1) }3640- end3641-3642- def test_header_border_toggle_with_header_lines3643- tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2), :Enter3644- block1 = <<~BLOCK3645- │ 53646- │ 43647- │ > 33648- ╰──────────3649- ╭──────────3650- │ 23651- │ 13652- ╰──────────3653- 98/98 ─3654- >3655- BLOCK3656- tmux.until { assert_block(block1, _1) }3657-3658- tmux.send_keys :Space3659- block2 = <<~BLOCK3660- │ 43661- │ > 33662- ╰──────────3663- ╭──────────3664- │ 23665- │ 13666- │ hello3667- ╰──────────3668- 98/98 ─3669- >3670- BLOCK3671- tmux.until { assert_block(block2, _1) }3672-3673- tmux.send_keys :Enter3674- tmux.until { assert_block(block1, _1) }3675- end3676-3677- def test_header_border_toggle_with_header_lines_header_first3678- tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first), :Enter3679- block1 = <<~BLOCK3680- │ 53681- │ 43682- │ > 33683- ╰──────────3684- 98/98 ─3685- >3686- ╭──────────3687- │ 23688- │ 13689- ╰──────────3690- BLOCK3691- tmux.until { assert_block(block1, _1) }3692-3693- tmux.send_keys :Space3694- block2 = <<~BLOCK3695- │ 43696- │ > 33697- ╰──────────3698- 98/98 ─3699- >3700- ╭──────────3701- │ 23702- │ 13703- │ hello3704- ╰──────────3705- BLOCK3706- tmux.until { assert_block(block2, _1) }3707-3708- tmux.send_keys :Enter3709- tmux.until { assert_block(block1, _1) }3710- end3711-3712- def test_header_border_toggle_with_header_lines_header_lines_border3713- tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-lines-border double), :Enter3714- block1 = <<~BLOCK3715- │ 53716- │ 43717- │ > 33718- ╰──────────3719- ╔══════════3720- ║ 23721- ║ 13722- ╚══════════3723- 98/98 ─3724- >3725- BLOCK3726- tmux.until { assert_block(block1, _1) }3727-3728- tmux.send_keys :Space3729- block2 = <<~BLOCK3730- │ > 33731- ╰──────────3732- ╔══════════3733- ║ 23734- ║ 13735- ╚══════════3736- ╭──────────3737- │ hello3738- ╰──────────3739- 98/98 ─3740- >3741- BLOCK3742- tmux.until { assert_block(block2, _1) }3743-3744- tmux.send_keys :Enter3745- tmux.until { assert_block(block1, _1) }3746- end3747-3748- def test_header_border_toggle_with_header_lines_header_first_header_lines_border3749- tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first --header-lines-border double), :Enter3750- block1 = <<~BLOCK3751- │ 53752- │ 43753- │ > 33754- ╰──────────3755- ╔══════════3756- ║ 23757- ║ 13758- ╚══════════3759- 98/98 ─3760- >3761- BLOCK3762- tmux.until { assert_block(block1, _1) }3763-3764- tmux.send_keys :Space3765- block2 = <<~BLOCK3766- │ > 33767- ╰──────────3768- ╔══════════3769- ║ 23770- ║ 13771- ╚══════════3772- 98/98 ─3773- >3774- ╭──────────3775- │ hello3776- ╰──────────3777- BLOCK3778- tmux.until { assert_block(block2, _1) }3779-3780- tmux.send_keys :Enter3781- tmux.until { assert_block(block1, _1) }3782- end3783-3784- def test_header_border_and_label_header_first3785- tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter3786- block = <<~BLOCK3787- │ 123788- │ 113789- │ > 103790- │ 19/97 ─3791- │ > 13792- │ ┌────────3793- │ │ 33794- │ │ 23795- │ │ 13796- │ └header──3797- │3798- ╰────────────3799- BLOCK3800- tmux.until { assert_block(block, _1) }3801- end3802-3803- def test_header_border_and_label_with_list_border3804- tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter3805- block = <<~BLOCK3806- │ ║ 123807- │ ║ 113808- │ ║ > 103809- │ ╚list══════3810- │ ┌──────────3811- │ │ 33812- │ │ 23813- │ │ 13814- │ └header────3815- │ 19/97 ─3816- │ > 13817- │3818- ╰──────────────3819- BLOCK3820- tmux.until { assert_block(block, _1) }3821- end3822-3823- def test_header_border_and_label_with_list_border_header_first3824- tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter3825- block = <<~BLOCK3826- │ ║ 123827- │ ║ 113828- │ ║ > 103829- │ ╚list══════3830- │ 19/97 ─3831- │ > 13832- │ ┌──────────3833- │ │ 33834- │ │ 23835- │ │ 13836- │ └header────3837- │3838- ╰──────────────3839- BLOCK3840- tmux.until { assert_block(block, _1) }3841- end3842-3843- def test_all_borders3844- tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom), :Enter3845- block = <<~BLOCK3846- │ ║ 123847- │ ║ 113848- │ ║ > 103849- │ ╚list══════3850- │ ┌──────────3851- │ │ 33852- │ │ 23853- │ │ 13854- │ └header────3855- │ ┏━━━━━━━━━━3856- │ ┃ 19/973857- │ ┃ > 13858- │ ┗input━━━━━3859- │3860- ╰──────────────3861- BLOCK3862- tmux.until { assert_block(block, _1) }3863- end3864-3865- def test_all_borders_header_first3866- tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom --header-first), :Enter3867- block = <<~BLOCK3868- │ ║ 123869- │ ║ 113870- │ ║ > 103871- │ ╚list══════3872- │ ┏━━━━━━━━━━3873- │ ┃ 19/973874- │ ┃ > 13875- │ ┗input━━━━━3876- │ ┌──────────3877- │ │ 33878- │ │ 23879- │ │ 13880- │ └header────3881- │3882- ╰──────────────3883- BLOCK3884- tmux.until { assert_block(block, _1) }3885- end3886-3887- def test_style_full_adaptive_height3888- tmux.send_keys %(seq 1| #{FZF} --style=full --height=~100% --header-lines=1 --info=default), :Enter3889- block = <<~BLOCK3890- ╭────────3891- ╰────────3892- ╭────────3893- │ 13894- ╰────────3895- ╭────────3896- │ 0/03897- │ >3898- ╰────────3899- BLOCK3900- tmux.until { assert_block(block, _1) }3901- end3902-3903- def test_style_full_adaptive_height_double3904- tmux.send_keys %(seq 1| #{FZF} --style=full:double --border --height=~100% --header-lines=1 --info=default), :Enter3905- block = <<~BLOCK3906- ╔══════════3907- ║ ╔════════3908- ║ ╚════════3909- ║ ╔════════3910- ║ ║ 13911- ║ ╚════════3912- ║ ╔════════3913- ║ ║ 0/03914- ║ ║ >3915- ║ ╚════════3916- ╚══════════3917- BLOCK3918- tmux.until { assert_block(block, _1) }3919- end3920-3921- def test_change_nth3922- input = [3923- *[''] * 1000,3924- 'foo bar bar bar bar',3925- 'foo foo bar bar bar',3926- 'foo foo foo bar bar',3927- 'foo foo foo foo bar',3928- *[''] * 10003929- ]3930- writelines(input)3931- nths = '1,2..4,-1,-3..,..2'3932- tmux.send_keys %(#{FZF} -qfoo -n#{nths} --bind 'space:change-nth(2|3|4|5|),result:transform-prompt:echo "[$FZF_NTH] "' < #{tempname}), :Enter3933-3934- tmux.until do |lines|3935- assert lines.any_include?("[#{nths}] foo")3936- assert_equal 4, lines.match_count3937- end3938- tmux.send_keys :Space3939- tmux.until do |lines|3940- assert lines.any_include?('[2] foo')3941- assert_equal 3, lines.match_count3942- end3943- tmux.send_keys :Space3944- tmux.until do |lines|3945- assert lines.any_include?('[3] foo')3946- assert_equal 2, lines.match_count3947- end3948- tmux.send_keys :Space3949- tmux.until do |lines|3950- assert lines.any_include?('[4] foo')3951- assert_equal 1, lines.match_count3952- end3953- tmux.send_keys :Space3954- tmux.until do |lines|3955- assert lines.any_include?('[5] foo')3956- assert_equal 0, lines.match_count3957- end3958- tmux.send_keys :Space3959- tmux.until do |lines|3960- assert lines.any_include?("[#{nths}] foo")3961- assert_equal 4, lines.match_count3962- end3963- end3964-end3965-3966-module TestShell3967- def setup3968- @tmux = Tmux.new(shell)3969- tmux.prepare3970- end3971-3972- def teardown3973- @tmux.kill3974- end3975-3976- def set_var(name, val)3977- tmux.prepare3978- tmux.send_keys "export #{name}='#{val}'", :Enter3979- tmux.prepare3980- end3981-3982- def unset_var(name)3983- tmux.prepare3984- tmux.send_keys "unset #{name}", :Enter3985- tmux.prepare3986- end3987-3988- def test_ctrl_t3989- set_var('FZF_CTRL_T_COMMAND', 'seq 100')3990-3991- tmux.prepare3992- tmux.send_keys 'C-t'3993- tmux.until { |lines| assert_equal 100, lines.item_count }3994- tmux.send_keys :Tab, :Tab, :Tab3995- tmux.until { |lines| assert lines.any_include?(' (3)') }3996- tmux.send_keys :Enter3997- tmux.until { |lines| assert lines.any_include?('1 2 3') }3998- tmux.send_keys 'C-c'3999- end4000-4001- def test_ctrl_t_unicode4002- writelines(['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])4003- set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")4004-4005- tmux.prepare4006- tmux.send_keys 'echo ', 'C-t'4007- tmux.until { |lines| assert_equal 2, lines.item_count }4008- tmux.send_keys 'fzf-unicode'4009- tmux.until { |lines| assert_equal 2, lines.match_count }4010-4011- tmux.send_keys '1'4012- tmux.until { |lines| assert_equal 1, lines.match_count }4013- tmux.send_keys :Tab4014- tmux.until { |lines| assert_equal 1, lines.select_count }4015-4016- tmux.send_keys :BSpace4017- tmux.until { |lines| assert_equal 2, lines.match_count }4018-4019- tmux.send_keys '2'4020- tmux.until { |lines| assert_equal 1, lines.match_count }4021- tmux.send_keys :Tab4022- tmux.until { |lines| assert_equal 2, lines.select_count }4023-4024- tmux.send_keys :Enter4025- tmux.until { |lines| assert_match(/echo .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines.join) }4026- tmux.send_keys :Enter4027- tmux.until { |lines| assert_equal 'fzf-unicode 테스트1 fzf-unicode 테스트2', lines[-1] }4028- end4029-4030- def test_alt_c4031- tmux.prepare4032- tmux.send_keys :Escape, :c4033- lines = tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4034- expected = lines.reverse.find { |l| l.start_with?('> ') }[2..]4035- tmux.send_keys :Enter4036- tmux.prepare4037- tmux.send_keys :pwd, :Enter4038- tmux.until { |lines| assert lines[-1]&.end_with?(expected) }4039- end4040-4041- def test_alt_c_command4042- set_var('FZF_ALT_C_COMMAND', 'echo /tmp')4043-4044- tmux.prepare4045- tmux.send_keys 'cd /', :Enter4046-4047- tmux.prepare4048- tmux.send_keys :Escape, :c4049- tmux.until { |lines| assert_equal 1, lines.item_count }4050- tmux.send_keys :Enter4051-4052- tmux.prepare4053- tmux.send_keys :pwd, :Enter4054- tmux.until { |lines| assert_equal '/tmp', lines[-1] }4055- end4056-4057- def test_ctrl_r4058- tmux.prepare4059- tmux.send_keys 'echo 1st', :Enter4060- tmux.prepare4061- tmux.send_keys 'echo 2nd', :Enter4062- tmux.prepare4063- tmux.send_keys 'echo 3d', :Enter4064- tmux.prepare4065- 3.times do4066- tmux.send_keys 'echo 3rd', :Enter4067- tmux.prepare4068- end4069- tmux.send_keys 'echo 4th', :Enter4070- tmux.prepare4071- tmux.send_keys 'C-r'4072- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4073- tmux.send_keys 'e3d'4074- # Duplicates removed: 3d (1) + 3rd (1) => 2 matches4075- tmux.until { |lines| assert_equal 2, lines.match_count }4076- tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3d') }4077- tmux.send_keys 'C-r'4078- tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3rd') }4079- tmux.send_keys :Enter4080- tmux.until { |lines| assert_equal 'echo 3rd', lines[-1] }4081- tmux.send_keys :Enter4082- tmux.until { |lines| assert_equal '3rd', lines[-1] }4083- end4084-4085- def test_ctrl_r_multiline4086- # NOTE: Current bash implementation shows an extra new line if there's4087- # only entry in the history4088- tmux.send_keys ':', :Enter4089- tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter4090- tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }4091- tmux.prepare4092- tmux.send_keys 'C-r'4093- tmux.until { |lines| assert_equal '>', lines[-1] }4094- tmux.send_keys 'foo bar'4095- tmux.until { |lines| assert lines[-4]&.match?(/"foo/) } unless shell == :zsh4096- tmux.until { |lines| assert lines[-3]&.match?(/bar"␊?/) }4097- tmux.send_keys :Enter4098- tmux.until { |lines| assert lines[-1]&.match?(/bar"␊?/) }4099- tmux.send_keys :Enter4100- tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }4101- end4102-4103- def test_ctrl_r_abort4104- skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && `#{Shell.bash} --version`[/(?<= version )\d+/].to_i < 44105- %w[foo ' "].each do |query|4106- tmux.prepare4107- tmux.send_keys :Enter, query4108- tmux.until { |lines| assert lines[-1]&.start_with?(query) }4109- tmux.send_keys 'C-r'4110- tmux.until { |lines| assert_equal "> #{query}", lines[-1] }4111- tmux.send_keys 'C-g'4112- tmux.until { |lines| assert lines[-1]&.start_with?(query) }4113- end4114- end4115-end4116-4117-module CompletionTest4118- def test_file_completion4119- FileUtils.mkdir_p('/tmp/fzf-test')4120- FileUtils.mkdir_p('/tmp/fzf test')4121- (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/#{i}") }4122- ['no~such~user', '/tmp/fzf test/foobar'].each do |f|4123- FileUtils.touch(File.expand_path(f))4124- end4125- tmux.prepare4126- tmux.send_keys 'cat /tmp/fzf-test/10**', :Tab4127- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4128- tmux.send_keys ' !d'4129- tmux.until { |lines| assert_equal 2, lines.match_count }4130- tmux.send_keys :Tab, :Tab4131- tmux.until { |lines| assert_equal 2, lines.select_count }4132- tmux.send_keys :Enter4133- tmux.until(true) do |lines|4134- assert_equal 'cat /tmp/fzf-test/10 /tmp/fzf-test/100', lines[-1]4135- end4136-4137- # ~USERNAME**<TAB>4138- user = `whoami`.chomp4139- tmux.send_keys 'C-u'4140- tmux.send_keys "cat ~#{user}**", :Tab4141- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4142- tmux.send_keys "/#{user}"4143- tmux.until { |lines| assert(lines.any? { |l| l.end_with?("/#{user}") }) }4144- tmux.send_keys :Enter4145- tmux.until(true) do |lines|4146- assert_match %r{cat .*/#{user}}, lines[-1]4147- end4148-4149- # ~INVALID_USERNAME**<TAB>4150- tmux.send_keys 'C-u'4151- tmux.send_keys 'cat ~such**', :Tab4152- tmux.until(true) { |lines| assert lines.any_include?('no~such~user') }4153- tmux.send_keys :Enter4154- tmux.until(true) { |lines| assert_equal 'cat no~such~user', lines[-1] }4155-4156- # /tmp/fzf\ test**<TAB>4157- tmux.send_keys 'C-u'4158- tmux.send_keys 'cat /tmp/fzf\ test/**', :Tab4159- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4160- tmux.send_keys 'foobar$'4161- tmux.until do |lines|4162- assert_equal 1, lines.match_count4163- assert lines.any_include?('> /tmp/fzf test/foobar')4164- end4165- tmux.send_keys :Enter4166- tmux.until(true) { |lines| assert_equal 'cat /tmp/fzf\ test/foobar', lines[-1] }4167-4168- # Should include hidden files4169- (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/.hidden-#{i}") }4170- tmux.send_keys 'C-u'4171- tmux.send_keys 'cat /tmp/fzf-test/hidden**', :Tab4172- tmux.until(true) do |lines|4173- assert_equal 100, lines.match_count4174- assert lines.any_include?('/tmp/fzf-test/.hidden-')4175- end4176- tmux.send_keys :Enter4177- ensure4178- ['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|4179- FileUtils.rm_rf(File.expand_path(f))4180- end4181- end4182-4183- def test_file_completion_root4184- tmux.send_keys 'ls /**', :Tab4185- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4186- tmux.send_keys :Enter4187- end4188-4189- def test_dir_completion4190- (1..100).each do |idx|4191- FileUtils.mkdir_p("/tmp/fzf-test/d#{idx}")4192- end4193- FileUtils.touch('/tmp/fzf-test/d55/xxx')4194- tmux.prepare4195- tmux.send_keys 'cd /tmp/fzf-test/**', :Tab4196- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4197- tmux.send_keys :Tab, :Tab # Tab does not work here4198- tmux.send_keys 554199- tmux.until do |lines|4200- assert_equal 1, lines.match_count4201- assert_includes lines, '> 55'4202- assert_includes lines, '> /tmp/fzf-test/d55'4203- end4204- tmux.send_keys :Enter4205- tmux.until(true) { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }4206- tmux.send_keys :xx4207- tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }4208-4209- # Should not match regular files (bash-only)4210- if instance_of?(TestBash)4211- tmux.send_keys :Tab4212- tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }4213- end4214-4215- # Fail back to plusdirs4216- tmux.send_keys :BSpace, :BSpace, :BSpace4217- tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55', lines[-1] }4218- tmux.send_keys :Tab4219- tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }4220- end4221-4222- def test_process_completion4223- tmux.send_keys 'sleep 12345 &', :Enter4224- lines = tmux.until { |lines| assert lines[-1]&.start_with?('[1] ') }4225- pid = lines[-1]&.split&.last4226- tmux.prepare4227- tmux.send_keys 'C-L'4228- tmux.send_keys 'kill **', :Tab4229- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4230- tmux.send_keys 'sleep12345'4231- tmux.until { |lines| assert lines.any_include?('sleep 12345') }4232- tmux.send_keys :Enter4233- tmux.until(true) { |lines| assert_equal "kill #{pid}", lines[-1] }4234- ensure4235- if pid4236- begin4237- Process.kill('KILL', pid.to_i)4238- rescue StandardError4239- nil4240- end4241- end4242- end4243-4244- def test_custom_completion4245- tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter4246- tmux.prepare4247- tmux.send_keys 'ls /tmp/**', :Tab4248- tmux.until { |lines| assert_equal 11, lines.match_count }4249- tmux.send_keys :Tab, :Tab, :Tab4250- tmux.until { |lines| assert_equal 3, lines.select_count }4251- tmux.send_keys :Enter4252- tmux.until(true) { |lines| assert_equal 'ls /tmp 1 2', lines[-1] }4253- end4254-4255- def test_unset_completion4256- tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter4257- tmux.prepare4258-4259- # Using tmux4260- tmux.send_keys 'unset FZFFOOBR**', :Tab4261- tmux.until { |lines| assert_equal 1, lines.match_count }4262- tmux.send_keys :Enter4263- tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }4264- tmux.send_keys 'C-c'4265-4266- # FZF_TMUX=14267- new_shell4268- tmux.focus4269- tmux.send_keys 'unset FZFFOOBR**', :Tab4270- tmux.until { |lines| assert_equal 1, lines.match_count }4271- tmux.send_keys :Enter4272- tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }4273- end4274-4275- def test_completion_in_command_sequence4276- tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter4277- tmux.prepare4278-4279- triggers = ['**', '~~', '++', 'ff', '/']4280- triggers.concat(['&', '[', ';', '`']) if instance_of?(TestZsh)4281-4282- triggers.each do |trigger|4283- set_var('FZF_COMPLETION_TRIGGER', trigger)4284- command = "echo foo; QUX=THUD unset FZFFOOBR#{trigger}"4285- tmux.send_keys command.sub(/(;|`)$/, '\\\\\1'), :Tab4286- tmux.until { |lines| assert_equal 1, lines.match_count }4287- tmux.send_keys :Enter4288- tmux.until { |lines| assert_equal 'echo foo; QUX=THUD unset FZFFOOBAR', lines[-1] }4289- end4290- end4291-4292- def test_file_completion_unicode4293- FileUtils.mkdir_p('/tmp/fzf-test')4294- 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'"4295- tmux.prepare4296- tmux.send_keys 'cat fzf-unicode**', :Tab4297- tmux.until { |lines| assert_equal 2, lines.match_count }4298-4299- tmux.send_keys '1'4300- tmux.until { |lines| assert_equal 1, lines.match_count }4301- tmux.send_keys :Tab4302- tmux.until { |lines| assert_equal 1, lines.select_count }4303-4304- tmux.send_keys :BSpace4305- tmux.until { |lines| assert_equal 2, lines.match_count }4306-4307- tmux.send_keys '2'4308- tmux.until { |lines| assert_equal 1, lines.select_count }4309- tmux.send_keys :Tab4310- tmux.until { |lines| assert_equal 2, lines.select_count }4311-4312- tmux.send_keys :Enter4313- tmux.until(true) { |lines| assert_match(/cat .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines[-1]) }4314- tmux.send_keys :Enter4315- tmux.until { |lines| assert_equal %w[test3 test4], lines[-2..] }4316- end4317-4318- def test_custom_completion_api4319- tmux.send_keys 'eval "_fzf$(declare -f _comprun)"', :Enter4320- %w[f g].each do |command|4321- tmux.prepare4322- tmux.send_keys "#{command} b**", :Tab4323- tmux.until do |lines|4324- assert_equal 2, lines.item_count4325- assert_equal 1, lines.match_count4326- assert lines.any_include?("prompt-#{command}")4327- assert lines.any_include?("preview-#{command}-bar")4328- end4329- tmux.send_keys :Enter4330- tmux.until { |lines| assert_equal "#{command} #{command}barbar", lines[-1] }4331- tmux.send_keys 'C-u'4332- end4333- ensure4334- tmux.prepare4335- tmux.send_keys 'unset -f _fzf_comprun', :Enter4336- end4337-4338- def test_ssh_completion4339- (1..5).each { |i| FileUtils.touch("/tmp/fzf-test-ssh-#{i}") }4340-4341- tmux.send_keys 'ssh jg@localhost**', :Tab4342- tmux.until do |lines|4343- assert lines.match_count >= 14344- end4345-4346- tmux.send_keys :Enter4347- tmux.until { |lines| assert lines.any_include?('ssh jg@localhost') }4348- tmux.send_keys ' -i /tmp/fzf-test-ssh**', :Tab4349- tmux.until do |lines|4350- assert lines.match_count >= 54351- assert_equal 0, lines.select_count4352- end4353- tmux.send_keys :Tab, :Tab, :Tab4354- tmux.until do |lines|4355- assert_equal 3, lines.select_count4356- end4357- tmux.send_keys :Enter4358- tmux.until { |lines| assert lines.any_include?('ssh jg@localhost -i /tmp/fzf-test-ssh-') }4359-4360- tmux.send_keys 'localhost**', :Tab4361- tmux.until do |lines|4362- assert lines.match_count >= 14363- end4364- end4365-end4366-4367-class TestBash < TestBase4368- include TestShell4369- include CompletionTest4370-4371- def shell4372- :bash4373- end4374-4375- def new_shell4376- tmux.prepare4377- tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter4378- tmux.prepare4379- end4380-4381- def test_dynamic_completion_loader4382- tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'4383- tmux.paste '_completion_loader() { complete -o default fake; }'4384- tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'4385- tmux.send_keys 'fake /tmp/foo**', :Tab4386- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4387- tmux.send_keys 'C-c'4388-4389- tmux.prepare4390- tmux.send_keys 'fake /tmp/foo'4391- tmux.send_keys :Tab, 'C-u'4392-4393- tmux.prepare4394- tmux.send_keys 'fake /tmp/foo**', :Tab4395- tmux.until { |lines| assert_operator lines.match_count, :>, 0 }4396- end4397-end4398-4399-class TestZsh < TestBase4400- include TestShell4401- include CompletionTest4402-4403- def shell4404- :zsh4405- end4406-4407- def new_shell4408- tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter4409- tmux.prepare4410- end4411-4412- def test_complete_quoted_command4413- tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter4414- ['unset', '\unset', "'unset'"].each do |command|4415- tmux.prepare4416- tmux.send_keys "#{command} FZFFOOBR**", :Tab4417- tmux.until { |lines| assert_equal 1, lines.match_count }4418- tmux.send_keys :Enter4419- tmux.until { |lines| assert_equal "#{command} FZFFOOBAR", lines[-1] }4420- tmux.send_keys 'C-c'4421- end4422- end4423-end4424-4425-class TestFish < TestBase4426- include TestShell4427-4428- def shell4429- :fish4430- end4431-4432- def new_shell4433- tmux.send_keys 'env FZF_TMUX=1 FZF_DEFAULT_OPTS=--no-scrollbar fish', :Enter4434- tmux.send_keys 'function fish_prompt; end; clear', :Enter4435- tmux.until { |lines| assert_empty lines }4436- end4437-4438- def set_var(name, val)4439- tmux.prepare4440- tmux.send_keys "set -g #{name} '#{val}'", :Enter4441- tmux.prepare4442- end4443-end4444-4445-__END__4446-set -u4447-PS1= PROMPT_COMMAND= HISTFILE= HISTSIZE=1004448-unset <%= UNSETS.join(' ') %>4449-unset $(env | sed -n /^_fzf_orig/s/=.*//p)4450-unset $(declare -F | sed -n "/_fzf/s/.*-f //p")4451-4452-export FZF_DEFAULT_OPTS="--no-scrollbar --pointer '>' --marker '>'"4453-4454-# Setup fzf4455-# ---------4456-if [[ ! "$PATH" == *<%= BASE %>/bin* ]]; then4457- export PATH="${PATH:+${PATH}:}<%= BASE %>/bin"4458-fi4459-4460-# Auto-completion4461-# ---------------4462-[[ $- == *i* ]] && source "<%= BASE %>/shell/completion.<%= __method__ %>" 2> /dev/null4463-4464-# Key bindings4465-# ------------4466-source "<%= BASE %>/shell/key-bindings.<%= __method__ %>"4467-4468-# Old API4469-_fzf_complete_f() {4470- _fzf_complete "+m --multi --prompt \"prompt-f> \"" "$@" < <(4471- echo foo4472- echo bar4473- )4474-}4475-4476-# New API4477-_fzf_complete_g() {4478- _fzf_complete +m --multi --prompt "prompt-g> " -- "$@" < <(4479- echo foo4480- echo bar4481- )4482-}4483-4484-_fzf_complete_f_post() {4485- awk '{print "f" $0 $0}'4486-}4487-4488-_fzf_complete_g_post() {4489- awk '{print "g" $0 $0}'4490-}4491-4492-[ -n "${BASH-}" ] && complete -F _fzf_complete_f -o default -o bashdefault f4493-[ -n "${BASH-}" ] && complete -F _fzf_complete_g -o default -o bashdefault g4494-4495-_comprun() {4496- local command=$14497- shift4498-4499- case "$command" in4500- f) fzf "$@" --preview 'echo preview-f-{}' ;;4501- g) fzf "$@" --preview 'echo preview-g-{}' ;;4502- *) fzf "$@" ;;4503- esac4504-}added:test/test_layout.rb+848 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Test cases that mainly use assert_block to verify the layout of fzf6+class TestLayout < TestInteractive7+ def assert_block(expected, lines)8+ cols = expected.lines.map { it.chomp.length }.max9+ top = lines.take(expected.lines.length).map { _1[0, cols].rstrip + "\n" }.join10+ bottom = lines.reverse.take(expected.lines.length).reverse.map { _1[0, cols].rstrip + "\n" }.join11+ assert_includes [top, bottom], expected12+ end13+14+ def test_vanilla15+ tmux.send_keys "seq 1 100000 | #{fzf}", :Enter16+ block = <<~BLOCK17+ 218+ > 119+ 100000/10000020+ >21+ BLOCK22+ tmux.until { assert_block(block, _1) }23+24+ # Testing basic key bindings25+ tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'26+ block = <<~BLOCK27+ > 391028+ 39129+ 856/10000030+ > 39131+ BLOCK32+ tmux.until { assert_block(block, _1) }33+34+ tmux.send_keys :Enter35+ assert_equal '3910', fzf_output36+ end37+38+ def test_header_first39+ tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first", :Enter40+ block = <<~OUTPUT41+ > 442+ 997/99743+ >44+ 345+ 246+ 147+ foobar48+ OUTPUT49+ tmux.until { assert_block(block, _1) }50+ end51+52+ def test_header_first_reverse53+ tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first --reverse --inline-info", :Enter54+ block = <<~OUTPUT55+ foobar56+ 157+ 258+ 359+ > < 997/99760+ > 461+ OUTPUT62+ tmux.until { assert_block(block, _1) }63+ end64+65+ def test_change_and_transform_header66+ [67+ 'space:change-header:$(seq 4)',68+ 'space:transform-header:seq 4'69+ ].each_with_index do |binding, i|70+ tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "#{binding}"), :Enter71+ expected = <<~OUTPUT72+ > 373+ 274+ 175+ bar76+ 1/177+ >78+ OUTPUT79+ tmux.until { assert_block(expected, _1) }80+ tmux.send_keys :Space81+ expected = <<~OUTPUT82+ > 383+ 284+ 185+ 186+ 287+ 388+ 489+ 1/190+ >91+ OUTPUT92+ tmux.until { assert_block(expected, _1) }93+ next unless i.zero?94+95+ teardown96+ setup97+ end98+ end99+100+ def test_change_header101+ tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "space:change-header:$(seq 4)"), :Enter102+ expected = <<~OUTPUT103+ > 3104+ 2105+ 1106+ bar107+ 1/1108+ >109+ OUTPUT110+ tmux.until { assert_block(expected, _1) }111+ tmux.send_keys :Space112+ expected = <<~OUTPUT113+ > 3114+ 2115+ 1116+ 1117+ 2118+ 3119+ 4120+ 1/1121+ >122+ OUTPUT123+ tmux.until { assert_block(expected, _1) }124+ end125+126+ def test_reload_and_change_cache127+ tmux.send_keys "echo bar | #{FZF} --bind 'zero:change-header(foo)+reload(echo foo)+clear-query'", :Enter128+ expected = <<~OUTPUT129+ > bar130+ 1/1131+ >132+ OUTPUT133+ tmux.until { assert_block(expected, _1) }134+ tmux.send_keys :z135+ expected = <<~OUTPUT136+ > foo137+ foo138+ 1/1139+ >140+ OUTPUT141+ tmux.until { assert_block(expected, _1) }142+ end143+144+ def test_toggle_header145+ tmux.send_keys "seq 4 | #{FZF} --header-lines 2 --header foo --bind space:toggle-header --header-first --height 10 --border rounded", :Enter146+ before = <<~OUTPUT147+ ╭───────148+ │149+ │ 4150+ │ > 3151+ │ 2/2152+ │ >153+ │ 2154+ │ 1155+ │ foo156+ ╰───────157+ OUTPUT158+ tmux.until { assert_block(before, _1) }159+ tmux.send_keys :Space160+ after = <<~OUTPUT161+ ╭───────162+ │163+ │164+ │165+ │166+ │ 4167+ │ > 3168+ │ 2/2169+ │ >170+ ╰───────171+ OUTPUT172+ tmux.until { assert_block(after, _1) }173+ tmux.send_keys :Space174+ tmux.until { assert_block(before, _1) }175+ end176+177+ def test_height_range_fit178+ tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded', :Enter179+ expected = <<~OUTPUT180+ ╭──────────181+ │ 3182+ │ 2183+ │ > 1184+ │ > < 3/3185+ ╰──────────186+ OUTPUT187+ tmux.until { assert_block(expected, _1) }188+ end189+190+ def test_height_range_fit_preview_above191+ tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded --preview-window border-rounded --preview "seq {}" --preview-window up,60%', :Enter192+ expected = <<~OUTPUT193+ ╭──────────194+ │ ╭────────195+ │ │ 1196+ │ │197+ │ │198+ │ │199+ │ ╰────────200+ │ 3201+ │ 2202+ │ > 1203+ │ > < 3/3204+ ╰──────────205+ OUTPUT206+ tmux.until { assert_block(expected, _1) }207+ end208+209+ def test_height_range_fit_preview_above_alternative210+ tmux.send_keys 'seq 3 | fzf --height ~100% --border=sharp --preview "seq {}" --preview-window up,40%,border-bottom --padding 1 --exit-0 --header hello --header-lines=2', :Enter211+ expected = <<~OUTPUT212+ ┌─────────213+ │214+ │ 1215+ │ 2216+ │ 3217+ │ ───────218+ │ > 3219+ │ 2220+ │ 1221+ │ hello222+ │ 1/1 ─223+ │ >224+ │225+ └─────────226+ OUTPUT227+ tmux.until { assert_block(expected, _1) }228+ end229+230+ def test_height_range_fit_preview_left231+ tmux.send_keys "seq 3 | fzf --height ~100% --border=vertical --preview 'seq {}' --preview-window left,5,border-right --padding 1 --exit-0 --header $'hello\\nworld' --header-lines=2", :Enter232+ expected = <<~OUTPUT233+ │234+ │ 1 │ > 3235+ │ 2 │ 2236+ │ 3 │ 1237+ │ │ hello238+ │ │ world239+ │ │ 1/1 ─240+ │ │ >241+ │242+ OUTPUT243+ tmux.until { assert_block(expected, _1) }244+ end245+246+ def test_height_range_overflow247+ tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border rounded', :Enter248+ expected = <<~OUTPUT249+ ╭──────────────250+ │ 2251+ │ > 1252+ │ > < 100/100253+ ╰──────────────254+ OUTPUT255+ tmux.until { assert_block(expected, _1) }256+ end257+258+ def test_no_extra_newline_issue_3209259+ tmux.send_keys(%(seq 100 | #{FZF} --height 10 --preview-window up,wrap,border-rounded --preview 'printf "─%.0s" $(seq 1 "$((FZF_PREVIEW_COLUMNS - 5))"); printf $"\\e[7m%s\\e[0m" title; echo; echo something'), :Enter)260+ expected = <<~OUTPUT261+ ╭──────────262+ │ ─────────263+ │ something264+ │265+ ╰──────────266+ 3267+ 2268+ > 1269+ 100/100 ─270+ >271+ OUTPUT272+ tmux.until { assert_block(expected, _1) }273+ end274+275+ def test_fzf_multi_line276+ tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded], :Enter277+ block = <<~BLOCK278+ │ ┃998279+ │ ┃999280+ │ ┃1000281+ │ ╹282+ │ ╻1283+ │ ╹2284+ │ >>0285+ │ 3/3 (3)286+ │ >287+ ╰───────────288+ BLOCK289+ tmux.until { assert_block(block, _1) }290+ tmux.send_keys :Up, :Up291+ block = <<~BLOCK292+ ╭───────293+ │ >╻1294+ │ >┃2295+ │ >┃3296+ BLOCK297+ tmux.until { assert_block(block, _1) }298+299+ block = <<~BLOCK300+ │ >┃301+ │302+ │ >303+ ╰───304+ BLOCK305+ tmux.until { assert_block(block, _1) }306+ end307+308+ def test_fzf_multi_line_reverse309+ tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse], :Enter310+ block = <<~BLOCK311+ ╭───────────312+ │ >313+ │ 3/3 (3)314+ │ >>0315+ │ ╻1316+ │ ╹2317+ │ ╻1318+ │ ┃2319+ │ ┃3320+ BLOCK321+ tmux.until { assert_block(block, _1) }322+ end323+324+ def test_fzf_multi_line_no_pointer_and_marker325+ tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse --pointer '' --marker '' --marker-multi-line ''], :Enter326+ block = <<~BLOCK327+ ╭───────────328+ │ >329+ │ 3/3 (3)330+ │ 0331+ │ 1332+ │ 2333+ │ 1334+ │ 2335+ │ 3336+ BLOCK337+ tmux.until { assert_block(block, _1) }338+ end339+340+ def test_gap341+ tmux.send_keys %(seq 100 | #{FZF} --gap --border --reverse), :Enter342+ block = <<~BLOCK343+ ╭─────────────────344+ │ >345+ │ 100/100 ──────346+ │ > 1347+ │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈348+ │ 2349+ │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈350+ │ 3351+ │ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈352+ │ 4353+ BLOCK354+ tmux.until { assert_block(block, _1) }355+ end356+357+ def test_gap_2358+ tmux.send_keys %(seq 100 | #{FZF} --gap=2 --gap-line xyz --border --reverse), :Enter359+ block = <<~BLOCK360+ ╭─────────────────361+ │ >362+ │ 100/100 ──────363+ │ > 1364+ │365+ │ xyzxyzxyzxyzxy366+ │ 2367+ │368+ │ xyzxyzxyzxyzxy369+ │ 3370+ BLOCK371+ tmux.until { assert_block(block, _1) }372+ end373+374+ def test_list_border_and_label375+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --query 1 --padding 1,2), :Enter376+ block = <<~BLOCK377+ │ ║ 11378+ │ ║ > 10379+ │ ║ 3380+ │ ║ 2381+ │ ║ 1382+ │ ║ 19/97 ─383+ │ ║ > 1384+ │ ╚list══════385+ │386+ ╰──────────────387+ BLOCK388+ tmux.until { assert_block(block, _1) }389+ end390+391+ def test_input_border_and_label392+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2), :Enter393+ block = <<~BLOCK394+ │ 11395+ │ > 10396+ │ 3397+ │ 2398+ │ 1399+ │ ┏input━━━━━400+ │ ┃ 19/97401+ │ ┃ > 1402+ │ ┗━━━━━━━━━━403+ │404+ ╰──────────────405+ BLOCK406+ tmux.until { assert_block(block, _1) }407+ end408+409+ def test_input_border_and_label_header_first410+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 --header-first), :Enter411+ block = <<~BLOCK412+ │ 11413+ │ > 10414+ │ ┏input━━━━━415+ │ ┃ 19/97416+ │ ┃ > 1417+ │ ┗━━━━━━━━━━418+ │ 3419+ │ 2420+ │ 1421+ │422+ ╰──────────────423+ BLOCK424+ tmux.until { assert_block(block, _1) }425+ end426+427+ def test_list_input_border_and_label428+ tmux.send_keys %(429+ seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \430+ --bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \431+ --bind 'space:change-input-label( input )+change-list-label( list )'432+ ).strip, :Enter433+ block = <<~BLOCK434+ │ ║ 11435+ │ ║ > 10436+ │ ╚LIST══════437+ │ 3438+ │ 2439+ │ 1440+ │ ┏INPUT━━━━━441+ │ ┃ 19/97442+ │ ┃ > 1443+ │ ┗━━━━━━━━━━444+ │445+ ╰──────────────446+ BLOCK447+ tmux.until { assert_block(block, _1) }448+ tmux.send_keys :Space449+ block = <<~BLOCK450+ │ ║ 11451+ │ ║ > 10452+ │ ╚ list ════453+ │ 3454+ │ 2455+ │ 1456+ │ ┏ input ━━━457+ │ ┃ 19/97458+ │ ┃ > 1459+ │ ┗━━━━━━━━━━460+ │461+ ╰──────────────462+ BLOCK463+ tmux.until { assert_block(block, _1) }464+ end465+466+ def test_list_input_border_and_label_header_first467+ tmux.send_keys %(468+ seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \469+ --bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \470+ --bind 'space:change-input-label( input )+change-list-label( list )' --header-first471+ ).strip, :Enter472+ block = <<~BLOCK473+ │ ║ 11474+ │ ║ > 10475+ │ ╚LIST══════476+ │ ┏INPUT━━━━━477+ │ ┃ 19/97478+ │ ┃ > 1479+ │ ┗━━━━━━━━━━480+ │ 3481+ │ 2482+ │ 1483+ │484+ ╰──────────────485+ BLOCK486+ tmux.until { assert_block(block, _1) }487+ tmux.send_keys :Space488+ block = <<~BLOCK489+ │ ║ 11490+ │ ║ > 10491+ │ ╚ list ════492+ │ ┏ input ━━━493+ │ ┃ 19/97494+ │ ┃ > 1495+ │ ┗━━━━━━━━━━496+ │ 3497+ │ 2498+ │ 1499+ │500+ ╰──────────────501+ BLOCK502+ tmux.until { assert_block(block, _1) }503+ end504+505+ def test_header_border_and_label506+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter507+ block = <<~BLOCK508+ │ 12509+ │ 11510+ │ > 10511+ │ ┌────────512+ │ │ 3513+ │ │ 2514+ │ │ 1515+ │ └header──516+ │ 19/97 ─517+ │ > 1518+ │519+ ╰────────────520+ BLOCK521+ tmux.until { assert_block(block, _1) }522+ end523+524+ def test_header_border_toggle525+ tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()'), :Enter526+ block1 = <<~BLOCK527+ │ 5528+ │ 4529+ │ 3530+ │ 2531+ │ > 1532+ │ 100/100 ─533+ │ >534+ ╰────────────535+ BLOCK536+ tmux.until { assert_block(block1, _1) }537+538+ tmux.send_keys :Space539+ block2 = <<~BLOCK540+ │ 3541+ │ 2542+ │ > 1543+ ╰────────────544+ ╭────────────545+ │ hello546+ ╰────────────547+ 100/100 ─548+ >549+ BLOCK550+ tmux.until { assert_block(block2, _1) }551+552+ tmux.send_keys :Enter553+ tmux.until { assert_block(block1, _1) }554+ end555+556+ def test_header_border_toggle_with_header_lines557+ tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2), :Enter558+ block1 = <<~BLOCK559+ │ 5560+ │ 4561+ │ > 3562+ ╰──────────563+ ╭──────────564+ │ 2565+ │ 1566+ ╰──────────567+ 98/98 ─568+ >569+ BLOCK570+ tmux.until { assert_block(block1, _1) }571+572+ tmux.send_keys :Space573+ block2 = <<~BLOCK574+ │ 4575+ │ > 3576+ ╰──────────577+ ╭──────────578+ │ 2579+ │ 1580+ │ hello581+ ╰──────────582+ 98/98 ─583+ >584+ BLOCK585+ tmux.until { assert_block(block2, _1) }586+587+ tmux.send_keys :Enter588+ tmux.until { assert_block(block1, _1) }589+ end590+591+ def test_header_border_toggle_with_header_lines_header_first592+ tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first), :Enter593+ block1 = <<~BLOCK594+ │ 5595+ │ 4596+ │ > 3597+ ╰──────────598+ 98/98 ─599+ >600+ ╭──────────601+ │ 2602+ │ 1603+ ╰──────────604+ BLOCK605+ tmux.until { assert_block(block1, _1) }606+607+ tmux.send_keys :Space608+ block2 = <<~BLOCK609+ │ 4610+ │ > 3611+ ╰──────────612+ 98/98 ─613+ >614+ ╭──────────615+ │ 2616+ │ 1617+ │ hello618+ ╰──────────619+ BLOCK620+ tmux.until { assert_block(block2, _1) }621+622+ tmux.send_keys :Enter623+ tmux.until { assert_block(block1, _1) }624+ end625+626+ def test_header_border_toggle_with_header_lines_header_lines_border627+ tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-lines-border double), :Enter628+ block1 = <<~BLOCK629+ │ 5630+ │ 4631+ │ > 3632+ ╰──────────633+ ╔══════════634+ ║ 2635+ ║ 1636+ ╚══════════637+ 98/98 ─638+ >639+ BLOCK640+ tmux.until { assert_block(block1, _1) }641+642+ tmux.send_keys :Space643+ block2 = <<~BLOCK644+ │ > 3645+ ╰──────────646+ ╔══════════647+ ║ 2648+ ║ 1649+ ╚══════════650+ ╭──────────651+ │ hello652+ ╰──────────653+ 98/98 ─654+ >655+ BLOCK656+ tmux.until { assert_block(block2, _1) }657+658+ tmux.send_keys :Enter659+ tmux.until { assert_block(block1, _1) }660+ end661+662+ def test_header_border_toggle_with_header_lines_header_first_header_lines_border663+ tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first --header-lines-border double), :Enter664+ block1 = <<~BLOCK665+ │ 5666+ │ 4667+ │ > 3668+ ╰──────────669+ ╔══════════670+ ║ 2671+ ║ 1672+ ╚══════════673+ 98/98 ─674+ >675+ BLOCK676+ tmux.until { assert_block(block1, _1) }677+678+ tmux.send_keys :Space679+ block2 = <<~BLOCK680+ │ > 3681+ ╰──────────682+ ╔══════════683+ ║ 2684+ ║ 1685+ ╚══════════686+ 98/98 ─687+ >688+ ╭──────────689+ │ hello690+ ╰──────────691+ BLOCK692+ tmux.until { assert_block(block2, _1) }693+694+ tmux.send_keys :Enter695+ tmux.until { assert_block(block1, _1) }696+ end697+698+ def test_header_border_and_label_header_first699+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter700+ block = <<~BLOCK701+ │ 12702+ │ 11703+ │ > 10704+ │ 19/97 ─705+ │ > 1706+ │ ┌────────707+ │ │ 3708+ │ │ 2709+ │ │ 1710+ │ └header──711+ │712+ ╰────────────713+ BLOCK714+ tmux.until { assert_block(block, _1) }715+ end716+717+ def test_header_border_and_label_with_list_border718+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter719+ block = <<~BLOCK720+ │ ║ 12721+ │ ║ 11722+ │ ║ > 10723+ │ ╚list══════724+ │ ┌──────────725+ │ │ 3726+ │ │ 2727+ │ │ 1728+ │ └header────729+ │ 19/97 ─730+ │ > 1731+ │732+ ╰──────────────733+ BLOCK734+ tmux.until { assert_block(block, _1) }735+ end736+737+ def test_header_border_and_label_with_list_border_header_first738+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter739+ block = <<~BLOCK740+ │ ║ 12741+ │ ║ 11742+ │ ║ > 10743+ │ ╚list══════744+ │ 19/97 ─745+ │ > 1746+ │ ┌──────────747+ │ │ 3748+ │ │ 2749+ │ │ 1750+ │ └header────751+ │752+ ╰──────────────753+ BLOCK754+ tmux.until { assert_block(block, _1) }755+ end756+757+ def test_all_borders758+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom), :Enter759+ block = <<~BLOCK760+ │ ║ 12761+ │ ║ 11762+ │ ║ > 10763+ │ ╚list══════764+ │ ┌──────────765+ │ │ 3766+ │ │ 2767+ │ │ 1768+ │ └header────769+ │ ┏━━━━━━━━━━770+ │ ┃ 19/97771+ │ ┃ > 1772+ │ ┗input━━━━━773+ │774+ ╰──────────────775+ BLOCK776+ tmux.until { assert_block(block, _1) }777+ end778+779+ def test_all_borders_header_first780+ tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom --header-first), :Enter781+ block = <<~BLOCK782+ │ ║ 12783+ │ ║ 11784+ │ ║ > 10785+ │ ╚list══════786+ │ ┏━━━━━━━━━━787+ │ ┃ 19/97788+ │ ┃ > 1789+ │ ┗input━━━━━790+ │ ┌──────────791+ │ │ 3792+ │ │ 2793+ │ │ 1794+ │ └header────795+ │796+ ╰──────────────797+ BLOCK798+ tmux.until { assert_block(block, _1) }799+ end800+801+ def test_style_full_adaptive_height802+ tmux.send_keys %(seq 1| #{FZF} --style=full --height=~100% --header-lines=1 --info=default), :Enter803+ block = <<~BLOCK804+ ╭────────805+ ╰────────806+ ╭────────807+ │ 1808+ ╰────────809+ ╭────────810+ │ 0/0811+ │ >812+ ╰────────813+ BLOCK814+ tmux.until { assert_block(block, _1) }815+ end816+817+ def test_style_full_adaptive_height_double818+ tmux.send_keys %(seq 1| #{FZF} --style=full:double --border --height=~100% --header-lines=1 --info=default), :Enter819+ block = <<~BLOCK820+ ╔══════════821+ ║ ╔════════822+ ║ ╚════════823+ ║ ╔════════824+ ║ ║ 1825+ ║ ╚════════826+ ║ ╔════════827+ ║ ║ 0/0828+ ║ ║ >829+ ║ ╚════════830+ ╚══════════831+ BLOCK832+ tmux.until { assert_block(block, _1) }833+ end834+835+ def test_preview_window_noinfo836+ # │ 1 ││837+ tmux.send_keys %(#{FZF} --preview 'seq 1000' --preview-window top,noinfo --scrollbar --bind space:change-preview-window:info), :Enter838+ tmux.until do |lines|839+ assert lines[1]&.start_with?('│ 1')840+ assert lines[1]&.end_with?(' ││')841+ end842+ tmux.send_keys :Space843+ tmux.until do |lines|844+ assert lines[1]&.start_with?('│ 1')845+ assert lines[1]&.end_with?('1000││')846+ end847+ end848+endadded:test/test_preview.rb+545 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Test cases for preview6+class TestPreview < TestInteractive7+ def test_preview8+ tmux.send_keys %(seq 1000 | sed s/^2$// | #{FZF} -m --preview 'sleep 0.2; echo {{}-{+}}' --bind ?:toggle-preview), :Enter9+ tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }10+ tmux.send_keys :Up11+ tmux.until { |lines| assert_includes lines[1], ' {-} ' }12+ tmux.send_keys '555'13+ tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }14+ tmux.send_keys '?'15+ tmux.until { |lines| refute_includes lines[1], ' {555-555} ' }16+ tmux.send_keys '?'17+ tmux.until { |lines| assert_includes lines[1], ' {555-555} ' }18+ tmux.send_keys :BSpace19+ tmux.until { |lines| assert lines[-2]&.start_with?(' 28/1000 ') }20+ tmux.send_keys 'foobar'21+ tmux.until { |lines| refute_includes lines[1], ' {55-55} ' }22+ tmux.send_keys 'C-u'23+ tmux.until { |lines| assert_equal 1000, lines.match_count }24+ tmux.until { |lines| assert_includes lines[1], ' {1-1} ' }25+ tmux.send_keys :BTab26+ tmux.until { |lines| assert_includes lines[1], ' {-1} ' }27+ tmux.send_keys :BTab28+ tmux.until { |lines| assert_includes lines[1], ' {3-1 } ' }29+ tmux.send_keys :BTab30+ tmux.until { |lines| assert_includes lines[1], ' {4-1 3} ' }31+ tmux.send_keys :BTab32+ tmux.until { |lines| assert_includes lines[1], ' {5-1 3 4} ' }33+ end34+35+ def test_toggle_preview_without_default_preview_command36+ tmux.send_keys %(seq 100 | #{FZF} --bind 'space:preview(echo [{}]),enter:toggle-preview' --preview-window up,border-double), :Enter37+ tmux.until do |lines|38+ assert_equal 100, lines.match_count39+ refute_includes lines[1], '║ [1]'40+ end41+42+ # toggle-preview should do nothing43+ tmux.send_keys :Enter44+ tmux.until { |lines| refute_includes lines[1], '║ [1]' }45+ tmux.send_keys :Up46+ tmux.until do |lines|47+ refute_includes lines[1], '║ [1]'48+ refute_includes lines[1], '║ [2]'49+ end50+51+ tmux.send_keys :Up52+ tmux.until do |lines|53+ assert_includes lines, '> 3'54+ refute_includes lines[1], '║ [3]'55+ end56+57+ # One-off preview action58+ tmux.send_keys :Space59+ tmux.until { |lines| assert_includes lines[1], '║ [3]' }60+61+ # toggle-preview to hide it62+ tmux.send_keys :Enter63+ tmux.until { |lines| refute_includes lines[1], '║ [3]' }64+65+ # toggle-preview again does nothing66+ tmux.send_keys :Enter, :Up67+ tmux.until do |lines|68+ assert_includes lines, '> 4'69+ refute_includes lines[1], '║ [4]'70+ end71+ end72+73+ def test_show_and_hide_preview74+ tmux.send_keys %(seq 100 | #{FZF} --preview-window hidden,border-bold --preview 'echo [{}]' --bind 'a:show-preview,b:hide-preview'), :Enter75+76+ # Hidden by default77+ tmux.until do |lines|78+ assert_equal 100, lines.match_count79+ refute_includes lines[1], '┃ [1]'80+ end81+82+ # Show83+ tmux.send_keys :a84+ tmux.until { |lines| assert_includes lines[1], '┃ [1]' }85+86+ # Already shown87+ tmux.send_keys :a88+ tmux.send_keys :Up89+ tmux.until { |lines| assert_includes lines[1], '┃ [2]' }90+91+ # Hide92+ tmux.send_keys :b93+ tmux.send_keys :Up94+ tmux.until do |lines|95+ assert_includes lines, '> 3'96+ refute_includes lines[1], '┃ [3]'97+ end98+99+ # Already hidden100+ tmux.send_keys :b101+ tmux.send_keys :Up102+ tmux.until do |lines|103+ assert_includes lines, '> 4'104+ refute_includes lines[1], '┃ [4]'105+ end106+107+ # Show it again108+ tmux.send_keys :a109+ tmux.until { |lines| assert_includes lines[1], '┃ [4]' }110+ end111+112+ def test_preview_hidden113+ tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter114+ tmux.until { |lines| assert_equal '>', lines[-1] }115+ tmux.send_keys '?'116+ tmux.until { |lines| assert_match(/ {1-1-1-[0-9]+}/, lines[-2]) }117+ tmux.send_keys '555'118+ tmux.until { |lines| assert_match(/ {555-555-1-[0-9]+}/, lines[-2]) }119+ tmux.send_keys '?'120+ tmux.until { |lines| assert_equal '> 555', lines[-1] }121+ end122+123+ def test_preview_size_0124+ tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0 --bind space:toggle-preview), :Enter125+ tmux.until do |lines|126+ assert_equal 100, lines.item_count127+ assert_equal ' 100/100', lines[1]128+ assert_equal '> 1', lines[2]129+ end130+ wait do131+ assert_path_exists tempname132+ assert_equal %w[1], File.readlines(tempname, chomp: true)133+ end134+ tmux.send_keys :Space, :Down, :Down135+ tmux.until { |lines| assert_equal '> 3', lines[4] }136+ wait do137+ assert_path_exists tempname138+ assert_equal %w[1], File.readlines(tempname, chomp: true)139+ end140+ tmux.send_keys :Space, :Down141+ tmux.until { |lines| assert_equal '> 4', lines[5] }142+ wait do143+ assert_path_exists tempname144+ assert_equal %w[1 3 4], File.readlines(tempname, chomp: true)145+ end146+ end147+148+ def test_preview_size_0_hidden149+ tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0,hidden --bind space:toggle-preview), :Enter150+ tmux.until { |lines| assert_equal 100, lines.item_count }151+ tmux.send_keys :Down, :Down152+ tmux.until { |lines| assert_includes lines, '> 3' }153+ wait { refute_path_exists tempname }154+ tmux.send_keys :Space155+ wait do156+ assert_path_exists tempname157+ assert_equal %w[3], File.readlines(tempname, chomp: true)158+ end159+ tmux.send_keys :Down160+ wait do161+ assert_equal %w[3 4], File.readlines(tempname, chomp: true)162+ end163+ tmux.send_keys :Space, :Down164+ tmux.until { |lines| assert_includes lines, '> 5' }165+ tmux.send_keys :Down166+ tmux.until { |lines| assert_includes lines, '> 6' }167+ tmux.send_keys :Space168+ wait do169+ assert_equal %w[3 4 6], File.readlines(tempname, chomp: true)170+ end171+ end172+173+ def test_preview_flags174+ tmux.send_keys %(seq 10 | sed 's/^/:: /; s/$/ /' |175+ #{FZF} --multi --preview 'echo {{2}/{s2}/{+2}/{+s2}/{q}/{n}/{+n}}'), :Enter176+ tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 //0/0} ' }177+ tmux.send_keys '123'178+ tmux.until { |lines| assert_includes lines[1], ' {////123//} ' }179+ tmux.send_keys 'C-u', '1'180+ tmux.until { |lines| assert_equal 2, lines.match_count }181+ tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 /1/0/0} ' }182+ tmux.send_keys :BTab183+ tmux.until { |lines| assert_includes lines[1], ' {10/10 /1/1 /1/9/0} ' }184+ tmux.send_keys :BTab185+ tmux.until { |lines| assert_includes lines[1], ' {10/10 /1 10/1 10 /1/9/0 9} ' }186+ tmux.send_keys '2'187+ tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /12//0 9} ' }188+ tmux.send_keys '3'189+ tmux.until { |lines| assert_includes lines[1], ' {//1 10/1 10 /123//0 9} ' }190+ end191+192+ def test_preview_file193+ tmux.send_keys %[(echo foo bar; echo bar foo) | #{FZF} --multi --preview 'cat {+f} {+f2} {+nf} {+fn}' --print0], :Enter194+ tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }195+ tmux.send_keys :BTab196+ tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }197+ tmux.send_keys :BTab198+ tmux.until { |lines| assert_includes lines[1], ' foo barbar foobarfoo0101 ' }199+ end200+201+ def test_preview_q_no_match202+ tmux.send_keys %(: | #{FZF} --preview 'echo foo {q} foo'), :Enter203+ tmux.until { |lines| assert_equal 0, lines.match_count }204+ tmux.until { |lines| assert_includes lines[1], ' foo foo' }205+ tmux.send_keys 'bar'206+ tmux.until { |lines| assert_includes lines[1], ' foo bar foo' }207+ tmux.send_keys 'C-u'208+ tmux.until { |lines| assert_includes lines[1], ' foo foo' }209+ end210+211+ def test_preview_q_no_match_with_initial_query212+ tmux.send_keys %(: | #{FZF} --preview 'echo foo {q}{q}' --query foo), :Enter213+ tmux.until { |lines| assert_equal 0, lines.match_count }214+ tmux.until { |lines| assert_includes lines[1], ' foofoo ' }215+ end216+217+ def test_preview_update_on_select218+ tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),219+ :Enter220+ tmux.until { |lines| assert_equal 10, lines.item_count }221+ tmux.send_keys 'a'222+ tmux.until { |lines| assert(lines.any? { |line| line.include?(' 1 2 3 4 5 ') }) }223+ tmux.send_keys 'a'224+ tmux.until { |lines| lines.each { |line| refute_includes line, ' 1 2 3 4 5 ' } }225+ end226+227+ def test_preview_correct_tab_width_after_ansi_reset_code228+ writelines(["\x1b[31m+\x1b[m\t\x1b[32mgreen"])229+ tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter230+ tmux.until { |lines| assert_includes lines[1], ' + green ' }231+ end232+233+ def test_preview_bindings_with_default_preview234+ tmux.send_keys "seq 10 | #{FZF} --preview 'echo [{}]' --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter235+ tmux.until { |lines| lines.item_count == 10 }236+ tmux.until { |lines| assert_includes lines[1], '[1]' }237+ tmux.send_keys 'a'238+ tmux.until { |lines| assert_includes lines[1], '[11]' }239+ tmux.send_keys 'c'240+ tmux.until { |lines| assert_includes lines[1], '[1]' }241+ tmux.send_keys 'b'242+ tmux.until { |lines| assert_includes lines[1], '[111]' }243+ tmux.send_keys :Up244+ tmux.until { |lines| assert_includes lines[1], '[2]' }245+ end246+247+ def test_preview_bindings_without_default_preview248+ tmux.send_keys "seq 10 | #{FZF} --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter249+ tmux.until { |lines| lines.item_count == 10 }250+ tmux.until { |lines| refute_includes lines[1], '1' }251+ tmux.send_keys 'a'252+ tmux.until { |lines| assert_includes lines[1], '[11]' }253+ tmux.send_keys 'c' # does nothing254+ tmux.until { |lines| assert_includes lines[1], '[11]' }255+ tmux.send_keys 'b'256+ tmux.until { |lines| assert_includes lines[1], '[111]' }257+ tmux.send_keys 9258+ tmux.until { |lines| lines.match_count == 1 }259+ tmux.until { |lines| refute_includes lines[1], '2' }260+ tmux.until { |lines| assert_includes lines[1], '[111]' }261+ end262+263+ def test_preview_scroll_begin_constant264+ tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+123", :Enter265+ tmux.until { |lines| assert_match %r{1/1}, lines[-2] }266+ tmux.until { |lines| assert_match %r{123.*123/1000}, lines[1] }267+ end268+269+ def test_preview_scroll_begin_expr270+ tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{3}", :Enter271+ tmux.until { |lines| assert_match %r{1/1}, lines[-2] }272+ tmux.until { |lines| assert_match %r{321.*321/1000}, lines[1] }273+ end274+275+ def test_preview_scroll_begin_and_offset276+ ['echo foo 123 321', 'echo foo :123: 321'].each do |input|277+ tmux.send_keys "#{input} | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter278+ tmux.until { |lines| assert_match %r{1/1}, lines[-2] }279+ tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] }280+ tmux.send_keys 'C-c'281+ end282+ end283+284+ def test_preview_clear_screen285+ 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'}, :Enter286+ tmux.until { |lines| lines.item_count == 100 }287+ tmux.until { |lines| lines[1]&.include?('[200]') }288+ end289+290+ def test_preview_window_follow291+ file = Tempfile.new('fzf-follow')292+ file.sync = true293+294+ tmux.send_keys %(seq 100 | #{FZF} --preview 'echo start; tail -f "#{file.path}"' --preview-window follow --bind 'up:preview-up,down:preview-down,space:change-preview-window:follow|nofollow' --preview-window '~4'), :Enter295+ tmux.until { |lines| lines.item_count == 100 }296+297+ # Write to the temporary file, and check if the preview window is showing298+ # the last line of the file299+ tmux.until { |lines| assert_includes lines[1], 'start' }300+ 3.times { file.puts _1 } # header lines301+ 1000.times { file.puts _1 }302+ tmux.until { |lines| assert_includes lines[1], '/1004' }303+ tmux.until { |lines| assert_includes lines[-2], '999' }304+305+ # Scroll the preview window and fzf should stop following the file content306+ tmux.send_keys :Up307+ tmux.until { |lines| assert_includes lines[-2], '998' }308+ file.puts 'foo', 'bar'309+ tmux.until do |lines|310+ assert_includes lines[1], '/1006'311+ assert_includes lines[-2], '998'312+ end313+314+ # Scroll back to the bottom and fzf should start following the file again315+ %w[999 foo bar].each do |item|316+ wait do317+ tmux.send_keys :Down318+ tmux.until { |lines| assert_includes lines[-2], item }319+ end320+ end321+ file.puts 'baz'322+ tmux.until do |lines|323+ assert_includes lines[1], '/1007'324+ assert_includes lines[-2], 'baz'325+ end326+327+ # Scroll upwards to stop following328+ tmux.send_keys :Up329+ wait { assert_includes lines[-2], 'bar' }330+ file.puts 'aaa'331+ tmux.until do |lines|332+ assert_includes lines[1], '/1008'333+ assert_includes lines[-2], 'bar'334+ end335+336+ # Manually enable following337+ tmux.send_keys :Space338+ tmux.until { |lines| assert_includes lines[-2], 'aaa' }339+ file.puts 'bbb'340+ tmux.until do |lines|341+ assert_includes lines[1], '/1009'342+ assert_includes lines[-2], 'bbb'343+ end344+345+ # Disable following346+ tmux.send_keys :Space347+ file.puts 'ccc', 'ddd'348+ tmux.until do |lines|349+ assert_includes lines[1], '/1011'350+ assert_includes lines[-2], 'bbb'351+ end352+ rescue StandardError353+ file.close354+ file.unlink355+ end356+357+ def test_toggle_preview_wrap358+ 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", :Enter359+ 2.times do360+ tmux.until { |lines| assert_includes lines[2], '2nd line' }361+ tmux.send_keys 'C-w'362+ tmux.until do |lines|363+ assert_includes lines[2], 'wrapped'364+ assert_includes lines[3], '2nd line'365+ end366+ tmux.send_keys 'C-w'367+ end368+ end369+370+ def test_close371+ tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter372+ tmux.until { |lines| assert_equal 100, lines.match_count }373+ tmux.until { |lines| assert_includes lines[1], 'foo' }374+ tmux.send_keys 'C-c'375+ tmux.until { |lines| refute_includes lines[1], 'foo' }376+ tmux.send_keys '10'377+ tmux.until { |lines| assert_equal 2, lines.match_count }378+ tmux.send_keys 'C-c'379+ tmux.send_keys 'C-l', 'closed'380+ tmux.until { |lines| assert_includes lines[0], 'closed' }381+ end382+383+ def test_preview_header384+ tmux.send_keys "seq 100 | #{FZF} --bind ctrl-k:preview-up+preview-up,ctrl-j:preview-down+preview-down+preview-down --preview 'seq 1000' --preview-window 'top:+{1}:~3'", :Enter385+ tmux.until { |lines| assert_equal 100, lines.item_count }386+ top5 = ->(lines) { lines.drop(1).take(5).map { |s| s[/[0-9]+/] } }387+ tmux.until do |lines|388+ assert_includes lines[1], '4/1000'389+ assert_equal(%w[1 2 3 4 5], top5[lines])390+ end391+ tmux.send_keys '55'392+ tmux.until do |lines|393+ assert_equal 1, lines.match_count394+ assert_equal(%w[1 2 3 55 56], top5[lines])395+ end396+ tmux.send_keys 'C-J'397+ tmux.until do |lines|398+ assert_equal(%w[1 2 3 58 59], top5[lines])399+ end400+ tmux.send_keys :BSpace401+ tmux.until do |lines|402+ assert_equal 19, lines.match_count403+ assert_equal(%w[1 2 3 5 6], top5[lines])404+ end405+ tmux.send_keys 'C-K'406+ tmux.until { |lines| assert_equal(%w[1 2 3 4 5], top5[lines]) }407+ end408+409+ def test_change_preview_window410+ tmux.send_keys "seq 1000 | #{FZF} --preview 'echo [[{}]]' --no-preview-border --bind '" \411+ 'a:change-preview(echo __{}__),' \412+ 'b:change-preview-window(down)+change-preview(echo =={}==)+change-preview-window(up),' \413+ 'c:change-preview(),d:change-preview-window(hidden),' \414+ "e:preview(printf ::%${FZF_PREVIEW_COLUMNS}s{})+change-preview-window(up),f:change-preview-window(up,wrap)'", :Enter415+ tmux.until { |lines| assert_equal 1000, lines.item_count }416+ tmux.until { |lines| assert_includes lines[0], '[[1]]' }417+418+ # change-preview action permanently changes the preview command set by --preview419+ tmux.send_keys 'a'420+ tmux.until { |lines| assert_includes lines[0], '__1__' }421+ tmux.send_keys :Up422+ tmux.until { |lines| assert_includes lines[0], '__2__' }423+424+ # When multiple change-preview-window actions are bound to a single key,425+ # the last one wins and the updated options are immediately applied to the new preview426+ tmux.send_keys 'b'427+ tmux.until { |lines| assert_equal '==2==', lines[0] }428+ tmux.send_keys :Up429+ tmux.until { |lines| assert_equal '==3==', lines[0] }430+431+ # change-preview with an empty preview command closes the preview window432+ tmux.send_keys 'c'433+ tmux.until { |lines| refute_includes lines[0], '==' }434+435+ # change-preview again to re-open the preview window436+ tmux.send_keys 'a'437+ tmux.until { |lines| assert_equal '__3__', lines[0] }438+439+ # Hide the preview window with hidden flag440+ tmux.send_keys 'd'441+ tmux.until { |lines| refute_includes lines[0], '__3__' }442+443+ # One-off preview444+ tmux.send_keys 'e'445+ tmux.until do |lines|446+ assert_equal '::', lines[0]447+ refute_includes lines[1], '3'448+ end449+450+ # Wrapped451+ tmux.send_keys 'f'452+ tmux.until do |lines|453+ assert_equal '::', lines[0]454+ assert_equal ' 3', lines[1]455+ end456+ end457+458+ def test_change_preview_window_should_not_reset_change_preview459+ tmux.send_keys "#{FZF} --preview-window up,border-none --bind 'start:change-preview(echo hello)' --bind 'enter:change-preview-window(border-left)'", :Enter460+ tmux.until { |lines| assert_includes lines, 'hello' }461+ tmux.send_keys :Enter462+ tmux.until { |lines| assert_includes lines, '│ hello' }463+ end464+465+ def test_change_preview_window_rotate466+ tmux.send_keys "seq 100 | #{FZF} --preview-window left,border-none --preview 'echo hello' --bind '" \467+ "a:change-preview-window(right|down|up|hidden|)'", :Enter468+ tmux.until { |lines| assert(lines.any? { _1.include?('100/100') }) }469+ 3.times do470+ tmux.until { |lines| lines[0].start_with?('hello') }471+ tmux.send_keys 'a'472+ tmux.until { |lines| lines[0].end_with?('hello') }473+ tmux.send_keys 'a'474+ tmux.until { |lines| lines[-1].start_with?('hello') }475+ tmux.send_keys 'a'476+ tmux.until { |lines| assert_equal 'hello', lines[0] }477+ tmux.send_keys 'a'478+ tmux.until { |lines| refute_includes lines[0], 'hello' }479+ tmux.send_keys 'a'480+ end481+ end482+483+ def test_change_preview_window_rotate_hidden484+ tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \485+ "a:change-preview-window(nohidden||down,1|)'", :Enter486+ tmux.until { |lines| assert_equal 100, lines.match_count }487+ tmux.until { |lines| refute_includes lines[1], '==1==' }488+ tmux.send_keys 'a'489+ tmux.until { |lines| assert_includes lines[1], '==1==' }490+ tmux.send_keys 'a'491+ tmux.until { |lines| refute_includes lines[1], '==1==' }492+ tmux.send_keys 'a'493+ tmux.until { |lines| assert_includes lines[-2], '==1==' }494+ tmux.send_keys 'a'495+ tmux.until { |lines| refute_includes lines[-2], '==1==' }496+ tmux.send_keys 'a'497+ tmux.until { |lines| assert_includes lines[1], '==1==' }498+ end499+500+ def test_change_preview_window_rotate_hidden_down501+ tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter502+ tmux.until { |lines| assert_equal 100, lines.match_count }503+ tmux.until { |lines| refute_includes lines[1], '==1==' }504+ tmux.send_keys '?'505+ tmux.until { |lines| assert_includes lines[1], '==1==' }506+ tmux.send_keys '?'507+ tmux.until { |lines| refute_includes lines[1], '==1==' }508+ tmux.send_keys '?'509+ tmux.until { |lines| assert_includes lines[-2], '==1==' }510+ tmux.send_keys '?'511+ tmux.until { |lines| refute_includes lines[-2], '==1==' }512+ tmux.send_keys '?'513+ tmux.until { |lines| assert_includes lines[1], '==1==' }514+ end515+516+ def test_toggle_alternative_preview_window517+ tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter518+ tmux.until { |lines| assert_equal 10, lines.item_count }519+ tmux.until { |lines| refute_includes lines, '/1/1/' }520+ tmux.send_keys :Space521+ tmux.until { |lines| assert_includes lines, '/1/1/' }522+ end523+524+ def test_alternative_preview_window_opts525+ tmux.send_keys "seq 10 | #{FZF} --preview-window '~5,2,+0,<100000(~0,+100,wrap,noinfo)' --preview 'seq 1000'", :Enter526+ tmux.until { |lines| assert_equal 10, lines.item_count }527+ tmux.until do |lines|528+ assert_equal ['╭────╮', '│ 10 │', '│ 0 │', '│ 10 │', '│ 1 │'], lines.take(5).map(&:strip)529+ end530+ end531+532+ def test_preview_window_width_exception533+ tmux.send_keys "seq 10 | #{FZF} --scrollbar --preview-window border-left --border --preview 'seq 1000'", :Enter534+ tmux.until do |lines|535+ assert lines[1]&.end_with?(' 1/1000││')536+ end537+ end538+539+ def test_preview_window_hidden_on_focus540+ tmux.send_keys "seq 3 | #{FZF} --preview 'echo {}' --bind focus:hide-preview", :Enter541+ tmux.until { |lines| assert_includes lines, '> 1' }542+ tmux.send_keys :Up543+ tmux.until { |lines| assert_includes lines, '> 2' }544+ end545+endadded:test/test_server.rb+52 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Test cases for API server6+class TestServer < TestInteractive7+ def test_listen8+ { '--listen 6266' => -> { URI('http://localhost:6266') },9+ "--listen --sync --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'" =>10+ -> { URI("http://localhost:#{File.read('/tmp/fzf-port').chomp}") } }.each do |opts, fn|11+ tmux.send_keys "seq 10 | fzf #{opts}", :Enter12+ tmux.until { |lines| assert_equal 10, lines.item_count }13+ state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)14+ assert_equal 10, state[:totalCount]15+ assert_equal 10, state[:matchCount]16+ assert_empty state[:query]17+ assert_equal({ index: 0, text: '1' }, state[:current])18+19+ Net::HTTP.post(fn.call, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ')20+ tmux.until { |lines| assert_equal 100, lines.item_count }21+ tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }22+ state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)23+ assert_equal 100, state[:totalCount]24+ assert_equal 0, state[:matchCount]25+ assert_equal 'yo', state[:query]26+ assert_nil state[:current]27+28+ teardown29+ setup30+ end31+ end32+33+ def test_listen_with_api_key34+ post_uri = URI('http://localhost:6266')35+ tmux.send_keys 'seq 10 | FZF_API_KEY=123abc fzf --listen 6266', :Enter36+ tmux.until { |lines| assert_equal 10, lines.item_count }37+ # Incorrect API Key38+ [nil, { 'x-api-key' => '' }, { 'x-api-key' => '124abc' }].each do |headers|39+ res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)40+ assert_equal '401', res.code41+ assert_equal 'Unauthorized', res.message42+ assert_equal "invalid api key\n", res.body43+ end44+ # Valid API Key45+ [{ 'x-api-key' => '123abc' }, { 'X-API-Key' => '123abc' }].each do |headers|46+ res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)47+ assert_equal '200', res.code48+ tmux.until { |lines| assert_equal 100, lines.item_count }49+ tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }50+ end51+ end52+endadded:test/test_shell_integration.rb+485 added
1+# frozen_string_literal: true2+3+require_relative 'lib/common'4+5+# Testing shell integration6+module TestShell7+ attr_reader :tmux8+9+ def setup10+ @tmux = Tmux.new(shell)11+ tmux.prepare12+ end13+14+ def teardown15+ @tmux.kill16+ end17+18+ def set_var(name, val)19+ tmux.prepare20+ tmux.send_keys "export #{name}='#{val}'", :Enter21+ tmux.prepare22+ end23+24+ def unset_var(name)25+ tmux.prepare26+ tmux.send_keys "unset #{name}", :Enter27+ tmux.prepare28+ end29+30+ def test_ctrl_t31+ set_var('FZF_CTRL_T_COMMAND', 'seq 100')32+33+ tmux.prepare34+ tmux.send_keys 'C-t'35+ tmux.until { |lines| assert_equal 100, lines.item_count }36+ tmux.send_keys :Tab, :Tab, :Tab37+ tmux.until { |lines| assert lines.any_include?(' (3)') }38+ tmux.send_keys :Enter39+ tmux.until { |lines| assert lines.any_include?('1 2 3') }40+ tmux.send_keys 'C-c'41+ end42+43+ def test_ctrl_t_unicode44+ writelines(['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])45+ set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")46+47+ tmux.prepare48+ tmux.send_keys 'echo ', 'C-t'49+ tmux.until { |lines| assert_equal 2, lines.item_count }50+ tmux.send_keys 'fzf-unicode'51+ tmux.until { |lines| assert_equal 2, lines.match_count }52+53+ tmux.send_keys '1'54+ tmux.until { |lines| assert_equal 1, lines.match_count }55+ tmux.send_keys :Tab56+ tmux.until { |lines| assert_equal 1, lines.select_count }57+58+ tmux.send_keys :BSpace59+ tmux.until { |lines| assert_equal 2, lines.match_count }60+61+ tmux.send_keys '2'62+ tmux.until { |lines| assert_equal 1, lines.match_count }63+ tmux.send_keys :Tab64+ tmux.until { |lines| assert_equal 2, lines.select_count }65+66+ tmux.send_keys :Enter67+ tmux.until { |lines| assert_match(/echo .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines.join) }68+ tmux.send_keys :Enter69+ tmux.until { |lines| assert_equal 'fzf-unicode 테스트1 fzf-unicode 테스트2', lines[-1] }70+ end71+72+ def test_alt_c73+ tmux.prepare74+ tmux.send_keys :Escape, :c75+ lines = tmux.until { |lines| assert_operator lines.match_count, :>, 0 }76+ expected = lines.reverse.find { |l| l.start_with?('> ') }[2..]77+ tmux.send_keys :Enter78+ tmux.prepare79+ tmux.send_keys :pwd, :Enter80+ tmux.until { |lines| assert lines[-1]&.end_with?(expected) }81+ end82+83+ def test_alt_c_command84+ set_var('FZF_ALT_C_COMMAND', 'echo /tmp')85+86+ tmux.prepare87+ tmux.send_keys 'cd /', :Enter88+89+ tmux.prepare90+ tmux.send_keys :Escape, :c91+ tmux.until { |lines| assert_equal 1, lines.item_count }92+ tmux.send_keys :Enter93+94+ tmux.prepare95+ tmux.send_keys :pwd, :Enter96+ tmux.until { |lines| assert_equal '/tmp', lines[-1] }97+ end98+99+ def test_ctrl_r100+ tmux.prepare101+ tmux.send_keys 'echo 1st', :Enter102+ tmux.prepare103+ tmux.send_keys 'echo 2nd', :Enter104+ tmux.prepare105+ tmux.send_keys 'echo 3d', :Enter106+ tmux.prepare107+ 3.times do108+ tmux.send_keys 'echo 3rd', :Enter109+ tmux.prepare110+ end111+ tmux.send_keys 'echo 4th', :Enter112+ tmux.prepare113+ tmux.send_keys 'C-r'114+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }115+ tmux.send_keys 'e3d'116+ # Duplicates removed: 3d (1) + 3rd (1) => 2 matches117+ tmux.until { |lines| assert_equal 2, lines.match_count }118+ tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3d') }119+ tmux.send_keys 'C-r'120+ tmux.until { |lines| assert lines[-3]&.end_with?(' echo 3rd') }121+ tmux.send_keys :Enter122+ tmux.until { |lines| assert_equal 'echo 3rd', lines[-1] }123+ tmux.send_keys :Enter124+ tmux.until { |lines| assert_equal '3rd', lines[-1] }125+ end126+127+ def test_ctrl_r_multiline128+ # NOTE: Current bash implementation shows an extra new line if there's129+ # only entry in the history130+ tmux.send_keys ':', :Enter131+ tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter132+ tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }133+ tmux.prepare134+ tmux.send_keys 'C-r'135+ tmux.until { |lines| assert_equal '>', lines[-1] }136+ tmux.send_keys 'foo bar'137+ tmux.until { |lines| assert_includes lines[-4], '"foo' } unless shell == :zsh138+ tmux.until { |lines| assert lines[-3]&.match?(/bar"␊?/) }139+ tmux.send_keys :Enter140+ tmux.until { |lines| assert lines[-1]&.match?(/bar"␊?/) }141+ tmux.send_keys :Enter142+ tmux.until { |lines| assert_equal %w[foo bar], lines[-2..] }143+ end144+145+ def test_ctrl_r_abort146+ skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && `#{Shell.bash} --version`[/(?<= version )\d+/].to_i < 4147+ %w[foo ' "].each do |query|148+ tmux.prepare149+ tmux.send_keys :Enter, query150+ tmux.until { |lines| assert lines[-1]&.start_with?(query) }151+ tmux.send_keys 'C-r'152+ tmux.until { |lines| assert_equal "> #{query}", lines[-1] }153+ tmux.send_keys 'C-g'154+ tmux.until { |lines| assert lines[-1]&.start_with?(query) }155+ end156+ end157+end158+159+module CompletionTest160+ def test_file_completion161+ FileUtils.mkdir_p('/tmp/fzf-test')162+ FileUtils.mkdir_p('/tmp/fzf test')163+ (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/#{i}") }164+ ['no~such~user', '/tmp/fzf test/foobar'].each do |f|165+ FileUtils.touch(File.expand_path(f))166+ end167+ tmux.prepare168+ tmux.send_keys 'cat /tmp/fzf-test/10**', :Tab169+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }170+ tmux.send_keys ' !d'171+ tmux.until { |lines| assert_equal 2, lines.match_count }172+ tmux.send_keys :Tab, :Tab173+ tmux.until { |lines| assert_equal 2, lines.select_count }174+ tmux.send_keys :Enter175+ tmux.until(true) do |lines|176+ assert_equal 'cat /tmp/fzf-test/10 /tmp/fzf-test/100', lines[-1]177+ end178+179+ # ~USERNAME**<TAB>180+ user = `whoami`.chomp181+ tmux.send_keys 'C-u'182+ tmux.send_keys "cat ~#{user}**", :Tab183+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }184+ tmux.send_keys "/#{user}"185+ tmux.until { |lines| assert(lines.any? { |l| l.end_with?("/#{user}") }) }186+ tmux.send_keys :Enter187+ tmux.until(true) do |lines|188+ assert_match %r{cat .*/#{user}}, lines[-1]189+ end190+191+ # ~INVALID_USERNAME**<TAB>192+ tmux.send_keys 'C-u'193+ tmux.send_keys 'cat ~such**', :Tab194+ tmux.until(true) { |lines| assert lines.any_include?('no~such~user') }195+ tmux.send_keys :Enter196+ tmux.until(true) { |lines| assert_equal 'cat no~such~user', lines[-1] }197+198+ # /tmp/fzf\ test**<TAB>199+ tmux.send_keys 'C-u'200+ tmux.send_keys 'cat /tmp/fzf\ test/**', :Tab201+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }202+ tmux.send_keys 'foobar$'203+ tmux.until do |lines|204+ assert_equal 1, lines.match_count205+ assert lines.any_include?('> /tmp/fzf test/foobar')206+ end207+ tmux.send_keys :Enter208+ tmux.until(true) { |lines| assert_equal 'cat /tmp/fzf\ test/foobar', lines[-1] }209+210+ # Should include hidden files211+ (1..100).each { |i| FileUtils.touch("/tmp/fzf-test/.hidden-#{i}") }212+ tmux.send_keys 'C-u'213+ tmux.send_keys 'cat /tmp/fzf-test/hidden**', :Tab214+ tmux.until(true) do |lines|215+ assert_equal 100, lines.match_count216+ assert lines.any_include?('/tmp/fzf-test/.hidden-')217+ end218+ tmux.send_keys :Enter219+ ensure220+ ['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|221+ FileUtils.rm_rf(File.expand_path(f))222+ end223+ end224+225+ def test_file_completion_root226+ tmux.send_keys 'ls /**', :Tab227+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }228+ tmux.send_keys :Enter229+ end230+231+ def test_dir_completion232+ (1..100).each do |idx|233+ FileUtils.mkdir_p("/tmp/fzf-test/d#{idx}")234+ end235+ FileUtils.touch('/tmp/fzf-test/d55/xxx')236+ tmux.prepare237+ tmux.send_keys 'cd /tmp/fzf-test/**', :Tab238+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }239+ tmux.send_keys :Tab, :Tab # Tab does not work here240+ tmux.send_keys 55241+ tmux.until do |lines|242+ assert_equal 1, lines.match_count243+ assert_includes lines, '> 55'244+ assert_includes lines, '> /tmp/fzf-test/d55'245+ end246+ tmux.send_keys :Enter247+ tmux.until(true) { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }248+ tmux.send_keys :xx249+ tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }250+251+ # Should not match regular files (bash-only)252+ if instance_of?(TestBash)253+ tmux.send_keys :Tab254+ tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/xx', lines[-1] }255+ end256+257+ # Fail back to plusdirs258+ tmux.send_keys :BSpace, :BSpace, :BSpace259+ tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55', lines[-1] }260+ tmux.send_keys :Tab261+ tmux.until { |lines| assert_equal 'cd /tmp/fzf-test/d55/', lines[-1] }262+ end263+264+ def test_process_completion265+ tmux.send_keys 'sleep 12345 &', :Enter266+ lines = tmux.until { |lines| assert lines[-1]&.start_with?('[1] ') }267+ pid = lines[-1]&.split&.last268+ tmux.prepare269+ tmux.send_keys 'C-L'270+ tmux.send_keys 'kill **', :Tab271+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }272+ tmux.send_keys 'sleep12345'273+ tmux.until { |lines| assert lines.any_include?('sleep 12345') }274+ tmux.send_keys :Enter275+ tmux.until(true) { |lines| assert_equal "kill #{pid}", lines[-1] }276+ ensure277+ if pid278+ begin279+ Process.kill('KILL', pid.to_i)280+ rescue StandardError281+ nil282+ end283+ end284+ end285+286+ def test_custom_completion287+ tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter288+ tmux.prepare289+ tmux.send_keys 'ls /tmp/**', :Tab290+ tmux.until { |lines| assert_equal 11, lines.match_count }291+ tmux.send_keys :Tab, :Tab, :Tab292+ tmux.until { |lines| assert_equal 3, lines.select_count }293+ tmux.send_keys :Enter294+ tmux.until(true) { |lines| assert_equal 'ls /tmp 1 2', lines[-1] }295+ end296+297+ def test_unset_completion298+ tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter299+ tmux.prepare300+301+ # Using tmux302+ tmux.send_keys 'unset FZFFOOBR**', :Tab303+ tmux.until { |lines| assert_equal 1, lines.match_count }304+ tmux.send_keys :Enter305+ tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }306+ tmux.send_keys 'C-c'307+308+ # FZF_TMUX=1309+ new_shell310+ tmux.focus311+ tmux.send_keys 'unset FZFFOOBR**', :Tab312+ tmux.until { |lines| assert_equal 1, lines.match_count }313+ tmux.send_keys :Enter314+ tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }315+ end316+317+ def test_completion_in_command_sequence318+ tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter319+ tmux.prepare320+321+ triggers = ['**', '~~', '++', 'ff', '/']322+ triggers.push('&', '[', ';', '`') if instance_of?(TestZsh)323+324+ triggers.each do |trigger|325+ set_var('FZF_COMPLETION_TRIGGER', trigger)326+ command = "echo foo; QUX=THUD unset FZFFOOBR#{trigger}"327+ tmux.send_keys command.sub(/(;|`)$/, '\\\\\1'), :Tab328+ tmux.until { |lines| assert_equal 1, lines.match_count }329+ tmux.send_keys :Enter330+ tmux.until { |lines| assert_equal 'echo foo; QUX=THUD unset FZFFOOBAR', lines[-1] }331+ end332+ end333+334+ def test_file_completion_unicode335+ FileUtils.mkdir_p('/tmp/fzf-test')336+ 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'"337+ tmux.prepare338+ tmux.send_keys 'cat fzf-unicode**', :Tab339+ tmux.until { |lines| assert_equal 2, lines.match_count }340+341+ tmux.send_keys '1'342+ tmux.until { |lines| assert_equal 1, lines.match_count }343+ tmux.send_keys :Tab344+ tmux.until { |lines| assert_equal 1, lines.select_count }345+346+ tmux.send_keys :BSpace347+ tmux.until { |lines| assert_equal 2, lines.match_count }348+349+ tmux.send_keys '2'350+ tmux.until { |lines| assert_equal 1, lines.select_count }351+ tmux.send_keys :Tab352+ tmux.until { |lines| assert_equal 2, lines.select_count }353+354+ tmux.send_keys :Enter355+ tmux.until(true) { |lines| assert_match(/cat .*fzf-unicode.*1.* .*fzf-unicode.*2/, lines[-1]) }356+ tmux.send_keys :Enter357+ tmux.until { |lines| assert_equal %w[test3 test4], lines[-2..] }358+ end359+360+ def test_custom_completion_api361+ tmux.send_keys 'eval "_fzf$(declare -f _comprun)"', :Enter362+ %w[f g].each do |command|363+ tmux.prepare364+ tmux.send_keys "#{command} b**", :Tab365+ tmux.until do |lines|366+ assert_equal 2, lines.item_count367+ assert_equal 1, lines.match_count368+ assert lines.any_include?("prompt-#{command}")369+ assert lines.any_include?("preview-#{command}-bar")370+ end371+ tmux.send_keys :Enter372+ tmux.until { |lines| assert_equal "#{command} #{command}barbar", lines[-1] }373+ tmux.send_keys 'C-u'374+ end375+ ensure376+ tmux.prepare377+ tmux.send_keys 'unset -f _fzf_comprun', :Enter378+ end379+380+ def test_ssh_completion381+ (1..5).each { |i| FileUtils.touch("/tmp/fzf-test-ssh-#{i}") }382+383+ tmux.send_keys 'ssh jg@localhost**', :Tab384+ tmux.until do |lines|385+ assert_operator lines.match_count, :>=, 1386+ end387+388+ tmux.send_keys :Enter389+ tmux.until { |lines| assert lines.any_include?('ssh jg@localhost') }390+ tmux.send_keys ' -i /tmp/fzf-test-ssh**', :Tab391+ tmux.until do |lines|392+ assert_operator lines.match_count, :>=, 5393+ assert_equal 0, lines.select_count394+ end395+ tmux.send_keys :Tab, :Tab, :Tab396+ tmux.until do |lines|397+ assert_equal 3, lines.select_count398+ end399+ tmux.send_keys :Enter400+ tmux.until { |lines| assert lines.any_include?('ssh jg@localhost -i /tmp/fzf-test-ssh-') }401+402+ tmux.send_keys 'localhost**', :Tab403+ tmux.until do |lines|404+ assert_operator lines.match_count, :>=, 1405+ end406+ end407+end408+409+class TestBash < TestBase410+ include TestShell411+ include CompletionTest412+413+ def shell414+ :bash415+ end416+417+ def new_shell418+ tmux.prepare419+ tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter420+ tmux.prepare421+ end422+423+ def test_dynamic_completion_loader424+ tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'425+ tmux.paste '_completion_loader() { complete -o default fake; }'426+ tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'427+ tmux.send_keys 'fake /tmp/foo**', :Tab428+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }429+ tmux.send_keys 'C-c'430+431+ tmux.prepare432+ tmux.send_keys 'fake /tmp/foo'433+ tmux.send_keys :Tab, 'C-u'434+435+ tmux.prepare436+ tmux.send_keys 'fake /tmp/foo**', :Tab437+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }438+ end439+end440+441+class TestZsh < TestBase442+ include TestShell443+ include CompletionTest444+445+ def shell446+ :zsh447+ end448+449+ def new_shell450+ tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter451+ tmux.prepare452+ end453+454+ def test_complete_quoted_command455+ tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter456+ ['unset', '\unset', "'unset'"].each do |command|457+ tmux.prepare458+ tmux.send_keys "#{command} FZFFOOBR**", :Tab459+ tmux.until { |lines| assert_equal 1, lines.match_count }460+ tmux.send_keys :Enter461+ tmux.until { |lines| assert_equal "#{command} FZFFOOBAR", lines[-1] }462+ tmux.send_keys 'C-c'463+ end464+ end465+end466+467+class TestFish < TestBase468+ include TestShell469+470+ def shell471+ :fish472+ end473+474+ def new_shell475+ tmux.send_keys 'env FZF_TMUX=1 FZF_DEFAULT_OPTS=--no-scrollbar fish', :Enter476+ tmux.send_keys 'function fish_prompt; end; clear', :Enter477+ tmux.until { |lines| assert_empty lines }478+ end479+480+ def set_var(name, val)481+ tmux.prepare482+ tmux.send_keys "set -g #{name} '#{val}'", :Enter483+ tmux.prepare484+ end485+endmodified:.gitignore-1 removed
1 unmodified line2 bin/fzf.exe3 dist4 target5 pkg6-Gemfile.lock6 .DS_Store7 doc/tags8 vendor9 gopath4 unmodified linesmodified:.rubocop.yml+8 added
12345622 unmodified lines293031323334353637383940AllCops: NewCops: enableLayout/LineLength: Enabled: falseMetrics: Enabled: false22 unmodified linesStyle/WordArray: MinSize: 1Minitest/AssertEqual: Enabled: falseMinitest/EmptyLineBeforeAssertionMethods: Enabled: falseNaming/VariableNumber: Enabled: falseLint/EmptyBlock: Enabled: falseStyle/SafeNavigationChainLength: Enabled: falsemodified:.tool-versions+1 added
1 golang 1.20.132+ruby 3.4.1added:Gemfile+8 added
1+# frozen_string_literal: true2+3+source 'https://rubygems.org'4+5+gem 'minitest', '5.25.4'6+gem 'rubocop', '1.71.0'7+gem 'rubocop-minitest', '0.36.0'8+gem 'rubocop-performance', '1.23.1'added:Gemfile.lock+47 added
1+GEM2+ remote: https://rubygems.org/3+ specs:4+ ast (2.4.2)5+ json (2.9.1)6+ language_server-protocol (3.17.0.3)7+ minitest (5.25.4)8+ parallel (1.26.3)9+ parser (3.3.7.0)10+ ast (~> 2.4.1)11+ racc12+ racc (1.8.1)13+ rainbow (3.1.1)14+ regexp_parser (2.10.0)15+ rubocop (1.71.0)16+ json (~> 2.3)17+ language_server-protocol (>= 3.17.0)18+ parallel (~> 1.10)19+ parser (>= 3.3.0.2)20+ rainbow (>= 2.2.2, < 4.0)21+ regexp_parser (>= 2.9.3, < 3.0)22+ rubocop-ast (>= 1.36.2, < 2.0)23+ ruby-progressbar (~> 1.7)24+ unicode-display_width (>= 2.4.0, < 4.0)25+ rubocop-ast (1.37.0)26+ parser (>= 3.3.1.0)27+ rubocop-minitest (0.36.0)28+ rubocop (>= 1.61, < 2.0)29+ rubocop-ast (>= 1.31.1, < 2.0)30+ rubocop-performance (1.23.1)31+ rubocop (>= 1.48.1, < 2.0)32+ rubocop-ast (>= 1.31.1, < 2.0)33+ ruby-progressbar (1.13.0)34+ unicode-display_width (2.6.0)35+36+PLATFORMS37+ arm64-darwin-2338+ ruby39+40+DEPENDENCIES41+ minitest (= 5.25.4)42+ rubocop (= 1.71.0)43+ rubocop-minitest (= 0.36.0)44+ rubocop-performance (= 1.23.1)45+46+BUNDLED WITH47+ 2.6.2modified:Makefile+6 added-3 removed
80 unmodified lines81 github.com/junegunn/fzf/src/algo \82 github.com/junegunn/fzf/src/tui \83 github.com/junegunn/fzf/src/util84 85+itest:86+ ruby test/runner.rb87+88 bench:89 cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem90 88-lint: $(SOURCES) test/test_go.rb91+lint: $(SOURCES) test/*.rb test/lib/*.rb92 [ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)90- rubocop --require rubocop-minitest --require rubocop-performance93+ bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance94 95 install: bin/fzf96 97 generate:90 unmodified lines188 update:189 $(GO) get -u190 $(GO) mod tidy191 189-.PHONY: all generate build release test bench lint install clean docker docker-test update192+.PHONY: all generate build release test itest bench lint install clean docker docker-test update