Add test cases for --select-1 and --exit-0
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent be5c176 · Browse files · 1 file·+38 added−7 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+38 added−7 removed
- tests:+38 added−7 removed
Provenance
- Commit
c3a198d- Tree
63b4926- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
be5c176
1 file changed+38 added−7 removed
modified:test/test_go.rb+38 added-7 removed
1 unmodified line2 # encoding: utf-83 4 require 'minitest/autorun'5 6+class NilClass7+ def include? str8+ false9+ end10+end11+12 class Tmux13 TEMPNAME = '/tmp/fzf-test.txt'14 15 attr_reader :win68 unmodified lines84 def tempname85 '/tmp/output'86 end87 88+ def readtemp89+ waited = 090+ while waited < 591+ begin92+ return File.read(tempname)93+ rescue94+ sleep 0.195+ waited += 0.196+ end97+ end98+ raise "failed to read tempfile"99+ end100+101 def setup102 ENV.delete 'FZF_DEFAULT_OPTS'103 ENV.delete 'FZF_DEFAULT_COMMAND'104 @prev = Tmux.current25 unmodified lines130 assert_equal '> 391', lines[-1]131 132 tmux.send_keys :Enter133 tmux.close115- assert_equal '1391', File.read(tempname).chomp134+ assert_equal '1391', readtemp.chomp135 end136 137 def test_fzf_default_command138 tmux.send_keys "FZF_DEFAULT_COMMAND='echo hello' fzf > #{tempname}", :Enter139 tmux.until { |lines| lines.last =~ /^>/ }140 141 tmux.send_keys :Enter142 tmux.close124- assert_equal 'hello', File.read(tempname).chomp143+ assert_equal 'hello', readtemp.chomp144 end145 146 def test_key_bindings147 tmux.send_keys "fzf -q 'foo bar foo-bar'", :Enter69 unmodified lines217 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6218 :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7219 tmux.until { |lines| lines[-2].include? '(6)' }220 tmux.send_keys "C-M"202- assert_equal %w[3 2 5 6 8 7], File.read(tempname).split($/)221+ assert_equal %w[3 2 5 6 8 7], readtemp.split($/)222 tmux.close223 end224 225 def test_with_nth1 unmodified line227 tmux.send_keys "(echo ' 1st 2nd 3rd/';228 echo ' first second third/') |229 fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname}",230 :Enter212- tmux.until { |lines| lines[-2] && lines[-2].include?('2/2') }231+ tmux.until { |lines| lines[-2].include?('2/2') }232 233 # Transformed list234 lines = tmux.capture235 assert_equal ' second third/first', lines[-4]1 unmodified line237 238 # However, the output must not be transformed239 if multi240 tmux.send_keys :BTab, :BTab, :Enter222- assert_equal [' 1st 2nd 3rd/', ' first second third/'], File.read(tempname).split($/)241+ assert_equal [' 1st 2nd 3rd/', ' first second third/'], readtemp.split($/)242 else243 tmux.send_keys '^', '3'244 tmux.until { |lines| lines[-2].include?('1/2') }245 tmux.send_keys :Enter246 tmux.send_keys 'echo -n done', :Enter247 tmux.until { |lines| lines[-1].include?('done') }229- assert_equal [' 1st 2nd 3rd/'], File.read(tempname).split($/)248+ assert_equal [' 1st 2nd 3rd/'], readtemp.split($/)249 end250 end251 end252 7 unmodified lines260 end261 tmux.send_keys :Enter262 tmux.send_keys 'echo -n done', :Enter263 tmux.until { |lines| lines[-1].include?('done') }245- assert_equal '100', File.read(tempname).chomp264+ assert_equal '100', readtemp.chomp265 end266 end267+268+ def test_select_1269+ tmux.send_keys "seq 1 100 | fzf --with-nth ..,.. --print-query -q 5555 -1 > #{tempname} && echo -n done", :Enter270+ tmux.until { |lines| lines[-1].include?('done') }271+ assert_equal ['5555', '55'], readtemp.split($/)272+ end273+274+ def test_exit_0275+ tmux.send_keys "seq 1 100 | fzf --with-nth ..,.. --print-query -q 555555 -0 > #{tempname} && echo -n done", :Enter276+ tmux.until { |lines| lines[-1].include?('done') }277+ assert_equal ['555555'], readtemp.split($/)278+ end279 end280