diff options
author | Jack Bates <jack@nottheoilrig.com> | 2020-02-28 04:06:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 20:06:38 +0900 |
commit | e34c7c00b1df84085c6ade0380409bce61793a12 (patch) | |
tree | 2e423aa78b8b56123410266bd0a5715f62d885fe /test | |
parent | 7c447bbdc7adb1fe0c848e171780f68cacf3e80e (diff) |
Test multi-line C-r (#1892)
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_go.rb | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/test/test_go.rb b/test/test_go.rb index 41aaf8d5..aa1589ca 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -87,8 +87,8 @@ class Tmux attr_reader :win def initialize(shell = :bash) - @win = go("new-window -d -P -F '#I' '#{Shell.send(shell)}'").first - go("set-window-option -t #{@win} pane-base-index 0") + @win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first + go(%W[set-window-option -t #{@win} pane-base-index 0]) return unless shell == :fish send_keys('function fish_prompt; end; clear', :Enter) @@ -96,30 +96,19 @@ class Tmux end def kill - go("kill-window -t #{win} 2> /dev/null") + go(%W[kill-window -t #{win}]) end def send_keys(*args) target = if args.last.is_a?(Hash) hash = args.pop - go("select-window -t #{win}") + go(%W[select-window -t #{win}]) "#{win}.#{hash[:pane]}" else win end - enum = (args + [nil]).each_cons(2) - loop do - pair = enum.next - if pair.first == :Escape - arg = pair.compact.map { |key| %("#{key}") }.join(' ') - go(%(send-keys -t #{target} #{arg})) - enum.next if pair.last - else - go(%(send-keys -t #{target} "#{pair.first}")) - end - break unless pair.last - end + go(%W[send-keys -t #{target}] + args.map(&:to_s)) end def paste(str) @@ -127,7 +116,7 @@ class Tmux end def capture(pane = 0) - go("capture-pane -p -t #{win}.#{pane}") + go(%W[capture-pane -p -t #{win}.#{pane}]).reverse.drop_while(&:empty?).reverse end def until(refresh = false, pane = 0) @@ -189,8 +178,8 @@ class Tmux private - def go(*args) - `tmux #{args.join ' '}`.split($INPUT_RECORD_SEPARATOR) + def go(args) + IO.popen(['tmux'] + args) { |io| io.readlines(chomp: true) } end end @@ -501,7 +490,7 @@ class TestGoFZF < TestBase end def test_sync - tmux.send_keys "seq 1 100 | #{fzf! :multi} | awk '{print \\$1 \\$1}' | #{fzf :sync}", :Enter + tmux.send_keys "seq 1 100 | #{fzf! :multi} | awk '{print $1 $1}' | #{fzf :sync}", :Enter tmux.until { |lines| lines[-1] == '>' } tmux.send_keys 9 tmux.until { |lines| lines[-2] == ' 19/100' } @@ -782,7 +771,7 @@ class TestGoFZF < TestBase end def test_invalid_cache_query_type - command = %[(echo 'foo\\$bar'; echo 'barfoo'; echo 'foo^bar'; echo \\"foo'1-2\\"; seq 100) | #{fzf}] + command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{fzf}] # Suffix match tmux.send_keys command, :Enter @@ -941,7 +930,7 @@ class TestGoFZF < TestBase def test_execute output = '/tmp/fzf-test-execute' - opts = %[--bind \\"alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}\\"] + opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"] wait = ->(exp) { tmux.until { |lines| lines[-2].include? exp } } writelines tempname, %w[foo'bar foo"bar foo$bar] tmux.send_keys "cat #{tempname} | #{fzf opts}; sync", :Enter @@ -980,7 +969,7 @@ class TestGoFZF < TestBase def test_execute_multi output = '/tmp/fzf-test-execute-multi' - opts = %[--multi --bind \\"alt-a:execute-multi(echo {}/{+} >> #{output}; sync)\\"] + opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output}; sync)"] writelines tempname, %w[foo'bar foo"bar foo$bar foobar] tmux.send_keys "cat #{tempname} | #{fzf opts}", :Enter tmux.until { |lines| lines[-2].include? '4/4' } @@ -1166,7 +1155,7 @@ class TestGoFZF < TestBase end def test_header - tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{FILE})\\\""}", :Enter + tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\""}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[-2].include?('100/100') && @@ -1176,7 +1165,7 @@ class TestGoFZF < TestBase end def test_header_reverse - tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --reverse"}", :Enter + tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\" --reverse"}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[1].include?('100/100') && @@ -1186,7 +1175,7 @@ class TestGoFZF < TestBase end def test_header_reverse_list - tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --layout=reverse-list"}", :Enter + tmux.send_keys "seq 100 | #{fzf "--header \"$(head -5 #{FILE})\" --layout=reverse-list"}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[-2].include?('100/100') && @@ -1196,7 +1185,7 @@ class TestGoFZF < TestBase end def test_header_and_header_lines - tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter + tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[-2].include?('90/90') && @@ -1206,7 +1195,7 @@ class TestGoFZF < TestBase end def test_header_and_header_lines_reverse - tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter + tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[1].include?('90/90') && @@ -1216,7 +1205,7 @@ class TestGoFZF < TestBase end def test_header_and_header_lines_reverse_list - tmux.send_keys "seq 100 | #{fzf "--layout=reverse-list --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter + tmux.send_keys "seq 100 | #{fzf "--layout=reverse-list --header-lines 10 --header \"$(head -5 #{FILE})\""}", :Enter header = File.readlines(FILE).take(5).map(&:strip) tmux.until do |lines| lines[-2].include?('90/90') && @@ -1327,7 +1316,7 @@ class TestGoFZF < TestBase def test_exitstatus_empty { '99' => '0', '999' => '1' }.each do |query, status| - tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --\\$?--", :Enter + tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter tmux.until { |lines| lines[-2] =~ %r{ [10]/100} } tmux.send_keys :Enter tmux.until { |lines| lines.last.include? "--#{status}--" } @@ -1472,7 +1461,7 @@ class TestGoFZF < TestBase end def test_preview_hidden - tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$FZF_PREVIEW_LINES-\\$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter + tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter tmux.until { |lines| lines[-1] == '>' } tmux.send_keys '?' tmux.until { |lines| lines[-2] =~ / {1-1-1-[0-9]+}/ } @@ -1849,6 +1838,19 @@ module TestShell tmux.until { |lines| lines[-1] == '3rd' } end + def test_ctrl_r_multiline + tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter + tmux.until { |lines| lines[-2..-1] == ['foo', 'bar'] } + tmux.send_keys 'C-r' + tmux.until { |lines| lines[-1] == '>' } + tmux.send_keys 'foo bar' + tmux.until { |lines| lines[-3].end_with? 'bar"' } + tmux.send_keys :Enter + tmux.until { |lines| lines[-1].end_with? 'bar"' } + tmux.send_keys :Enter + tmux.until { |lines| lines[-2..-1] == ['foo', 'bar'] } + end + def test_ctrl_r_abort 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 < 4 tmux.send_keys 'foo' @@ -1988,7 +1990,7 @@ module CompletionTest end def test_custom_completion - tmux.send_keys '_fzf_compgen_path() { echo "\$1"; seq 10; }', :Enter + tmux.send_keys '_fzf_compgen_path() { echo "$1"; seq 10; }', :Enter tmux.prepare tmux.send_keys 'ls /tmp/**', :Tab tmux.until { |lines| lines.match_count == 11 } |