Test multi-line C-r (#1892)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jack Bates · committed by GitHub · parent 7c447bb · Browse files · 1 file·+34 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+34 added−32 removed
- tests:+34 added−32 removed
Provenance
- Commit
e34c7c0- Tree
2e423aa- Author
Jack Bates <jack@nottheoilrig.com>- Committer
GitHub <noreply@github.com>- Parent
7c447bb
1 file changed+34 added−32 removed
modified:test/test_go.rb+34 added-32 removed
85 unmodified lines86 class Tmux87 attr_reader :win88 89 def initialize(shell = :bash)90- @win = go("new-window -d -P -F '#I' '#{Shell.send(shell)}'").first91- go("set-window-option -t #{@win} pane-base-index 0")90+ @win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first91+ go(%W[set-window-option -t #{@win} pane-base-index 0])92 return unless shell == :fish93 94 send_keys('function fish_prompt; end; clear', :Enter)95 self.until(&:empty?)96 end97 98 def kill99- go("kill-window -t #{win} 2> /dev/null")99+ go(%W[kill-window -t #{win}])100 end101 102 def send_keys(*args)103 target =104 if args.last.is_a?(Hash)105 hash = args.pop106- go("select-window -t #{win}")106+ go(%W[select-window -t #{win}])107 "#{win}.#{hash[:pane]}"108 else109 win110 end111- enum = (args + [nil]).each_cons(2)112- loop do113- pair = enum.next114- if pair.first == :Escape115- arg = pair.compact.map { |key| %("#{key}") }.join(' ')116- go(%(send-keys -t #{target} #{arg}))117- enum.next if pair.last118- else119- go(%(send-keys -t #{target} "#{pair.first}"))120- end121- break unless pair.last122- end111+ go(%W[send-keys -t #{target}] + args.map(&:to_s))112 end113 114 def paste(str)115 system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')116 end117 118 def capture(pane = 0)130- go("capture-pane -p -t #{win}.#{pane}")119+ go(%W[capture-pane -p -t #{win}.#{pane}]).reverse.drop_while(&:empty?).reverse120 end121 122 def until(refresh = false, pane = 0)123 lines = nil53 unmodified lines177 end178 179 private180 192- def go(*args)193- `tmux #{args.join ' '}`.split($INPUT_RECORD_SEPARATOR)181+ def go(args)182+ IO.popen(['tmux'] + args) { |io| io.readlines(chomp: true) }183 end184 end185 186 class TestBase < Minitest::Test302 unmodified lines489 assert_equal ['가나다'], readonce.split($INPUT_RECORD_SEPARATOR)490 end491 492 def test_sync504- tmux.send_keys "seq 1 100 | #{fzf! :multi} | awk '{print \\$1 \\$1}' | #{fzf :sync}", :Enter493+ tmux.send_keys "seq 1 100 | #{fzf! :multi} | awk '{print $1 $1}' | #{fzf :sync}", :Enter494 tmux.until { |lines| lines[-1] == '>' }495 tmux.send_keys 9496 tmux.until { |lines| lines[-2] == ' 19/100' }497 tmux.send_keys :BTab, :BTab, :BTab272 unmodified lines770 tmux.send_keys :Enter771 end772 773 def test_invalid_cache_query_type785- command = %[(echo 'foo\\$bar'; echo 'barfoo'; echo 'foo^bar'; echo \\"foo'1-2\\"; seq 100) | #{fzf}]774+ command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{fzf}]775 776 # Suffix match777 tmux.send_keys command, :Enter778 tmux.until { |lines| lines.match_count == 104 }150 unmodified lines929 end930 931 def test_execute932 output = '/tmp/fzf-test-execute'944- opts = %[--bind \\"alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}\\"]933+ opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"]934 wait = ->(exp) { tmux.until { |lines| lines[-2].include? exp } }935 writelines tempname, %w[foo'bar foo"bar foo$bar]936 tmux.send_keys "cat #{tempname} | #{fzf opts}; sync", :Enter937 wait['3/3']30 unmodified lines968 end969 970 def test_execute_multi971 output = '/tmp/fzf-test-execute-multi'983- opts = %[--multi --bind \\"alt-a:execute-multi(echo {}/{+} >> #{output}; sync)\\"]972+ opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output}; sync)"]973 writelines tempname, %w[foo'bar foo"bar foo$bar foobar]974 tmux.send_keys "cat #{tempname} | #{fzf opts}", :Enter975 tmux.until { |lines| lines[-2].include? '4/4' }976 tmux.send_keys :Escape, :a177 unmodified lines1154 assert_equal '6', readonce.chomp1155 end1156 1157 def test_header1169- tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1158+ tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\""}", :Enter1159 header = File.readlines(FILE).take(5).map(&:strip)1160 tmux.until do |lines|1161 lines[-2].include?('100/100') &&1162 lines[-7..-3].map(&:strip) == header &&1 unmodified line1164 end1165 end1166 1167 def test_header_reverse1179- tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --reverse"}", :Enter1168+ tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\" --reverse"}", :Enter1169 header = File.readlines(FILE).take(5).map(&:strip)1170 tmux.until do |lines|1171 lines[1].include?('100/100') &&1172 lines[2..6].map(&:strip) == header &&1 unmodified line1174 end1175 end1176 1177 def test_header_reverse_list1189- tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --layout=reverse-list"}", :Enter1178+ tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\" --layout=reverse-list"}", :Enter1179 header = File.readlines(FILE).take(5).map(&:strip)1180 tmux.until do |lines|1181 lines[-2].include?('100/100') &&1182 lines[-7..-3].map(&:strip) == header &&1 unmodified line1184 end1185 end1186 1187 def test_header_and_header_lines1199- tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1188+ tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter1189 header = File.readlines(FILE).take(5).map(&:strip)1190 tmux.until do |lines|1191 lines[-2].include?('90/90') &&1192 lines[-7...-2].map(&:strip) == header &&1 unmodified line1194 end1195 end1196 1197 def test_header_and_header_lines_reverse1209- tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1198+ tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter1199 header = File.readlines(FILE).take(5).map(&:strip)1200 tmux.until do |lines|1201 lines[1].include?('90/90') &&1202 lines[2...7].map(&:strip) == header &&1 unmodified line1204 end1205 end1206 1207 def test_header_and_header_lines_reverse_list1219- tmux.send_keys "seq 100 | #{fzf "--layout=reverse-list --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter1208+ tmux.send_keys "seq 100 | #{fzf "--layout=reverse-list --header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter1209 header = File.readlines(FILE).take(5).map(&:strip)1210 tmux.until do |lines|1211 lines[-2].include?('90/90') &&1212 lines[-7...-2].map(&:strip) == header &&102 unmodified lines1315 end1316 1317 def test_exitstatus_empty1318 { '99' => '0', '999' => '1' }.each do |query, status|1330- tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --\\$?--", :Enter1319+ tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter1320 tmux.until { |lines| lines[-2] =~ %r{ [10]/100} }1321 tmux.send_keys :Enter1322 tmux.until { |lines| lines.last.include? "--#{status}--" }1323 end136 unmodified lines1460 tmux.until { |lines| lines[1].include?(' {5-1 3 4}') }1461 end1462 1463 def test_preview_hidden1475- tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$FZF_PREVIEW_LINES-\\$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1464+ tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter1465 tmux.until { |lines| lines[-1] == '>' }1466 tmux.send_keys '?'1467 tmux.until { |lines| lines[-2] =~ / {1-1-1-[0-9]+}/ }1468 tmux.send_keys '555'368 unmodified lines1837 tmux.send_keys :Enter1838 tmux.until { |lines| lines[-1] == '3rd' }1839 end1840 1841+ def test_ctrl_r_multiline1842+ tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter1843+ tmux.until { |lines| lines[-2..-1] == ['foo', 'bar'] }1844+ tmux.send_keys 'C-r'1845+ tmux.until { |lines| lines[-1] == '>' }1846+ tmux.send_keys 'foo bar'1847+ tmux.until { |lines| lines[-3].end_with? 'bar"' }1848+ tmux.send_keys :Enter1849+ tmux.until { |lines| lines[-1].end_with? 'bar"' }1850+ tmux.send_keys :Enter1851+ tmux.until { |lines| lines[-2..-1] == ['foo', 'bar'] }1852+ end1853+1854 def test_ctrl_r_abort1855 skip "doesn't restore the original line when search is aborted pre Bash 4" if shell == :bash && /(?<= version )\d+/.match(`#{Shell.bash} --version`).to_s.to_i < 41856 tmux.send_keys 'foo'1857 tmux.until { |lines| lines[-1].start_with? 'foo' }131 unmodified lines1989 end1990 end1991 1992 def test_custom_completion1991- tmux.send_keys '_fzf_compgen_path() { echo "\$1"; seq 10; }', :Enter1993+ tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter1994 tmux.prepare1995 tmux.send_keys 'ls /tmp/**', :Tab1996 tmux.until { |lines| lines.match_count == 11 }1997 tmux.send_keys :Tab, :Tab, :Tab134 unmodified lines