Test refactoring
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 8973207 · Browse files · 1 file·+9 added−29 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+9 added−29 removed
- tests:+9 added−29 removed
Provenance
- Commit
8b618f7- Tree
53f05c6- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
8973207
1 file changed+9 added−29 removed
modified:test/test_go.rb+9 added-29 removed
70 unmodified lines71 self.until { |lines| lines.empty? }72 end73 end74 75- def closed?76- !go("list-window -F '#I'").include?(win)77- end78-79- def close80- wait do81- send_keys 'C-c', 'C-u', 'exit', :Enter82- closed?83- end84- end85-75 def kill76 go("kill-window -t #{win} 2> /dev/null")77 end78 61 unmodified lines140 TEMPNAME = '/tmp/output'141 142 attr_reader :tmux143 144+ def tempname145+ [TEMPNAME,146+ caller_locations.map(&:label).find { |l| l =~ /^test_/ }].join '-'147+ end148+149 def setup150 ENV.delete 'FZF_DEFAULT_OPTS'151 ENV.delete 'FZF_DEFAULT_COMMAND'158- File.unlink TEMPNAME while File.exists?(TEMPNAME)152 end153 154 def readonce162- wait { File.exists?(TEMPNAME) }163- File.read(TEMPNAME)155+ wait { File.exists?(tempname) }156+ File.read(tempname)157 ensure165- File.unlink TEMPNAME while File.exists?(TEMPNAME)158+ File.unlink tempname while File.exists?(tempname)159 end160 161 def fzf(*opts)169- fzf!(*opts) + " > #{TEMPNAME}.tmp; mv #{TEMPNAME}.tmp #{TEMPNAME}"162+ fzf!(*opts) + " > #{tempname}.tmp; mv #{tempname}.tmp #{tempname}"163 end164 165 def fzf!(*opts)166 opts = opts.map { |o|39 unmodified lines206 assert_equal ' 856/100000', lines[-2]207 assert_equal '> 391', lines[-1]208 209 tmux.send_keys :Enter217- tmux.close210 assert_equal '1391', readonce.chomp211 end212 213 def test_fzf_default_command214 tmux.send_keys "FZF_DEFAULT_COMMAND='echo hello' #{fzf}", :Enter215 tmux.until { |lines| lines.last =~ /^>/ }216 217 tmux.send_keys :Enter226- tmux.close218 assert_equal 'hello', readonce.chomp219 end220 221 def test_key_bindings58 unmodified lines280 281 # CTRL-M282 tmux.send_keys "C-M"283 tmux.until { |lines| lines.last !~ /^>/ }293- tmux.close284 end285 286 def test_multi_order287 tmux.send_keys "seq 1 10 | #{fzf :multi}", :Enter4 unmodified lines292 :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7293 tmux.until { |lines| lines[-2].include? '(6)' }294 tmux.send_keys "C-M"295 assert_equal %w[3 2 5 6 8 7], readonce.split($/)306- tmux.close296 end297 298 def test_with_nth299 [true, false].each do |multi|142 unmodified lines442 end443 end444 445 def test_unicode_case457- tempname = TEMPNAME + Time.now.to_f.to_s446 writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]447 assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)448 assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)461- rescue462- File.unlink tempname449 end450 451 def test_tiebreak466- tempname = TEMPNAME + Time.now.to_f.to_s452 input = %w[453 --foobar--------454 -----foobar---455 ----foobar--28 unmodified lines484 --foobar--------485 ], `cat #{tempname} | #{FZF} -ffoobar --tiebreak end`.split($/)486 487 assert_equal input, `cat #{tempname} | #{FZF} -f"!z" -x --tiebreak end`.split($/)503- rescue504- File.unlink tempname488 end489 490 def test_invalid_cache491 tmux.send_keys "(echo d; echo D; echo x) | #{fzf '-q d'}", :Enter17 unmodified lines509 assert_equal %w[4 5 6 9], readonce.split($/)510 end511 512 def test_long_line530- tempname = TEMPNAME + Time.now.to_f.to_s513 data = '.' * 256 * 1024514 File.open(tempname, 'w') do |f|515 f << data516 end517 assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp536- ensure537- File.unlink tempname518 end519 520 def test_null521 lines = `find .`.split($/)287 unmodified lines