| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require_relative 'lib/common' |
| 4 |
|
| 5 |
# Testing basic features of fzf |
| 6 |
class TestCore < TestInteractive |
| 7 |
def test_fzf_default_command |
| 8 |
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter |
| 9 |
tmux.until { |lines| assert_equal '> hello', lines[-3] } |
| 10 |
|
| 11 |
tmux.send_keys :Enter |
| 12 |
assert_equal 'hello', fzf_output |
| 13 |
end |
| 14 |
|
| 15 |
def test_fzf_default_command_failure |
| 16 |
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter |
| 17 |
tmux.until { |lines| assert_includes lines[-2], ' [Command failed: false] ─' } |
| 18 |
tmux.send_keys :Enter |
| 19 |
end |
| 20 |
|
| 21 |
def test_key_bindings |
| 22 |
tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter |
| 23 |
tmux.until { |lines| assert_equal '> foo bar foo-bar', lines.last } |
| 24 |
|
| 25 |
# CTRL-A |
| 26 |
tmux.send_keys 'C-A', '(' |
| 27 |
tmux.until { |lines| assert_equal '> (foo bar foo-bar', lines.last } |
| 28 |
|
| 29 |
# META-F |
| 30 |
tmux.send_keys :Escape, :f, ')' |
| 31 |
tmux.until { |lines| assert_equal '> (foo) bar foo-bar', lines.last } |
| 32 |
|
| 33 |
# CTRL-B |
| 34 |
tmux.send_keys 'C-B', 'var' |
| 35 |
tmux.until { |lines| assert_equal '> (foovar) bar foo-bar', lines.last } |
| 36 |
|
| 37 |
# Left, CTRL-D |
| 38 |
tmux.send_keys :Left, :Left, 'C-D' |
| 39 |
tmux.until { |lines| assert_equal '> (foovr) bar foo-bar', lines.last } |
| 40 |
|
| 41 |
# META-BS |
| 42 |
tmux.send_keys :Escape, :BSpace |
| 43 |
tmux.until { |lines| assert_equal '> (r) bar foo-bar', lines.last } |
| 44 |
|
| 45 |
# CTRL-Y |
| 46 |
tmux.send_keys 'C-Y', 'C-Y' |
| 47 |
tmux.until { |lines| assert_equal '> (foovfoovr) bar foo-bar', lines.last } |
| 48 |
|
| 49 |
# META-B |
| 50 |
tmux.send_keys :Escape, :b, :Space, :Space |
| 51 |
tmux.until { |lines| assert_equal '> ( foovfoovr) bar foo-bar', lines.last } |
| 52 |
|
| 53 |
# CTRL-F / Right |
| 54 |
tmux.send_keys 'C-F', :Right, '/' |
| 55 |
tmux.until { |lines| assert_equal '> ( fo/ovfoovr) bar foo-bar', lines.last } |
| 56 |
|
| 57 |
# CTRL-H / BS |
| 58 |
tmux.send_keys 'C-H', :BSpace |
| 59 |
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-bar', lines.last } |
| 60 |
|
| 61 |
# CTRL-E |
| 62 |
tmux.send_keys 'C-E', 'baz' |
| 63 |
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last } |
| 64 |
|
| 65 |
# CTRL-U |
| 66 |
tmux.send_keys 'C-U' |
| 67 |
tmux.until { |lines| assert_equal '>', lines.last } |
| 68 |
|
| 69 |
# CTRL-Y |
| 70 |
tmux.send_keys 'C-Y' |
| 71 |
tmux.until { |lines| assert_equal '> ( fovfoovr) bar foo-barbaz', lines.last } |
| 72 |
|
| 73 |
# CTRL-W |
| 74 |
tmux.send_keys 'C-W', 'bar-foo' |
| 75 |
tmux.until { |lines| assert_equal '> ( fovfoovr) bar bar-foo', lines.last } |
| 76 |
|
| 77 |
# META-D |
| 78 |
tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, 'C-A', 'C-Y' |
| 79 |
tmux.until { |lines| assert_equal '> bar( fovfoovr) bar -foo', lines.last } |
| 80 |
|
| 81 |
# CTRL-M |
| 82 |
tmux.send_keys 'C-M' |
| 83 |
tmux.until { |lines| refute_equal '>', lines.last } |
| 84 |
end |
| 85 |
|
| 86 |
def test_file_word |
| 87 |
tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter |
| 88 |
tmux.until { |lines| assert_equal '> --/foo bar/foo-bar/baz', lines.last } |
| 89 |
|
| 90 |
tmux.send_keys :Escape, :b |
| 91 |
tmux.send_keys :Escape, :b |
| 92 |
tmux.send_keys :Escape, :b |
| 93 |
tmux.send_keys :Escape, :d |
| 94 |
tmux.send_keys :Escape, :f |
| 95 |
tmux.send_keys :Escape, :BSpace |
| 96 |
tmux.until { |lines| assert_equal '> --///baz', lines.last } |
| 97 |
end |
| 98 |
|
| 99 |
def test_multi_order |
| 100 |
tmux.send_keys "seq 1 10 | #{fzf(:multi)}", :Enter |
| 101 |
tmux.until { |lines| assert_equal '>', lines.last } |
| 102 |
|
| 103 |
tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2 |
| 104 |
'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6 |
| 105 |
:PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7 |
| 106 |
tmux.until { |lines| assert_equal ' 10/10 (6)', lines[-2] } |
| 107 |
tmux.send_keys 'C-M' |
| 108 |
assert_equal %w[3 2 5 6 8 7], fzf_output_lines |
| 109 |
end |
| 110 |
|
| 111 |
def test_subword_forward |
| 112 |
tmux.send_keys "#{FZF} --bind K:kill-subword,F:forward-subword -q 'foo bar foo-bar fooFooBar'", :Enter, :Home |
| 113 |
tmux.until { |lines| assert_equal '> foo bar foo-bar fooFooBar', lines.last } |
| 114 |
|
| 115 |
tmux.send_keys 'F', :Delete |
| 116 |
tmux.until { |lines| assert_equal '> foobar foo-bar fooFooBar', lines.last } |
| 117 |
|
| 118 |
tmux.send_keys 'K' |
| 119 |
tmux.until { |lines| assert_equal '> foo foo-bar fooFooBar', lines.last } |
| 120 |
|
| 121 |
tmux.send_keys 'F', 'K' |
| 122 |
tmux.until { |lines| assert_equal '> foo foo fooFooBar', lines.last } |
| 123 |
|
| 124 |
tmux.send_keys 'F', 'F', 'K' |
| 125 |
tmux.until { |lines| assert_equal '> foo foo fooFoo', lines.last } |
| 126 |
end |
| 127 |
|
| 128 |
def test_subword_backward |
| 129 |
tmux.send_keys "#{FZF} --bind K:backward-kill-subword,B:backward-subword -q 'foo bar foo-bar fooBar'", :Enter |
| 130 |
tmux.until { |lines| assert_equal '> foo bar foo-bar fooBar', lines.last } |
| 131 |
|
| 132 |
tmux.send_keys 'B', :BSpace |
| 133 |
tmux.until { |lines| assert_equal '> foo bar foo-bar foBar', lines.last } |
| 134 |
|
| 135 |
tmux.send_keys 'K' |
| 136 |
tmux.until { |lines| assert_equal '> foo bar foo-bar Bar', lines.last } |
| 137 |
|
| 138 |
tmux.send_keys 'B', :BSpace |
| 139 |
tmux.until { |lines| assert_equal '> foo bar foobar Bar', lines.last } |
| 140 |
|
| 141 |
tmux.send_keys 'B', 'B', :BSpace |
| 142 |
tmux.until { |lines| assert_equal '> foobar foobar Bar', lines.last } |
| 143 |
end |
| 144 |
|
| 145 |
def test_multi_max |
| 146 |
tmux.send_keys "seq 1 10 | #{FZF} -m 3 --bind A:select-all,T:toggle-all --preview 'echo [{+}]/{}'", :Enter |
| 147 |
|
| 148 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 149 |
|
| 150 |
tmux.send_keys '1' |
| 151 |
tmux.until do |lines| |
| 152 |
assert_includes lines[1], ' [1]/1 ' |
| 153 |
assert lines[-2]&.start_with?(' 2/10 ') |
| 154 |
end |
| 155 |
|
| 156 |
tmux.send_keys 'A' |
| 157 |
tmux.until do |lines| |
| 158 |
assert_includes lines[1], ' [1 10]/1 ' |
| 159 |
assert lines[-2]&.start_with?(' 2/10 (2/3)') |
| 160 |
end |
| 161 |
|
| 162 |
tmux.send_keys :BSpace |
| 163 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') } |
| 164 |
|
| 165 |
tmux.send_keys 'T' |
| 166 |
tmux.until do |lines| |
| 167 |
assert_includes lines[1], ' [2 3 4]/1 ' |
| 168 |
assert lines[-2]&.start_with?(' 10/10 (3/3)') |
| 169 |
end |
| 170 |
|
| 171 |
%w[T A].each do |key| |
| 172 |
tmux.send_keys key |
| 173 |
tmux.until do |lines| |
| 174 |
assert_includes lines[1], ' [1 5 6]/1 ' |
| 175 |
assert lines[-2]&.start_with?(' 10/10 (3/3)') |
| 176 |
end |
| 177 |
end |
| 178 |
|
| 179 |
tmux.send_keys :BTab |
| 180 |
tmux.until do |lines| |
| 181 |
assert_includes lines[1], ' [5 6]/2 ' |
| 182 |
assert lines[-2]&.start_with?(' 10/10 (2/3)') |
| 183 |
end |
| 184 |
|
| 185 |
[:BTab, :BTab, 'A'].each do |key| |
| 186 |
tmux.send_keys key |
| 187 |
tmux.until do |lines| |
| 188 |
assert_includes lines[1], ' [5 6 2]/3 ' |
| 189 |
assert lines[-2]&.start_with?(' 10/10 (3/3)') |
| 190 |
end |
| 191 |
end |
| 192 |
|
| 193 |
tmux.send_keys '2' |
| 194 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 1/10 (3/3)') } |
| 195 |
|
| 196 |
tmux.send_keys 'T' |
| 197 |
tmux.until do |lines| |
| 198 |
assert_includes lines[1], ' [5 6]/2 ' |
| 199 |
assert lines[-2]&.start_with?(' 1/10 (2/3)') |
| 200 |
end |
| 201 |
|
| 202 |
tmux.send_keys :BSpace |
| 203 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') } |
| 204 |
|
| 205 |
tmux.send_keys 'A' |
| 206 |
tmux.until do |lines| |
| 207 |
assert_includes lines[1], ' [5 6 1]/1 ' |
| 208 |
assert lines[-2]&.start_with?(' 10/10 (3/3)') |
| 209 |
end |
| 210 |
end |
| 211 |
|
| 212 |
def test_multi_action |
| 213 |
tmux.send_keys "seq 10 | #{FZF} --bind 'a:change-multi,b:change-multi(3),c:change-multi(xxx),d:change-multi(0)'", :Enter |
| 214 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 215 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 ') } |
| 216 |
tmux.send_keys 'a' |
| 217 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0)') } |
| 218 |
tmux.send_keys 'b' |
| 219 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (0/3)') } |
| 220 |
tmux.send_keys :BTab |
| 221 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (1/3)') } |
| 222 |
tmux.send_keys 'c' |
| 223 |
tmux.send_keys :BTab |
| 224 |
tmux.until { |lines| assert lines[-2]&.start_with?(' 10/10 (2/3)') } |
| 225 |
tmux.send_keys 'd' |
| 226 |
tmux.until do |lines| |
| 227 |
assert lines[-2]&.start_with?(' 10/10 ') && !lines[-2]&.include?('(') |
| 228 |
end |
| 229 |
end |
| 230 |
|
| 231 |
def test_with_nth |
| 232 |
[true, false].each do |multi| |
| 233 |
tmux.send_keys "(echo ' 1st 2nd 3rd/'; |
| 234 |
echo ' first second third/') | |
| 235 |
#{fzf(multi && :multi, :x, :nth, 2, :with_nth, '2,-1,1')}", |
| 236 |
:Enter |
| 237 |
tmux.until { |lines| assert_equal multi ? ' 2/2 (0)' : ' 2/2', lines[-2] } |
| 238 |
|
| 239 |
# Transformed list |
| 240 |
lines = tmux.capture |
| 241 |
assert_equal ' second third/first', lines[-4] |
| 242 |
assert_equal '> 2nd 3rd/1st', lines[-3] |
| 243 |
|
| 244 |
# However, the output must not be transformed |
| 245 |
if multi |
| 246 |
tmux.send_keys :BTab, :BTab |
| 247 |
tmux.until { |lines| assert_equal ' 2/2 (2)', lines[-2] } |
| 248 |
tmux.send_keys :Enter |
| 249 |
assert_equal [' 1st 2nd 3rd/', ' first second third/'], fzf_output_lines |
| 250 |
else |
| 251 |
tmux.send_keys '^', '3' |
| 252 |
tmux.until { |lines| assert_equal ' 1/2', lines[-2] } |
| 253 |
tmux.send_keys :Enter |
| 254 |
assert_equal [' 1st 2nd 3rd/'], fzf_output_lines |
| 255 |
end |
| 256 |
end |
| 257 |
end |
| 258 |
|
| 259 |
def test_scroll |
| 260 |
[true, false].each do |rev| |
| 261 |
tmux.send_keys "seq 1 100 | #{fzf(rev && :reverse)}", :Enter |
| 262 |
tmux.until { |lines| assert_equal ' 100/100', lines[rev ? 1 : -2] } |
| 263 |
tmux.send_keys(*Array.new(110) { rev ? :Down : :Up }) |
| 264 |
tmux.until { |lines| assert_includes lines, '> 100' } |
| 265 |
tmux.send_keys :Enter |
| 266 |
assert_equal '100', fzf_output |
| 267 |
end |
| 268 |
end |
| 269 |
|
| 270 |
def test_select_1 |
| 271 |
tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter |
| 272 |
assert_equal %w[5555 55], fzf_output_lines |
| 273 |
end |
| 274 |
|
| 275 |
def test_select_1_accept_nth |
| 276 |
tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1', :accept_nth, '"{1} // {1}"')}", :Enter |
| 277 |
assert_equal ['5555', '55 // 55'], fzf_output_lines |
| 278 |
end |
| 279 |
|
| 280 |
def test_exit_0 |
| 281 |
tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter |
| 282 |
assert_equal %w[555555], fzf_output_lines |
| 283 |
end |
| 284 |
|
| 285 |
def test_select_1_exit_0_fail |
| 286 |
[:'0', :'1', %i[1 0]].each do |opt| |
| 287 |
tmux.send_keys "seq 1 100 | #{fzf(:print_query, :multi, :q, 5, *opt)}", :Enter |
| 288 |
tmux.until { |lines| assert_equal '> 5', lines.last } |
| 289 |
tmux.send_keys :BTab, :BTab, :BTab |
| 290 |
tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] } |
| 291 |
tmux.send_keys :Enter |
| 292 |
assert_equal %w[5 5 50 51], fzf_output_lines |
| 293 |
end |
| 294 |
end |
| 295 |
|
| 296 |
def test_query_unicode |
| 297 |
tmux.paste "(echo abc; echo $'\\352\\260\\200\\353\\202\\230\\353\\213\\244') | #{fzf(:query, "$'\\352\\260\\200\\353\\213\\244'")}" |
| 298 |
tmux.until { |lines| assert_equal ' 1/2', lines[-2] } |
| 299 |
tmux.send_keys :Enter |
| 300 |
assert_equal %w[가나다], fzf_output_lines |
| 301 |
end |
| 302 |
|
| 303 |
def test_sync |
| 304 |
tmux.send_keys "seq 1 100 | #{FZF} --multi | awk '{print $1 $1}' | #{fzf(:sync)}", :Enter |
| 305 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 306 |
tmux.send_keys 9 |
| 307 |
tmux.until { |lines| assert_equal ' 19/100 (0)', lines[-2] } |
| 308 |
tmux.send_keys :BTab, :BTab, :BTab |
| 309 |
tmux.until { |lines| assert_equal ' 19/100 (3)', lines[-2] } |
| 310 |
tmux.send_keys :Enter |
| 311 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 312 |
tmux.send_keys 'C-K', :Enter |
| 313 |
assert_equal %w[9090], fzf_output_lines |
| 314 |
end |
| 315 |
|
| 316 |
def test_tac |
| 317 |
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter |
| 318 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 319 |
tmux.send_keys :BTab, :BTab, :BTab |
| 320 |
tmux.until { |lines| assert_equal ' 1000/1000 (3)', lines[-2] } |
| 321 |
tmux.send_keys :Enter |
| 322 |
assert_equal %w[1000 999 998], fzf_output_lines |
| 323 |
end |
| 324 |
|
| 325 |
def test_tac_sort |
| 326 |
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :multi)}", :Enter |
| 327 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 328 |
tmux.send_keys '99' |
| 329 |
tmux.until { |lines| assert_equal ' 28/1000 (0)', lines[-2] } |
| 330 |
tmux.send_keys :BTab, :BTab, :BTab |
| 331 |
tmux.until { |lines| assert_equal ' 28/1000 (3)', lines[-2] } |
| 332 |
tmux.send_keys :Enter |
| 333 |
assert_equal %w[99 999 998], fzf_output_lines |
| 334 |
end |
| 335 |
|
| 336 |
def test_tac_nosort |
| 337 |
tmux.send_keys "seq 1 1000 | #{fzf(:tac, :no_sort, :multi)}", :Enter |
| 338 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 339 |
tmux.send_keys '00' |
| 340 |
tmux.until { |lines| assert_equal ' 10/1000 (0)', lines[-2] } |
| 341 |
tmux.send_keys :BTab, :BTab, :BTab |
| 342 |
tmux.until { |lines| assert_equal ' 10/1000 (3)', lines[-2] } |
| 343 |
tmux.send_keys :Enter |
| 344 |
assert_equal %w[1000 900 800], fzf_output_lines |
| 345 |
end |
| 346 |
|
| 347 |
def test_expect |
| 348 |
test = lambda do |key, feed, expected = key| |
| 349 |
tmux.send_keys "seq 1 100 | #{fzf(:expect, key, :prompt, "[#{key}]")}", :Enter |
| 350 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 351 |
tmux.send_keys '55' |
| 352 |
tmux.until { |lines| assert_equal ' 1/100', lines[-2] } |
| 353 |
tmux.send_keys(*feed) |
| 354 |
tmux.prepare |
| 355 |
assert_equal [expected, '55'], fzf_output_lines |
| 356 |
end |
| 357 |
test.call('ctrl-t', 'C-T') |
| 358 |
test.call('ctrl-t', 'Enter', '') |
| 359 |
test.call('alt-c', %i[Escape c]) |
| 360 |
test.call('f1', 'f1') |
| 361 |
test.call('f2', 'f2') |
| 362 |
test.call('f3', 'f3') |
| 363 |
test.call('f2,f4', 'f2', 'f2') |
| 364 |
test.call('f2,f4', 'f4', 'f4') |
| 365 |
test.call('alt-/', %i[Escape /]) |
| 366 |
%w[f5 f6 f7 f8 f9 f10].each do |key| |
| 367 |
test.call('f5,f6,f7,f8,f9,f10', key, key) |
| 368 |
end |
| 369 |
test.call('@', '@') |
| 370 |
end |
| 371 |
|
| 372 |
def test_expect_with_bound_actions |
| 373 |
tmux.send_keys "seq 1 100 | #{fzf('--query 1 --print-query --expect z --bind z:up+up')}", :Enter |
| 374 |
tmux.until { |lines| assert_equal 20, lines.match_count } |
| 375 |
tmux.send_keys('z') |
| 376 |
assert_equal %w[1 z 1], fzf_output_lines |
| 377 |
end |
| 378 |
|
| 379 |
def test_expect_print_query |
| 380 |
tmux.send_keys "seq 1 100 | #{fzf('--expect=alt-z', :print_query)}", :Enter |
| 381 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 382 |
tmux.send_keys '55' |
| 383 |
tmux.until { |lines| assert_equal ' 1/100', lines[-2] } |
| 384 |
tmux.send_keys :Escape, :z |
| 385 |
assert_equal %w[55 alt-z 55], fzf_output_lines |
| 386 |
end |
| 387 |
|
| 388 |
def test_expect_printable_character_print_query |
| 389 |
tmux.send_keys "seq 1 100 | #{fzf('--expect=z --print-query')}", :Enter |
| 390 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 391 |
tmux.send_keys '55' |
| 392 |
tmux.until { |lines| assert_equal ' 1/100', lines[-2] } |
| 393 |
tmux.send_keys 'z' |
| 394 |
assert_equal %w[55 z 55], fzf_output_lines |
| 395 |
end |
| 396 |
|
| 397 |
def test_expect_print_query_select_1 |
| 398 |
tmux.send_keys "seq 1 100 | #{fzf('-q55 -1 --expect=alt-z --print-query')}", :Enter |
| 399 |
assert_equal ['55', '', '55'], fzf_output_lines |
| 400 |
end |
| 401 |
|
| 402 |
def test_toggle_sort |
| 403 |
['--toggle-sort=ctrl-r', '--bind=ctrl-r:toggle-sort'].each do |opt| |
| 404 |
tmux.send_keys "seq 1 111 | #{fzf("-m +s --tac #{opt} -q11")}", :Enter |
| 405 |
tmux.until { |lines| assert_equal '> 111', lines[-3] } |
| 406 |
tmux.send_keys :Tab |
| 407 |
tmux.until { |lines| assert_equal ' 4/111 (1) -S', lines[-2] } |
| 408 |
tmux.send_keys 'C-R' |
| 409 |
tmux.until { |lines| assert_equal '> 11', lines[-3] } |
| 410 |
tmux.send_keys :Tab |
| 411 |
tmux.until { |lines| assert_equal ' 4/111 (2) +S', lines[-2] } |
| 412 |
tmux.send_keys :Enter |
| 413 |
assert_equal %w[111 11], fzf_output_lines |
| 414 |
end |
| 415 |
end |
| 416 |
|
| 417 |
def test_invalid_cache |
| 418 |
tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter |
| 419 |
tmux.until { |lines| assert_equal ' 2/3', lines[-2] } |
| 420 |
tmux.send_keys :BSpace |
| 421 |
tmux.until { |lines| assert_equal ' 3/3', lines[-2] } |
| 422 |
tmux.send_keys :D |
| 423 |
tmux.until { |lines| assert_equal ' 1/3', lines[-2] } |
| 424 |
tmux.send_keys :Enter |
| 425 |
end |
| 426 |
|
| 427 |
def test_invalid_cache_query_type |
| 428 |
command = %[(echo 'foo$bar'; echo 'barfoo'; echo 'foo^bar'; echo "foo'1-2"; seq 100) | #{FZF}] |
| 429 |
|
| 430 |
# Suffix match |
| 431 |
tmux.send_keys command, :Enter |
| 432 |
tmux.until { |lines| assert_equal 104, lines.match_count } |
| 433 |
tmux.send_keys 'foo$' |
| 434 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 435 |
tmux.send_keys 'bar' |
| 436 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 437 |
tmux.send_keys :Enter |
| 438 |
|
| 439 |
# Prefix match |
| 440 |
tmux.prepare |
| 441 |
tmux.send_keys command, :Enter |
| 442 |
tmux.until { |lines| assert_equal 104, lines.match_count } |
| 443 |
tmux.send_keys '^bar' |
| 444 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 445 |
tmux.send_keys 'C-a', 'foo' |
| 446 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 447 |
tmux.send_keys :Enter |
| 448 |
|
| 449 |
# Exact match |
| 450 |
tmux.prepare |
| 451 |
tmux.send_keys command, :Enter |
| 452 |
tmux.until { |lines| assert_equal 104, lines.match_count } |
| 453 |
tmux.send_keys "'12" |
| 454 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 455 |
tmux.send_keys 'C-a', 'foo' |
| 456 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 457 |
end |
| 458 |
|
| 459 |
def test_bind |
| 460 |
tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:accept,u,:,U:up,X,,,Z:toggle-up,t:toggle')}", :Enter |
| 461 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 462 |
tmux.send_keys 'uU:', 'X,Z', 'tt', 'uu', 'ttt', 'C-j' |
| 463 |
assert_equal %w[4 5 6 9], fzf_output_lines |
| 464 |
end |
| 465 |
|
| 466 |
def test_bind_print_query |
| 467 |
tmux.send_keys "seq 1 1000 | #{fzf('-m --bind=ctrl-j:print-query')}", :Enter |
| 468 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 469 |
tmux.send_keys 'print-my-query', 'C-j' |
| 470 |
assert_equal %w[print-my-query], fzf_output_lines |
| 471 |
end |
| 472 |
|
| 473 |
def test_bind_replace_query |
| 474 |
tmux.send_keys "seq 1 1000 | #{fzf('--print-query --bind=ctrl-j:replace-query')}", :Enter |
| 475 |
tmux.send_keys '1' |
| 476 |
tmux.until { |lines| assert_equal ' 272/1000', lines[-2] } |
| 477 |
tmux.send_keys 'C-k', 'C-j' |
| 478 |
tmux.until { |lines| assert_equal ' 29/1000', lines[-2] } |
| 479 |
tmux.until { |lines| assert_equal '> 10', lines[-1] } |
| 480 |
end |
| 481 |
|
| 482 |
def test_bind_replace_query_does_not_mutate_item |
| 483 |
tmux.send_keys "echo '한글abcde' | #{fzf('--bind=ctrl-j:replace-query,ctrl-o:clear-query')}", :Enter |
| 484 |
tmux.until { |lines| assert_equal ' 1/1', lines[-2] } |
| 485 |
tmux.send_keys 'C-j' |
| 486 |
tmux.until { |lines| assert_equal '> 한글abcde', lines[-1] } |
| 487 |
# Editing away from the end used to write into the item itself |
| 488 |
tmux.send_keys :Left, :BSpace |
| 489 |
tmux.until { |lines| assert_equal '> 한글abce', lines[-1] } |
| 490 |
tmux.send_keys 'C-o' |
| 491 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 492 |
tmux.until { |lines| assert_equal '> 한글abcde', lines[-3] } |
| 493 |
end |
| 494 |
|
| 495 |
def test_select_all_deselect_all_toggle_all |
| 496 |
tmux.send_keys "seq 100 | #{fzf('--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all --multi')}", :Enter |
| 497 |
tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] } |
| 498 |
tmux.send_keys :BTab, :BTab, :BTab |
| 499 |
tmux.until { |lines| assert_equal ' 100/100 (3)', lines[-2] } |
| 500 |
tmux.send_keys 'C-t' |
| 501 |
tmux.until { |lines| assert_equal ' 100/100 (97)', lines[-2] } |
| 502 |
tmux.send_keys 'C-a' |
| 503 |
tmux.until { |lines| assert_equal ' 100/100 (100)', lines[-2] } |
| 504 |
tmux.send_keys :Tab, :Tab |
| 505 |
tmux.until { |lines| assert_equal ' 100/100 (98)', lines[-2] } |
| 506 |
tmux.send_keys '100' |
| 507 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 508 |
tmux.send_keys 'C-d' |
| 509 |
tmux.until { |lines| assert_equal ' 1/100 (97)', lines[-2] } |
| 510 |
tmux.send_keys 'C-u' |
| 511 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 512 |
tmux.send_keys 'C-d' |
| 513 |
tmux.until { |lines| assert_equal ' 100/100 (0)', lines[-2] } |
| 514 |
tmux.send_keys :BTab, :BTab |
| 515 |
tmux.until { |lines| assert_equal ' 100/100 (2)', lines[-2] } |
| 516 |
tmux.send_keys 0 |
| 517 |
tmux.until { |lines| assert_equal ' 10/100 (2)', lines[-2] } |
| 518 |
tmux.send_keys 'C-a' |
| 519 |
tmux.until { |lines| assert_equal ' 10/100 (12)', lines[-2] } |
| 520 |
tmux.send_keys :Enter |
| 521 |
assert_equal %w[1 2 10 20 30 40 50 60 70 80 90 100], |
| 522 |
fzf_output_lines |
| 523 |
end |
| 524 |
|
| 525 |
def test_history |
| 526 |
history_file = '/tmp/fzf-test-history' |
| 527 |
|
| 528 |
# History with limited number of entries |
| 529 |
FileUtils.rm_f(history_file) |
| 530 |
opts = "--history=#{history_file} --history-size=4" |
| 531 |
input = %w[00 11 22 33 44] |
| 532 |
input.each do |keys| |
| 533 |
tmux.prepare |
| 534 |
tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter |
| 535 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 536 |
tmux.send_keys keys |
| 537 |
tmux.until { |lines| assert_equal ' 1/100', lines[-2] } |
| 538 |
tmux.send_keys :Enter |
| 539 |
end |
| 540 |
wait do |
| 541 |
assert_path_exists history_file |
| 542 |
assert_equal input[1..], File.readlines(history_file, chomp: true) |
| 543 |
end |
| 544 |
|
| 545 |
# Update history entries (not changed on disk) |
| 546 |
tmux.send_keys "seq 100 | #{FZF} #{opts}", :Enter |
| 547 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 548 |
tmux.send_keys 'C-p' |
| 549 |
tmux.until { |lines| assert_equal '> 44', lines[-1] } |
| 550 |
tmux.send_keys 'C-p' |
| 551 |
tmux.until { |lines| assert_equal '> 33', lines[-1] } |
| 552 |
tmux.send_keys :BSpace |
| 553 |
tmux.until { |lines| assert_equal '> 3', lines[-1] } |
| 554 |
tmux.send_keys 1 |
| 555 |
tmux.until { |lines| assert_equal '> 31', lines[-1] } |
| 556 |
tmux.send_keys 'C-p' |
| 557 |
tmux.until { |lines| assert_equal '> 22', lines[-1] } |
| 558 |
tmux.send_keys 'C-n' |
| 559 |
tmux.until { |lines| assert_equal '> 31', lines[-1] } |
| 560 |
tmux.send_keys 0 |
| 561 |
tmux.until { |lines| assert_equal '> 310', lines[-1] } |
| 562 |
tmux.send_keys :Enter |
| 563 |
wait do |
| 564 |
assert_path_exists history_file |
| 565 |
assert_equal %w[22 33 44 310], File.readlines(history_file, chomp: true) |
| 566 |
end |
| 567 |
|
| 568 |
# Respect --bind option |
| 569 |
tmux.send_keys "seq 100 | #{FZF} #{opts} --bind ctrl-p:next-history,ctrl-n:previous-history", :Enter |
| 570 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 571 |
tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p' |
| 572 |
tmux.until { |lines| assert_equal '> 33', lines[-1] } |
| 573 |
tmux.send_keys :Enter |
| 574 |
ensure |
| 575 |
FileUtils.rm_f(history_file) |
| 576 |
end |
| 577 |
|
| 578 |
def test_cycle |
| 579 |
tmux.send_keys "seq 8 | #{FZF} --cycle", :Enter |
| 580 |
tmux.until { |lines| assert_equal ' 8/8', lines[-2] } |
| 581 |
tmux.send_keys :Down |
| 582 |
tmux.until { |lines| assert_equal '> 8', lines[-10] } |
| 583 |
tmux.send_keys :Down |
| 584 |
tmux.until { |lines| assert_equal '> 7', lines[-9] } |
| 585 |
tmux.send_keys :Up |
| 586 |
tmux.until { |lines| assert_equal '> 8', lines[-10] } |
| 587 |
tmux.send_keys :PgUp |
| 588 |
tmux.until { |lines| assert_equal '> 8', lines[-10] } |
| 589 |
tmux.send_keys :Up |
| 590 |
tmux.until { |lines| assert_equal '> 1', lines[-3] } |
| 591 |
tmux.send_keys :PgDn |
| 592 |
tmux.until { |lines| assert_equal '> 1', lines[-3] } |
| 593 |
tmux.send_keys :Down |
| 594 |
tmux.until { |lines| assert_equal '> 8', lines[-10] } |
| 595 |
end |
| 596 |
|
| 597 |
def test_header_lines |
| 598 |
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5')}", :Enter |
| 599 |
2.times do |
| 600 |
tmux.until do |lines| |
| 601 |
assert_equal ' 18/90', lines[-2] |
| 602 |
assert_equal ' 1', lines[-3] |
| 603 |
assert_equal ' 2', lines[-4] |
| 604 |
assert_equal '> 50', lines[-13] |
| 605 |
end |
| 606 |
tmux.send_keys :Down |
| 607 |
end |
| 608 |
tmux.send_keys :Enter |
| 609 |
assert_equal '50', fzf_output |
| 610 |
end |
| 611 |
|
| 612 |
def test_header_lines_reverse |
| 613 |
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --reverse')}", :Enter |
| 614 |
2.times do |
| 615 |
tmux.until do |lines| |
| 616 |
assert_equal ' 18/90', lines[1] |
| 617 |
assert_equal ' 1', lines[2] |
| 618 |
assert_equal ' 2', lines[3] |
| 619 |
assert_equal '> 50', lines[12] |
| 620 |
end |
| 621 |
tmux.send_keys :Up |
| 622 |
end |
| 623 |
tmux.send_keys :Enter |
| 624 |
assert_equal '50', fzf_output |
| 625 |
end |
| 626 |
|
| 627 |
def test_header_lines_reverse_list |
| 628 |
tmux.send_keys "seq 100 | #{fzf('--header-lines=10 -q 5 --layout=reverse-list')}", :Enter |
| 629 |
2.times do |
| 630 |
tmux.until do |lines| |
| 631 |
assert_equal ' 9', lines[8] |
| 632 |
assert_equal ' 10', lines[9] |
| 633 |
assert_equal '> 50', lines[10] |
| 634 |
assert_equal ' 18/90', lines[-2] |
| 635 |
end |
| 636 |
tmux.send_keys :Up |
| 637 |
end |
| 638 |
tmux.send_keys :Enter |
| 639 |
assert_equal '50', fzf_output |
| 640 |
end |
| 641 |
|
| 642 |
def test_header_lines_overflow |
| 643 |
tmux.send_keys "seq 100 | #{fzf('--header-lines=200')}", :Enter |
| 644 |
tmux.until do |lines| |
| 645 |
assert_equal ' 0/0', lines[-2] |
| 646 |
assert_equal ' 1', lines[-3] |
| 647 |
end |
| 648 |
tmux.send_keys :Enter |
| 649 |
assert_equal '', fzf_output |
| 650 |
end |
| 651 |
|
| 652 |
def test_header_lines_with_nth |
| 653 |
tmux.send_keys "seq 100 | #{fzf('--header-lines 5 --with-nth 1,1,1,1,1')}", :Enter |
| 654 |
tmux.until do |lines| |
| 655 |
assert_equal ' 95/95', lines[-2] |
| 656 |
assert_equal ' 11111', lines[-3] |
| 657 |
assert_equal ' 55555', lines[-7] |
| 658 |
assert_equal '> 66666', lines[-8] |
| 659 |
end |
| 660 |
tmux.send_keys :Enter |
| 661 |
assert_equal '6', fzf_output |
| 662 |
end |
| 663 |
|
| 664 |
def test_header |
| 665 |
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})"], :Enter |
| 666 |
header = File.readlines(FILE, chomp: true).take(5) |
| 667 |
tmux.until do |lines| |
| 668 |
assert_equal ' 100/100', lines[-2] |
| 669 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3] |
| 670 |
assert_equal '> 1', lines[-8] |
| 671 |
end |
| 672 |
end |
| 673 |
|
| 674 |
def test_header_reverse |
| 675 |
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --reverse], :Enter |
| 676 |
header = File.readlines(FILE, chomp: true).take(5) |
| 677 |
tmux.until do |lines| |
| 678 |
assert_equal ' 100/100', lines[1] |
| 679 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[2..6] |
| 680 |
assert_equal '> 1', lines[7] |
| 681 |
end |
| 682 |
end |
| 683 |
|
| 684 |
def test_header_reverse_list |
| 685 |
tmux.send_keys %[seq 100 | #{FZF} --header "$(head -5 #{FILE})" --layout=reverse-list], :Enter |
| 686 |
header = File.readlines(FILE, chomp: true).take(5) |
| 687 |
tmux.until do |lines| |
| 688 |
assert_equal ' 100/100', lines[-2] |
| 689 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7..-3] |
| 690 |
assert_equal '> 1', lines[0] |
| 691 |
end |
| 692 |
end |
| 693 |
|
| 694 |
def test_header_and_header_lines |
| 695 |
tmux.send_keys %[seq 100 | #{FZF} --header-lines 10 --header "$(head -5 #{FILE})"], :Enter |
| 696 |
header = File.readlines(FILE, chomp: true).take(5) |
| 697 |
tmux.until do |lines| |
| 698 |
assert_equal ' 90/90', lines[-2] |
| 699 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2] |
| 700 |
assert_equal (' 1'..' 10').to_a.reverse, lines[-17...-7] |
| 701 |
end |
| 702 |
end |
| 703 |
|
| 704 |
def test_header_and_header_lines_reverse |
| 705 |
tmux.send_keys %[seq 100 | #{FZF} --reverse --header-lines 10 --header "$(head -5 #{FILE})"], :Enter |
| 706 |
header = File.readlines(FILE, chomp: true).take(5) |
| 707 |
tmux.until do |lines| |
| 708 |
assert_equal ' 90/90', lines[1] |
| 709 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[2...7] |
| 710 |
assert_equal (' 1'..' 10').to_a, lines[7...17] |
| 711 |
end |
| 712 |
end |
| 713 |
|
| 714 |
def test_header_and_header_lines_reverse_list |
| 715 |
tmux.send_keys %[seq 100 | #{FZF} --layout=reverse-list --header-lines 10 --header "$(head -5 #{FILE})"], :Enter |
| 716 |
header = File.readlines(FILE, chomp: true).take(5) |
| 717 |
tmux.until do |lines| |
| 718 |
assert_equal ' 90/90', lines[-2] |
| 719 |
assert_equal header.map { |line| " #{line}".rstrip }, lines[-7...-2] |
| 720 |
assert_equal (' 1'..' 10').to_a, lines.take(10) |
| 721 |
end |
| 722 |
end |
| 723 |
|
| 724 |
def test_cancel |
| 725 |
tmux.send_keys "seq 10 | #{FZF} --bind 2:cancel", :Enter |
| 726 |
tmux.until { |lines| assert_equal ' 10/10', lines[-2] } |
| 727 |
tmux.send_keys '123' |
| 728 |
tmux.until do |lines| |
| 729 |
assert_equal '> 3', lines[-1] |
| 730 |
assert_equal ' 1/10', lines[-2] |
| 731 |
end |
| 732 |
tmux.send_keys 'C-y', 'C-y' |
| 733 |
tmux.until { |lines| assert_equal '> 311', lines[-1] } |
| 734 |
tmux.send_keys 2 |
| 735 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 736 |
tmux.send_keys 2 |
| 737 |
tmux.prepare |
| 738 |
end |
| 739 |
|
| 740 |
def test_margin |
| 741 |
tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3", :Enter |
| 742 |
tmux.until do |lines| |
| 743 |
assert_equal '', lines[4] |
| 744 |
assert_equal ' y', lines[5] |
| 745 |
end |
| 746 |
tmux.send_keys :Enter |
| 747 |
end |
| 748 |
|
| 749 |
def test_margin_reverse |
| 750 |
tmux.send_keys "seq 1000 | #{FZF} --margin 7,5 --reverse", :Enter |
| 751 |
tmux.until { |lines| assert_equal ' 1000/1000', lines[1 + 7] } |
| 752 |
tmux.send_keys :Enter |
| 753 |
end |
| 754 |
|
| 755 |
def test_margin_reverse_list |
| 756 |
tmux.send_keys "yes | head -1000 | #{FZF} --margin 5,3 --layout=reverse-list", :Enter |
| 757 |
tmux.until do |lines| |
| 758 |
assert_equal '', lines[4] |
| 759 |
assert_equal ' > y', lines[5] |
| 760 |
end |
| 761 |
tmux.send_keys :Enter |
| 762 |
end |
| 763 |
|
| 764 |
def test_tabstop |
| 765 |
writelines(%W[f\too\tba\tr\tbaz\tbarfooq\tux]) |
| 766 |
{ |
| 767 |
1 => '> f oo ba r baz barfooq ux', |
| 768 |
2 => '> f oo ba r baz barfooq ux', |
| 769 |
3 => '> f oo ba r baz barfooq ux', |
| 770 |
4 => '> f oo ba r baz barfooq ux', |
| 771 |
5 => '> f oo ba r baz barfooq ux', |
| 772 |
6 => '> f oo ba r baz barfooq ux', |
| 773 |
7 => '> f oo ba r baz barfooq ux', |
| 774 |
8 => '> f oo ba r baz barfooq ux', |
| 775 |
9 => '> f oo ba r baz barfooq ux' |
| 776 |
}.each do |ts, exp| |
| 777 |
tmux.prepare |
| 778 |
tmux.send_keys %(cat #{tempname} | fzf --tabstop=#{ts}), :Enter |
| 779 |
tmux.until(true) do |lines| |
| 780 |
assert_equal exp, lines[-3] |
| 781 |
end |
| 782 |
tmux.send_keys :Enter |
| 783 |
end |
| 784 |
end |
| 785 |
|
| 786 |
def test_exit_0_exit_code |
| 787 |
`echo foo | #{FZF} -q bar -0` |
| 788 |
assert_equal 1, $CHILD_STATUS.exitstatus |
| 789 |
end |
| 790 |
|
| 791 |
def test_invalid_option |
| 792 |
lines = `#{FZF} --foobar 2>&1` |
| 793 |
assert_equal 2, $CHILD_STATUS.exitstatus |
| 794 |
assert_includes lines, 'unknown option: --foobar' |
| 795 |
end |
| 796 |
|
| 797 |
def test_exitstatus_empty |
| 798 |
{ '99' => '0', '999' => '1' }.each do |query, status| |
| 799 |
tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --$?--", :Enter |
| 800 |
tmux.until { |lines| assert_match %r{ [10]/100}, lines[-2] } |
| 801 |
tmux.send_keys :Enter |
| 802 |
tmux.until { |lines| assert_equal "--#{status}--", lines.last } |
| 803 |
end |
| 804 |
end |
| 805 |
|
| 806 |
def test_hscroll_off |
| 807 |
writelines([('=' * 10_000) + '0123456789']) |
| 808 |
[0, 3, 6].each do |off| |
| 809 |
tmux.prepare |
| 810 |
tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 --bind space:toggle-hscroll < #{tempname}", :Enter |
| 811 |
tmux.until { |lines| assert lines[-3]&.end_with?((0..off).to_a.join + '··') } |
| 812 |
tmux.send_keys '9' |
| 813 |
tmux.until { |lines| assert lines[-3]&.end_with?('789') } |
| 814 |
tmux.send_keys :Space |
| 815 |
tmux.until { |lines| assert lines[-3]&.end_with?('=··') } |
| 816 |
tmux.send_keys :Space |
| 817 |
tmux.until { |lines| assert lines[-3]&.end_with?('789') } |
| 818 |
tmux.send_keys :Enter |
| 819 |
end |
| 820 |
end |
| 821 |
|
| 822 |
def test_partial_caching |
| 823 |
tmux.send_keys 'seq 1000 | fzf -e', :Enter |
| 824 |
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } |
| 825 |
tmux.send_keys 11 |
| 826 |
tmux.until { |lines| assert_equal ' 19/1000', lines[-2] } |
| 827 |
tmux.send_keys 'C-a', "'" |
| 828 |
tmux.until { |lines| assert_equal ' 28/1000', lines[-2] } |
| 829 |
tmux.send_keys :Enter |
| 830 |
end |
| 831 |
|
| 832 |
def test_jump |
| 833 |
tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump'")}", :Enter |
| 834 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 835 |
tmux.send_keys 'C-j' |
| 836 |
tmux.until { |lines| assert_equal '5 5', lines[-7] } |
| 837 |
tmux.until { |lines| assert_equal ' 6', lines[-8] } |
| 838 |
tmux.send_keys '5' |
| 839 |
tmux.until { |lines| assert_equal '> 5', lines[-7] } |
| 840 |
tmux.send_keys :Tab |
| 841 |
tmux.until { |lines| assert_equal ' >5', lines[-7] } |
| 842 |
tmux.send_keys 'C-j' |
| 843 |
tmux.until { |lines| assert_equal '5>5', lines[-7] } |
| 844 |
tmux.send_keys '2' |
| 845 |
tmux.until { |lines| assert_equal '> 2', lines[-4] } |
| 846 |
tmux.send_keys :Tab |
| 847 |
tmux.until { |lines| assert_equal ' >2', lines[-4] } |
| 848 |
tmux.send_keys 'C-j' |
| 849 |
tmux.until { |lines| assert_equal '5>5', lines[-7] } |
| 850 |
|
| 851 |
# Press any key other than jump labels to cancel jump |
| 852 |
tmux.send_keys '6' |
| 853 |
tmux.until { |lines| assert_equal '> 1', lines[-3] } |
| 854 |
tmux.send_keys :Tab |
| 855 |
tmux.until { |lines| assert_equal '>>1', lines[-3] } |
| 856 |
tmux.send_keys :Enter |
| 857 |
assert_equal %w[5 2 1], fzf_output_lines |
| 858 |
end |
| 859 |
|
| 860 |
def test_jump_accept |
| 861 |
tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump-accept'")}", :Enter |
| 862 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 863 |
tmux.send_keys 'C-j' |
| 864 |
tmux.until { |lines| assert_equal '5 5', lines[-7] } |
| 865 |
tmux.send_keys '3' |
| 866 |
assert_equal '3', fzf_output |
| 867 |
end |
| 868 |
|
| 869 |
def test_jump_events |
| 870 |
tmux.send_keys "seq 1000 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump,jump:preview(echo jumped to {}),jump-cancel:preview(echo jump cancelled at {})'", :Enter |
| 871 |
tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] } |
| 872 |
tmux.send_keys 'C-j' |
| 873 |
tmux.until { |lines| assert_includes lines[-7], '5 5' } |
| 874 |
tmux.send_keys '3' |
| 875 |
tmux.until { |lines| assert(lines.any? { it.include?('jumped to 3') }) } |
| 876 |
tmux.send_keys 'C-j' |
| 877 |
tmux.until { |lines| assert_includes lines[-7], '5 5' } |
| 878 |
tmux.send_keys 'C-c' |
| 879 |
tmux.until { |lines| assert(lines.any? { it.include?('jump cancelled at 3') }) } |
| 880 |
end |
| 881 |
|
| 882 |
def test_jump_no_pointer |
| 883 |
tmux.send_keys "seq 100 | #{FZF} --pointer= --jump-labels 12345 --bind ctrl-j:jump", :Enter |
| 884 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 885 |
tmux.send_keys 'C-j' |
| 886 |
tmux.until { |lines| assert_equal '5 5', lines[-7] } |
| 887 |
tmux.send_keys 'C-c' |
| 888 |
tmux.until { |lines| assert_equal ' 5', lines[-7] } |
| 889 |
end |
| 890 |
|
| 891 |
def test_jump_no_pointer_no_marker |
| 892 |
tmux.send_keys "seq 100 | #{FZF} --pointer= --marker= --jump-labels 12345 --bind ctrl-j:jump", :Enter |
| 893 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 894 |
tmux.send_keys 'C-j' |
| 895 |
tmux.until { |lines| assert_equal '55', lines[-7] } |
| 896 |
tmux.send_keys 'C-c' |
| 897 |
tmux.until { |lines| assert_equal '5', lines[-7] } |
| 898 |
end |
| 899 |
|
| 900 |
def test_pointer |
| 901 |
tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter |
| 902 |
# Assert that specified pointer is displayed |
| 903 |
tmux.until { |lines| assert_equal '>> 1', lines[-3] } |
| 904 |
end |
| 905 |
|
| 906 |
def test_pointer_with_jump |
| 907 |
tmux.send_keys "seq 10 | #{FZF} --multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '>>'", :Enter |
| 908 |
tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] } |
| 909 |
tmux.send_keys 'C-j' |
| 910 |
# Correctly padded jump label should appear |
| 911 |
tmux.until { |lines| assert_equal '5 5', lines[-7] } |
| 912 |
tmux.until { |lines| assert_equal ' 6', lines[-8] } |
| 913 |
tmux.send_keys '5' |
| 914 |
# Assert that specified pointer is displayed |
| 915 |
tmux.until { |lines| assert_equal '>> 5', lines[-7] } |
| 916 |
end |
| 917 |
|
| 918 |
def test_marker |
| 919 |
tmux.send_keys "seq 10 | #{FZF} --multi --marker '>>'", :Enter |
| 920 |
tmux.until { |lines| assert_equal ' 10/10 (0)', lines[-2] } |
| 921 |
tmux.send_keys :BTab |
| 922 |
# Assert that specified marker is displayed |
| 923 |
tmux.until { |lines| assert_equal ' >>1', lines[-3] } |
| 924 |
end |
| 925 |
|
| 926 |
def test_no_clear |
| 927 |
tmux.send_keys "seq 10 | #{fzf('--no-clear --inline-info --height 5')}", :Enter |
| 928 |
prompt = '> < 10/10' |
| 929 |
tmux.until { |lines| assert_equal prompt, lines[-1] } |
| 930 |
tmux.send_keys :Enter |
| 931 |
assert_equal %w[1], fzf_output_lines |
| 932 |
tmux.until { |lines| assert_equal prompt, lines[-1] } |
| 933 |
end |
| 934 |
|
| 935 |
def test_info_hidden |
| 936 |
tmux.send_keys 'seq 10 | fzf --info=hidden --no-separator', :Enter |
| 937 |
tmux.until { |lines| assert_equal '> 1', lines[-2] } |
| 938 |
end |
| 939 |
|
| 940 |
def test_info_inline_separator |
| 941 |
tmux.send_keys 'seq 10 | fzf --info=inline:___ --no-separator', :Enter |
| 942 |
tmux.until { |lines| assert_equal '> ___10/10', lines[-1] } |
| 943 |
end |
| 944 |
|
| 945 |
def test_change_first_last |
| 946 |
tmux.send_keys %(seq 1000 | #{FZF} --bind change:first,alt-Z:last), :Enter |
| 947 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 948 |
tmux.send_keys :Up |
| 949 |
tmux.until { |lines| assert_equal '> 2', lines[-4] } |
| 950 |
tmux.send_keys 1 |
| 951 |
tmux.until { |lines| assert_equal '> 1', lines[-3] } |
| 952 |
tmux.send_keys :Up |
| 953 |
tmux.until { |lines| assert_equal '> 10', lines[-4] } |
| 954 |
tmux.send_keys 1 |
| 955 |
tmux.until { |lines| assert_equal '> 11', lines[-3] } |
| 956 |
tmux.send_keys 'C-u' |
| 957 |
tmux.until { |lines| assert_equal '> 1', lines[-3] } |
| 958 |
tmux.send_keys :Escape, 'Z' |
| 959 |
tmux.until { |lines| assert_equal '> 1000', lines[0] } |
| 960 |
tmux.send_keys :Enter |
| 961 |
end |
| 962 |
|
| 963 |
def test_pos |
| 964 |
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:pos(3),b:pos(-3),c:pos(1),d:pos(-1),e:pos(0)' --preview 'echo {}/{}'), :Enter |
| 965 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 966 |
tmux.send_keys :a |
| 967 |
tmux.until { |lines| assert_includes lines[1], ' 3/3' } |
| 968 |
tmux.send_keys :b |
| 969 |
tmux.until { |lines| assert_includes lines[1], ' 998/998' } |
| 970 |
tmux.send_keys :c |
| 971 |
tmux.until { |lines| assert_includes lines[1], ' 1/1' } |
| 972 |
tmux.send_keys :d |
| 973 |
tmux.until { |lines| assert_includes lines[1], ' 1000/1000' } |
| 974 |
tmux.send_keys :e |
| 975 |
tmux.until { |lines| assert_includes lines[1], ' 1/1' } |
| 976 |
end |
| 977 |
|
| 978 |
def test_put |
| 979 |
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:put+put,b:put+put(ravo)' --preview 'echo {q}/{q}'), :Enter |
| 980 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 981 |
tmux.send_keys :a |
| 982 |
tmux.until { |lines| assert_includes lines[1], ' aa/aa' } |
| 983 |
tmux.send_keys :b |
| 984 |
tmux.until { |lines| assert_includes lines[1], ' aabravo/aabravo' } |
| 985 |
end |
| 986 |
|
| 987 |
def test_transform_put |
| 988 |
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:transform:echo put'), :Enter |
| 989 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 990 |
tmux.send_keys :a |
| 991 |
tmux.until { |lines| assert_equal '> a', lines.last } |
| 992 |
tmux.send_keys :b |
| 993 |
tmux.until { |lines| assert_equal '> ab', lines.last } |
| 994 |
end |
| 995 |
|
| 996 |
# The async callback runs in a later iteration, but 'put' must still insert |
| 997 |
# the key that triggered the bg-transform (snapshot of the scheduling event). |
| 998 |
def test_bg_transform_put |
| 999 |
tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:bg-transform:sleep 0.5; echo put'), :Enter |
| 1000 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1001 |
tmux.send_keys 'ab' |
| 1002 |
tmux.until { |lines| assert_equal '> ba', lines.last } |
| 1003 |
end |
| 1004 |
|
| 1005 |
def test_accept_non_empty |
| 1006 |
tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter |
| 1007 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1008 |
tmux.send_keys 'foo' |
| 1009 |
tmux.until { |lines| assert_equal ' 0/1000', lines[-2] } |
| 1010 |
# fzf doesn't exit since there's no selection |
| 1011 |
tmux.send_keys :Enter |
| 1012 |
tmux.until { |lines| assert_equal ' 0/1000', lines[-2] } |
| 1013 |
tmux.send_keys 'C-u' |
| 1014 |
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } |
| 1015 |
tmux.send_keys '999' |
| 1016 |
tmux.until { |lines| assert_equal ' 1/1000', lines[-2] } |
| 1017 |
tmux.send_keys :Enter |
| 1018 |
assert_equal %w[999 999], fzf_output_lines |
| 1019 |
end |
| 1020 |
|
| 1021 |
def test_accept_non_empty_with_multi_selection |
| 1022 |
tmux.send_keys %(seq 1000 | #{fzf('-m --print-query --bind enter:accept-non-empty')}), :Enter |
| 1023 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1024 |
tmux.send_keys :Tab |
| 1025 |
tmux.until { |lines| assert_equal ' 1000/1000 (1)', lines[-2] } |
| 1026 |
tmux.send_keys 'foo' |
| 1027 |
tmux.until { |lines| assert_equal ' 0/1000 (1)', lines[-2] } |
| 1028 |
# fzf will exit in this case even though there's no match for the current query |
| 1029 |
tmux.send_keys :Enter |
| 1030 |
assert_equal %w[foo 1], fzf_output_lines |
| 1031 |
end |
| 1032 |
|
| 1033 |
def test_accept_non_empty_with_empty_list |
| 1034 |
tmux.send_keys %(: | #{fzf('-q foo --print-query --bind enter:accept-non-empty')}), :Enter |
| 1035 |
tmux.until { |lines| assert_equal ' 0/0', lines[-2] } |
| 1036 |
tmux.send_keys :Enter |
| 1037 |
# fzf will exit anyway since input list is empty |
| 1038 |
assert_equal %w[foo], fzf_output_lines |
| 1039 |
end |
| 1040 |
|
| 1041 |
def test_accept_or_print_query_without_match |
| 1042 |
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter |
| 1043 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1044 |
tmux.send_keys 99_999 |
| 1045 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 1046 |
tmux.send_keys :Enter |
| 1047 |
assert_equal %w[99999], fzf_output_lines |
| 1048 |
end |
| 1049 |
|
| 1050 |
def test_accept_or_print_query_with_match |
| 1051 |
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter |
| 1052 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1053 |
tmux.send_keys '^99$' |
| 1054 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1055 |
tmux.send_keys :Enter |
| 1056 |
assert_equal %w[99], fzf_output_lines |
| 1057 |
end |
| 1058 |
|
| 1059 |
def test_accept_or_print_query_with_multi_selection |
| 1060 |
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter |
| 1061 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1062 |
tmux.send_keys :BTab, :BTab, :BTab |
| 1063 |
tmux.until { |lines| assert_equal 3, lines.select_count } |
| 1064 |
tmux.send_keys 99_999 |
| 1065 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 1066 |
tmux.send_keys :Enter |
| 1067 |
assert_equal %w[1 2 3], fzf_output_lines |
| 1068 |
end |
| 1069 |
|
| 1070 |
def test_inverse_only_search_should_not_sort_the_result |
| 1071 |
# Filter |
| 1072 |
assert_equal %w[aaaaa b ccc], |
| 1073 |
`printf '%s\n' aaaaa b ccc BAD | #{FZF} -f '!bad'`.lines(chomp: true) |
| 1074 |
|
| 1075 |
# Interactive |
| 1076 |
tmux.send_keys %(printf '%s\n' aaaaa b ccc BAD | #{FZF} -q '!bad'), :Enter |
| 1077 |
tmux.until do |lines| |
| 1078 |
assert_equal 4, lines.item_count |
| 1079 |
assert_equal 3, lines.match_count |
| 1080 |
end |
| 1081 |
tmux.until { |lines| assert_equal '> aaaaa', lines[-3] } |
| 1082 |
tmux.until { |lines| assert_equal ' b', lines[-4] } |
| 1083 |
tmux.until { |lines| assert_equal ' ccc', lines[-5] } |
| 1084 |
end |
| 1085 |
|
| 1086 |
def test_disabled |
| 1087 |
tmux.send_keys %(seq 1000 | #{FZF} --query 333 --disabled --bind a:enable-search,b:disable-search,c:toggle-search --preview 'echo {} {q}'), :Enter |
| 1088 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1089 |
tmux.until { |lines| assert_includes lines[1], ' 1 333 ' } |
| 1090 |
tmux.send_keys 'foo' |
| 1091 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1092 |
tmux.until { |lines| assert_includes lines[1], ' 1 333foo ' } |
| 1093 |
|
| 1094 |
# Already disabled, no change |
| 1095 |
tmux.send_keys 'b' |
| 1096 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1097 |
|
| 1098 |
# Enable search |
| 1099 |
tmux.send_keys 'a' |
| 1100 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 1101 |
tmux.send_keys :BSpace, :BSpace, :BSpace |
| 1102 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1103 |
tmux.until { |lines| assert_includes lines[1], ' 333 333 ' } |
| 1104 |
|
| 1105 |
# Toggle search -> disabled again, but retains the previous result |
| 1106 |
tmux.send_keys 'c' |
| 1107 |
tmux.send_keys 'foo' |
| 1108 |
tmux.until { |lines| assert_includes lines[1], ' 333 333foo ' } |
| 1109 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1110 |
|
| 1111 |
# Enabled, no match |
| 1112 |
tmux.send_keys 'c' |
| 1113 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 1114 |
tmux.until { |lines| assert_includes lines[1], ' 333foo ' } |
| 1115 |
end |
| 1116 |
|
| 1117 |
def test_clear_query |
| 1118 |
tmux.send_keys %(: | #{FZF} --query foo --bind space:clear-query), :Enter |
| 1119 |
tmux.until { |lines| assert_equal 0, lines.item_count } |
| 1120 |
tmux.until { |lines| assert_equal '> foo', lines.last } |
| 1121 |
tmux.send_keys 'C-a', 'bar' |
| 1122 |
tmux.until { |lines| assert_equal '> barfoo', lines.last } |
| 1123 |
tmux.send_keys :Space |
| 1124 |
tmux.until { |lines| assert_equal '>', lines.last } |
| 1125 |
end |
| 1126 |
|
| 1127 |
def test_change_query |
| 1128 |
tmux.send_keys %(: | #{FZF} --query foo --bind space:change-query:foobar), :Enter |
| 1129 |
tmux.until { |lines| assert_equal 0, lines.item_count } |
| 1130 |
tmux.until { |lines| assert_equal '> foo', lines.last } |
| 1131 |
tmux.send_keys :Space, 'baz' |
| 1132 |
tmux.until { |lines| assert_equal '> foobarbaz', lines.last } |
| 1133 |
end |
| 1134 |
|
| 1135 |
def test_transform_query |
| 1136 |
tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter |
| 1137 |
tmux.until { |lines| assert_equal '> bar', lines[-1] } |
| 1138 |
tmux.send_keys 'C-r' |
| 1139 |
tmux.until { |lines| assert_equal '> rab', lines[-1] } |
| 1140 |
tmux.send_keys 'C-u' |
| 1141 |
tmux.until { |lines| assert_equal '> RAB', lines[-1] } |
| 1142 |
end |
| 1143 |
|
| 1144 |
def test_transform_prompt |
| 1145 |
tmux.send_keys %{#{FZF} --bind 'ctrl-r:transform-query(rev <<< {q}),ctrl-u:transform-query: tr "[:lower:]" "[:upper:]" <<< {q}' --query bar}, :Enter |
| 1146 |
tmux.until { |lines| assert_equal '> bar', lines[-1] } |
| 1147 |
tmux.send_keys 'C-r' |
| 1148 |
tmux.until { |lines| assert_equal '> rab', lines[-1] } |
| 1149 |
tmux.send_keys 'C-u' |
| 1150 |
tmux.until { |lines| assert_equal '> RAB', lines[-1] } |
| 1151 |
end |
| 1152 |
|
| 1153 |
def test_transform |
| 1154 |
tmux.send_keys %{#{FZF} --bind 'focus:transform:echo "change-prompt({fzf:action})"'}, :Enter |
| 1155 |
tmux.until { |lines| assert_equal 'start', lines[-1] } |
| 1156 |
tmux.send_keys :Up |
| 1157 |
tmux.until { |lines| assert_equal 'up', lines[-1] } |
| 1158 |
end |
| 1159 |
|
| 1160 |
def test_search |
| 1161 |
tmux.send_keys %(seq 100 | #{FZF} --query 0 --bind space:search:1), :Enter |
| 1162 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 1163 |
tmux.send_keys :Space |
| 1164 |
tmux.until { |lines| assert_equal 20, lines.match_count } |
| 1165 |
tmux.send_keys '0' |
| 1166 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1167 |
end |
| 1168 |
|
| 1169 |
def test_transform_search |
| 1170 |
tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:transform-search:echo {q}{q}'), :Enter |
| 1171 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1172 |
tmux.send_keys '1' |
| 1173 |
tmux.until { |lines| assert_equal 28, lines.match_count } |
| 1174 |
tmux.send_keys :BSpace, '0' |
| 1175 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 1176 |
end |
| 1177 |
|
| 1178 |
def test_wait_action |
| 1179 |
tmux.send_keys %((seq 100; sleep 15) | #{FZF} --bind 'start:search(1)+wait+best'), :Enter |
| 1180 |
tmux.until { |lines| assert_equal 20, lines.match_count } |
| 1181 |
tmux.until { |lines| assert lines.any_include?('20/100 (..)') } |
| 1182 |
tmux.send_keys 'C-c' |
| 1183 |
tmux.until { |lines| refute lines.any_include?('20/100 (..)') } |
| 1184 |
# Ctrl-C cancels the wait; fzf keeps running and accepts input again |
| 1185 |
tmux.send_keys '99' |
| 1186 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1187 |
end |
| 1188 |
|
| 1189 |
def test_wait_action_start |
| 1190 |
# 'start:wait' blocks on the initial load until reading completes |
| 1191 |
tmux.send_keys %((seq 100; sleep 15) | #{FZF} --bind 'start:wait'), :Enter |
| 1192 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1193 |
tmux.until { |lines| assert lines.any_include?('(..)') } |
| 1194 |
tmux.send_keys 'C-c' |
| 1195 |
tmux.until { |lines| refute lines.any_include?('(..)') } |
| 1196 |
# Ctrl-C cancels the wait; fzf keeps running and accepts input again |
| 1197 |
tmux.send_keys '99' |
| 1198 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1199 |
end |
| 1200 |
|
| 1201 |
def test_wait_action_bg_transform |
| 1202 |
# A bg-transform result is unrelated to the wait, so it's applied while the |
| 1203 |
# wait is still blocking rather than dropped. The long read keeps the wait |
| 1204 |
# blocked so the (instant) bg-transform completes during the block; the |
| 1205 |
# header must show while '(..)' is still displayed. |
| 1206 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:bg-transform-header(echo hello)+search(5)+wait'), :Enter |
| 1207 |
tmux.until { |lines| assert(lines.any_include?('(..)') && lines.any_include?('hello')) } |
| 1208 |
end |
| 1209 |
|
| 1210 |
def test_wait_action_bg_transform_actions |
| 1211 |
# Actions parsed from a generic bg-transform result are also applied |
| 1212 |
# while wait-blocked |
| 1213 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:bg-transform(echo change-header:hello)+search(5)+wait'), :Enter |
| 1214 |
tmux.until { |lines| assert(lines.any_include?('(..)') && lines.any_include?('hello')) } |
| 1215 |
end |
| 1216 |
|
| 1217 |
def test_wait_action_bg_transform_join |
| 1218 |
# A 'wait' in a bg-transform result body joins the ongoing wait; the |
| 1219 |
# actions after it run when the wait unblocks instead of being dropped |
| 1220 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:bg-transform(echo change-header{hello}+wait+change-footer{world})+search(5)+wait'), :Enter |
| 1221 |
tmux.until { |lines| assert(lines.any_include?('(..)') && lines.any_include?('hello') && !lines.any_include?('world')) } |
| 1222 |
tmux.until { |lines| assert(lines.any_include?('world') && !lines.any_include?('(..)')) } |
| 1223 |
end |
| 1224 |
|
| 1225 |
def test_wait_action_query_change |
| 1226 |
# Query-editing actions must also make wait block; accept must run on the |
| 1227 |
# results of the new query, not the stale ones |
| 1228 |
tmux.send_keys %(seq 100 | #{fzf("--bind 'space:change-query(55)+wait+accept'")}), :Enter |
| 1229 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1230 |
tmux.send_keys :Space |
| 1231 |
assert_equal '55', fzf_output |
| 1232 |
end |
| 1233 |
|
| 1234 |
def test_wait_action_trigger_join |
| 1235 |
# A wait armed inside a triggered chord defers the remaining actions of |
| 1236 |
# the outer binding as well |
| 1237 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:trigger(x)+change-footer(world)' --bind 'x:search(5)+wait'), :Enter |
| 1238 |
tmux.until { |lines| assert(lines.any_include?('(..)') && !lines.any_include?('world')) } |
| 1239 |
tmux.until { |lines| assert(lines.any_include?('world') && !lines.any_include?('(..)')) } |
| 1240 |
end |
| 1241 |
|
| 1242 |
def test_wait_action_trigger_siblings |
| 1243 |
# Chords after a wait-arming chord are deferred, not dropped |
| 1244 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:trigger(x,y)+change-footer(world)' --bind 'x:search(5)+wait' --bind 'y:change-header(hello)'), :Enter |
| 1245 |
tmux.until { |lines| assert(lines.any_include?('(..)') && !lines.any_include?('hello') && !lines.any_include?('world')) } |
| 1246 |
tmux.until { |lines| assert(lines.any_include?('hello') && lines.any_include?('world') && !lines.any_include?('(..)')) } |
| 1247 |
end |
| 1248 |
|
| 1249 |
def test_wait_action_cancel_rearm |
| 1250 |
# Deferral works even when the wait is cancelled and re-armed within a |
| 1251 |
# single action list. --query keeps 'cancel' non-fatal in case the Space |
| 1252 |
# arrives after the initial wait has already unblocked. |
| 1253 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --query 5 --bind 'start:wait' --bind 'space:cancel+trigger(x)+change-footer(world)' --bind 'x:search(5)+wait'), :Enter |
| 1254 |
tmux.until { |lines| assert lines.any_include?('(..)') } |
| 1255 |
tmux.send_keys :Space |
| 1256 |
tmux.until { |lines| assert(lines.any_include?('world') && !lines.any_include?('(..)')) } |
| 1257 |
end |
| 1258 |
|
| 1259 |
def test_wait_action_jump |
| 1260 |
# A pending jump action must survive the wake-up event after unblock |
| 1261 |
tmux.send_keys %((seq 100; sleep 2) | #{FZF} --jump-labels abc --bind 'start:search(5)+wait+jump'), :Enter |
| 1262 |
tmux.until { |lines| assert_equal 'a 5', lines[-3] } |
| 1263 |
tmux.send_keys 'a' |
| 1264 |
tmux.until { |lines| assert_equal '> 5', lines[-3] } |
| 1265 |
end |
| 1266 |
|
| 1267 |
def test_wait_action_bracketed_paste |
| 1268 |
# A wait armed by a binding fired from a pasted character must not break |
| 1269 |
# bracketed paste handling: paste-end passes through the block so |
| 1270 |
# t.pasting is cleared and the pending search is dispatched |
| 1271 |
tmux.send_keys %(seq 100 | #{FZF} --bind 'a:put(a)+wait+first'), :Enter |
| 1272 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1273 |
tmux.paste_bracketed('1a2') |
| 1274 |
# Search for the edited query must run; blocked forever before the fix |
| 1275 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 1276 |
# Filtering must still work afterwards |
| 1277 |
tmux.send_keys 'C-u', '55' |
| 1278 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1279 |
end |
| 1280 |
|
| 1281 |
def test_wait_action_expect |
| 1282 |
# --expect keys are ignored while wait-blocked, like the rest of the input |
| 1283 |
tmux.send_keys %((seq 100; sleep 2) | #{fzf('--expect ctrl-t --bind start:wait')}), :Enter |
| 1284 |
tmux.until { |lines| assert lines.any_include?('(..)') } |
| 1285 |
tmux.send_keys 'C-t' |
| 1286 |
# fzf must still be running; the wait unblocks when loading completes |
| 1287 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1288 |
tmux.until { |lines| refute lines.any_include?('(..)') } |
| 1289 |
tmux.send_keys 'C-t' |
| 1290 |
assert_equal %w[ctrl-t 1], fzf_output_lines |
| 1291 |
end |
| 1292 |
|
| 1293 |
def test_track_blocked_bg_transform |
| 1294 |
# A bg-transform result completing while track-blocked is applied, not |
| 1295 |
# dropped. The header must show while '+T*' is still displayed. |
| 1296 |
tmux.send_keys "seq 100 | #{FZF} --track --id-nth .. --bind 'ctrl-r:bg-transform-header(echo hello)+reload(sleep 2; seq 100)'", :Enter |
| 1297 |
tmux.until { |lines| assert_includes lines[-2], '+T' } |
| 1298 |
tmux.send_keys 'C-r' |
| 1299 |
tmux.until { |lines| assert(lines.any_include?('+T*') && lines.any_include?('hello')) } |
| 1300 |
end |
| 1301 |
|
| 1302 |
def test_clear_selection |
| 1303 |
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter |
| 1304 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1305 |
tmux.send_keys :Tab |
| 1306 |
tmux.until { |lines| assert_equal ' 100/100 (1)', lines[-2] } |
| 1307 |
tmux.send_keys 'foo' |
| 1308 |
tmux.until { |lines| assert_equal ' 0/100 (1)', lines[-2] } |
| 1309 |
tmux.send_keys :Space |
| 1310 |
tmux.until { |lines| assert_equal ' 0/100 (0)', lines[-2] } |
| 1311 |
end |
| 1312 |
|
| 1313 |
def test_backward_delete_char_eof |
| 1314 |
tmux.send_keys "seq 1000 | #{FZF} --bind 'bs:backward-delete-char/eof'", :Enter |
| 1315 |
tmux.until { |lines| assert_equal ' 1000/1000', lines[-2] } |
| 1316 |
tmux.send_keys '11' |
| 1317 |
tmux.until { |lines| assert_equal '> 11', lines[-1] } |
| 1318 |
tmux.send_keys :BSpace |
| 1319 |
tmux.until { |lines| assert_equal '> 1', lines[-1] } |
| 1320 |
tmux.send_keys :BSpace |
| 1321 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 1322 |
tmux.send_keys :BSpace |
| 1323 |
tmux.prepare |
| 1324 |
end |
| 1325 |
|
| 1326 |
def test_strip_xterm_osc_sequence |
| 1327 |
%W[\x07 \x1b\\].each do |esc| |
| 1328 |
writelines([%(printf $1"\e]4;3;rgb:aa/bb/cc#{esc} "$2)]) |
| 1329 |
File.chmod(0o755, tempname) |
| 1330 |
tmux.prepare |
| 1331 |
tmux.send_keys \ |
| 1332 |
%(echo foo bar | #{FZF} --preview '#{tempname} {2} {1}'), :Enter |
| 1333 |
|
| 1334 |
tmux.until { |lines| assert lines.any_include?('bar foo') } |
| 1335 |
tmux.send_keys :Enter |
| 1336 |
end |
| 1337 |
end |
| 1338 |
|
| 1339 |
def test_keep_right |
| 1340 |
tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right --no-multi-line --bind space:toggle-multi-line", :Enter |
| 1341 |
tmux.until { |lines| assert lines.any_include?('9999␊10000') } |
| 1342 |
tmux.send_keys :Space |
| 1343 |
tmux.until { |lines| assert lines.any_include?('> 1') } |
| 1344 |
tmux.send_keys :Space |
| 1345 |
tmux.until { |lines| assert lines.any_include?('9999␊10000') } |
| 1346 |
end |
| 1347 |
|
| 1348 |
def test_freeze_left_tabstop |
| 1349 |
writelines(%W[1\t2\t3]) |
| 1350 |
# With --freeze-left 1 and --tabstop=2: |
| 1351 |
# Frozen left: "1" (width 1) |
| 1352 |
# Middle starts with "\t" at prefix width 1, tabstop 2 → 1 space |
| 1353 |
# Then "2" at column 2, next "\t" at column 3 → 1 space, then "3" |
| 1354 |
tmux.send_keys %(cat #{tempname} | #{FZF} --tabstop=2 --freeze-left 1), :Enter |
| 1355 |
tmux.until { |lines| assert_equal '> 1 2 3', lines[-3] } |
| 1356 |
end |
| 1357 |
|
| 1358 |
def test_freeze_left_keep_right |
| 1359 |
tmux.send_keys %(seq 10000 | #{FZF} --read0 --delimiter "\n" --freeze-left 3 --keep-right --ellipsis XX --no-multi-line --bind space:toggle-multi-line), :Enter |
| 1360 |
tmux.until { |lines| assert_match(/^> 1␊2␊3XX.*10000␊$/, lines[-3]) } |
| 1361 |
tmux.send_keys '5' |
| 1362 |
tmux.until { |lines| assert_match(/^> 1␊2␊3␊4␊5␊.*XX$/, lines[-3]) } |
| 1363 |
tmux.send_keys :Space |
| 1364 |
tmux.until { |lines| assert lines.any_include?('> 1') } |
| 1365 |
tmux.send_keys :Space |
| 1366 |
tmux.until { |lines| assert lines.any_include?('1␊2␊3␊4␊5␊') } |
| 1367 |
end |
| 1368 |
|
| 1369 |
def test_freeze_left_and_right |
| 1370 |
tmux.send_keys %(seq 10000 | tr "\n" ' ' | #{FZF} --freeze-left 3 --freeze-right 3 --ellipsis XX), :Enter |
| 1371 |
tmux.until { |lines| assert_match(/XX9998 9999 10000$/, lines[-3]) } |
| 1372 |
tmux.send_keys "'1000" |
| 1373 |
tmux.until { |lines| assert_match(/^> 1 2 3XX.*XX9998 9999 10000$/, lines[-3]) } |
| 1374 |
end |
| 1375 |
|
| 1376 |
def test_freeze_left_and_right_delimiter |
| 1377 |
tmux.send_keys %(seq 10000 | tr "\n" ' ' | sed 's/ / , /g' | #{FZF} --freeze-left 3 --freeze-right 3 --ellipsis XX --delimiter ' , '), :Enter |
| 1378 |
tmux.until { |lines| assert_match(/XX, 9999 , 10000 ,$/, lines[-3]) } |
| 1379 |
tmux.send_keys "'1000" |
| 1380 |
tmux.until { |lines| assert_match(/^> 1 , 2 , 3 ,XX.*XX, 9999 , 10000 ,$/, lines[-3]) } |
| 1381 |
end |
| 1382 |
|
| 1383 |
def test_freeze_right_exceed_range |
| 1384 |
tmux.send_keys %(seq 10000 | tr "\n" ' ' | #{FZF} --freeze-right 100000 --ellipsis XX), :Enter |
| 1385 |
['', "'1000"].each do |query| |
| 1386 |
tmux.send_keys query |
| 1387 |
tmux.until { |lines| assert lines.any_include?("> #{query}".strip) } |
| 1388 |
tmux.until do |lines| |
| 1389 |
assert_match(/ 9998 9999 10000$/, lines[-3]) |
| 1390 |
assert_equal(1, lines[-3].scan('XX').size) |
| 1391 |
end |
| 1392 |
end |
| 1393 |
end |
| 1394 |
|
| 1395 |
def test_freeze_right_exceed_range_with_freeze_left |
| 1396 |
tmux.send_keys %(seq 10000 | tr "\n" ' ' | #{FZF} --freeze-left 3 --freeze-right 100000 --ellipsis XX), :Enter |
| 1397 |
tmux.until do |lines| |
| 1398 |
assert_match(/^> 1 2 3XX.*9998 9999 10000$/, lines[-3]) |
| 1399 |
assert_equal(1, lines[-3].scan('XX').size) |
| 1400 |
end |
| 1401 |
end |
| 1402 |
|
| 1403 |
def test_freeze_right_with_ellipsis_and_scrolling |
| 1404 |
tmux.send_keys "{ seq 6; ruby -e 'print \"g\"*1000, \"\\n\"'; seq 8 100; } | #{FZF} --ellipsis='777' --freeze-right 1 --scroll-off 0 --bind a:offset-up", :Enter |
| 1405 |
tmux.until { |lines| assert_equal ' 100/100', lines[-2] } |
| 1406 |
tmux.send_keys(*Array.new(6) { :a }) |
| 1407 |
tmux.until do |lines| |
| 1408 |
assert_match(/> 777g+$/, lines[-3]) |
| 1409 |
assert_equal(1, lines.count { |l| l.end_with?('g') }) |
| 1410 |
end |
| 1411 |
end |
| 1412 |
|
| 1413 |
def test_backward_eof |
| 1414 |
tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter |
| 1415 |
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 } |
| 1416 |
tmux.send_keys 'x' |
| 1417 |
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 0 } |
| 1418 |
tmux.send_keys :BSpace |
| 1419 |
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 } |
| 1420 |
tmux.send_keys :BSpace |
| 1421 |
tmux.until { |lines| lines.item_count == 100 && lines.match_count == 100 } |
| 1422 |
end |
| 1423 |
|
| 1424 |
def test_change_prompt |
| 1425 |
tmux.send_keys "#{FZF} --bind 'a:change-prompt(a> ),b:change-prompt:b> ' --query foo", :Enter |
| 1426 |
tmux.until { |lines| assert_equal '> foo', lines[-1] } |
| 1427 |
tmux.send_keys 'a' |
| 1428 |
tmux.until { |lines| assert_equal 'a> foo', lines[-1] } |
| 1429 |
tmux.send_keys 'b' |
| 1430 |
tmux.until { |lines| assert_equal 'b> foo', lines[-1] } |
| 1431 |
end |
| 1432 |
|
| 1433 |
def test_select_deselect |
| 1434 |
tmux.send_keys "seq 3 | #{FZF} --multi --bind up:deselect+up,down:select+down", :Enter |
| 1435 |
tmux.until { |lines| assert_equal 3, lines.match_count } |
| 1436 |
tmux.send_keys :Tab |
| 1437 |
tmux.until { |lines| assert_equal 1, lines.select_count } |
| 1438 |
tmux.send_keys :Up |
| 1439 |
tmux.until { |lines| assert_equal 0, lines.select_count } |
| 1440 |
tmux.send_keys :Down, :Down |
| 1441 |
tmux.until { |lines| assert_equal 2, lines.select_count } |
| 1442 |
tmux.send_keys :Tab |
| 1443 |
tmux.until { |lines| assert_equal 1, lines.select_count } |
| 1444 |
tmux.send_keys :Down, :Down |
| 1445 |
tmux.until { |lines| assert_equal 2, lines.select_count } |
| 1446 |
tmux.send_keys :Up |
| 1447 |
tmux.until { |lines| assert_equal 1, lines.select_count } |
| 1448 |
tmux.send_keys :Down |
| 1449 |
tmux.until { |lines| assert_equal 1, lines.select_count } |
| 1450 |
tmux.send_keys :Down |
| 1451 |
tmux.until { |lines| assert_equal 2, lines.select_count } |
| 1452 |
end |
| 1453 |
|
| 1454 |
def test_unbind_rebind_toggle_bind |
| 1455 |
tmux.send_keys "seq 100 | #{FZF} --bind 'c:clear-query,d:unbind(c,d),e:rebind(c,d),f:toggle-bind(c)'", :Enter |
| 1456 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1457 |
tmux.send_keys 'ab' |
| 1458 |
tmux.until { |lines| assert_equal '> ab', lines[-1] } |
| 1459 |
tmux.send_keys 'c' |
| 1460 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 1461 |
tmux.send_keys 'dabcd' |
| 1462 |
tmux.until { |lines| assert_equal '> abcd', lines[-1] } |
| 1463 |
tmux.send_keys 'ecabddc' |
| 1464 |
tmux.until { |lines| assert_equal '> abdc', lines[-1] } |
| 1465 |
tmux.send_keys 'fcabfc' |
| 1466 |
tmux.until { |lines| assert_equal '> abc', lines[-1] } |
| 1467 |
tmux.send_keys 'fc' |
| 1468 |
tmux.until { |lines| assert_equal '>', lines[-1] } |
| 1469 |
end |
| 1470 |
|
| 1471 |
def test_scroll_off |
| 1472 |
tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter |
| 1473 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1474 |
height = tmux.until { |lines| lines }.first.to_i |
| 1475 |
tmux.send_keys :PgUp |
| 1476 |
tmux.until do |lines| |
| 1477 |
assert_equal height + 3, lines.first.to_i |
| 1478 |
assert_equal "> #{height}", lines[3].strip |
| 1479 |
end |
| 1480 |
tmux.send_keys :Up |
| 1481 |
tmux.until { |lines| assert_equal "> #{height + 1}", lines[3].strip } |
| 1482 |
tmux.send_keys 'l' |
| 1483 |
tmux.until { |lines| assert_equal '> 1000', lines.first.strip } |
| 1484 |
tmux.send_keys :PgDn |
| 1485 |
tmux.until { |lines| assert_equal "> #{1000 - height + 1}", lines.reverse[5].strip } |
| 1486 |
tmux.send_keys :Down |
| 1487 |
tmux.until { |lines| assert_equal "> #{1000 - height}", lines.reverse[5].strip } |
| 1488 |
end |
| 1489 |
|
| 1490 |
def test_scroll_off_large |
| 1491 |
tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter |
| 1492 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1493 |
height = tmux.until { |lines| lines }.first.to_i |
| 1494 |
tmux.send_keys :PgUp |
| 1495 |
tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip } |
| 1496 |
tmux.send_keys :Up |
| 1497 |
tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip } |
| 1498 |
tmux.send_keys :Up |
| 1499 |
tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip } |
| 1500 |
tmux.send_keys :Down |
| 1501 |
tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip } |
| 1502 |
end |
| 1503 |
|
| 1504 |
def test_ellipsis |
| 1505 |
tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter |
| 1506 |
tmux.until { |lines| assert_equal 1, lines.match_count } |
| 1507 |
tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) } |
| 1508 |
end |
| 1509 |
|
| 1510 |
def test_start_event |
| 1511 |
tmux.send_keys 'seq 100 | fzf --multi --sync --preview-window hidden:border-none --bind "start:select-all+last+preview(echo welcome)"', :Enter |
| 1512 |
tmux.until do |lines| |
| 1513 |
assert_match(/>100.*welcome/, lines[0]) |
| 1514 |
assert_includes(lines[-2], '100/100 (100)') |
| 1515 |
end |
| 1516 |
end |
| 1517 |
|
| 1518 |
def test_focus_event |
| 1519 |
tmux.send_keys 'seq 100 | fzf --bind "focus:transform-prompt(echo [[{}]]),?:unbind(focus)"', :Enter |
| 1520 |
tmux.until { |lines| assert_includes(lines[-1], '[[1]]') } |
| 1521 |
tmux.send_keys :Up |
| 1522 |
tmux.until { |lines| assert_includes(lines[-1], '[[2]]') } |
| 1523 |
tmux.send_keys :X |
| 1524 |
tmux.until { |lines| assert_includes(lines[-1], '[[]]') } |
| 1525 |
tmux.send_keys :BSpace |
| 1526 |
tmux.until { |lines| assert_includes(lines[-1], '[[1]]') } |
| 1527 |
tmux.send_keys :X |
| 1528 |
tmux.until { |lines| assert_includes(lines[-1], '[[]]') } |
| 1529 |
tmux.send_keys '?' |
| 1530 |
tmux.send_keys :BSpace |
| 1531 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1532 |
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') } |
| 1533 |
end |
| 1534 |
|
| 1535 |
def test_result_event |
| 1536 |
tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter |
| 1537 |
tmux.until { |lines| assert_equal 11, lines.match_count } |
| 1538 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 1539 |
tmux.send_keys '9' |
| 1540 |
tmux.until { |lines| assert_includes lines, '> 9' } |
| 1541 |
tmux.send_keys :BSpace |
| 1542 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 1543 |
end |
| 1544 |
|
| 1545 |
def test_result_final_event |
| 1546 |
tmux.send_keys %[(seq 100; sleep 1; seq 100) | #{FZF} \\ |
| 1547 |
--query 1 \\ |
| 1548 |
--bind 'result:transform-header(echo "R=$FZF_MATCH_COUNT")' \\ |
| 1549 |
--bind 'result-final:transform-footer(echo "F=$FZF_MATCH_COUNT")'], :Enter |
| 1550 |
tmux.until { |lines| assert lines.any_include?('R=20') } |
| 1551 |
tmux.until { |lines| refute lines.any_include?('F=20') } |
| 1552 |
tmux.until { |lines| assert lines.any_include?('R=40') } |
| 1553 |
tmux.until { |lines| assert lines.any_include?('F=40') } |
| 1554 |
end |
| 1555 |
|
| 1556 |
def test_every_event |
| 1557 |
tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-prompt(cat #{tempname})'), :Enter |
| 1558 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1559 |
# Trigger external state changes; the every() tick should pick them up. |
| 1560 |
writelines(['AAA>']) |
| 1561 |
tmux.until { |lines| assert_includes lines[-1], 'AAA>' } |
| 1562 |
writelines(['BBB>']) |
| 1563 |
tmux.until { |lines| assert_includes lines[-1], 'BBB>' } |
| 1564 |
end |
| 1565 |
|
| 1566 |
def test_every_event_multiple_independent_timers |
| 1567 |
# Two timers with different durations should fire independently. |
| 1568 |
fast = tempname + '.fast' |
| 1569 |
slow = tempname + '.slow' |
| 1570 |
FileUtils.rm_f(fast) |
| 1571 |
FileUtils.rm_f(slow) |
| 1572 |
tmux.send_keys %(seq 100 | fzf \\ |
| 1573 |
--bind 'every(0.1):execute-silent(printf . >> #{fast})' \\ |
| 1574 |
--bind 'every(0.5):execute-silent(printf . >> #{slow})'), :Enter |
| 1575 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1576 |
sleep(1.2) |
| 1577 |
a = File.exist?(fast) ? File.size(fast) : 0 |
| 1578 |
b = File.exist?(slow) ? File.size(slow) : 0 |
| 1579 |
# Sanity: faster timer fired more times. |
| 1580 |
assert_operator a, :>, b, "fast timer should fire more (#{a} vs #{b})" |
| 1581 |
# Sanity: slow timer fired at least once. |
| 1582 |
assert_operator b, :>=, 1, "slow timer should have fired at least once (#{b})" |
| 1583 |
ensure |
| 1584 |
FileUtils.rm_f(fast) |
| 1585 |
FileUtils.rm_f(slow) |
| 1586 |
end |
| 1587 |
|
| 1588 |
def test_every_event_unbind |
| 1589 |
tmux.send_keys %(seq 100 | fzf --bind 'every(0.1):transform-header(date +%S.%N)' --bind 'space:unbind(every(0.1))+change-header(STOPPED)'), :Enter |
| 1590 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1591 |
# Header should be ticking |
| 1592 |
tmux.until { |lines| assert_match(/^ \d{2}\.\d+/, lines[-3]) } |
| 1593 |
tmux.send_keys :Space |
| 1594 |
tmux.until { |lines| assert_includes lines[-3], 'STOPPED' } |
| 1595 |
sleep(0.4) |
| 1596 |
# Header must stay STOPPED after the unbind |
| 1597 |
assert_includes tmux.capture[-3], 'STOPPED' |
| 1598 |
end |
| 1599 |
|
| 1600 |
def test_fzf_idle_time_env |
| 1601 |
# FZF_IDLE_TIME + FZF_IDLE_TIME_MS combined with every() implement idle-based behavior. |
| 1602 |
tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-header(echo "s=$FZF_IDLE_TIME ms_ok=$((FZF_IDLE_TIME_MS / 1000 == FZF_IDLE_TIME))")'), :Enter |
| 1603 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1604 |
# Idle counter advances without any input; ms/1000 stays consistent with seconds. |
| 1605 |
tmux.until { |lines| assert_includes lines[-3], 's=1 ms_ok=1' } |
| 1606 |
tmux.until { |lines| assert_includes lines[-3], 's=2 ms_ok=1' } |
| 1607 |
# Any keystroke resets the counter |
| 1608 |
tmux.send_keys 'x' |
| 1609 |
tmux.until { |lines| assert_includes lines[-3], 's=0 ms_ok=1' } |
| 1610 |
tmux.send_keys :BSpace |
| 1611 |
# And it advances again afterwards |
| 1612 |
tmux.until { |lines| assert_includes lines[-3], 's=1 ms_ok=1' } |
| 1613 |
end |
| 1614 |
|
| 1615 |
def test_every_event_rejects_invalid_arg |
| 1616 |
%w[every(0) every(-1) every(abc) every()].each do |spec| |
| 1617 |
tmux.send_keys %(seq 1 | fzf --bind '#{spec}:abort' 2>&1; echo done=$?), :Enter |
| 1618 |
tmux.until { |lines| assert(lines.any? { |l| l.include?('done=2') }) } |
| 1619 |
tmux.send_keys 'clear', :Enter |
| 1620 |
end |
| 1621 |
end |
| 1622 |
|
| 1623 |
def test_fzf_key_ignores_synthetic_events |
| 1624 |
tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-prompt(echo "[$FZF_KEY]> ")'), :Enter |
| 1625 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 1626 |
# No user input yet: prompt should show empty FZF_KEY |
| 1627 |
tmux.until { |lines| assert_includes lines[-1], '[]>' } |
| 1628 |
tmux.send_keys 'x' |
| 1629 |
tmux.until { |lines| assert_includes lines[-1], '[x]>' } |
| 1630 |
# every() ticks shouldn't overwrite FZF_KEY |
| 1631 |
sleep(1) |
| 1632 |
assert_includes tmux.capture[-1], '[x]>' |
| 1633 |
end |
| 1634 |
|
| 1635 |
def test_labels_center |
| 1636 |
tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter |
| 1637 |
tmux.until do |
| 1638 |
assert_includes(it[0], '─foobar─') |
| 1639 |
assert_includes(it[1], '─barfoo─') |
| 1640 |
end |
| 1641 |
tmux.send_keys :space |
| 1642 |
tmux.until do |
| 1643 |
assert_includes(it[0], '─foobarfoo─') |
| 1644 |
assert_includes(it[1], '─barfoobar─') |
| 1645 |
end |
| 1646 |
tmux.send_keys :Enter |
| 1647 |
tmux.until do |
| 1648 |
assert_includes(it[0], '─fooxfoo─') |
| 1649 |
assert_includes(it[1], '─barxbar─') |
| 1650 |
end |
| 1651 |
end |
| 1652 |
|
| 1653 |
def test_labels_left |
| 1654 |
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2 --preview : --preview-label barfoo --preview-label-pos 2', :Enter |
| 1655 |
tmux.until do |
| 1656 |
assert_includes(it[0], '╭foobar─') |
| 1657 |
assert_includes(it[1], '╭barfoo─') |
| 1658 |
end |
| 1659 |
end |
| 1660 |
|
| 1661 |
def test_labels_right |
| 1662 |
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos -2 --preview : --preview-label barfoo --preview-label-pos -2', :Enter |
| 1663 |
tmux.until do |
| 1664 |
assert_includes(it[0], '─foobar╮') |
| 1665 |
assert_includes(it[1], '─barfoo╮') |
| 1666 |
end |
| 1667 |
end |
| 1668 |
|
| 1669 |
def test_labels_bottom |
| 1670 |
tmux.send_keys ': | fzf --border rounded --preview-window border-rounded --border-label foobar --border-label-pos 2:bottom --preview : --preview-label barfoo --preview-label-pos -2:bottom', :Enter |
| 1671 |
tmux.until do |
| 1672 |
assert_includes(it[-1], '╰foobar─') |
| 1673 |
assert_includes(it[-2], '─barfoo╯') |
| 1674 |
end |
| 1675 |
end |
| 1676 |
|
| 1677 |
def test_labels_variables |
| 1678 |
tmux.send_keys ': | fzf --border --border-label foobar --preview "echo \$FZF_BORDER_LABEL // \$FZF_PREVIEW_LABEL" --preview-label barfoo --bind "space:change-border-label(barbaz)+change-preview-label(bazbar)+refresh-preview,enter:transform-border-label(echo 123)+transform-preview-label(echo 456)+refresh-preview"', :Enter |
| 1679 |
tmux.until do |
| 1680 |
assert_includes(it[0], '─foobar─') |
| 1681 |
assert_includes(it[1], '─barfoo─') |
| 1682 |
assert_includes(it[2], ' foobar // barfoo ') |
| 1683 |
end |
| 1684 |
tmux.send_keys :Space |
| 1685 |
tmux.until do |
| 1686 |
assert_includes(it[0], '─barbaz─') |
| 1687 |
assert_includes(it[1], '─bazbar─') |
| 1688 |
assert_includes(it[2], ' barbaz // bazbar ') |
| 1689 |
end |
| 1690 |
tmux.send_keys :Enter |
| 1691 |
tmux.until do |
| 1692 |
assert_includes(it[0], '─123─') |
| 1693 |
assert_includes(it[1], '─456─') |
| 1694 |
assert_includes(it[2], ' 123 // 456 ') |
| 1695 |
end |
| 1696 |
end |
| 1697 |
|
| 1698 |
def test_info_separator_unicode |
| 1699 |
tmux.send_keys 'seq 100 | fzf -q55', :Enter |
| 1700 |
tmux.until { assert_includes(it[-2], ' 1/100 ─') } |
| 1701 |
end |
| 1702 |
|
| 1703 |
def test_info_separator_no_unicode |
| 1704 |
tmux.send_keys 'seq 100 | fzf -q55 --no-unicode', :Enter |
| 1705 |
tmux.until { assert_includes(it[-2], ' 1/100 -') } |
| 1706 |
end |
| 1707 |
|
| 1708 |
def test_info_separator_repeat |
| 1709 |
tmux.send_keys 'seq 100 | fzf -q55 --separator _-', :Enter |
| 1710 |
tmux.until { assert_includes(it[-2], ' 1/100 _-_-') } |
| 1711 |
end |
| 1712 |
|
| 1713 |
def test_info_separator_ansi_colors_and_tabs |
| 1714 |
tmux.send_keys "seq 100 | fzf -q55 --tabstop 4 --separator $'\\x1b[33ma\\tb'", :Enter |
| 1715 |
tmux.until { assert_includes(it[-2], ' 1/100 a ba ba') } |
| 1716 |
end |
| 1717 |
|
| 1718 |
def test_info_no_separator |
| 1719 |
tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter |
| 1720 |
tmux.until { assert_operator(it[-2], :==, ' 1/100') } |
| 1721 |
end |
| 1722 |
|
| 1723 |
def test_info_right |
| 1724 |
tmux.send_keys "#{FZF} --info=right --separator x --bind 'start:reload:seq 100; sleep 10'", :Enter |
| 1725 |
tmux.until { assert_match(%r{xxx [⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, it[-2]) } |
| 1726 |
end |
| 1727 |
|
| 1728 |
def test_info_inline_right |
| 1729 |
tmux.send_keys "#{FZF} --info=inline-right --bind 'start:reload:seq 100; sleep 10'", :Enter |
| 1730 |
tmux.until { assert_match(%r{[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏] 100/100}, it[-1]) } |
| 1731 |
end |
| 1732 |
|
| 1733 |
def test_info_inline_right_clearance |
| 1734 |
tmux.send_keys "seq 100000 | #{FZF} --info inline-right", :Enter |
| 1735 |
tmux.until { assert_match(%r{100000/100000}, it[-1]) } |
| 1736 |
tmux.send_keys 'x' |
| 1737 |
tmux.until { assert_match(%r{ 0/100000}, it[-1]) } |
| 1738 |
end |
| 1739 |
|
| 1740 |
def test_info_command |
| 1741 |
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"'), :Enter) |
| 1742 |
tmux.until { assert_match(%r{^ --1/10000/10000-- xx}, it[-2]) } |
| 1743 |
tmux.send_keys :Up |
| 1744 |
tmux.until { assert_match(%r{^ --2/10000/10000-- xx}, it[-2]) } |
| 1745 |
end |
| 1746 |
|
| 1747 |
def test_info_command_inline |
| 1748 |
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline:xx), :Enter) |
| 1749 |
tmux.until { assert_match(%r{^> xx--1/10000/10000-- xx}, it[-1]) } |
| 1750 |
end |
| 1751 |
|
| 1752 |
def test_info_command_right |
| 1753 |
tmux.send_keys(%(seq 10000 | #{FZF} --separator x --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info right), :Enter) |
| 1754 |
tmux.until { assert_match(%r{xx --1/10000/10000-- *$}, it[-2]) } |
| 1755 |
end |
| 1756 |
|
| 1757 |
def test_info_command_inline_right |
| 1758 |
tmux.send_keys(%(seq 10000 | #{FZF} --info-command 'echo -e "--\\x1b[33m$FZF_POS\\x1b[m/$FZF_INFO--"' --info inline-right), :Enter) |
| 1759 |
tmux.until { assert_match(%r{ --1/10000/10000-- *$}, it[-1]) } |
| 1760 |
end |
| 1761 |
|
| 1762 |
def test_info_command_inline_right_no_ansi |
| 1763 |
tmux.send_keys(%(seq 10000 | #{FZF} --info-command 'echo -e "--$FZF_POS/$FZF_INFO--"' --info inline-right), :Enter) |
| 1764 |
tmux.until { assert_match(%r{ --1/10000/10000-- *$}, it[-1]) } |
| 1765 |
end |
| 1766 |
|
| 1767 |
def test_info_command_and_focus |
| 1768 |
tmux.send_keys(%(seq 100 | #{FZF} --separator x --info-command 'echo $FZF_POS' --bind focus:clear-query), :Enter) |
| 1769 |
tmux.until { assert_match(/^ 1 xx/, it[-2]) } |
| 1770 |
tmux.send_keys :Up |
| 1771 |
tmux.until { assert_match(/^ 2 xx/, it[-2]) } |
| 1772 |
end |
| 1773 |
|
| 1774 |
def test_prev_next_selected |
| 1775 |
tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter |
| 1776 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 1777 |
tmux.send_keys :BTab, :BTab, :Up, :BTab |
| 1778 |
tmux.until { |lines| assert_equal 3, lines.select_count } |
| 1779 |
tmux.send_keys 'C-n' |
| 1780 |
tmux.until { |lines| assert_includes lines, '>>4' } |
| 1781 |
tmux.send_keys 'C-n' |
| 1782 |
tmux.until { |lines| assert_includes lines, '>>2' } |
| 1783 |
tmux.send_keys 'C-n' |
| 1784 |
tmux.until { |lines| assert_includes lines, '>>1' } |
| 1785 |
tmux.send_keys 'C-n' |
| 1786 |
tmux.until { |lines| assert_includes lines, '>>4' } |
| 1787 |
tmux.send_keys 'C-p' |
| 1788 |
tmux.until { |lines| assert_includes lines, '>>1' } |
| 1789 |
tmux.send_keys 'C-p' |
| 1790 |
tmux.until { |lines| assert_includes lines, '>>2' } |
| 1791 |
end |
| 1792 |
|
| 1793 |
def test_track |
| 1794 |
tmux.send_keys "seq 1000 | #{FZF} --query 555 --track --bind t:toggle-track", :Enter |
| 1795 |
tmux.until do |lines| |
| 1796 |
assert_equal 1, lines.match_count |
| 1797 |
assert_includes lines, '> 555' |
| 1798 |
end |
| 1799 |
tmux.send_keys :BSpace |
| 1800 |
index = tmux.until do |lines| |
| 1801 |
assert_equal 28, lines.match_count |
| 1802 |
assert_includes lines, '> 555' |
| 1803 |
end.index('> 555') |
| 1804 |
tmux.send_keys :BSpace |
| 1805 |
tmux.until do |lines| |
| 1806 |
assert_equal 271, lines.match_count |
| 1807 |
assert_equal '> 555', lines[index] |
| 1808 |
end |
| 1809 |
tmux.send_keys :BSpace |
| 1810 |
tmux.until do |lines| |
| 1811 |
assert_equal 1000, lines.match_count |
| 1812 |
assert_equal '> 555', lines[index] |
| 1813 |
end |
| 1814 |
tmux.send_keys '555' |
| 1815 |
tmux.until do |lines| |
| 1816 |
assert_equal 1, lines.match_count |
| 1817 |
assert_includes lines, '> 555' |
| 1818 |
assert_includes lines[-2], '+T' |
| 1819 |
end |
| 1820 |
tmux.send_keys 't' |
| 1821 |
tmux.until do |lines| |
| 1822 |
refute_includes lines[-2], '+T' |
| 1823 |
end |
| 1824 |
tmux.send_keys :BSpace |
| 1825 |
tmux.until do |lines| |
| 1826 |
assert_equal 28, lines.match_count |
| 1827 |
assert_includes lines, '> 55' |
| 1828 |
end |
| 1829 |
tmux.send_keys :BSpace |
| 1830 |
tmux.until do |lines| |
| 1831 |
assert_equal 271, lines.match_count |
| 1832 |
assert_includes lines, '> 5' |
| 1833 |
end |
| 1834 |
tmux.send_keys 't' |
| 1835 |
tmux.until do |lines| |
| 1836 |
assert_includes lines[-2], '+T' |
| 1837 |
end |
| 1838 |
tmux.send_keys :BSpace |
| 1839 |
tmux.until do |lines| |
| 1840 |
assert_equal 1000, lines.match_count |
| 1841 |
assert_includes lines, '> 5' |
| 1842 |
end |
| 1843 |
end |
| 1844 |
|
| 1845 |
def test_track_action |
| 1846 |
tmux.send_keys "seq 1000 | #{FZF} --pointer x --query 555 --bind t:track,T:up+track", :Enter |
| 1847 |
tmux.until do |lines| |
| 1848 |
assert_equal 1, lines.match_count |
| 1849 |
assert_includes lines, 'x 555' |
| 1850 |
assert_includes lines, '> 555' |
| 1851 |
end |
| 1852 |
tmux.send_keys :BSpace |
| 1853 |
tmux.until do |lines| |
| 1854 |
assert_equal 28, lines.match_count |
| 1855 |
assert_includes lines, 'x 55' |
| 1856 |
assert_includes lines, '> 55' |
| 1857 |
end |
| 1858 |
tmux.send_keys :t |
| 1859 |
tmux.until do |lines| |
| 1860 |
assert_includes lines[-2], '+t' |
| 1861 |
end |
| 1862 |
tmux.send_keys :BSpace |
| 1863 |
tmux.until do |lines| |
| 1864 |
assert_equal 271, lines.match_count |
| 1865 |
assert_includes lines, 'x 55' |
| 1866 |
assert_includes lines, '> 5' |
| 1867 |
end |
| 1868 |
|
| 1869 |
# Automatically disabled when the tracking item is no longer visible |
| 1870 |
tmux.send_keys '4' |
| 1871 |
tmux.until do |lines| |
| 1872 |
assert_equal 28, lines.match_count |
| 1873 |
refute_includes lines[-2], '+t' |
| 1874 |
end |
| 1875 |
tmux.send_keys :BSpace |
| 1876 |
tmux.until do |lines| |
| 1877 |
assert_equal 271, lines.match_count |
| 1878 |
assert_includes lines, 'x 52' |
| 1879 |
assert_includes lines, '> 5' |
| 1880 |
end |
| 1881 |
tmux.send_keys :t |
| 1882 |
tmux.until do |lines| |
| 1883 |
assert_includes lines[-2], '+t' |
| 1884 |
end |
| 1885 |
|
| 1886 |
# Automatically disabled when the focus has moved |
| 1887 |
tmux.send_keys :Up |
| 1888 |
tmux.until do |lines| |
| 1889 |
assert_includes lines, 'x 53' |
| 1890 |
refute_includes lines[-2], '+t' |
| 1891 |
end |
| 1892 |
|
| 1893 |
# Should work even when combined with a focus moving actions |
| 1894 |
tmux.send_keys 'T' |
| 1895 |
tmux.until do |lines| |
| 1896 |
assert_includes lines, 'x 54' |
| 1897 |
assert_includes lines[-2], '+t' |
| 1898 |
end |
| 1899 |
|
| 1900 |
tmux.send_keys 'T' |
| 1901 |
tmux.until do |lines| |
| 1902 |
assert_includes lines, 'x 55' |
| 1903 |
assert_includes lines[-2], '+t' |
| 1904 |
end |
| 1905 |
end |
| 1906 |
|
| 1907 |
def test_track_nth_reload_whole_line |
| 1908 |
# --track --id-nth .. should track by entire line across reloads |
| 1909 |
tmux.send_keys "seq 1000 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:seq 1000 | sort -R'", :Enter |
| 1910 |
tmux.until { |lines| assert_equal 1000, lines.match_count } |
| 1911 |
|
| 1912 |
# Move to item 555 |
| 1913 |
tmux.send_keys '555' |
| 1914 |
tmux.until do |lines| |
| 1915 |
assert_equal 1, lines.match_count |
| 1916 |
assert_includes lines, '> 555' |
| 1917 |
end |
| 1918 |
tmux.send_keys :BSpace, :BSpace, :BSpace |
| 1919 |
|
| 1920 |
# Reload with shuffled order - cursor should track "555" |
| 1921 |
tmux.send_keys 'C-r' |
| 1922 |
tmux.until do |lines| |
| 1923 |
assert_equal 1000, lines.match_count |
| 1924 |
assert_includes lines, '> 555' |
| 1925 |
assert_includes lines[-2], '+T' |
| 1926 |
refute_includes lines[-2], '+T*' |
| 1927 |
end |
| 1928 |
end |
| 1929 |
|
| 1930 |
def test_track_nth_reload_field |
| 1931 |
# --track --id-nth 1 should track by first field across reloads |
| 1932 |
tmux.send_keys "printf '1 apple\\n2 banana\\n3 cherry\\n' | #{FZF} --track --id-nth 1 --bind 'ctrl-r:reload:printf \"1 apricot\\n2 blueberry\\n3 cranberry\\n\"'", :Enter |
| 1933 |
tmux.until do |lines| |
| 1934 |
assert_equal 3, lines.match_count |
| 1935 |
assert_includes lines, '> 1 apple' |
| 1936 |
end |
| 1937 |
|
| 1938 |
# Move up to "2 banana" |
| 1939 |
tmux.send_keys :Up |
| 1940 |
tmux.until { |lines| assert_includes lines, '> 2 banana' } |
| 1941 |
|
| 1942 |
# Reload - the second field changes, but first field "2" stays |
| 1943 |
tmux.send_keys 'C-r' |
| 1944 |
tmux.until do |lines| |
| 1945 |
assert_equal 3, lines.match_count |
| 1946 |
assert_includes lines, '> 2 blueberry' |
| 1947 |
end |
| 1948 |
end |
| 1949 |
|
| 1950 |
def test_track_nth_reload_no_match |
| 1951 |
# When tracked item is not found after reload, cursor stays at current position |
| 1952 |
tmux.send_keys "printf 'alpha\\nbeta\\ngamma\\n' | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:printf \"delta\\nepsilon\\nzeta\\n\"'", :Enter |
| 1953 |
tmux.until { |lines| assert_equal 3, lines.match_count } |
| 1954 |
tmux.send_keys :Up |
| 1955 |
tmux.until { |lines| assert_includes lines, '> beta' } |
| 1956 |
|
| 1957 |
# Reload with completely different items - no match for "beta" |
| 1958 |
# Cursor stays at the same position (second item) |
| 1959 |
tmux.send_keys 'C-r' |
| 1960 |
tmux.until do |lines| |
| 1961 |
assert_equal 3, lines.match_count |
| 1962 |
assert_includes lines, '> epsilon' |
| 1963 |
refute_includes lines[-2], '+T*' |
| 1964 |
end |
| 1965 |
end |
| 1966 |
|
| 1967 |
def test_track_nth_blocked_indicator |
| 1968 |
# +T* should appear during reload and disappear when match is found |
| 1969 |
tmux.send_keys "seq 100 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:sleep 1; seq 100 | sort -R'", :Enter |
| 1970 |
tmux.until do |lines| |
| 1971 |
assert_equal 100, lines.match_count |
| 1972 |
assert_includes lines[-2], '+T' |
| 1973 |
end |
| 1974 |
|
| 1975 |
# Trigger slow reload - should show +T* while blocked |
| 1976 |
tmux.send_keys 'C-r' |
| 1977 |
tmux.until { |lines| assert_includes lines[-2], '+T*' } |
| 1978 |
|
| 1979 |
# After reload completes, +T* should clear back to +T |
| 1980 |
tmux.until do |lines| |
| 1981 |
assert_equal 100, lines.match_count |
| 1982 |
assert_includes lines[-2], '+T' |
| 1983 |
refute_includes lines[-2], '+T*' |
| 1984 |
end |
| 1985 |
end |
| 1986 |
|
| 1987 |
def test_track_nth_abort_unblocks |
| 1988 |
# Escape during track-blocked state should unblock, not quit |
| 1989 |
tmux.send_keys "seq 100 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:sleep 3; seq 100'", :Enter |
| 1990 |
tmux.until do |lines| |
| 1991 |
assert_equal 100, lines.match_count |
| 1992 |
assert_includes lines[-2], '+T' |
| 1993 |
end |
| 1994 |
|
| 1995 |
# Trigger slow reload |
| 1996 |
tmux.send_keys 'C-r' |
| 1997 |
tmux.until { |lines| assert_includes lines[-2], '+T*' } |
| 1998 |
|
| 1999 |
# Escape should unblock, not quit fzf |
| 2000 |
tmux.send_keys :Escape |
| 2001 |
tmux.until do |lines| |
| 2002 |
assert_includes lines[-2], '+T' |
| 2003 |
refute_includes lines[-2], '+T*' |
| 2004 |
end |
| 2005 |
end |
| 2006 |
|
| 2007 |
def test_track_nth_reload_async_unblocks_early |
| 2008 |
# With async reload, +T* should clear as soon as the match streams in, |
| 2009 |
# even while loading is still in progress. |
| 2010 |
# sleep 1 first so +T* is observable, then the match arrives, then more items after a delay. |
| 2011 |
tmux.send_keys "seq 5 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:sleep 1; echo 1; sleep 2; seq 2 10'", :Enter |
| 2012 |
tmux.until do |lines| |
| 2013 |
assert_equal 5, lines.match_count |
| 2014 |
assert_includes lines, '> 1' |
| 2015 |
end |
| 2016 |
|
| 2017 |
# Trigger reload - blocked during initial sleep |
| 2018 |
tmux.send_keys 'C-r' |
| 2019 |
tmux.until { |lines| assert_includes lines[-2], '+T*' } |
| 2020 |
# Match "1" arrives, unblocks before the remaining items load |
| 2021 |
tmux.until do |lines| |
| 2022 |
assert_equal 1, lines.match_count |
| 2023 |
assert_includes lines, '> 1' |
| 2024 |
assert_includes lines[-2], '+T' |
| 2025 |
refute_includes lines[-2], '+T*' |
| 2026 |
end |
| 2027 |
end |
| 2028 |
|
| 2029 |
def test_track_nth_reload_sync_blocks_until_complete |
| 2030 |
# With reload-sync, +T* should stay until the entire stream is complete, |
| 2031 |
# even though the match arrives early in the stream. |
| 2032 |
tmux.send_keys "seq 5 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload-sync:sleep 1; echo 1; sleep 2; seq 2 10'", :Enter |
| 2033 |
tmux.until do |lines| |
| 2034 |
assert_equal 5, lines.match_count |
| 2035 |
assert_includes lines, '> 1' |
| 2036 |
end |
| 2037 |
|
| 2038 |
# Trigger reload-sync - every observable state must be either: |
| 2039 |
# 1. +T* (still blocked), or |
| 2040 |
# 2. final state (count=10, +T without *) |
| 2041 |
# Any other combination (e.g. unblocked while count < 10) is a bug. |
| 2042 |
tmux.send_keys 'C-r' |
| 2043 |
tmux.until do |lines| |
| 2044 |
info = lines[-2] |
| 2045 |
blocked = info&.include?('+T*') |
| 2046 |
unless blocked |
| 2047 |
raise "Unblocked before stream complete (count: #{lines.match_count})" if lines.match_count != 10 |
| 2048 |
|
| 2049 |
assert_includes info, '+T' |
| 2050 |
assert_includes lines, '> 1' |
| 2051 |
end |
| 2052 |
!blocked |
| 2053 |
end |
| 2054 |
end |
| 2055 |
|
| 2056 |
def test_track_nth_toggle_track_unblocks |
| 2057 |
# toggle-track during track-blocked state should unblock and disable tracking |
| 2058 |
tmux.send_keys "seq 100 | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:sleep 5; seq 100' --bind 'ctrl-t:toggle-track'", :Enter |
| 2059 |
tmux.until do |lines| |
| 2060 |
assert_equal 100, lines.match_count |
| 2061 |
assert_includes lines[-2], '+T' |
| 2062 |
end |
| 2063 |
|
| 2064 |
# Trigger slow reload |
| 2065 |
tmux.send_keys 'C-r' |
| 2066 |
tmux.until { |lines| assert_includes lines[-2], '+T*' } |
| 2067 |
|
| 2068 |
# toggle-track should unblock and disable tracking before reload completes |
| 2069 |
tmux.send_keys 'C-t' |
| 2070 |
tmux.until(timeout: 3) do |lines| |
| 2071 |
refute_includes lines[-2], '+T' |
| 2072 |
end |
| 2073 |
end |
| 2074 |
|
| 2075 |
def test_track_nth_reload_async_no_match |
| 2076 |
# With async reload, when tracked item is not found, cursor stays at |
| 2077 |
# current position after stream completes |
| 2078 |
tmux.send_keys "printf 'alpha\\nbeta\\ngamma\\n' | #{FZF} --track --id-nth .. --bind 'ctrl-r:reload:sleep 1; printf \"delta\\nepsilon\\nzeta\\n\"'", :Enter |
| 2079 |
tmux.until { |lines| assert_equal 3, lines.match_count } |
| 2080 |
tmux.send_keys :Up |
| 2081 |
tmux.until { |lines| assert_includes lines, '> beta' } |
| 2082 |
|
| 2083 |
# Reload with completely different items - no match for "beta" |
| 2084 |
tmux.send_keys 'C-r' |
| 2085 |
tmux.until { |lines| assert_includes lines[-2], '+T*' } |
| 2086 |
# After stream completes, unblocks with cursor at same position (second item) |
| 2087 |
tmux.until do |lines| |
| 2088 |
assert_equal 3, lines.match_count |
| 2089 |
assert_includes lines, '> epsilon' |
| 2090 |
refute_includes lines[-2], '+T*' |
| 2091 |
end |
| 2092 |
end |
| 2093 |
|
| 2094 |
def test_track_action_with_id_nth |
| 2095 |
# track-current with --id-nth should track by specified field |
| 2096 |
tmux.send_keys "printf '1 apple\\n2 banana\\n3 cherry\\n' | #{FZF} --id-nth 1 --bind 'ctrl-t:track-current,ctrl-r:reload:printf \"1 apricot\\n2 blueberry\\n3 cranberry\\n\"'", :Enter |
| 2097 |
tmux.until { |lines| assert_equal 3, lines.match_count } |
| 2098 |
|
| 2099 |
# Move to "2 banana" and activate tracking |
| 2100 |
tmux.send_keys :Up |
| 2101 |
tmux.until { |lines| assert_includes lines, '> 2 banana' } |
| 2102 |
tmux.send_keys 'C-t' |
| 2103 |
tmux.until { |lines| assert_includes lines[-2], '+t' } |
| 2104 |
|
| 2105 |
# Reload - should track by field "2" |
| 2106 |
tmux.send_keys 'C-r' |
| 2107 |
tmux.until do |lines| |
| 2108 |
assert_equal 3, lines.match_count |
| 2109 |
assert_includes lines, '> 2 blueberry' |
| 2110 |
end |
| 2111 |
end |
| 2112 |
|
| 2113 |
def test_id_nth_preserve_multi_selection |
| 2114 |
# --id-nth with --multi should preserve selections across reload-sync |
| 2115 |
File.write(tempname, "1 apricot\n2 blueberry\n3 cranberry\n") |
| 2116 |
tmux.send_keys "printf '1 apple\\n2 banana\\n3 cherry\\n' | #{fzf("--multi --id-nth 1 --bind 'ctrl-r:reload-sync:cat #{tempname}'")}", :Enter |
| 2117 |
tmux.until { |lines| assert_equal 3, lines.match_count } |
| 2118 |
|
| 2119 |
# Select first item (1 apple) and third item (3 cherry) |
| 2120 |
tmux.send_keys :Tab |
| 2121 |
tmux.send_keys :Up, :Up, :Tab |
| 2122 |
tmux.until { |lines| assert_includes lines[-2], '(2)' } |
| 2123 |
|
| 2124 |
# Reload - selections should be preserved by id-nth key |
| 2125 |
tmux.send_keys 'C-r' |
| 2126 |
tmux.until do |lines| |
| 2127 |
assert_equal 3, lines.match_count |
| 2128 |
assert_includes lines[-2], '(2)' |
| 2129 |
assert(lines.any? { |l| l.include?('apricot') }) |
| 2130 |
end |
| 2131 |
|
| 2132 |
# Accept and verify the correct items were preserved |
| 2133 |
tmux.send_keys :Enter |
| 2134 |
assert_equal ['1 apricot', '3 cranberry'], fzf_output_lines |
| 2135 |
end |
| 2136 |
|
| 2137 |
def test_one_and_zero |
| 2138 |
tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter |
| 2139 |
tmux.send_keys '1' |
| 2140 |
tmux.until do |lines| |
| 2141 |
assert_equal 2, lines.match_count |
| 2142 |
refute(lines.any? { it.include?('only match') }) |
| 2143 |
refute(lines.any? { it.include?('no match') }) |
| 2144 |
end |
| 2145 |
tmux.send_keys '0' |
| 2146 |
tmux.until do |lines| |
| 2147 |
assert_equal 1, lines.match_count |
| 2148 |
assert(lines.any? { it.include?('only match') }) |
| 2149 |
end |
| 2150 |
tmux.send_keys '0' |
| 2151 |
tmux.until do |lines| |
| 2152 |
assert_equal 0, lines.match_count |
| 2153 |
assert(lines.any? { it.include?('no match') }) |
| 2154 |
end |
| 2155 |
end |
| 2156 |
|
| 2157 |
def test_height_range_with_exit_0 |
| 2158 |
tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter |
| 2159 |
tmux.until { |lines| assert_equal 10, lines.match_count } |
| 2160 |
tmux.send_keys :c |
| 2161 |
tmux.until { |lines| assert_equal 0, lines.match_count } |
| 2162 |
end |
| 2163 |
|
| 2164 |
def test_delete_with_modifiers |
| 2165 |
if ENV['GITHUB_ACTION'] |
| 2166 |
# Expected: "[3]" |
| 2167 |
# Actual: "[]3;5~" |
| 2168 |
skip('CTRL-DELETE is not properly handled in GitHub Actions environment') |
| 2169 |
end |
| 2170 |
tmux.send_keys "seq 100 | #{FZF} --bind 'ctrl-delete:up+up,shift-delete:down,focus:transform-prompt:echo [{}]'", :Enter |
| 2171 |
tmux.until { |lines| assert_equal 100, lines.match_count } |
| 2172 |
tmux.send_keys 'C-Delete' |
| 2173 |
tmux.until { |lines| assert_equal '[3]', lines[-1] } |
| 2174 |
tmux.send_keys 'S-Delete' |
| 2175 |
tmux.until { |lines| assert_equal '[2]', lines[-1] } |
| 2176 |
end |
| 2177 |
|
| 2178 |
def test_fzf_pos |
| 2179 |
tmux.send_keys "seq 100 | #{FZF} --preview 'echo $FZF_POS / $FZF_MATCH_COUNT'", :Enter |
| 2180 |
tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 100') }) } |
| 2181 |
tmux.send_keys :Up |
| 2182 |
tmux.until { |lines| assert(lines.any? { |line| line.include?('2 / 100') }) } |
| 2183 |
tmux.send_keys '99' |
| 2184 |
tmux.until { |lines| assert(lines.any? { |line| line.include?('1 / 1') }) } |
| 2185 |
tmux.send_keys '99' |
| 2186 |
tmux.until { |lines| assert(lines.any? { |line| line.include?('0 / 0') }) } |
| 2187 |
end |
| 2188 |
|
| 2189 |
def test_change_nth |
| 2190 |
input = [ |
| 2191 |
*[''] * 1000, |
| 2192 |
'foo bar bar bar bar', |
| 2193 |
'foo foo bar bar bar', |
| 2194 |
'foo foo foo bar bar', |
| 2195 |
'foo foo foo foo bar', |
| 2196 |
*[''] * 1000 |
| 2197 |
] |
| 2198 |
writelines(input) |
| 2199 |
nths = '1,2..4,-1,-3..,..2' |
| 2200 |
tmux.send_keys %(#{FZF} -qfoo -n#{nths} --bind 'space:change-nth(2|3|4|5|),result:transform-prompt:echo "[$FZF_NTH] "' < #{tempname}), :Enter |
| 2201 |
|
| 2202 |
tmux.until do |lines| |
| 2203 |
assert lines.any_include?("[#{nths}] foo") |
| 2204 |
assert_equal 4, lines.match_count |
| 2205 |
end |
| 2206 |
tmux.send_keys :Space |
| 2207 |
tmux.until do |lines| |
| 2208 |
assert lines.any_include?('[2] foo') |
| 2209 |
assert_equal 3, lines.match_count |
| 2210 |
end |
| 2211 |
tmux.send_keys :Space |
| 2212 |
tmux.until do |lines| |
| 2213 |
assert lines.any_include?('[3] foo') |
| 2214 |
assert_equal 2, lines.match_count |
| 2215 |
end |
| 2216 |
tmux.send_keys :Space |
| 2217 |
tmux.until do |lines| |
| 2218 |
assert lines.any_include?('[4] foo') |
| 2219 |
assert_equal 1, lines.match_count |
| 2220 |
end |
| 2221 |
tmux.send_keys :Space |
| 2222 |
tmux.until do |lines| |
| 2223 |
assert lines.any_include?('[5] foo') |
| 2224 |
assert_equal 0, lines.match_count |
| 2225 |
end |
| 2226 |
tmux.send_keys :Space |
| 2227 |
tmux.until do |lines| |
| 2228 |
assert lines.any_include?("[#{nths}] foo") |
| 2229 |
assert_equal 4, lines.match_count |
| 2230 |
end |
| 2231 |
end |
| 2232 |
|
| 2233 |
def test_change_with_nth |
| 2234 |
input = [ |
| 2235 |
'foo bar baz', |
| 2236 |
'aaa bbb ccc', |
| 2237 |
'xxx yyy zzz' |
| 2238 |
] |
| 2239 |
writelines(input) |
| 2240 |
# Start with field 1 only, cycle through fields, verify $FZF_WITH_NTH via prompt |
| 2241 |
tmux.send_keys %(#{FZF} --with-nth 1 --bind 'space:change-with-nth(2|3|1),result:transform-prompt:echo "[$FZF_WITH_NTH]> "' < #{tempname}), :Enter |
| 2242 |
tmux.until do |lines| |
| 2243 |
assert_equal 3, lines.item_count |
| 2244 |
assert lines.any_include?('[1]>') |
| 2245 |
assert lines.any_include?('foo') |
| 2246 |
refute lines.any_include?('bar') |
| 2247 |
end |
| 2248 |
tmux.send_keys :Space |
| 2249 |
tmux.until do |lines| |
| 2250 |
assert lines.any_include?('[2]>') |
| 2251 |
assert lines.any_include?('bar') |
| 2252 |
refute lines.any_include?('foo') |
| 2253 |
end |
| 2254 |
tmux.send_keys :Space |
| 2255 |
tmux.until do |lines| |
| 2256 |
assert lines.any_include?('[3]>') |
| 2257 |
assert lines.any_include?('baz') |
| 2258 |
refute lines.any_include?('bar') |
| 2259 |
end |
| 2260 |
tmux.send_keys :Space |
| 2261 |
tmux.until do |lines| |
| 2262 |
assert lines.any_include?('[1]>') |
| 2263 |
assert lines.any_include?('foo') |
| 2264 |
refute lines.any_include?('bar') |
| 2265 |
end |
| 2266 |
end |
| 2267 |
|
| 2268 |
def test_change_with_nth_default |
| 2269 |
# Empty value restores the default --with-nth |
| 2270 |
tmux.send_keys %(echo -e 'a b c\nd e f' | #{FZF} --with-nth 1 --bind 'space:change-with-nth(2|)'), :Enter |
| 2271 |
tmux.until do |lines| |
| 2272 |
assert_equal 2, lines.item_count |
| 2273 |
assert lines.any_include?('a') |
| 2274 |
refute lines.any_include?('b') |
| 2275 |
end |
| 2276 |
# Switch to field 2 |
| 2277 |
tmux.send_keys :Space |
| 2278 |
tmux.until do |lines| |
| 2279 |
assert lines.any_include?('b') |
| 2280 |
refute lines.any_include?('a') |
| 2281 |
end |
| 2282 |
# Empty restores default (field 1) |
| 2283 |
tmux.send_keys :Space |
| 2284 |
tmux.until do |lines| |
| 2285 |
assert lines.any_include?('a') |
| 2286 |
refute lines.any_include?('b') |
| 2287 |
end |
| 2288 |
end |
| 2289 |
|
| 2290 |
def test_transform_with_nth_search |
| 2291 |
input = [ |
| 2292 |
'alpha bravo charlie', |
| 2293 |
'delta echo foxtrot', |
| 2294 |
'golf hotel india' |
| 2295 |
] |
| 2296 |
writelines(input) |
| 2297 |
tmux.send_keys %(#{FZF} --with-nth 1 --bind 'space:transform-with-nth(echo 2)' -q '^bravo$' < #{tempname}), :Enter |
| 2298 |
tmux.until do |lines| |
| 2299 |
assert_equal 0, lines.match_count |
| 2300 |
end |
| 2301 |
tmux.send_keys :Space |
| 2302 |
tmux.until do |lines| |
| 2303 |
assert_equal 1, lines.match_count |
| 2304 |
end |
| 2305 |
end |
| 2306 |
|
| 2307 |
def test_bg_transform_with_nth_output |
| 2308 |
tmux.send_keys %(echo -e 'a b c\nd e f' | #{FZF} --with-nth 2 --bind 'space:bg-transform-with-nth(echo 3)'), :Enter |
| 2309 |
tmux.until do |lines| |
| 2310 |
assert_equal 2, lines.item_count |
| 2311 |
assert lines.any_include?('b') |
| 2312 |
end |
| 2313 |
tmux.send_keys :Space |
| 2314 |
tmux.until do |lines| |
| 2315 |
assert lines.any_include?('c') |
| 2316 |
refute lines.any_include?('b') |
| 2317 |
end |
| 2318 |
tmux.send_keys :Enter |
| 2319 |
tmux.until { |lines| assert lines.any_include?('a b c') || lines.any_include?('d e f') } |
| 2320 |
end |
| 2321 |
|
| 2322 |
# Regression: actions emitted by bg-transform must affect the iteration that |
| 2323 |
# processes the async result, not the (no-longer-active) iteration that |
| 2324 |
# scheduled the transform. Covers reload (newCommand) and exclude (denylist). |
| 2325 |
def test_bg_transform_action_output |
| 2326 |
tmux.send_keys %(seq 5 | #{FZF} --bind 'a:bg-transform(echo reload:seq 10 20),b:bg-transform(echo exclude)'), :Enter |
| 2327 |
tmux.until { |lines| assert_equal 5, lines.item_count } |
| 2328 |
tmux.send_keys :a |
| 2329 |
tmux.until do |lines| |
| 2330 |
assert_equal 11, lines.match_count |
| 2331 |
assert_includes lines, '> 10' |
| 2332 |
end |
| 2333 |
tmux.send_keys :b |
| 2334 |
tmux.until do |lines| |
| 2335 |
assert_equal 10, lines.match_count |
| 2336 |
assert_includes lines, '> 11' |
| 2337 |
end |
| 2338 |
end |
| 2339 |
|
| 2340 |
def test_change_with_nth_search |
| 2341 |
input = [ |
| 2342 |
'alpha bravo charlie', |
| 2343 |
'delta echo foxtrot', |
| 2344 |
'golf hotel india' |
| 2345 |
] |
| 2346 |
writelines(input) |
| 2347 |
tmux.send_keys %(#{FZF} --with-nth 1 --bind 'space:change-with-nth(2)' -q '^bravo$' < #{tempname}), :Enter |
| 2348 |
tmux.until do |lines| |
| 2349 |
assert_equal 0, lines.match_count |
| 2350 |
end |
| 2351 |
tmux.send_keys :Space |
| 2352 |
tmux.until do |lines| |
| 2353 |
assert_equal 1, lines.match_count |
| 2354 |
end |
| 2355 |
end |
| 2356 |
|
| 2357 |
def test_change_with_nth_output |
| 2358 |
tmux.send_keys %(echo -e 'a b c\nd e f' | #{FZF} --with-nth 2 --bind 'space:change-with-nth(3)'), :Enter |
| 2359 |
tmux.until do |lines| |
| 2360 |
assert_equal 2, lines.item_count |
| 2361 |
assert lines.any_include?('b') |
| 2362 |
end |
| 2363 |
tmux.send_keys :Space |
| 2364 |
tmux.until do |lines| |
| 2365 |
assert lines.any_include?('c') |
| 2366 |
refute lines.any_include?('b') |
| 2367 |
end |
| 2368 |
tmux.send_keys :Enter |
| 2369 |
tmux.until { |lines| assert lines.any_include?('a b c') || lines.any_include?('d e f') } |
| 2370 |
end |
| 2371 |
|
| 2372 |
def test_change_with_nth_selection |
| 2373 |
# Items: field1 has unique values, field2 has 'match' or 'miss' |
| 2374 |
input = [ |
| 2375 |
'one match x', |
| 2376 |
'two miss y', |
| 2377 |
'three match z' |
| 2378 |
] |
| 2379 |
writelines(input) |
| 2380 |
# Start showing field 2 (match/miss), query 'match', select all matches, then switch to field 3 |
| 2381 |
tmux.send_keys %(#{FZF} --with-nth 2 --multi --bind 'ctrl-a:select-all,space:change-with-nth(3)' -q match < #{tempname}), :Enter |
| 2382 |
tmux.until do |lines| |
| 2383 |
assert_equal 2, lines.match_count |
| 2384 |
end |
| 2385 |
# Select all matching items |
| 2386 |
tmux.send_keys 'C-a' |
| 2387 |
tmux.until do |lines| |
| 2388 |
assert lines.any_include?('(2)') |
| 2389 |
end |
| 2390 |
# Now change with-nth to field 3; 'x' and 'z' don't contain 'match' |
| 2391 |
tmux.send_keys :Space |
| 2392 |
tmux.until do |lines| |
| 2393 |
assert_equal 0, lines.match_count |
| 2394 |
# Selections of non-matching items should be cleared |
| 2395 |
assert lines.any_include?('(0)') |
| 2396 |
end |
| 2397 |
end |
| 2398 |
|
| 2399 |
def test_change_with_nth_multiline |
| 2400 |
# Each item has 3 lines: "N-a\nN-b\nN-c" |
| 2401 |
# --with-nth 1 shows 1 line per item, --with-nth 1..3 shows 3 lines per item |
| 2402 |
tmux.send_keys %(seq 20 | xargs -I{} printf '{}-a\\n{}-b\\n{}-c\\0' | #{FZF} --read0 --delimiter "\n" --with-nth 1 --bind 'space:change-with-nth(1..3|1)' --no-sort), :Enter |
| 2403 |
tmux.until do |lines| |
| 2404 |
assert_equal 20, lines.item_count |
| 2405 |
assert lines.any_include?('1-a') |
| 2406 |
refute lines.any_include?('1-b') |
| 2407 |
end |
| 2408 |
# Expand to 3 lines per item |
| 2409 |
tmux.send_keys :Space |
| 2410 |
tmux.until do |lines| |
| 2411 |
assert lines.any_include?('1-a') |
| 2412 |
assert lines.any_include?('1-b') |
| 2413 |
assert lines.any_include?('1-c') |
| 2414 |
end |
| 2415 |
# Scroll down a few items |
| 2416 |
5.times { tmux.send_keys :Down } |
| 2417 |
tmux.until do |lines| |
| 2418 |
assert lines.any_include?('6-a') |
| 2419 |
assert lines.any_include?('6-b') |
| 2420 |
assert lines.any_include?('6-c') |
| 2421 |
end |
| 2422 |
# Collapse back to 1 line per item |
| 2423 |
tmux.send_keys :Space |
| 2424 |
tmux.until do |lines| |
| 2425 |
assert lines.any_include?('6-a') |
| 2426 |
refute lines.any_include?('6-b') |
| 2427 |
end |
| 2428 |
# Scroll down more after collapse |
| 2429 |
5.times { tmux.send_keys :Down } |
| 2430 |
tmux.until do |lines| |
| 2431 |
assert lines.any_include?('11-a') |
| 2432 |
refute lines.any_include?('11-b') |
| 2433 |
end |
| 2434 |
end |
| 2435 |
|
| 2436 |
def test_env_vars |
| 2437 |
def env_vars |
| 2438 |
return {} unless File.exist?(tempname) |
| 2439 |
|
| 2440 |
File.readlines(tempname).select { it.start_with?('FZF_') }.to_h do |
| 2441 |
key, val = it.chomp.split('=', 2) |
| 2442 |
[key.to_sym, val] |
| 2443 |
end |
| 2444 |
end |
| 2445 |
|
| 2446 |
tmux.send_keys %({ echo foo; seq 100; } | #{FZF} --header-lines 1 --multi --reverse --preview-window 0 --preview 'env | grep ^FZF_ | sort > #{tempname}' --no-input --bind enter:show-input+refresh-preview,space:disable-search+refresh-preview), :Enter |
| 2447 |
expected = { |
| 2448 |
FZF_DIRECTION: 'down', |
| 2449 |
FZF_TOTAL_COUNT: '100', |
| 2450 |
FZF_MATCH_COUNT: '100', |
| 2451 |
FZF_SELECT_COUNT: '0', |
| 2452 |
FZF_ACTION: 'start', |
| 2453 |
FZF_KEY: '', |
| 2454 |
FZF_POS: '1', |
| 2455 |
FZF_CURRENT_ITEM: '1', |
| 2456 |
FZF_QUERY: '', |
| 2457 |
FZF_POINTER: '>', |
| 2458 |
FZF_PROMPT: '> ', |
| 2459 |
FZF_INPUT_STATE: 'hidden' |
| 2460 |
} |
| 2461 |
tmux.until do |
| 2462 |
assert_equal expected, env_vars.slice(*expected.keys) |
| 2463 |
end |
| 2464 |
tmux.send_keys :Enter |
| 2465 |
tmux.until do |
| 2466 |
expected.merge!(FZF_INPUT_STATE: 'enabled', FZF_ACTION: 'show-input', FZF_KEY: 'enter') |
| 2467 |
assert_equal expected, env_vars.slice(*expected.keys) |
| 2468 |
end |
| 2469 |
tmux.send_keys :Tab, :Tab |
| 2470 |
tmux.until do |
| 2471 |
expected.merge!(FZF_ACTION: 'toggle-down', FZF_KEY: 'tab', FZF_POS: '3', FZF_CURRENT_ITEM: '3', FZF_SELECT_COUNT: '2') |
| 2472 |
assert_equal expected, env_vars.slice(*expected.keys) |
| 2473 |
end |
| 2474 |
tmux.send_keys '99' |
| 2475 |
tmux.until do |
| 2476 |
expected.merge!(FZF_ACTION: 'char', FZF_KEY: '9', FZF_QUERY: '99', FZF_MATCH_COUNT: '1', FZF_POS: '1', FZF_CURRENT_ITEM: '99') |
| 2477 |
assert_equal expected, env_vars.slice(*expected.keys) |
| 2478 |
end |
| 2479 |
tmux.send_keys :Space |
| 2480 |
tmux.until do |
| 2481 |
expected.merge!(FZF_INPUT_STATE: 'disabled', FZF_ACTION: 'disable-search', FZF_KEY: 'space') |
| 2482 |
assert_equal expected, env_vars.slice(*expected.keys) |
| 2483 |
end |
| 2484 |
end |
| 2485 |
|
| 2486 |
def test_env_current_item_size_limit |
| 2487 |
preview = %[(echo START; env | grep '^FZF_CURRENT_ITEM='; echo END) > #{tempname}] |
| 2488 |
# Large item (> 64 KB) is omitted so it cannot overflow ARG_MAX and break exec |
| 2489 |
tmux.send_keys %(head -c 70000 /dev/zero | tr '\\0' a | #{FZF} --preview-window 0 --preview "#{preview}"), :Enter |
| 2490 |
wait do |
| 2491 |
content = File.exist?(tempname) ? File.read(tempname) : '' |
| 2492 |
assert_includes content, 'END' |
| 2493 |
refute_includes content, 'FZF_CURRENT_ITEM=' |
| 2494 |
end |
| 2495 |
tmux.send_keys :Enter |
| 2496 |
FileUtils.rm_f(tempname) |
| 2497 |
# Smaller item is exported as usual |
| 2498 |
tmux.send_keys %(head -c 1000 /dev/zero | tr '\\0' a | #{FZF} --preview-window 0 --preview "#{preview}"), :Enter |
| 2499 |
wait do |
| 2500 |
content = File.exist?(tempname) ? File.read(tempname) : '' |
| 2501 |
assert_includes content, 'END' |
| 2502 |
assert_includes content, 'FZF_CURRENT_ITEM=' + ('a' * 1000) |
| 2503 |
end |
| 2504 |
end |
| 2505 |
|
| 2506 |
def test_abort_action_chain |
| 2507 |
tmux.send_keys %(seq 100 | #{FZF} --bind 'load:accept+up+up' > #{tempname}), :Enter |
| 2508 |
wait do |
| 2509 |
assert_path_exists tempname |
| 2510 |
assert_equal '1', File.read(tempname).chomp |
| 2511 |
end |
| 2512 |
tmux.send_keys %(seq 100 | #{FZF} --bind 'load:abort+become(echo {})' > #{tempname}), :Enter |
| 2513 |
wait do |
| 2514 |
assert_path_exists tempname |
| 2515 |
assert_equal '', File.read(tempname).chomp |
| 2516 |
end |
| 2517 |
end |
| 2518 |
|
| 2519 |
def test_exclude_multi |
| 2520 |
tmux.send_keys %(seq 1000 | #{FZF} --multi --bind 'a:exclude-multi,b:reload(seq 1000),c:reload-sync(seq 1000)'), :Enter |
| 2521 |
|
| 2522 |
tmux.until do |lines| |
| 2523 |
assert_equal 1000, lines.match_count |
| 2524 |
assert_includes lines, '> 1' |
| 2525 |
end |
| 2526 |
tmux.send_keys :a |
| 2527 |
tmux.until do |lines| |
| 2528 |
assert_includes lines, '> 2' |
| 2529 |
assert_equal 999, lines.match_count |
| 2530 |
end |
| 2531 |
tmux.send_keys :Up, :BTab, :BTab, :BTab, :a |
| 2532 |
tmux.until do |lines| |
| 2533 |
assert_equal 996, lines.match_count |
| 2534 |
assert_includes lines, '> 9' |
| 2535 |
end |
| 2536 |
tmux.send_keys :b |
| 2537 |
tmux.until do |lines| |
| 2538 |
assert_equal 1000, lines.match_count |
| 2539 |
assert_includes lines, '> 5' |
| 2540 |
end |
| 2541 |
tmux.send_keys :Tab, :Tab, :Tab, :a |
| 2542 |
tmux.until do |lines| |
| 2543 |
assert_equal 997, lines.match_count |
| 2544 |
assert_includes lines, '> 2' |
| 2545 |
end |
| 2546 |
tmux.send_keys :c |
| 2547 |
tmux.until do |lines| |
| 2548 |
assert_equal 1000, lines.match_count |
| 2549 |
assert_includes lines, '> 2' |
| 2550 |
end |
| 2551 |
|
| 2552 |
# TODO: We should also check the behavior of 'exclude' during reloads |
| 2553 |
end |
| 2554 |
|
| 2555 |
def test_exclude |
| 2556 |
tmux.send_keys %(seq 1000 | #{FZF} --multi --bind 'a:exclude,b:reload(seq 1000),c:reload-sync(seq 1000)'), :Enter |
| 2557 |
|
| 2558 |
tmux.until do |lines| |
| 2559 |
assert_equal 1000, lines.match_count |
| 2560 |
assert_includes lines, '> 1' |
| 2561 |
end |
| 2562 |
tmux.send_keys :a |
| 2563 |
tmux.until do |lines| |
| 2564 |
assert_includes lines, '> 2' |
| 2565 |
assert_equal 999, lines.match_count |
| 2566 |
end |
| 2567 |
tmux.send_keys :Up, :BTab, :BTab, :BTab, :a |
| 2568 |
tmux.until do |lines| |
| 2569 |
assert_equal 998, lines.match_count |
| 2570 |
assert_equal 3, lines.select_count |
| 2571 |
assert_includes lines, '> 7' |
| 2572 |
end |
| 2573 |
tmux.send_keys :b |
| 2574 |
tmux.until do |lines| |
| 2575 |
assert_equal 1000, lines.match_count |
| 2576 |
assert_equal 0, lines.select_count |
| 2577 |
assert_includes lines, '> 5' |
| 2578 |
end |
| 2579 |
tmux.send_keys :Tab, :Tab, :Tab, :a |
| 2580 |
tmux.until do |lines| |
| 2581 |
assert_equal 999, lines.match_count |
| 2582 |
assert_equal 3, lines.select_count |
| 2583 |
assert_includes lines, '>>3' |
| 2584 |
end |
| 2585 |
tmux.send_keys :a |
| 2586 |
tmux.until do |lines| |
| 2587 |
assert_equal 998, lines.match_count |
| 2588 |
assert_equal 2, lines.select_count |
| 2589 |
assert_includes lines, '>>4' |
| 2590 |
end |
| 2591 |
tmux.send_keys :c |
| 2592 |
tmux.until do |lines| |
| 2593 |
assert_equal 1000, lines.match_count |
| 2594 |
assert_includes lines, '> 2' |
| 2595 |
end |
| 2596 |
|
| 2597 |
# TODO: We should also check the behavior of 'exclude' during reloads |
| 2598 |
end |
| 2599 |
|
| 2600 |
def test_accept_nth |
| 2601 |
tmux.send_keys %((echo "foo bar baz"; echo "bar baz foo") | #{FZF} --multi --accept-nth 2,2 --sync --bind start:select-all+accept > #{tempname}), :Enter |
| 2602 |
wait do |
| 2603 |
assert_path_exists tempname |
| 2604 |
assert_equal ['bar bar', 'baz baz'], File.readlines(tempname, chomp: true) |
| 2605 |
end |
| 2606 |
end |
| 2607 |
|
| 2608 |
def test_accept_nth_string_delimiter |
| 2609 |
tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d, --accept-nth 2,2,1,3,1 --sync --bind start:accept > #{tempname}), :Enter |
| 2610 |
wait do |
| 2611 |
assert_path_exists tempname |
| 2612 |
# Last delimiter is removed |
| 2613 |
assert_equal ['bar,bar,foo ,bazfoo '], File.readlines(tempname, chomp: true) |
| 2614 |
end |
| 2615 |
end |
| 2616 |
|
| 2617 |
def test_accept_nth_regex_delimiter |
| 2618 |
tmux.send_keys %(echo "foo :,:bar,baz" | #{FZF} --delimiter=' *[:,]+ *' --accept-nth 2,2,1,3,1 --sync --bind start:accept > #{tempname}), :Enter |
| 2619 |
wait do |
| 2620 |
assert_path_exists tempname |
| 2621 |
# Last delimiter and the whitespaces are removed |
| 2622 |
assert_equal ['bar,bar,foo :,:bazfoo'], File.readlines(tempname, chomp: true) |
| 2623 |
end |
| 2624 |
end |
| 2625 |
|
| 2626 |
def test_accept_nth_regex_delimiter_strip_last |
| 2627 |
tmux.send_keys %((echo "foo:,bar:,baz"; echo "foo:,bar:,baz:,qux:,") | #{FZF} --multi --delimiter='[:,]+' --accept-nth 2.. --sync --bind 'load:select-all+accept' > #{tempname}), :Enter |
| 2628 |
wait do |
| 2629 |
assert_path_exists tempname |
| 2630 |
# Last delimiter and the whitespaces are removed |
| 2631 |
assert_equal ['bar:,baz', 'bar:,baz:,qux'], File.readlines(tempname, chomp: true) |
| 2632 |
end |
| 2633 |
end |
| 2634 |
|
| 2635 |
def test_accept_nth_template |
| 2636 |
tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d " *, *" --accept-nth '[{n}] 1st: {1}, 3rd: {3}, 2nd: {2}' --sync --bind start:accept > #{tempname}), :Enter |
| 2637 |
wait do |
| 2638 |
assert_path_exists tempname |
| 2639 |
# Last delimiter and the whitespaces are removed |
| 2640 |
assert_equal ['[0] 1st: foo, 3rd: baz, 2nd: bar'], File.readlines(tempname, chomp: true) |
| 2641 |
end |
| 2642 |
end |
| 2643 |
|
| 2644 |
def test_ghost |
| 2645 |
tmux.send_keys %(seq 100 | #{FZF} --prompt 'X ' --ghost 'Type in query ...' --bind 'space:change-ghost:Y Z' --bind 'enter:transform-ghost:echo Z Y'), :Enter |
| 2646 |
tmux.until do |lines| |
| 2647 |
assert_equal 100, lines.match_count |
| 2648 |
assert_includes lines, 'X Type in query ...' |
| 2649 |
end |
| 2650 |
tmux.send_keys '100' |
| 2651 |
tmux.until do |lines| |
| 2652 |
assert_equal 1, lines.match_count |
| 2653 |
assert_includes lines, 'X 100' |
| 2654 |
end |
| 2655 |
tmux.send_keys 'C-u' |
| 2656 |
tmux.until do |lines| |
| 2657 |
assert_equal 100, lines.match_count |
| 2658 |
assert_includes lines, 'X Type in query ...' |
| 2659 |
end |
| 2660 |
tmux.send_keys :Space |
| 2661 |
tmux.until { |lines| assert_includes lines, 'X Y Z' } |
| 2662 |
tmux.send_keys :Enter |
| 2663 |
tmux.until { |lines| assert_includes lines, 'X Z Y' } |
| 2664 |
end |
| 2665 |
|
| 2666 |
def test_ghost_inline |
| 2667 |
tmux.send_keys %(seq 100 | #{FZF} --info 'inline: Y' --no-separator --prompt 'X ' --ghost 'Type in query ...'), :Enter |
| 2668 |
tmux.until do |lines| |
| 2669 |
assert_includes lines, 'X Type in query ... Y100/100' |
| 2670 |
end |
| 2671 |
tmux.send_keys '100' |
| 2672 |
tmux.until do |lines| |
| 2673 |
assert_includes lines, 'X 100 Y1/100' |
| 2674 |
end |
| 2675 |
tmux.send_keys 'C-u' |
| 2676 |
tmux.until do |lines| |
| 2677 |
assert_includes lines, 'X Type in query ... Y100/100' |
| 2678 |
end |
| 2679 |
end |
| 2680 |
|
| 2681 |
def test_offset_middle |
| 2682 |
tmux.send_keys %(seq 1000 | #{FZF} --sync --no-input --reverse --height 5 --scroll-off 0 --bind space:offset-middle), :Enter |
| 2683 |
line = nil |
| 2684 |
tmux.until { |lines| line = lines.index('> 1') } |
| 2685 |
tmux.send_keys :PgDn |
| 2686 |
tmux.until { |lines| assert_includes lines[line + 4], '> 5' } |
| 2687 |
tmux.send_keys :Space |
| 2688 |
tmux.until { |lines| assert_includes lines[line + 2], '> 5' } |
| 2689 |
end |
| 2690 |
|
| 2691 |
def test_no_input_query |
| 2692 |
tmux.send_keys %(seq 1000 | #{FZF} --no-input --query 555 --bind space:toggle-input), :Enter |
| 2693 |
tmux.until { |lines| assert_includes lines, '> 555' } |
| 2694 |
tmux.send_keys :Space |
| 2695 |
tmux.until do |lines| |
| 2696 |
assert_equal 1, lines.match_count |
| 2697 |
assert_includes lines, '> 555' |
| 2698 |
end |
| 2699 |
end |
| 2700 |
|
| 2701 |
def test_no_input_change_query |
| 2702 |
tmux.send_keys %(seq 1000 | #{FZF} --multi --query 999 --no-input --bind 'enter:show-input+change-query(555)+hide-input,space:change-query(555)+select'), :Enter |
| 2703 |
tmux.until { |lines| assert_includes lines, '> 999' } |
| 2704 |
tmux.send_keys :Space |
| 2705 |
tmux.until do |lines| |
| 2706 |
assert_includes lines, '>>999' |
| 2707 |
refute_includes lines, '> 555' |
| 2708 |
end |
| 2709 |
tmux.send_keys :Enter |
| 2710 |
tmux.until do |lines| |
| 2711 |
refute_includes lines, '>>999' |
| 2712 |
assert_includes lines, '> 555' |
| 2713 |
end |
| 2714 |
end |
| 2715 |
|
| 2716 |
def test_search_override_query_in_no_input_mode |
| 2717 |
tmux.send_keys %(seq 1000 | #{FZF} --sync --no-input --bind 'enter:show-input+change-query(555)+hide-input+search(999),space:search(111)+show-input+change-query(777)'), :Enter |
| 2718 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 2719 |
tmux.send_keys :Enter |
| 2720 |
tmux.until { |lines| assert_includes lines, '> 999' } |
| 2721 |
tmux.send_keys :Space |
| 2722 |
tmux.until { |lines| assert_includes lines, '> 777' } |
| 2723 |
end |
| 2724 |
|
| 2725 |
def test_change_pointer |
| 2726 |
tmux.send_keys %(seq 2 | #{FZF} --bind 'a:change-pointer(a),b:change-pointer(bb),c:change-pointer(),d:change-pointer(ddd)'), :Enter |
| 2727 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 2728 |
tmux.send_keys 'a' |
| 2729 |
tmux.until { |lines| assert_includes lines, 'a 1' } |
| 2730 |
tmux.send_keys 'b' |
| 2731 |
tmux.until { |lines| assert_includes lines, 'bb 1' } |
| 2732 |
tmux.send_keys 'c' |
| 2733 |
tmux.until { |lines| assert_includes lines, ' 1' } |
| 2734 |
tmux.send_keys 'd' |
| 2735 |
tmux.until { |lines| refute_includes lines, 'ddd 1' } |
| 2736 |
tmux.send_keys :Up |
| 2737 |
tmux.until { |lines| assert_includes lines, ' 2' } |
| 2738 |
end |
| 2739 |
|
| 2740 |
def test_transform_pointer |
| 2741 |
tmux.send_keys %(seq 2 | #{FZF} --bind 'a:transform-pointer(echo a),b:transform-pointer(echo bb),c:transform-pointer(),d:transform-pointer(echo ddd)'), :Enter |
| 2742 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 2743 |
tmux.send_keys 'a' |
| 2744 |
tmux.until { |lines| assert_includes lines, 'a 1' } |
| 2745 |
tmux.send_keys 'b' |
| 2746 |
tmux.until { |lines| assert_includes lines, 'bb 1' } |
| 2747 |
tmux.send_keys 'c' |
| 2748 |
tmux.until { |lines| assert_includes lines, ' 1' } |
| 2749 |
tmux.send_keys 'd' |
| 2750 |
tmux.until { |lines| refute_includes lines, 'ddd 1' } |
| 2751 |
tmux.send_keys :Up |
| 2752 |
tmux.until { |lines| assert_includes lines, ' 2' } |
| 2753 |
end |
| 2754 |
|
| 2755 |
def test_change_header_on_header_window |
| 2756 |
tmux.send_keys %(seq 100 | #{FZF} --list-border --input-border --bind 'start:change-header(foo),space:change-header(bar)'), :Enter |
| 2757 |
tmux.until do |lines| |
| 2758 |
assert lines.any_include?('100/100') |
| 2759 |
assert lines.any_include?('foo') |
| 2760 |
end |
| 2761 |
tmux.send_keys :Space |
| 2762 |
tmux.until { |lines| assert lines.any_include?('bar') } |
| 2763 |
end |
| 2764 |
|
| 2765 |
def test_trailing_new_line |
| 2766 |
tmux.send_keys %(echo -en "foo\n" | fzf --read0 --no-multi-line), :Enter |
| 2767 |
tmux.until { |lines| assert_includes lines, '> foo␊' } |
| 2768 |
end |
| 2769 |
|
| 2770 |
def test_async_transform |
| 2771 |
time = Time.now |
| 2772 |
tmux.send_keys %( |
| 2773 |
seq 100 | #{FZF} --style full --border --preview : \ |
| 2774 |
--bind 'focus:bg-transform-header(sleep 0.5; echo th.)' \ |
| 2775 |
--bind 'focus:+bg-transform-footer(sleep 0.5; echo tf.)' \ |
| 2776 |
--bind 'focus:+bg-transform-border-label(sleep 0.5; echo tbl.)' \ |
| 2777 |
--bind "focus:+bg-transform-preview-label(sleep 0.5; echo tpl.)" \ |
| 2778 |
--bind 'focus:+bg-transform-input-label(sleep 0.5; echo til.)' \ |
| 2779 |
--bind 'focus:+bg-transform-list-label(sleep 0.5; echo tll.)' \ |
| 2780 |
--bind 'focus:+bg-transform-header-label(sleep 0.5; echo thl.)' \ |
| 2781 |
--bind 'focus:+bg-transform-footer-label(sleep 0.5; echo tfl.)' \ |
| 2782 |
--bind 'focus:+bg-transform-prompt(sleep 0.5; echo tp.)' \ |
| 2783 |
--bind 'focus:+bg-transform-ghost(sleep 0.5; echo tg.)' |
| 2784 |
).strip, :Enter |
| 2785 |
tmux.until do |lines| |
| 2786 |
assert lines.any_include?('100/100') |
| 2787 |
%w[th tf tbl tpl til tll thl tfl tp tg].each do |
| 2788 |
assert lines.any_include?("#{it}.") |
| 2789 |
end |
| 2790 |
end |
| 2791 |
elapsed = Time.now - time |
| 2792 |
assert_operator elapsed, :<, 2 |
| 2793 |
end |
| 2794 |
|
| 2795 |
def test_bg_cancel |
| 2796 |
tmux.send_keys %(seq 0 1 | #{FZF} --bind 'space:bg-cancel+bg-transform-header(sleep {}; echo [{}])'), :Enter |
| 2797 |
tmux.until { assert_equal 2, it.match_count } |
| 2798 |
tmux.send_keys '1' |
| 2799 |
tmux.until { assert_equal 1, it.match_count } |
| 2800 |
tmux.send_keys :Space |
| 2801 |
tmux.send_keys :BSpace |
| 2802 |
tmux.until { assert_equal 2, it.match_count } |
| 2803 |
tmux.send_keys :Space |
| 2804 |
tmux.until { |lines| assert lines.any_include?('[0]') } |
| 2805 |
sleep(2) |
| 2806 |
tmux.until do |lines| |
| 2807 |
assert lines.any_include?('[0]') |
| 2808 |
refute lines.any_include?('[1]') |
| 2809 |
end |
| 2810 |
end |
| 2811 |
|
| 2812 |
def test_render_order |
| 2813 |
tmux.send_keys %(seq 100 | #{FZF} --bind='focus:preview(echo boom)+change-footer(bam)'), :Enter |
| 2814 |
tmux.until { assert_equal 100, it.match_count } |
| 2815 |
tmux.until { assert it.any_include?('boom') } |
| 2816 |
tmux.until { assert it.any_include?('bam') } |
| 2817 |
end |
| 2818 |
|
| 2819 |
def test_multi_event |
| 2820 |
tmux.send_keys %(seq 100 | #{FZF} --multi --bind 'multi:transform-footer:(( FZF_SELECT_COUNT )) && echo "Selected $FZF_SELECT_COUNT item(s)"'), :Enter |
| 2821 |
tmux.until { assert_equal 100, it.match_count } |
| 2822 |
tmux.send_keys :Tab |
| 2823 |
tmux.until { assert_equal 1, it.select_count } |
| 2824 |
tmux.until { assert it.any_include?('Selected 1 item(s)') } |
| 2825 |
tmux.send_keys :Tab |
| 2826 |
tmux.until { assert_equal 0, it.select_count } |
| 2827 |
tmux.until { refute it.any_include?('Selected') } |
| 2828 |
end |
| 2829 |
|
| 2830 |
def test_preserve_selection_on_revision_bump |
| 2831 |
tmux.send_keys %(seq 100 | #{FZF} --multi --sync --query "'1" --bind 'a:select-all+change-header(pressed a),b:change-header(pressed b)+change-nth(1),c:exclude'), :Enter |
| 2832 |
tmux.until do |
| 2833 |
assert_equal 20, it.match_count |
| 2834 |
assert_equal 0, it.select_count |
| 2835 |
end |
| 2836 |
tmux.send_keys :a |
| 2837 |
tmux.until do |
| 2838 |
assert_equal 20, it.match_count |
| 2839 |
assert_equal 20, it.select_count |
| 2840 |
assert it.any_include?('pressed a') |
| 2841 |
end |
| 2842 |
tmux.send_keys :b |
| 2843 |
tmux.until do |
| 2844 |
assert_equal 20, it.match_count |
| 2845 |
assert_equal 20, it.select_count |
| 2846 |
refute it.any_include?('pressed a') |
| 2847 |
assert it.any_include?('pressed b') |
| 2848 |
end |
| 2849 |
tmux.send_keys :a |
| 2850 |
tmux.until do |
| 2851 |
assert_equal 20, it.match_count |
| 2852 |
assert_equal 20, it.select_count |
| 2853 |
assert it.any_include?('pressed a') |
| 2854 |
refute it.any_include?('pressed b') |
| 2855 |
end |
| 2856 |
tmux.send_keys :c |
| 2857 |
tmux.until do |
| 2858 |
assert_equal 19, it.match_count |
| 2859 |
assert_equal 19, it.select_count |
| 2860 |
end |
| 2861 |
end |
| 2862 |
|
| 2863 |
def test_trigger |
| 2864 |
tmux.send_keys %(seq 100 | #{FZF} --bind 'a:up+trigger(a),b:trigger(a,a,b,a)'), :Enter |
| 2865 |
tmux.until { assert_equal 100, it.match_count } |
| 2866 |
tmux.until { |lines| assert_includes lines, '> 1' } |
| 2867 |
tmux.send_keys :a |
| 2868 |
tmux.until { |lines| assert_includes lines, '> 3' } |
| 2869 |
tmux.send_keys :b |
| 2870 |
tmux.until { |lines| assert_includes lines, '> 9' } |
| 2871 |
end |
| 2872 |
|
| 2873 |
def test_change_nth_unset_default |
| 2874 |
tmux.send_keys %(echo foo bar | #{FZF} --nth 2 --query fb --bind space:change-nth:), :Enter |
| 2875 |
tmux.until do |
| 2876 |
assert_equal 1, it.item_count |
| 2877 |
assert_equal 0, it.match_count |
| 2878 |
end |
| 2879 |
|
| 2880 |
tmux.send_keys :Space |
| 2881 |
|
| 2882 |
tmux.until do |
| 2883 |
assert_equal 1, it.item_count |
| 2884 |
assert_equal 1, it.match_count |
| 2885 |
end |
| 2886 |
end |
| 2887 |
|
| 2888 |
def test_change_header_lines |
| 2889 |
tmux.send_keys %(seq 10 | #{FZF} --header-lines 3 --bind 'space:change-header-lines(5),enter:transform-header-lines(echo 1)'), :Enter |
| 2890 |
tmux.until do |lines| |
| 2891 |
assert_equal 7, lines.item_count |
| 2892 |
assert lines.any_include?('> 4') |
| 2893 |
end |
| 2894 |
tmux.send_keys :Space |
| 2895 |
tmux.until do |lines| |
| 2896 |
assert_equal 5, lines.item_count |
| 2897 |
assert lines.any_include?('> 6') |
| 2898 |
end |
| 2899 |
tmux.send_keys :Enter |
| 2900 |
tmux.until do |lines| |
| 2901 |
assert_equal 9, lines.item_count |
| 2902 |
assert lines.any_include?('> 6') |
| 2903 |
end |
| 2904 |
end |
| 2905 |
|
| 2906 |
def test_change_header_lines_to_zero |
| 2907 |
tmux.send_keys %(seq 5 | #{FZF} --header-lines 3 --bind 'space:bg-transform-header-lines(echo 0)'), :Enter |
| 2908 |
tmux.until do |lines| |
| 2909 |
assert_equal 2, lines.item_count |
| 2910 |
assert lines.any_include?('> 4') |
| 2911 |
end |
| 2912 |
tmux.send_keys :Space |
| 2913 |
tmux.until do |lines| |
| 2914 |
assert_equal 5, lines.item_count |
| 2915 |
# All items are now in the list, cursor stays on item 4 |
| 2916 |
assert lines.any_include?('> 4') |
| 2917 |
end |
| 2918 |
end |
| 2919 |
|
| 2920 |
def test_change_header_lines_deselect |
| 2921 |
# Selected items that become part of the header should be deselected |
| 2922 |
tmux.send_keys %(seq 10 | #{FZF} --multi --header-lines 0 --bind 'space:change-header-lines(3),enter:change-header-lines(1)'), :Enter |
| 2923 |
tmux.until do |lines| |
| 2924 |
assert_equal 10, lines.item_count |
| 2925 |
assert lines.any_include?('> 1') |
| 2926 |
end |
| 2927 |
# Select items 1, 2, 3 (these will become header lines) |
| 2928 |
tmux.send_keys :BTab, :BTab, :BTab |
| 2929 |
tmux.until { |lines| assert_equal 3, lines.select_count } |
| 2930 |
# Also select item 4 (this should remain selected) |
| 2931 |
tmux.send_keys :BTab |
| 2932 |
tmux.until { |lines| assert_equal 4, lines.select_count } |
| 2933 |
# Change header-lines to 3: items 1, 2, 3 become headers and should be deselected |
| 2934 |
tmux.send_keys :Space |
| 2935 |
tmux.until do |lines| |
| 2936 |
assert_equal 7, lines.item_count |
| 2937 |
assert_equal 1, lines.select_count |
| 2938 |
assert lines.any_include?('> 5') |
| 2939 |
end |
| 2940 |
# Change header-lines to 1 |
| 2941 |
tmux.send_keys :Enter |
| 2942 |
tmux.until do |lines| |
| 2943 |
assert_equal 9, lines.item_count |
| 2944 |
assert_equal 1, lines.select_count |
| 2945 |
assert lines.any_include?('> 5') |
| 2946 |
end |
| 2947 |
end |
| 2948 |
|
| 2949 |
def test_change_header_lines_reverse |
| 2950 |
tmux.send_keys %(seq 10 | #{FZF} --header-lines 2 --reverse --bind 'space:change-header-lines(4)'), :Enter |
| 2951 |
tmux.until do |lines| |
| 2952 |
assert_equal 8, lines.item_count |
| 2953 |
assert lines.any_include?('> 3') |
| 2954 |
end |
| 2955 |
tmux.send_keys :Space |
| 2956 |
tmux.until do |lines| |
| 2957 |
assert_equal 6, lines.item_count |
| 2958 |
assert lines.any_include?('> 5') |
| 2959 |
end |
| 2960 |
end |
| 2961 |
|
| 2962 |
def test_zero_width_characters |
| 2963 |
tmux.send_keys %(for i in {1..1000}; do string+="a̱$i"; printf '\\e[43m%s\\e[0m\\n' "$string"; done | #{FZF} --ansi --query a500 --ellipsis XX), :Enter |
| 2964 |
tmux.until do |lines| |
| 2965 |
assert_equal 981, lines.match_count |
| 2966 |
assert_match(/^> XX.*a̱500/, lines[-3]) |
| 2967 |
assert(lines.reverse.drop(5).all? { it.match?(/^ XX.*a̱500.*XX/) }) |
| 2968 |
end |
| 2969 |
end |
| 2970 |
end |