Skip to content
Myr

test_preview.rb

This file

Path

test/test_preview.rb

685 lines · 27.1 KiB · Ruby

Last changed by

Fix RuboCop errorsJunegunn Choibefore adoption367177d

History of this file

Take it

1# frozen_string_literal: true23require_relative 'lib/common'45# Test cases for preview6class 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  end3435  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    end4142    # 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    end5051    tmux.send_keys :Up52    tmux.until do |lines|53      assert_includes lines, '> 3'54      refute_includes lines[1], '║ [3]'55    end5657    # One-off preview action58    tmux.send_keys :Space59    tmux.until { |lines| assert_includes lines[1], '║ [3]' }6061    # toggle-preview to hide it62    tmux.send_keys :Enter63    tmux.until { |lines| refute_includes lines[1], '║ [3]' }6465    # 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  end7273  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'), :Enter7576    # Hidden by default77    tmux.until do |lines|78      assert_equal 100, lines.match_count79      refute_includes lines[1], '┃ [1]'80    end8182    # Show83    tmux.send_keys :a84    tmux.until { |lines| assert_includes lines[1], '┃ [1]' }8586    # Already shown87    tmux.send_keys :a88    tmux.send_keys :Up89    tmux.until { |lines| assert_includes lines[1], '┃ [2]' }9091    # 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    end9899    # 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    end106107    # Show it again108    tmux.send_keys :a109    tmux.until { |lines| assert_includes lines[1], '┃ [4]' }110  end111112  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  end122123  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.match_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  end147148  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.match_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  end172173  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  end191192  def test_preview_asterisk193    tmux.send_keys %(seq 5 | #{FZF} --multi --preview 'echo [{}/{+}/{*}/{*n}]' --preview-window '+{1}'), :Enter194    tmux.until { |lines| assert_equal 5, lines.match_count }195    tmux.until { |lines| assert_includes lines[1], ' [1/1/1 2 3 4 5/0 1 2 3 4] ' }196    tmux.send_keys :BTab197    tmux.until { |lines| assert_includes lines[1], ' [2/1/1 2 3 4 5/0 1 2 3 4] ' }198    tmux.send_keys :BTab199    tmux.until { |lines| assert_includes lines[1], ' [3/1 2/1 2 3 4 5/0 1 2 3 4] ' }200    tmux.send_keys '5'201    tmux.until { |lines| assert_includes lines[1], ' [5/1 2/5/4] ' }202    tmux.send_keys '5'203    tmux.until { |lines| assert_includes lines[1], ' [/1 2//] ' }204  end205206  def test_preview_file207    tmux.send_keys %[(echo foo bar; echo bar foo) | #{FZF} --multi --preview 'cat {+f} {+f2} {+nf} {+fn}' --print0], :Enter208    tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }209    tmux.send_keys :BTab210    tmux.until { |lines| assert_includes lines[1], ' foo barbar00 ' }211    tmux.send_keys :BTab212    tmux.until { |lines| assert_includes lines[1], ' foo barbar foobarfoo0101 ' }213  end214215  def test_preview_q_no_match216    tmux.send_keys %(: | #{FZF} --preview 'echo foo {q} foo'), :Enter217    tmux.until { |lines| assert_equal 0, lines.match_count }218    tmux.until { |lines| assert_includes lines[1], ' foo  foo' }219    tmux.send_keys 'bar'220    tmux.until { |lines| assert_includes lines[1], ' foo bar foo' }221    tmux.send_keys 'C-u'222    tmux.until { |lines| assert_includes lines[1], ' foo  foo' }223  end224225  def test_preview_q_no_match_with_initial_query226    tmux.send_keys %(: | #{FZF} --preview 'echo 1. /{q}/{q:1}/; echo 2. /{q:..}/{q:2}/{q:-1}/; echo 3. /{q:s-2}/{q:-2}/{q:x}/' --query 'foo bar'), :Enter227    tmux.until { |lines| assert_equal 0, lines.match_count }228    tmux.until { |lines| assert_includes lines[1], '1. /foo bar/foo/' }229    tmux.until { |lines| assert_includes lines[2], '2. /foo bar/bar/bar/' }230    tmux.until { |lines| assert_includes lines[3], '3. /foo /foo/{q:x}/' }231  end232233  def test_preview_update_on_select234    tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),235                   :Enter236    tmux.until { |lines| assert_equal 10, lines.match_count }237    tmux.send_keys 'a'238    tmux.until { |lines| assert(lines.any? { |line| line.include?(' 1 2 3 4 5 ') }) }239    tmux.send_keys 'a'240    tmux.until { |lines| lines.each { |line| refute_includes line, ' 1 2 3 4 5 ' } }241  end242243  def test_preview_correct_tab_width_after_ansi_reset_code244    writelines(["\x1b[31m+\x1b[m\t\x1b[32mgreen"])245    tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter246    tmux.until { |lines| assert_includes lines[1], ' +       green ' }247  end248249  def test_preview_bindings_with_default_preview250    tmux.send_keys "seq 10 | #{FZF} --preview 'echo [{}]' --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter251    tmux.until { |lines| lines.match_count == 10 }252    tmux.until { |lines| assert_includes lines[1], '[1]' }253    tmux.send_keys 'a'254    tmux.until { |lines| assert_includes lines[1], '[11]' }255    tmux.send_keys 'c'256    tmux.until { |lines| assert_includes lines[1], '[1]' }257    tmux.send_keys 'b'258    tmux.until { |lines| assert_includes lines[1], '[111]' }259    tmux.send_keys :Up260    tmux.until { |lines| assert_includes lines[1], '[2]' }261  end262263  def test_preview_bindings_without_default_preview264    tmux.send_keys "seq 10 | #{FZF} --bind 'a:preview(echo [{}{}]),b:preview(echo [{}{}{}]),c:refresh-preview'", :Enter265    tmux.until { |lines| lines.match_count == 10 }266    tmux.until { |lines| refute_includes lines[1], '1' }267    tmux.send_keys 'a'268    tmux.until { |lines| assert_includes lines[1], '[11]' }269    tmux.send_keys 'c' # does nothing270    tmux.until { |lines| assert_includes lines[1], '[11]' }271    tmux.send_keys 'b'272    tmux.until { |lines| assert_includes lines[1], '[111]' }273    tmux.send_keys 9274    tmux.until { |lines| lines.match_count == 1 }275    tmux.until { |lines| refute_includes lines[1], '2' }276    tmux.until { |lines| assert_includes lines[1], '[111]' }277  end278279  def test_preview_scroll_begin_constant280    tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+123", :Enter281    tmux.until { |lines| assert_match %r{1/1}, lines[-2] }282    tmux.until { |lines| assert_match %r{123.*123/1000}, lines[1] }283  end284285  def test_preview_scroll_begin_expr286    tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{3}", :Enter287    tmux.until { |lines| assert_match %r{1/1}, lines[-2] }288    tmux.until { |lines| assert_match %r{321.*321/1000}, lines[1] }289  end290291  def test_preview_scroll_begin_and_offset292    ['echo foo 123 321', 'echo foo :123: 321'].each do |input|293      tmux.send_keys "#{input} | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter294      tmux.until { |lines| assert_match %r{1/1}, lines[-2] }295      tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] }296      tmux.send_keys 'C-c'297    end298  end299300  def test_preview_clear_screen301    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'}, :Enter302    tmux.until { |lines| lines.match_count == 100 }303    tmux.until { |lines| lines[1]&.include?('[200]') }304  end305306  def test_preview_window_follow307    file = Tempfile.new('fzf-follow')308    file.sync = true309310    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'), :Enter311    tmux.until { |lines| lines.match_count == 100 }312313    # Write to the temporary file, and check if the preview window is showing314    # the last line of the file315    tmux.until { |lines| assert_includes lines[1], 'start' }316    3.times { file.puts _1 } # header lines317    1000.times { file.puts _1 }318    tmux.until { |lines| assert_includes lines[1], '/1004' }319    tmux.until { |lines| assert_includes lines[-2], '999' }320321    # Scroll the preview window and fzf should stop following the file content322    tmux.send_keys :Up323    tmux.until { |lines| assert_includes lines[-2], '998' }324    file.puts 'foo', 'bar'325    tmux.until do |lines|326      assert_includes lines[1], '/1006'327      assert_includes lines[-2], '998'328    end329330    # Scroll back to the bottom and fzf should start following the file again331    %w[999 foo bar].each do |item|332      wait do333        tmux.send_keys :Down334        tmux.until { |lines| assert_includes lines[-2], item }335      end336    end337    file.puts 'baz'338    tmux.until do |lines|339      assert_includes lines[1], '/1007'340      assert_includes lines[-2], 'baz'341    end342343    # Scroll upwards to stop following344    tmux.send_keys :Up345    wait { assert_includes lines[-2], 'bar' }346    file.puts 'aaa'347    tmux.until do |lines|348      assert_includes lines[1], '/1008'349      assert_includes lines[-2], 'bar'350    end351352    # Manually enable following353    tmux.send_keys :Space354    tmux.until { |lines| assert_includes lines[-2], 'aaa' }355    file.puts 'bbb'356    tmux.until do |lines|357      assert_includes lines[1], '/1009'358      assert_includes lines[-2], 'bbb'359    end360361    # Disable following362    tmux.send_keys :Space363    file.puts 'ccc', 'ddd'364    tmux.until do |lines|365      assert_includes lines[1], '/1011'366      assert_includes lines[-2], 'bbb'367    end368  rescue StandardError369    file.close370    file.unlink371  end372373  def test_toggle_preview_wrap374    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", :Enter375    2.times do376      tmux.until { |lines| assert_includes lines[2], '2nd line' }377      tmux.send_keys 'C-w'378      tmux.until do |lines|379        assert_includes lines[2], 'wrapped'380        assert_includes lines[3], '2nd line'381      end382      tmux.send_keys 'C-w'383    end384  end385386  def test_change_preview_window_preserves_wrap_toggle387    # https://github.com/junegunn/fzf/issues/4791388    tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \389                   "--preview-window 'right,nowrap,border-rounded' " \390                   '--bind ctrl-w:toggle-preview-wrap ' \391                   '--bind ctrl-r:change-preview-window:border-bold', :Enter392    sleep(2)393    # Initial: nowrap, rounded border. The long line is truncated; "wrapped" is hidden.394    tmux.until do |lines|395      assert_includes lines[2], '2nd line'396      assert(lines.any? { it.include?('╭') })397    end398    # Toggle wrap on.399    tmux.send_keys 'C-w'400    tmux.until do |lines|401      assert_includes lines[2], 'wrapped'402      assert_includes lines[3], '2nd line'403    end404    # change-preview-window swaps the border to bold; wrap state must persist.405    tmux.send_keys 'C-r'406    tmux.until do |lines|407      assert(lines.any? { it.include?('┏') })  # border actually changed408      refute(lines.any? { it.include?('╭') })409      assert_includes lines[2], 'wrapped'      # wrap was preserved410      assert_includes lines[3], '2nd line'411    end412  end413414  def test_change_preview_window_overrides_wrap_explicitly415    # When the new spec sets wrap/nowrap explicitly, it should still win.416    tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \417                   "--preview-window 'right,wrap' " \418                   '--bind ctrl-r:change-preview-window:nowrap', :Enter419    # Initial: wrap is on.420    tmux.until do |lines|421      assert_includes lines[2], 'wrapped'422      assert_includes lines[3], '2nd line'423    end424    # Explicit nowrap in the spec must override the (initially wrapped) state.425    tmux.send_keys 'C-r'426    tmux.until { |lines| assert_includes lines[2], '2nd line' }427  end428429  def test_preview_follow_wrap430    tmux.send_keys "seq 1 | #{FZF} --preview 'seq 1000' --preview-window right,2,follow,wrap", :Enter431    tmux.until { |lines| assert_equal 1, lines.match_count }432    tmux.until do |lines|433      idx = lines.rindex { it.include?('│ 10 │') }434      assert_includes lines[idx + 1], '│ ↳  │'435      assert_includes lines[idx + 2], '│ ↳  │'436    end437  end438439  def test_preview_follow_wrap_long_line440    tmux.send_keys %(seq 1 | #{FZF} --preview "seq 2; yes yes | head -10000 | tr '\n' ' '" --preview-window follow,wrap --bind up:preview-up,down:preview-down), :Enter441    tmux.until do |lines|442      assert_equal 1, lines.match_count443      assert lines.any_include?('3/3 │')444    end445    tmux.send_keys :Up446    tmux.until { |lines| assert lines.any_include?('2/3 │') }447    tmux.send_keys :Up448    tmux.until { |lines| assert lines.any_include?('1/3 │') }449    tmux.send_keys :Down450    tmux.until { |lines| assert lines.any_include?('2/3 │') }451  end452453  def test_close454    tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter455    tmux.until { |lines| assert_equal 100, lines.match_count }456    tmux.until { |lines| assert_includes lines[1], 'foo' }457    tmux.send_keys 'C-c'458    tmux.until { |lines| refute_includes lines[1], 'foo' }459    tmux.send_keys '10'460    tmux.until { |lines| assert_equal 2, lines.match_count }461    tmux.send_keys 'C-c'462    tmux.send_keys 'C-l', 'closed'463    tmux.until { |lines| assert_includes lines[0], 'closed' }464  end465466  def test_preview_header467    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'", :Enter468    tmux.until { |lines| assert_equal 100, lines.match_count }469    top5 = ->(lines) { lines.drop(1).take(5).map { |s| s[/[0-9]+/] } }470    tmux.until do |lines|471      assert_includes lines[1], '4/1000'472      assert_equal(%w[1 2 3 4 5], top5[lines])473    end474    tmux.send_keys '55'475    tmux.until do |lines|476      assert_equal 1, lines.match_count477      assert_equal(%w[1 2 3 55 56], top5[lines])478    end479    tmux.send_keys 'C-J'480    tmux.until do |lines|481      assert_equal(%w[1 2 3 58 59], top5[lines])482    end483    tmux.send_keys :BSpace484    tmux.until do |lines|485      assert_equal 19, lines.match_count486      assert_equal(%w[1 2 3 5 6], top5[lines])487    end488    tmux.send_keys 'C-K'489    tmux.until { |lines| assert_equal(%w[1 2 3 4 5], top5[lines]) }490  end491492  def test_change_preview_window493    tmux.send_keys "seq 1000 | #{FZF} --preview 'echo [[{}]]' --no-preview-border --bind '" \494                   'a:change-preview(echo __{}__),' \495                   'b:change-preview-window(down)+change-preview(echo =={}==)+change-preview-window(up),' \496                   'c:change-preview(),d:change-preview-window(hidden),' \497                   "e:preview(printf ::%${FZF_PREVIEW_COLUMNS}s{})+change-preview-window(up),f:change-preview-window(up,wrap)'", :Enter498    tmux.until { |lines| assert_equal 1000, lines.match_count }499    tmux.until { |lines| assert_includes lines[0], '[[1]]' }500501    # change-preview action permanently changes the preview command set by --preview502    tmux.send_keys 'a'503    tmux.until { |lines| assert_includes lines[0], '__1__' }504    tmux.send_keys :Up505    tmux.until { |lines| assert_includes lines[0], '__2__' }506507    # When multiple change-preview-window actions are bound to a single key,508    # the last one wins and the updated options are immediately applied to the new preview509    tmux.send_keys 'b'510    tmux.until { |lines| assert_equal '==2==', lines[0] }511    tmux.send_keys :Up512    tmux.until { |lines| assert_equal '==3==', lines[0] }513514    # change-preview with an empty preview command closes the preview window515    tmux.send_keys 'c'516    tmux.until { |lines| refute_includes lines[0], '==' }517518    # change-preview again to re-open the preview window519    tmux.send_keys 'a'520    tmux.until { |lines| assert_equal '__3__', lines[0] }521522    # Hide the preview window with hidden flag523    tmux.send_keys 'd'524    tmux.until { |lines| refute_includes lines[0], '__3__' }525526    # One-off preview527    tmux.send_keys 'e'528    tmux.until do |lines|529      assert_equal '::', lines[0]530      refute_includes lines[1], '3'531    end532533    # Wrapped534    tmux.send_keys 'f'535    tmux.until do |lines|536      assert_equal '::', lines[0]537      assert_equal '↳   3', lines[1]538    end539  end540541  def test_change_preview_window_should_not_reset_change_preview542    tmux.send_keys "#{FZF} --preview-window up,border-none --bind 'start:change-preview(echo hello)' --bind 'enter:change-preview-window(border-left)'", :Enter543    tmux.until { |lines| assert_includes lines, 'hello' }544    tmux.send_keys :Enter545    tmux.until { |lines| assert_includes lines, '│ hello' }546  end547548  def test_change_preview_window_rotate549    tmux.send_keys "seq 100 | #{FZF} --preview-window left,border-none --preview 'echo hello' --bind '" \550                   "a:change-preview-window(right|down|up|hidden|)'", :Enter551    tmux.until { |lines| assert(lines.any? { _1.include?('100/100') }) }552    3.times do553      tmux.until { |lines| lines[0].start_with?('hello') }554      tmux.send_keys 'a'555      tmux.until { |lines| lines[0].end_with?('hello') }556      tmux.send_keys 'a'557      tmux.until { |lines| lines[-1].start_with?('hello') }558      tmux.send_keys 'a'559      tmux.until { |lines| assert_equal 'hello', lines[0] }560      tmux.send_keys 'a'561      tmux.until { |lines| refute_includes lines[0], 'hello' }562      tmux.send_keys 'a'563    end564  end565566  def test_change_preview_window_rotate_hidden567    tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \568                   "a:change-preview-window(nohidden||down,1|)'", :Enter569    tmux.until { |lines| assert_equal 100, lines.match_count }570    tmux.until { |lines| refute_includes lines[1], '==1==' }571    tmux.send_keys 'a'572    tmux.until { |lines| assert_includes lines[1], '==1==' }573    tmux.send_keys 'a'574    tmux.until { |lines| refute_includes lines[1], '==1==' }575    tmux.send_keys 'a'576    tmux.until { |lines| assert_includes lines[-2], '==1==' }577    tmux.send_keys 'a'578    tmux.until { |lines| refute_includes lines[-2], '==1==' }579    tmux.send_keys 'a'580    tmux.until { |lines| assert_includes lines[1], '==1==' }581  end582583  def test_change_preview_window_rotate_hidden_down584    tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter585    tmux.until { |lines| assert_equal 100, lines.match_count }586    tmux.until { |lines| refute_includes lines[1], '==1==' }587    tmux.send_keys '?'588    tmux.until { |lines| assert_includes lines[1], '==1==' }589    tmux.send_keys '?'590    tmux.until { |lines| refute_includes lines[1], '==1==' }591    tmux.send_keys '?'592    tmux.until { |lines| assert_includes lines[-2], '==1==' }593    tmux.send_keys '?'594    tmux.until { |lines| refute_includes lines[-2], '==1==' }595    tmux.send_keys '?'596    tmux.until { |lines| assert_includes lines[1], '==1==' }597  end598599  def test_toggle_alternative_preview_window600    tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter601    tmux.until { |lines| assert_equal 10, lines.match_count }602    tmux.until { |lines| refute_includes lines, '/1/1/' }603    tmux.send_keys :Space604    tmux.until { |lines| assert_includes lines, '/1/1/' }605  end606607  def test_alternative_preview_window_opts608    tmux.send_keys "seq 10 | #{FZF} --preview-border rounded --preview-window '~5,2,+0,<100000(~0,+100,wrap,noinfo)' --preview 'seq 1000'", :Enter609    tmux.until { |lines| assert_equal 10, lines.match_count }610    tmux.until do |lines|611      assert_equal ['╭────╮', '│ 10 │', '│ ↳  │', '│ 10 │', '│ ↳  │'], lines.take(5).map(&:strip)612    end613  end614615  def test_preview_window_width_exception616    tmux.send_keys "seq 10 | #{FZF} --scrollbar --preview-window border-left --border --preview 'seq 1000'", :Enter617    tmux.until do |lines|618      assert lines[1]&.end_with?(' 1/1000││')619    end620  end621622  def test_preview_window_hidden_on_focus623    tmux.send_keys "seq 3 | #{FZF} --preview 'echo {}' --bind focus:hide-preview", :Enter624    tmux.until { |lines| assert_includes lines, '> 1' }625    tmux.send_keys :Up626    tmux.until { |lines| assert_includes lines, '> 2' }627  end628629  def test_preview_query_should_not_be_affected_by_search630    tmux.send_keys "seq 1 | #{FZF} --bind 'change:transform-search(echo {q:1})' --preview 'echo [{q}/{}]'", :Enter631    tmux.until { |lines| assert_equal 1, lines.match_count }632    tmux.send_keys '1'633    tmux.until { |lines| assert lines.any_include?('[1/1]') }634    tmux.send_keys :Space635    tmux.until { |lines| assert lines.any_include?('[1 /1]') }636    tmux.send_keys '2'637    tmux.until do |lines|638      assert lines.any_include?('[1 2/1]')639      assert_equal 1, lines.match_count640    end641  end642643  def test_preview_wrap_sign_between_ansi_fragments644    tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m1234567890 \\x1b[mhello"; echo -e "\\x1b[33m1234567890 \\x1b[mhello"' --preview-window 10,wrap-word), :Enter645    tmux.until do |lines|646      assert_equal 1, lines.match_count647      assert_equal(2, lines.count { |line| line.include?('│ 1234567890 │') })648      assert_equal(2, lines.count { |line| line.include?('│ ↳ hello    │') })649    end650  end651652  def test_preview_wrap_sign_between_ansi_fragments_overflow653    tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m123 \\x1b[mhi"; echo -e "\\x1b[33m123 \\x1b[mhi"' --preview-window 2,wrap-word,noinfo), :Enter654    tmux.until do |lines|655      assert_equal 1, lines.match_count656      assert_equal(2, lines.count { |line| line.include?('│ 12 │') })657      assert_equal(0, lines.count { |line| line.include?('│ h') })658    end659  end660661  def test_preview_wrap_sign_between_ansi_fragments_overflow2662    tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m123 \\x1b[mhi"; echo -e "\\x1b[33m123 \\x1b[mhi"' --preview-window 1,wrap-word,noinfo), :Enter663    tmux.until do |lines|664      assert_equal 1, lines.match_count665      assert_equal(2, lines.count { |line| line.include?('│ 1 │') })666      assert_equal(0, lines.count { |line| line.include?('│ h') })667    end668  end669670  def test_preview_toggle_should_redraw_scrollbar671    tmux.send_keys %(seq 1 | #{FZF} --no-border --scrollbar --preview 'seq $((FZF_PREVIEW_LINES + 1))' --preview-border line --bind tab:toggle-preview --header foo --header-border --footer bar --footer-border), :Enter672    tmux.until do |lines|673      assert_equal 1, lines.match_count674      assert_operator lines.count { |line| line.end_with?('│') }, :>, 2675    end676    tmux.send_keys :Tab677    tmux.until do |lines|678      assert_equal(2, lines.count { |line| line.end_with?('│') })679    end680    tmux.send_keys :Tab681    tmux.until do |lines|682      assert_operator lines.count { |line| line.end_with?('│') }, :>, 2683    end684  end685end