| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require_relative 'lib/common' |
| 4 |
|
| 5 |
# Test cases that mainly use assert_block to verify the layout of fzf |
| 6 |
class TestLayout < TestInteractive |
| 7 |
def assert_block(expected, lines) |
| 8 |
cols = expected.lines.map { it.chomp.length }.max |
| 9 |
top = lines.take(expected.lines.length).map { it[0, cols].rstrip + "\n" }.join.chomp |
| 10 |
bottom = lines.reverse.take(expected.lines.length).reverse.map { it[0, cols].rstrip + "\n" }.join.chomp |
| 11 |
assert_includes [top, bottom], expected.chomp |
| 12 |
end |
| 13 |
|
| 14 |
def test_vanilla |
| 15 |
tmux.send_keys "seq 1 100000 | #{fzf}", :Enter |
| 16 |
block = <<~BLOCK |
| 17 |
2 |
| 18 |
> 1 |
| 19 |
100000/100000 |
| 20 |
> |
| 21 |
BLOCK |
| 22 |
tmux.until { assert_block(block, it) } |
| 23 |
|
| 24 |
# Testing basic key bindings |
| 25 |
tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab' |
| 26 |
block = <<~BLOCK |
| 27 |
> 3910 |
| 28 |
391 |
| 29 |
856/100000 |
| 30 |
> 391 |
| 31 |
BLOCK |
| 32 |
tmux.until { assert_block(block, it) } |
| 33 |
|
| 34 |
tmux.send_keys :Enter |
| 35 |
assert_equal '3910', fzf_output |
| 36 |
end |
| 37 |
|
| 38 |
def test_header_first |
| 39 |
tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first", :Enter |
| 40 |
block = <<~OUTPUT |
| 41 |
> 4 |
| 42 |
3 |
| 43 |
2 |
| 44 |
1 |
| 45 |
997/997 |
| 46 |
> |
| 47 |
foobar |
| 48 |
OUTPUT |
| 49 |
tmux.until { assert_block(block, it) } |
| 50 |
end |
| 51 |
|
| 52 |
def test_header_first_reverse |
| 53 |
tmux.send_keys "seq 1000 | #{FZF} --header foobar --header-lines 3 --header-first --reverse --inline-info", :Enter |
| 54 |
block = <<~OUTPUT |
| 55 |
foobar |
| 56 |
> < 997/997 |
| 57 |
1 |
| 58 |
2 |
| 59 |
3 |
| 60 |
> 4 |
| 61 |
OUTPUT |
| 62 |
tmux.until { assert_block(block, it) } |
| 63 |
end |
| 64 |
|
| 65 |
def test_change_and_transform_header |
| 66 |
[ |
| 67 |
'space:change-header:$(seq 4)', |
| 68 |
'space:transform-header:seq 4' |
| 69 |
].each_with_index do |binding, i| |
| 70 |
tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "#{binding}"), :Enter |
| 71 |
expected = <<~OUTPUT |
| 72 |
> 3 |
| 73 |
2 |
| 74 |
1 |
| 75 |
bar |
| 76 |
1/1 |
| 77 |
> |
| 78 |
OUTPUT |
| 79 |
tmux.until { assert_block(expected, it) } |
| 80 |
tmux.send_keys :Space |
| 81 |
expected = <<~OUTPUT |
| 82 |
> 3 |
| 83 |
2 |
| 84 |
1 |
| 85 |
1 |
| 86 |
2 |
| 87 |
3 |
| 88 |
4 |
| 89 |
1/1 |
| 90 |
> |
| 91 |
OUTPUT |
| 92 |
tmux.until { assert_block(expected, it) } |
| 93 |
next unless i.zero? |
| 94 |
|
| 95 |
teardown |
| 96 |
setup |
| 97 |
end |
| 98 |
end |
| 99 |
|
| 100 |
def test_change_header |
| 101 |
tmux.send_keys %(seq 3 | #{FZF} --header-lines 2 --header bar --bind "space:change-header:$(seq 4)"), :Enter |
| 102 |
expected = <<~OUTPUT |
| 103 |
> 3 |
| 104 |
2 |
| 105 |
1 |
| 106 |
bar |
| 107 |
1/1 |
| 108 |
> |
| 109 |
OUTPUT |
| 110 |
tmux.until { assert_block(expected, it) } |
| 111 |
tmux.send_keys :Space |
| 112 |
expected = <<~OUTPUT |
| 113 |
> 3 |
| 114 |
2 |
| 115 |
1 |
| 116 |
1 |
| 117 |
2 |
| 118 |
3 |
| 119 |
4 |
| 120 |
1/1 |
| 121 |
> |
| 122 |
OUTPUT |
| 123 |
tmux.until { assert_block(expected, it) } |
| 124 |
end |
| 125 |
|
| 126 |
def test_reload_and_change_cache |
| 127 |
tmux.send_keys "echo bar | #{FZF} --bind 'zero:change-header(foo)+reload(echo foo)+clear-query'", :Enter |
| 128 |
expected = <<~OUTPUT |
| 129 |
> bar |
| 130 |
1/1 |
| 131 |
> |
| 132 |
OUTPUT |
| 133 |
tmux.until { assert_block(expected, it) } |
| 134 |
tmux.send_keys :z |
| 135 |
expected = <<~OUTPUT |
| 136 |
> foo |
| 137 |
foo |
| 138 |
1/1 |
| 139 |
> |
| 140 |
OUTPUT |
| 141 |
tmux.until { assert_block(expected, it) } |
| 142 |
end |
| 143 |
|
| 144 |
def test_toggle_header |
| 145 |
tmux.send_keys "seq 4 | #{FZF} --header-lines 2 --header foo --bind space:toggle-header --header-first --height 10 --border rounded", :Enter |
| 146 |
before = <<~OUTPUT |
| 147 |
╭─────── |
| 148 |
│ |
| 149 |
│ 4 |
| 150 |
│ > 3 |
| 151 |
│ 2 |
| 152 |
│ 1 |
| 153 |
│ 2/2 |
| 154 |
│ > |
| 155 |
│ foo |
| 156 |
╰─────── |
| 157 |
OUTPUT |
| 158 |
tmux.until { assert_block(before, it) } |
| 159 |
tmux.send_keys :Space |
| 160 |
after = <<~OUTPUT |
| 161 |
╭─────── |
| 162 |
│ |
| 163 |
│ |
| 164 |
│ |
| 165 |
│ |
| 166 |
│ 4 |
| 167 |
│ > 3 |
| 168 |
│ 2/2 |
| 169 |
│ > |
| 170 |
╰─────── |
| 171 |
OUTPUT |
| 172 |
tmux.until { assert_block(after, it) } |
| 173 |
tmux.send_keys :Space |
| 174 |
tmux.until { assert_block(before, it) } |
| 175 |
end |
| 176 |
|
| 177 |
def test_height_range_fit |
| 178 |
tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded', :Enter |
| 179 |
expected = <<~OUTPUT |
| 180 |
╭────────── |
| 181 |
│ ▌ 3 |
| 182 |
│ ▌ 2 |
| 183 |
│ > 1 |
| 184 |
│ > < 3/3 |
| 185 |
╰────────── |
| 186 |
OUTPUT |
| 187 |
tmux.until { assert_block(expected, it) } |
| 188 |
end |
| 189 |
|
| 190 |
def test_height_range_fit_preview_above |
| 191 |
tmux.send_keys 'seq 3 | fzf --height ~100% --info=inline --border rounded --preview-window border-rounded --preview "seq {}" --preview-window up,60%', :Enter |
| 192 |
expected = <<~OUTPUT |
| 193 |
╭────────── |
| 194 |
│ ╭──────── |
| 195 |
│ │ 1 |
| 196 |
│ │ |
| 197 |
│ │ |
| 198 |
│ │ |
| 199 |
│ ╰──────── |
| 200 |
│ ▌ 3 |
| 201 |
│ ▌ 2 |
| 202 |
│ > 1 |
| 203 |
│ > < 3/3 |
| 204 |
╰────────── |
| 205 |
OUTPUT |
| 206 |
tmux.until { assert_block(expected, it) } |
| 207 |
end |
| 208 |
|
| 209 |
def test_height_range_fit_preview_above_alternative |
| 210 |
tmux.send_keys 'seq 3 | fzf --height ~100% --border=sharp --preview "seq {}" --preview-window up,40%,border-bottom --padding 1 --exit-0 --header hello --header-lines=2', :Enter |
| 211 |
expected = <<~OUTPUT |
| 212 |
┌───────── |
| 213 |
│ |
| 214 |
│ 1 |
| 215 |
│ 2 |
| 216 |
│ 3 |
| 217 |
│ ─────── |
| 218 |
│ > 3 |
| 219 |
│ 2 |
| 220 |
│ 1 |
| 221 |
│ hello |
| 222 |
│ 1/1 ─ |
| 223 |
│ > |
| 224 |
│ |
| 225 |
└───────── |
| 226 |
OUTPUT |
| 227 |
tmux.until { assert_block(expected, it) } |
| 228 |
end |
| 229 |
|
| 230 |
def test_height_range_fit_preview_left |
| 231 |
tmux.send_keys "seq 3 | fzf --height ~100% --border=vertical --preview 'seq {}' --preview-window left,5,border-right --padding 1 --exit-0 --header $'hello\\nworld' --header-lines=2", :Enter |
| 232 |
expected = <<~OUTPUT |
| 233 |
│ |
| 234 |
│ 1 │ > 3 |
| 235 |
│ 2 │ 2 |
| 236 |
│ 3 │ 1 |
| 237 |
│ │ hello |
| 238 |
│ │ world |
| 239 |
│ │ 1/1 ─ |
| 240 |
│ │ > |
| 241 |
│ |
| 242 |
OUTPUT |
| 243 |
tmux.until { assert_block(expected, it) } |
| 244 |
end |
| 245 |
|
| 246 |
def test_preview_window_next_reverse |
| 247 |
# https://github.com/junegunn/fzf/issues/4798 |
| 248 |
tmux.send_keys %(seq 5 | #{FZF} --layout=reverse --preview 'echo PREVIEW' --preview-window=next:3 --prompt='line2$ > '), :Enter |
| 249 |
expected = <<~OUTPUT |
| 250 |
line2$ > |
| 251 |
5/5 |
| 252 |
╭──────── |
| 253 |
│ PREVIEW |
| 254 |
│ |
| 255 |
│ |
| 256 |
╰──────── |
| 257 |
> 1 |
| 258 |
OUTPUT |
| 259 |
tmux.until { assert_block(expected, it) } |
| 260 |
end |
| 261 |
|
| 262 |
def test_preview_window_next_default |
| 263 |
tmux.send_keys %(seq 5 | #{FZF} --preview 'echo PREVIEW' --preview-window=next:3), :Enter |
| 264 |
expected = <<~OUTPUT |
| 265 |
> 1 |
| 266 |
╭──────── |
| 267 |
│ PREVIEW |
| 268 |
│ |
| 269 |
│ |
| 270 |
╰──────── |
| 271 |
5/5 |
| 272 |
> |
| 273 |
OUTPUT |
| 274 |
tmux.until { assert_block(expected, it) } |
| 275 |
end |
| 276 |
|
| 277 |
def test_preview_window_next_border_line_at_runtime |
| 278 |
# change-preview-window to next,border-line should resolve BorderLine |
| 279 |
# to a single horizontal separator, matching the behavior |
| 280 |
# when next,border-line is the initial spec. |
| 281 |
tmux.send_keys %(seq 5 | #{FZF} --preview 'echo PREVIEW' --bind 'space:change-preview-window:next:3,border-line'), :Enter |
| 282 |
tmux.until { |lines| assert_equal 5, lines.match_count } |
| 283 |
tmux.send_keys :Space |
| 284 |
expected = <<~OUTPUT |
| 285 |
> 1 |
| 286 |
─────── |
| 287 |
PREVIEW |
| 288 |
OUTPUT |
| 289 |
tmux.until do |lines| |
| 290 |
cursor = lines.index { it.start_with?('> 1') } |
| 291 |
assert(cursor) |
| 292 |
assert_block(expected, lines[cursor..]) |
| 293 |
end |
| 294 |
end |
| 295 |
|
| 296 |
def test_header_first_change_header_at_runtime |
| 297 |
# --header-first with no initial --header content needs to grow a |
| 298 |
# header window when change-header adds content at runtime, so the |
| 299 |
# new header lands below the prompt (not on top of it). |
| 300 |
tmux.send_keys %(seq 5 | #{FZF} --header-first --bind 'space:change-header:foo'), :Enter |
| 301 |
tmux.until { |lines| assert_equal 5, lines.match_count } |
| 302 |
tmux.send_keys :Space |
| 303 |
expected = <<~OUTPUT |
| 304 |
> |
| 305 |
foo |
| 306 |
OUTPUT |
| 307 |
tmux.until do |lines| |
| 308 |
prompt = lines.index { it.start_with?('>') } |
| 309 |
assert(prompt) |
| 310 |
assert_block(expected, lines[prompt..]) |
| 311 |
end |
| 312 |
end |
| 313 |
|
| 314 |
def test_preview_window_next_style_full_line |
| 315 |
tmux.send_keys %(seq 5 | #{FZF} --reverse --preview 'echo PREVIEW' --preview-window=next:3 --header foo --footer bar --style full:line), :Enter |
| 316 |
expected = <<~OUTPUT |
| 317 |
> |
| 318 |
─────── |
| 319 |
PREVIEW |
| 320 |
|
| 321 |
|
| 322 |
─────── |
| 323 |
foo |
| 324 |
─────── |
| 325 |
> 1 |
| 326 |
OUTPUT |
| 327 |
tmux.until { assert_block(expected, it) } |
| 328 |
end |
| 329 |
|
| 330 |
def test_height_range_overflow |
| 331 |
tmux.send_keys 'seq 100 | fzf --height ~5 --info=inline --border rounded', :Enter |
| 332 |
expected = <<~OUTPUT |
| 333 |
╭────────────── |
| 334 |
│ ▌ 2 |
| 335 |
│ > 1 |
| 336 |
│ > < 100/100 |
| 337 |
╰────────────── |
| 338 |
OUTPUT |
| 339 |
tmux.until { assert_block(expected, it) } |
| 340 |
end |
| 341 |
|
| 342 |
def test_no_extra_newline_issue_3209 |
| 343 |
tmux.send_keys(%(seq 100 | #{FZF} --height 10 --preview-window up,wrap,border-rounded --preview 'printf "─%.0s" $(seq 1 "$((FZF_PREVIEW_COLUMNS - 5))"); printf $"\\e[7m%s\\e[0m" title; echo; echo something'), :Enter) |
| 344 |
expected = <<~OUTPUT |
| 345 |
╭────────── |
| 346 |
│ ───────── |
| 347 |
│ something |
| 348 |
│ |
| 349 |
╰────────── |
| 350 |
3 |
| 351 |
2 |
| 352 |
> 1 |
| 353 |
100/100 ─ |
| 354 |
> |
| 355 |
OUTPUT |
| 356 |
tmux.until { assert_block(expected, it) } |
| 357 |
end |
| 358 |
|
| 359 |
def test_fzf_multi_line |
| 360 |
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded], :Enter |
| 361 |
block = <<~BLOCK |
| 362 |
│ ▌┃998 |
| 363 |
│ ▌┃999 |
| 364 |
│ ▌┃1000 |
| 365 |
│ ▌╹ |
| 366 |
│ ▌╻1 |
| 367 |
│ ▌╹2 |
| 368 |
│ >>0 |
| 369 |
│ 3/3 (3) |
| 370 |
│ > |
| 371 |
╰─────────── |
| 372 |
BLOCK |
| 373 |
tmux.until { assert_block(block, it) } |
| 374 |
tmux.send_keys :Up, :Up |
| 375 |
block = <<~BLOCK |
| 376 |
╭─────── |
| 377 |
│ >╻1 |
| 378 |
│ >┃2 |
| 379 |
│ >┃3 |
| 380 |
BLOCK |
| 381 |
tmux.until { assert_block(block, it) } |
| 382 |
|
| 383 |
block = <<~BLOCK |
| 384 |
│ >┃ |
| 385 |
│ |
| 386 |
│ > |
| 387 |
╰─── |
| 388 |
BLOCK |
| 389 |
tmux.until { assert_block(block, it) } |
| 390 |
end |
| 391 |
|
| 392 |
def test_fzf_multi_line_reverse |
| 393 |
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse], :Enter |
| 394 |
block = <<~BLOCK |
| 395 |
╭─────────── |
| 396 |
│ > |
| 397 |
│ 3/3 (3) |
| 398 |
│ >>0 |
| 399 |
│ ▌╻1 |
| 400 |
│ ▌╹2 |
| 401 |
│ ▌╻1 |
| 402 |
│ ▌┃2 |
| 403 |
│ ▌┃3 |
| 404 |
BLOCK |
| 405 |
tmux.until { assert_block(block, it) } |
| 406 |
end |
| 407 |
|
| 408 |
def test_fzf_multi_line_no_pointer_and_marker |
| 409 |
tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse --pointer '' --marker '' --marker-multi-line ''], :Enter |
| 410 |
block = <<~BLOCK |
| 411 |
╭─────────── |
| 412 |
│ > |
| 413 |
│ 3/3 (3) |
| 414 |
│ 0 |
| 415 |
│ 1 |
| 416 |
│ 2 |
| 417 |
│ 1 |
| 418 |
│ 2 |
| 419 |
│ 3 |
| 420 |
BLOCK |
| 421 |
tmux.until { assert_block(block, it) } |
| 422 |
end |
| 423 |
|
| 424 |
def test_gap |
| 425 |
tmux.send_keys %(seq 100 | #{FZF} --gap --border rounded --reverse), :Enter |
| 426 |
block = <<~BLOCK |
| 427 |
╭───────────────── |
| 428 |
│ > |
| 429 |
│ 100/100 ────── |
| 430 |
│ > 1 |
| 431 |
│ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈ |
| 432 |
│ 2 |
| 433 |
│ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈ |
| 434 |
│ 3 |
| 435 |
│ ┈┈┈┈┈┈┈┈┈┈┈┈┈┈ |
| 436 |
│ 4 |
| 437 |
BLOCK |
| 438 |
tmux.until { assert_block(block, it) } |
| 439 |
end |
| 440 |
|
| 441 |
def test_gap_2 |
| 442 |
tmux.send_keys %(seq 100 | #{FZF} --gap=2 --gap-line xyz --border rounded --reverse), :Enter |
| 443 |
block = <<~BLOCK |
| 444 |
╭───────────────── |
| 445 |
│ > |
| 446 |
│ 100/100 ────── |
| 447 |
│ > 1 |
| 448 |
│ |
| 449 |
│ xyzxyzxyzxyzxy |
| 450 |
│ 2 |
| 451 |
│ |
| 452 |
│ xyzxyzxyzxyzxy |
| 453 |
│ 3 |
| 454 |
BLOCK |
| 455 |
tmux.until { assert_block(block, it) } |
| 456 |
end |
| 457 |
|
| 458 |
def test_list_border_and_label |
| 459 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --query 1 --padding 1,2), :Enter |
| 460 |
block = <<~BLOCK |
| 461 |
│ ║ 11 |
| 462 |
│ ║ > 10 |
| 463 |
│ ║ 3 |
| 464 |
│ ║ 2 |
| 465 |
│ ║ 1 |
| 466 |
│ ║ 19/97 ─ |
| 467 |
│ ║ > 1 |
| 468 |
│ ╚list══════ |
| 469 |
│ |
| 470 |
╰────────────── |
| 471 |
BLOCK |
| 472 |
tmux.until { assert_block(block, it) } |
| 473 |
end |
| 474 |
|
| 475 |
def test_input_border_and_label |
| 476 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2), :Enter |
| 477 |
block = <<~BLOCK |
| 478 |
│ 11 |
| 479 |
│ > 10 |
| 480 |
│ 3 |
| 481 |
│ 2 |
| 482 |
│ 1 |
| 483 |
│ ┏input━━━━━ |
| 484 |
│ ┃ 19/97 |
| 485 |
│ ┃ > 1 |
| 486 |
│ ┗━━━━━━━━━━ |
| 487 |
│ |
| 488 |
╰────────────── |
| 489 |
BLOCK |
| 490 |
tmux.until { assert_block(block, it) } |
| 491 |
end |
| 492 |
|
| 493 |
def test_input_border_and_label_header_first |
| 494 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --input-border bold --input-label input --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 --header-first), :Enter |
| 495 |
block = <<~BLOCK |
| 496 |
│ 11 |
| 497 |
│ > 10 |
| 498 |
│ ┏input━━━━━ |
| 499 |
│ ┃ 19/97 |
| 500 |
│ ┃ > 1 |
| 501 |
│ ┗━━━━━━━━━━ |
| 502 |
│ 3 |
| 503 |
│ 2 |
| 504 |
│ 1 |
| 505 |
│ |
| 506 |
╰────────────── |
| 507 |
BLOCK |
| 508 |
tmux.until { assert_block(block, it) } |
| 509 |
end |
| 510 |
|
| 511 |
def test_list_input_border_and_label |
| 512 |
tmux.send_keys %( |
| 513 |
seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \ |
| 514 |
--bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \ |
| 515 |
--bind 'space:change-input-label( input )+change-list-label( list )' |
| 516 |
).strip, :Enter |
| 517 |
block = <<~BLOCK |
| 518 |
│ ║ 11 |
| 519 |
│ ║ > 10 |
| 520 |
│ ╚LIST══════ |
| 521 |
│ 3 |
| 522 |
│ 2 |
| 523 |
│ 1 |
| 524 |
│ ┏INPUT━━━━━ |
| 525 |
│ ┃ 19/97 |
| 526 |
│ ┃ > 1 |
| 527 |
│ ┗━━━━━━━━━━ |
| 528 |
│ |
| 529 |
╰────────────── |
| 530 |
BLOCK |
| 531 |
tmux.until { assert_block(block, it) } |
| 532 |
tmux.send_keys :Space |
| 533 |
block = <<~BLOCK |
| 534 |
│ ║ 11 |
| 535 |
│ ║ > 10 |
| 536 |
│ ╚ list ════ |
| 537 |
│ 3 |
| 538 |
│ 2 |
| 539 |
│ 1 |
| 540 |
│ ┏ input ━━━ |
| 541 |
│ ┃ 19/97 |
| 542 |
│ ┃ > 1 |
| 543 |
│ ┗━━━━━━━━━━ |
| 544 |
│ |
| 545 |
╰────────────── |
| 546 |
BLOCK |
| 547 |
tmux.until { assert_block(block, it) } |
| 548 |
end |
| 549 |
|
| 550 |
def test_list_input_border_and_label_header_first |
| 551 |
tmux.send_keys %( |
| 552 |
seq 100 | #{FZF} --border rounded --list-border double --input-border bold --list-label-pos 2:bottom --input-label-pos 2 --header-lines 3 --query 1 --padding 1,2 \ |
| 553 |
--bind 'start:transform-input-label(echo INPUT)+transform-list-label(echo LIST)' \ |
| 554 |
--bind 'space:change-input-label( input )+change-list-label( list )' --header-first |
| 555 |
).strip, :Enter |
| 556 |
block = <<~BLOCK |
| 557 |
│ ║ 11 |
| 558 |
│ ║ > 10 |
| 559 |
│ ╚LIST══════ |
| 560 |
│ ┏INPUT━━━━━ |
| 561 |
│ ┃ 19/97 |
| 562 |
│ ┃ > 1 |
| 563 |
│ ┗━━━━━━━━━━ |
| 564 |
│ 3 |
| 565 |
│ 2 |
| 566 |
│ 1 |
| 567 |
│ |
| 568 |
╰────────────── |
| 569 |
BLOCK |
| 570 |
tmux.until { assert_block(block, it) } |
| 571 |
tmux.send_keys :Space |
| 572 |
block = <<~BLOCK |
| 573 |
│ ║ 11 |
| 574 |
│ ║ > 10 |
| 575 |
│ ╚ list ════ |
| 576 |
│ ┏ input ━━━ |
| 577 |
│ ┃ 19/97 |
| 578 |
│ ┃ > 1 |
| 579 |
│ ┗━━━━━━━━━━ |
| 580 |
│ 3 |
| 581 |
│ 2 |
| 582 |
│ 1 |
| 583 |
│ |
| 584 |
╰────────────── |
| 585 |
BLOCK |
| 586 |
tmux.until { assert_block(block, it) } |
| 587 |
end |
| 588 |
|
| 589 |
def test_header_border_and_label |
| 590 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter |
| 591 |
block = <<~BLOCK |
| 592 |
│ 12 |
| 593 |
│ 11 |
| 594 |
│ > 10 |
| 595 |
│ ┌──────── |
| 596 |
│ │ 3 |
| 597 |
│ │ 2 |
| 598 |
│ │ 1 |
| 599 |
│ └header── |
| 600 |
│ 19/97 |
| 601 |
│ > 1 |
| 602 |
│ |
| 603 |
╰──────────── |
| 604 |
BLOCK |
| 605 |
tmux.until { assert_block(block, it) } |
| 606 |
end |
| 607 |
|
| 608 |
def test_header_border_toggle |
| 609 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()'), :Enter |
| 610 |
block1 = <<~BLOCK |
| 611 |
│ 5 |
| 612 |
│ 4 |
| 613 |
│ 3 |
| 614 |
│ 2 |
| 615 |
│ > 1 |
| 616 |
│ 100/100 ─ |
| 617 |
│ > |
| 618 |
╰──────────── |
| 619 |
BLOCK |
| 620 |
tmux.until { assert_block(block1, it) } |
| 621 |
|
| 622 |
tmux.send_keys :Space |
| 623 |
block2 = <<~BLOCK |
| 624 |
│ 3 |
| 625 |
│ 2 |
| 626 |
│ > 1 |
| 627 |
╰──────────── |
| 628 |
╭──────────── |
| 629 |
│ hello |
| 630 |
╰──────────── |
| 631 |
100/100 |
| 632 |
> |
| 633 |
BLOCK |
| 634 |
tmux.until { assert_block(block2, it) } |
| 635 |
|
| 636 |
tmux.send_keys :Enter |
| 637 |
tmux.until { assert_block(block1, it) } |
| 638 |
end |
| 639 |
|
| 640 |
def test_header_border_toggle_with_header_lines |
| 641 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2), :Enter |
| 642 |
block1 = <<~BLOCK |
| 643 |
│ 5 |
| 644 |
│ 4 |
| 645 |
│ > 3 |
| 646 |
╰────────── |
| 647 |
╭────────── |
| 648 |
│ 2 |
| 649 |
│ 1 |
| 650 |
╰────────── |
| 651 |
98/98 |
| 652 |
> |
| 653 |
BLOCK |
| 654 |
tmux.until { assert_block(block1, it) } |
| 655 |
|
| 656 |
tmux.send_keys :Space |
| 657 |
block2 = <<~BLOCK |
| 658 |
│ 4 |
| 659 |
│ > 3 |
| 660 |
╰────────── |
| 661 |
╭────────── |
| 662 |
│ 2 |
| 663 |
│ 1 |
| 664 |
│ hello |
| 665 |
╰────────── |
| 666 |
98/98 |
| 667 |
> |
| 668 |
BLOCK |
| 669 |
tmux.until { assert_block(block2, it) } |
| 670 |
|
| 671 |
tmux.send_keys :Enter |
| 672 |
tmux.until { assert_block(block1, it) } |
| 673 |
end |
| 674 |
|
| 675 |
def test_header_border_toggle_with_header_lines_header_first |
| 676 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first), :Enter |
| 677 |
block1 = <<~BLOCK |
| 678 |
│ 5 |
| 679 |
│ 4 |
| 680 |
│ > 3 |
| 681 |
╰────────── |
| 682 |
98/98 |
| 683 |
> |
| 684 |
╭────────── |
| 685 |
│ 2 |
| 686 |
│ 1 |
| 687 |
╰────────── |
| 688 |
BLOCK |
| 689 |
tmux.until { assert_block(block1, it) } |
| 690 |
|
| 691 |
tmux.send_keys :Space |
| 692 |
block2 = <<~BLOCK |
| 693 |
│ 4 |
| 694 |
│ > 3 |
| 695 |
╰────────── |
| 696 |
2 |
| 697 |
1 |
| 698 |
98/98 ─ |
| 699 |
> |
| 700 |
╭────────── |
| 701 |
│ hello |
| 702 |
╰────────── |
| 703 |
BLOCK |
| 704 |
tmux.until { assert_block(block2, it) } |
| 705 |
|
| 706 |
tmux.send_keys :Enter |
| 707 |
tmux.until { assert_block(block1, it) } |
| 708 |
end |
| 709 |
|
| 710 |
def test_header_border_toggle_with_header_lines_header_lines_border |
| 711 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-lines-border double), :Enter |
| 712 |
block1 = <<~BLOCK |
| 713 |
│ 5 |
| 714 |
│ 4 |
| 715 |
│ > 3 |
| 716 |
╰────────── |
| 717 |
╔══════════ |
| 718 |
║ 2 |
| 719 |
║ 1 |
| 720 |
╚══════════ |
| 721 |
98/98 |
| 722 |
> |
| 723 |
BLOCK |
| 724 |
tmux.until { assert_block(block1, it) } |
| 725 |
|
| 726 |
tmux.send_keys :Space |
| 727 |
block2 = <<~BLOCK |
| 728 |
│ > 3 |
| 729 |
╰────────── |
| 730 |
╔══════════ |
| 731 |
║ 2 |
| 732 |
║ 1 |
| 733 |
╚══════════ |
| 734 |
╭────────── |
| 735 |
│ hello |
| 736 |
╰────────── |
| 737 |
98/98 |
| 738 |
> |
| 739 |
BLOCK |
| 740 |
tmux.until { assert_block(block2, it) } |
| 741 |
|
| 742 |
tmux.send_keys :Enter |
| 743 |
tmux.until { assert_block(block1, it) } |
| 744 |
end |
| 745 |
|
| 746 |
def test_header_border_toggle_with_header_lines_header_first_header_lines_border |
| 747 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header-border rounded --bind 'space:change-header(hello),enter:change-header()' --header-lines 2 --header-first --header-lines-border double), :Enter |
| 748 |
block1 = <<~BLOCK |
| 749 |
│ 5 |
| 750 |
│ 4 |
| 751 |
│ > 3 |
| 752 |
╰────────── |
| 753 |
98/98 |
| 754 |
> |
| 755 |
╔══════════ |
| 756 |
║ 2 |
| 757 |
║ 1 |
| 758 |
╚══════════ |
| 759 |
BLOCK |
| 760 |
tmux.until { assert_block(block1, it) } |
| 761 |
|
| 762 |
tmux.send_keys :Space |
| 763 |
block2 = <<~BLOCK |
| 764 |
│ > 3 |
| 765 |
╰────────── |
| 766 |
╔══════════ |
| 767 |
║ 2 |
| 768 |
║ 1 |
| 769 |
╚══════════ |
| 770 |
98/98 |
| 771 |
> |
| 772 |
╭────────── |
| 773 |
│ hello |
| 774 |
╰────────── |
| 775 |
BLOCK |
| 776 |
tmux.until { assert_block(block2, it) } |
| 777 |
|
| 778 |
tmux.send_keys :Enter |
| 779 |
tmux.until { assert_block(block1, it) } |
| 780 |
end |
| 781 |
|
| 782 |
def test_header_border_and_label_header_first |
| 783 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter |
| 784 |
block = <<~BLOCK |
| 785 |
│ 12 |
| 786 |
│ 11 |
| 787 |
│ > 10 |
| 788 |
│ 19/97 ─ |
| 789 |
│ > 1 |
| 790 |
│ ┌──────── |
| 791 |
│ │ 3 |
| 792 |
│ │ 2 |
| 793 |
│ │ 1 |
| 794 |
│ └header── |
| 795 |
│ |
| 796 |
╰──────────── |
| 797 |
BLOCK |
| 798 |
tmux.until { assert_block(block, it) } |
| 799 |
end |
| 800 |
|
| 801 |
def test_header_border_and_label_with_list_border |
| 802 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2), :Enter |
| 803 |
block = <<~BLOCK |
| 804 |
│ ║ 12 |
| 805 |
│ ║ 11 |
| 806 |
│ ║ > 10 |
| 807 |
│ ╚list══════ |
| 808 |
│ ┌────────── |
| 809 |
│ │ 3 |
| 810 |
│ │ 2 |
| 811 |
│ │ 1 |
| 812 |
│ └header──── |
| 813 |
│ 19/97 |
| 814 |
│ > 1 |
| 815 |
│ |
| 816 |
╰────────────── |
| 817 |
BLOCK |
| 818 |
tmux.until { assert_block(block, it) } |
| 819 |
end |
| 820 |
|
| 821 |
def test_header_border_and_label_with_list_border_header_first |
| 822 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --header-first), :Enter |
| 823 |
block = <<~BLOCK |
| 824 |
│ ║ 12 |
| 825 |
│ ║ 11 |
| 826 |
│ ║ > 10 |
| 827 |
│ ╚list══════ |
| 828 |
│ 19/97 |
| 829 |
│ > 1 |
| 830 |
│ ┌────────── |
| 831 |
│ │ 3 |
| 832 |
│ │ 2 |
| 833 |
│ │ 1 |
| 834 |
│ └header──── |
| 835 |
│ |
| 836 |
╰────────────── |
| 837 |
BLOCK |
| 838 |
tmux.until { assert_block(block, it) } |
| 839 |
end |
| 840 |
|
| 841 |
def test_all_borders |
| 842 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom), :Enter |
| 843 |
block = <<~BLOCK |
| 844 |
│ ║ 12 |
| 845 |
│ ║ 11 |
| 846 |
│ ║ > 10 |
| 847 |
│ ╚list══════ |
| 848 |
│ ┌────────── |
| 849 |
│ │ 3 |
| 850 |
│ │ 2 |
| 851 |
│ │ 1 |
| 852 |
│ └header──── |
| 853 |
│ ┏━━━━━━━━━━ |
| 854 |
│ ┃ 19/97 |
| 855 |
│ ┃ > 1 |
| 856 |
│ ┗input━━━━━ |
| 857 |
│ |
| 858 |
╰────────────── |
| 859 |
BLOCK |
| 860 |
tmux.until { assert_block(block, it) } |
| 861 |
end |
| 862 |
|
| 863 |
def test_all_borders_header_first |
| 864 |
tmux.send_keys %(seq 100 | #{FZF} --border rounded --list-border double --list-label list --list-label-pos 2:bottom --header-lines 3 --header-border sharp --header-label header --header-label-pos 2:bottom --query 1 --padding 1,2 --input-border bold --input-label input --input-label-pos 2:bottom --header-first), :Enter |
| 865 |
block = <<~BLOCK |
| 866 |
│ ║ 12 |
| 867 |
│ ║ 11 |
| 868 |
│ ║ > 10 |
| 869 |
│ ╚list══════ |
| 870 |
│ ┏━━━━━━━━━━ |
| 871 |
│ ┃ 19/97 |
| 872 |
│ ┃ > 1 |
| 873 |
│ ┗input━━━━━ |
| 874 |
│ ┌────────── |
| 875 |
│ │ 3 |
| 876 |
│ │ 2 |
| 877 |
│ │ 1 |
| 878 |
│ └header──── |
| 879 |
│ |
| 880 |
╰────────────── |
| 881 |
BLOCK |
| 882 |
tmux.until { assert_block(block, it) } |
| 883 |
end |
| 884 |
|
| 885 |
def test_adaptive_height_with_inline_sections |
| 886 |
tmux.send_keys %(seq 10 | #{FZF} --height=~100% --list-border --header-lines=1 --header-lines-border=inline), :Enter |
| 887 |
block = <<~BLOCK |
| 888 |
╭────── |
| 889 |
│ 10 |
| 890 |
│ 9 |
| 891 |
│ 8 |
| 892 |
│ 7 |
| 893 |
│ 6 |
| 894 |
│ 5 |
| 895 |
│ 4 |
| 896 |
│ 3 |
| 897 |
│ > 2 |
| 898 |
├────── |
| 899 |
│ 1 |
| 900 |
╰────── |
| 901 |
9/9 |
| 902 |
> |
| 903 |
BLOCK |
| 904 |
tmux.until { assert_block(block, it) } |
| 905 |
end |
| 906 |
|
| 907 |
def test_style_full_adaptive_height |
| 908 |
tmux.send_keys %(seq 1| #{FZF} --style=full:rounded --height=~100% --header-lines=1 --info=default), :Enter |
| 909 |
block = <<~BLOCK |
| 910 |
╭──────── |
| 911 |
╰──────── |
| 912 |
╭──────── |
| 913 |
│ 1 |
| 914 |
╰──────── |
| 915 |
╭──────── |
| 916 |
│ 0/0 |
| 917 |
│ > |
| 918 |
╰──────── |
| 919 |
BLOCK |
| 920 |
tmux.until { assert_block(block, it) } |
| 921 |
end |
| 922 |
|
| 923 |
def test_style_full_adaptive_height_double |
| 924 |
tmux.send_keys %(seq 1| #{FZF} --style=full:double --border --height=~100% --header-lines=1 --info=default), :Enter |
| 925 |
block = <<~BLOCK |
| 926 |
╔══════════ |
| 927 |
║ ╔════════ |
| 928 |
║ ╚════════ |
| 929 |
║ ╔════════ |
| 930 |
║ ║ 1 |
| 931 |
║ ╚════════ |
| 932 |
║ ╔════════ |
| 933 |
║ ║ 0/0 |
| 934 |
║ ║ > |
| 935 |
║ ╚════════ |
| 936 |
╚══════════ |
| 937 |
BLOCK |
| 938 |
tmux.until { assert_block(block, it) } |
| 939 |
end |
| 940 |
|
| 941 |
def test_preview_window_noinfo |
| 942 |
# │ 1 ││ |
| 943 |
tmux.send_keys %(#{FZF} --preview 'seq 1000' --preview-window top,noinfo --scrollbar --bind space:change-preview-window:info), :Enter |
| 944 |
tmux.until do |lines| |
| 945 |
assert lines[1]&.start_with?('│ 1') |
| 946 |
assert lines[1]&.end_with?(' ││') |
| 947 |
end |
| 948 |
tmux.send_keys :Space |
| 949 |
tmux.until do |lines| |
| 950 |
assert lines[1]&.start_with?('│ 1') |
| 951 |
assert lines[1]&.end_with?('1000││') |
| 952 |
end |
| 953 |
end |
| 954 |
|
| 955 |
def test_min_height_no_auto |
| 956 |
tmux.send_keys %(seq 100 | #{FZF} --border sharp --style full:sharp --height 1% --min-height 5), :Enter |
| 957 |
|
| 958 |
block = <<~BLOCK |
| 959 |
┌─────── |
| 960 |
│ ┌───── |
| 961 |
│ │ > |
| 962 |
│ └───── |
| 963 |
└─────── |
| 964 |
BLOCK |
| 965 |
tmux.until { assert_block(block, it) } |
| 966 |
end |
| 967 |
|
| 968 |
def test_min_height_auto |
| 969 |
tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --height 1% --min-height 5+), :Enter |
| 970 |
|
| 971 |
block = <<~BLOCK |
| 972 |
┌───────── |
| 973 |
│ 5 |
| 974 |
│ 4 |
| 975 |
│ 3 |
| 976 |
│ 2 |
| 977 |
│ > 1 |
| 978 |
└───────── |
| 979 |
┌───────── |
| 980 |
│ > |
| 981 |
└───────── |
| 982 |
BLOCK |
| 983 |
tmux.until { assert_block(block, it) } |
| 984 |
end |
| 985 |
|
| 986 |
def test_min_height_auto_no_input |
| 987 |
tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --no-input --height 1% --min-height 5+), :Enter |
| 988 |
|
| 989 |
block = <<~BLOCK |
| 990 |
┌───────── |
| 991 |
│ 5 |
| 992 |
│ 4 |
| 993 |
│ 3 |
| 994 |
│ 2 |
| 995 |
│ > 1 |
| 996 |
└───────── |
| 997 |
BLOCK |
| 998 |
tmux.until { assert_block(block, it) } |
| 999 |
end |
| 1000 |
|
| 1001 |
def test_min_height_auto_no_input_reverse_list |
| 1002 |
tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --layout reverse-list --no-input --height 1% --min-height 5+ --bind a:show-input,b:hide-input,c:toggle-input), :Enter |
| 1003 |
|
| 1004 |
block = <<~BLOCK |
| 1005 |
┌───────── |
| 1006 |
│ > 1 |
| 1007 |
│ 2 |
| 1008 |
│ 3 |
| 1009 |
│ 4 |
| 1010 |
│ 5 |
| 1011 |
└───────── |
| 1012 |
BLOCK |
| 1013 |
tmux.until { assert_block(block, it) } |
| 1014 |
tmux.send_keys :a |
| 1015 |
block2 = <<~BLOCK |
| 1016 |
┌───── |
| 1017 |
│ > 1 |
| 1018 |
│ 2 |
| 1019 |
└───── |
| 1020 |
┌───── |
| 1021 |
│ > |
| 1022 |
└───── |
| 1023 |
BLOCK |
| 1024 |
tmux.until { assert_block(block2, it) } |
| 1025 |
tmux.send_keys :b |
| 1026 |
tmux.until { assert_block(block, it) } |
| 1027 |
tmux.send_keys :c |
| 1028 |
tmux.until { assert_block(block2, it) } |
| 1029 |
tmux.send_keys :c |
| 1030 |
tmux.until { assert_block(block, it) } |
| 1031 |
end |
| 1032 |
|
| 1033 |
def test_layout_reverse_list |
| 1034 |
prefix = "seq 5 | #{FZF} --layout reverse-list --no-list-border --height ~100% --border sharp " |
| 1035 |
suffixes = [ |
| 1036 |
%(), |
| 1037 |
%[--header "$(seq 101 103)"], |
| 1038 |
%[--header "$(seq 101 103)" --header-first], |
| 1039 |
%[--header "$(seq 101 103)" --header-lines 3], |
| 1040 |
%[--header "$(seq 101 103)" --header-lines 3 --header-first], |
| 1041 |
%[--header "$(seq 101 103)" --header-border sharp], |
| 1042 |
%[--header "$(seq 101 103)" --header-border sharp --header-first], |
| 1043 |
%[--header "$(seq 101 103)" --header-border sharp --header-lines 3], |
| 1044 |
%[--header "$(seq 101 103)" --header-border sharp --header-lines 3 --header-lines-border sharp], |
| 1045 |
%[--header "$(seq 101 103)" --header-border sharp --header-lines 3 --header-lines-border sharp --header-first], |
| 1046 |
%[--header "$(seq 101 103)" --header-border sharp --header-lines 3 --header-lines-border sharp --header-first --input-border sharp], |
| 1047 |
%[--header "$(seq 101 103)" --header-border sharp --header-lines 3 --header-lines-border sharp --header-first --no-input], |
| 1048 |
%[--header "$(seq 101 103)" --input-border sharp], |
| 1049 |
%[--header "$(seq 101 103)" --style full:sharp], |
| 1050 |
%[--header "$(seq 101 103)" --style full:sharp --header-first] |
| 1051 |
] |
| 1052 |
output = <<~BLOCK |
| 1053 |
┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌───────── ┌─────── ┌───────── ┌───────── ┌───────── |
| 1054 |
│ > 1 │ > 1 │ > 1 │ 1 │ 1 │ > 1 │ > 1 │ 1 │ ┌────── │ ┌────── │ ┌─────── │ ┌───── │ > 1 │ ┌─────── │ ┌─────── |
| 1055 |
│ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ │ 1 │ │ 1 │ │ 1 │ │ 1 │ 2 │ │ > 1 │ │ > 1 |
| 1056 |
│ 3 │ 3 │ 3 │ 3 │ 3 │ 3 │ 3 │ 3 │ │ 2 │ │ 2 │ │ 2 │ │ 2 │ 3 │ │ 2 │ │ 2 |
| 1057 |
│ 4 │ 4 │ 4 │ > 4 │ > 4 │ 4 │ 4 │ > 4 │ │ 3 │ │ 3 │ │ 3 │ │ 3 │ 4 │ │ 3 │ │ 3 |
| 1058 |
│ 5 │ 5 │ 5 │ 5 │ 5 │ 5 │ 5 │ 5 │ └────── │ └────── │ └─────── │ └───── │ 5 │ │ 4 │ │ 4 |
| 1059 |
│ 5/5 ─ │ 101 │ 5/5 ─ │ 101 │ 2/2 ─ │ ┌────── │ 5/5 ─ │ ┌────── │ > 4 │ > 4 │ > 4 │ > 4 │ 101 │ │ 5 │ │ 5 |
| 1060 |
│ > │ 102 │ > │ 102 │ > │ │ 101 │ > │ │ 101 │ 5 │ 5 │ 5 │ 5 │ 102 │ └─────── │ └─────── |
| 1061 |
└──────── │ 103 │ 101 │ 103 │ 101 │ │ 102 │ ┌────── │ │ 102 │ ┌────── │ 2/2 ─ │ ┌─────── │ ┌───── │ 103 │ ┌─────── │ ┌─────── |
| 1062 |
│ 5/5 ─ │ 102 │ 2/2 ─ │ 102 │ │ 103 │ │ 101 │ │ 103 │ │ 101 │ > │ │ 2/2 │ │ 101 │ ┌─────── │ │ 101 │ │ > |
| 1063 |
│ > │ 103 │ > │ 103 │ └────── │ │ 102 │ └────── │ │ 102 │ ┌────── │ │ > │ │ 102 │ │ 5/5 │ │ 102 │ └─────── |
| 1064 |
└──────── └──────── └──────── └──────── │ 5/5 │ │ 103 │ 2/2 │ │ 103 │ │ 101 │ └─────── │ │ 103 │ │ > │ │ 103 │ ┌─────── |
| 1065 |
│ > │ └────── │ > │ └────── │ │ 102 │ ┌─────── │ └───── │ └─────── │ └─────── │ │ 101 |
| 1066 |
└──────── └──────── └──────── │ 2/2 │ │ 103 │ │ 101 └─────── └───────── │ ┌─────── │ │ 102 |
| 1067 |
│ > │ └────── │ │ 102 │ │ > │ │ 103 |
| 1068 |
└──────── └──────── │ │ 103 │ └─────── │ └─────── |
| 1069 |
│ └─────── └───────── └───────── |
| 1070 |
└───────── |
| 1071 |
BLOCK |
| 1072 |
|
| 1073 |
expects = [] |
| 1074 |
output.each_line.first.scan(/\S+/) do |
| 1075 |
offset = Regexp.last_match.offset(0) |
| 1076 |
expects << output.lines.filter_map { it[offset[0]...offset[1]]&.strip }.take_while { !it.empty? }.join("\n") |
| 1077 |
end |
| 1078 |
|
| 1079 |
suffixes.zip(expects).each do |suffix, block| |
| 1080 |
tmux.send_keys(prefix + suffix, :Enter) |
| 1081 |
tmux.until { assert_block(block, it) } |
| 1082 |
|
| 1083 |
teardown |
| 1084 |
setup |
| 1085 |
end |
| 1086 |
end |
| 1087 |
|
| 1088 |
def test_layout_default_with_footer |
| 1089 |
prefix = %[ |
| 1090 |
seq 3 | #{FZF} --no-list-border --height ~100% \ |
| 1091 |
--border sharp --footer "$(seq 201 202)" --footer-label FOOT --footer-label-pos 3 \ |
| 1092 |
--header-label HEAD --header-label-pos 3:bottom \ |
| 1093 |
--bind 'space:transform-footer-label(echo foot)+change-header-label(head)' |
| 1094 |
].strip + ' ' |
| 1095 |
suffixes = [ |
| 1096 |
%(), |
| 1097 |
%[--header "$(seq 101 102)"], |
| 1098 |
%[--header "$(seq 101 102)" --header-first], |
| 1099 |
%[--header "$(seq 101 102)" --header-lines 2], |
| 1100 |
%[--header "$(seq 101 102)" --header-lines 2 --header-first], |
| 1101 |
%[--header "$(seq 101 102)" --header-border sharp], |
| 1102 |
%[--header "$(seq 101 102)" --header-border sharp --header-first], |
| 1103 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2], |
| 1104 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --no-header-lines-border], |
| 1105 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border none], |
| 1106 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp], |
| 1107 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp --header-first --input-border sharp], |
| 1108 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp --header-first --no-input], |
| 1109 |
%[--header "$(seq 101 102)" --footer-border sharp --input-border line], |
| 1110 |
%[--header "$(seq 101 102)" --style full:sharp --header-first] |
| 1111 |
] |
| 1112 |
output = <<~BLOCK |
| 1113 |
┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌───────── ┌──────── ┌──────── ┌───────── |
| 1114 |
│ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ ┌─FOOT─ │ ┌─FOOT── |
| 1115 |
│ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ │ 201 │ │ 201 |
| 1116 |
│ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT── │ ──FOOT─ │ │ 202 │ │ 202 |
| 1117 |
│ 3 │ 3 │ 3 │ > 3 │ > 3 │ 3 │ 3 │ > 3 │ > 3 │ > 3 │ > 3 │ > 3 │ > 3 │ └────── │ └─────── |
| 1118 |
│ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ ┌────── │ ┌────── │ 2 │ ┌────── │ ┌─────── │ ┌────── │ 3 │ ┌─────── |
| 1119 |
│ > 1 │ > 1 │ > 1 │ 1 │ 1 │ > 1 │ > 1 │ │ 2 │ │ 2 │ 1 │ │ 2 │ │ 2 │ │ 2 │ 2 │ │ 3 |
| 1120 |
│ 3/3 ─ │ 101 │ 3/3 ─ │ 101 │ 1/1 ─ │ ┌────── │ 3/3 ─ │ │ 1 │ │ 1 │ ┌────── │ │ 1 │ │ 1 │ │ 1 │ > 1 │ │ 2 |
| 1121 |
│ > │ 102 │ > │ 102 │ > │ │ 101 │ > │ │ 101 │ │ 101 │ │ 101 │ └────── │ └─────── │ └────── │ 101 │ │ > 1 |
| 1122 |
└──────── │ 3/3 ─ │ 101 │ 1/1 ─ │ 101 │ │ 102 │ ┌────── │ │ 102 │ │ 102 │ │ 102 │ ┌────── │ ┌─────── │ ┌────── │ 102 │ └─────── |
| 1123 |
│ > │ 102 │ > │ 102 │ └─HEAD─ │ │ 101 │ └─HEAD─ │ └─HEAD─ │ └─HEAD─ │ │ 101 │ │ 1/1 │ │ 101 │ ─────── │ ┌─────── |
| 1124 |
└──────── └──────── └──────── └──────── │ 3/3 │ │ 102 │ 1/1 │ 1/1 │ 1/1 │ │ 102 │ │ > │ │ 102 │ 3/3 │ │ > |
| 1125 |
│ > │ └─HEAD─ │ > │ > │ > │ └─HEAD─ │ └─────── │ └─HEAD─ │ > │ └─────── |
| 1126 |
└──────── └──────── └──────── └──────── └──────── │ 1/1 │ ┌─────── └──────── └──────── │ ┌─────── |
| 1127 |
│ > │ │ 101 │ │ 101 |
| 1128 |
└──────── │ │ 102 │ │ 102 |
| 1129 |
│ └─HEAD── │ └─HEAD── |
| 1130 |
└───────── └───────── |
| 1131 |
BLOCK |
| 1132 |
|
| 1133 |
expects = [] |
| 1134 |
output.each_line.first.scan(/\S+/) do |
| 1135 |
offset = Regexp.last_match.offset(0) |
| 1136 |
expects << output.lines.filter_map { it[offset[0]...offset[1]]&.strip }.take_while { !it.empty? }.join("\n") |
| 1137 |
end |
| 1138 |
|
| 1139 |
suffixes.zip(expects).each do |suffix, block| |
| 1140 |
tmux.send_keys(prefix + suffix, :Enter) |
| 1141 |
tmux.until { assert_block(block, it) } |
| 1142 |
tmux.send_keys :Space |
| 1143 |
tmux.until { assert_block(block.downcase, it) } |
| 1144 |
|
| 1145 |
teardown |
| 1146 |
setup |
| 1147 |
end |
| 1148 |
end |
| 1149 |
|
| 1150 |
def test_layout_reverse_list_with_footer |
| 1151 |
prefix = %[ |
| 1152 |
seq 3 | #{FZF} --layout reverse-list --no-list-border --height ~100% \ |
| 1153 |
--border sharp --footer "$(seq 201 202)" --footer-label FOOT --footer-label-pos 3 \ |
| 1154 |
--header-label HEAD --header-label-pos 3:bottom \ |
| 1155 |
--bind 'space:transform-footer-label(echo foot)+change-header-label(head)' |
| 1156 |
].strip + ' ' |
| 1157 |
suffixes = [ |
| 1158 |
%(), |
| 1159 |
%[--header "$(seq 101 102)"], |
| 1160 |
%[--header "$(seq 101 102)" --header-first], |
| 1161 |
%[--header "$(seq 101 102)" --header-lines 2], |
| 1162 |
%[--header "$(seq 101 102)" --header-lines 2 --header-first], |
| 1163 |
%[--header "$(seq 101 102)" --header-border sharp], |
| 1164 |
%[--header "$(seq 101 102)" --header-border sharp --header-first], |
| 1165 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2], |
| 1166 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp], |
| 1167 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp --header-first --input-border sharp], |
| 1168 |
%[--header "$(seq 101 102)" --header-border sharp --header-lines 2 --header-lines-border sharp --header-first --no-input], |
| 1169 |
%[--header "$(seq 101 102)" --footer-border sharp --input-border line], |
| 1170 |
%[--header "$(seq 101 102)" --style full:sharp --header-first] |
| 1171 |
] |
| 1172 |
output = <<~BLOCK |
| 1173 |
┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌──────── ┌───────── ┌──────── ┌──────── ┌───────── |
| 1174 |
│ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ 201 │ ┌─FOOT─ │ ┌─FOOT── |
| 1175 |
│ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ 202 │ │ 201 │ │ 201 |
| 1176 |
│ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT─ │ ──FOOT── │ ──FOOT─ │ │ 202 │ │ 202 |
| 1177 |
│ > 1 │ > 1 │ > 1 │ 1 │ 1 │ > 1 │ > 1 │ 1 │ ┌────── │ ┌─────── │ ┌────── │ └────── │ └─────── |
| 1178 |
│ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ 2 │ │ 1 │ │ 1 │ │ 1 │ > 1 │ ┌─────── |
| 1179 |
│ 3 │ 3 │ 3 │ > 3 │ > 3 │ 3 │ 3 │ > 3 │ │ 2 │ │ 2 │ │ 2 │ 2 │ │ > 1 |
| 1180 |
│ 3/3 ─ │ 101 │ 3/3 ─ │ 101 │ 1/1 ─ │ ┌────── │ 3/3 ─ │ ┌────── │ └────── │ └─────── │ └────── │ 3 │ │ 2 |
| 1181 |
│ > │ 102 │ > │ 102 │ > │ │ 101 │ > │ │ 101 │ > 3 │ > 3 │ > 3 │ 101 │ │ 3 |
| 1182 |
└──────── │ 3/3 ─ │ 101 │ 1/1 ─ │ 101 │ │ 102 │ ┌────── │ │ 102 │ ┌────── │ ┌─────── │ ┌────── │ 102 │ └─────── |
| 1183 |
│ > │ 102 │ > │ 102 │ └─HEAD─ │ │ 101 │ └─HEAD─ │ │ 101 │ │ 1/1 │ │ 101 │ ─────── │ ┌─────── |
| 1184 |
└──────── └──────── └──────── └──────── │ 3/3 │ │ 102 │ 1/1 │ │ 102 │ │ > │ │ 102 │ 3/3 │ │ > |
| 1185 |
│ > │ └─HEAD─ │ > │ └─HEAD─ │ └─────── │ └─HEAD─ │ > │ └─────── |
| 1186 |
└──────── └──────── └──────── │ 1/1 │ ┌─────── └──────── └──────── │ ┌─────── |
| 1187 |
│ > │ │ 101 │ │ 101 |
| 1188 |
└──────── │ │ 102 │ │ 102 |
| 1189 |
│ └─HEAD── │ └─HEAD── |
| 1190 |
└───────── └───────── |
| 1191 |
BLOCK |
| 1192 |
|
| 1193 |
expects = [] |
| 1194 |
output.each_line.first.scan(/\S+/) do |
| 1195 |
offset = Regexp.last_match.offset(0) |
| 1196 |
expects << output.lines.filter_map { it[offset[0]...offset[1]]&.strip }.take_while { !it.empty? }.join("\n") |
| 1197 |
end |
| 1198 |
|
| 1199 |
suffixes.zip(expects).each do |suffix, block| |
| 1200 |
tmux.send_keys(prefix + suffix, :Enter) |
| 1201 |
tmux.until { assert_block(block, it) } |
| 1202 |
tmux.send_keys :Space |
| 1203 |
tmux.until { assert_block(block.downcase, it) } |
| 1204 |
|
| 1205 |
teardown |
| 1206 |
setup |
| 1207 |
end |
| 1208 |
end |
| 1209 |
|
| 1210 |
def test_change_header_and_label_at_once |
| 1211 |
tmux.send_keys %(seq 10 | #{FZF} --border sharp --header-border sharp --header-label-pos 3 --bind 'focus:change-header(header)+change-header-label(label)'), :Enter |
| 1212 |
block = <<~BLOCK |
| 1213 |
│ ┌─label── |
| 1214 |
│ │ header |
| 1215 |
│ └──────── |
| 1216 |
│ 10/10 |
| 1217 |
│ > |
| 1218 |
└────────── |
| 1219 |
BLOCK |
| 1220 |
tmux.until { assert_block(block, it) } |
| 1221 |
end |
| 1222 |
|
| 1223 |
def test_label_truncation |
| 1224 |
command = <<~CMD |
| 1225 |
seq 10 | #{FZF} --style full --border --header-lines=1 --preview ':' \\ |
| 1226 |
--border-label "#{'b' * 1000}" \\ |
| 1227 |
--preview-label "#{'p' * 1000}" \\ |
| 1228 |
--header-label "#{'h' * 1000}" \\ |
| 1229 |
--header-label "#{'h' * 1000}" \\ |
| 1230 |
--input-label "#{'i' * 1000}" \\ |
| 1231 |
--list-label "#{'l' * 1000}" |
| 1232 |
CMD |
| 1233 |
writelines(command.lines.map(&:chomp)) |
| 1234 |
tmux.send_keys("sh #{tempname}", :Enter) |
| 1235 |
tmux.until do |lines| |
| 1236 |
text = lines.join |
| 1237 |
assert_includes text, 'b··' |
| 1238 |
assert_includes text, 'l··p' |
| 1239 |
assert_includes text, 'p··' |
| 1240 |
assert_includes text, 'h··' |
| 1241 |
assert_includes text, 'i··' |
| 1242 |
end |
| 1243 |
end |
| 1244 |
|
| 1245 |
def test_separator_no_ellipsis |
| 1246 |
tmux.send_keys %(seq 10 | #{FZF} --separator "$(seq 1000 | tr '\\n' ' ')"), :Enter |
| 1247 |
tmux.until do |lines| |
| 1248 |
assert_equal 10, lines.match_count |
| 1249 |
refute_includes lines.join, '··' |
| 1250 |
end |
| 1251 |
end |
| 1252 |
|
| 1253 |
def test_separator_with_input_border |
| 1254 |
# Border line below input does not face the list; separator is shown |
| 1255 |
tmux.send_keys %(seq 100 | #{FZF} --input-border bottom), :Enter |
| 1256 |
block = <<~BLOCK |
| 1257 |
> 1 |
| 1258 |
100/100 ── |
| 1259 |
> |
| 1260 |
──────────── |
| 1261 |
BLOCK |
| 1262 |
tmux.until { assert_block(block, it) } |
| 1263 |
teardown |
| 1264 |
setup |
| 1265 |
|
| 1266 |
# List border faces the input instead; separator is hidden |
| 1267 |
tmux.send_keys %(seq 100 | #{FZF} --input-border bottom --list-border rounded), :Enter |
| 1268 |
block = <<~BLOCK |
| 1269 |
│ > 1 |
| 1270 |
╰──────────── |
| 1271 |
100/100 |
| 1272 |
> |
| 1273 |
───────────── |
| 1274 |
BLOCK |
| 1275 |
tmux.until { assert_block(block, it) } |
| 1276 |
teardown |
| 1277 |
setup |
| 1278 |
|
| 1279 |
# Border line above input faces the list; separator is hidden |
| 1280 |
tmux.send_keys %(seq 100 | #{FZF} --input-border top), :Enter |
| 1281 |
block = <<~BLOCK |
| 1282 |
> 1 |
| 1283 |
──────────── |
| 1284 |
100/100 |
| 1285 |
> |
| 1286 |
BLOCK |
| 1287 |
tmux.until { assert_block(block, it) } |
| 1288 |
end |
| 1289 |
|
| 1290 |
def test_separator_with_input_border_reverse |
| 1291 |
# Border line above input does not face the list; separator is shown |
| 1292 |
tmux.send_keys %(seq 100 | #{FZF} --layout reverse --input-border top), :Enter |
| 1293 |
block = <<~BLOCK |
| 1294 |
──────────── |
| 1295 |
> |
| 1296 |
100/100 ── |
| 1297 |
> 1 |
| 1298 |
BLOCK |
| 1299 |
tmux.until { assert_block(block, it) } |
| 1300 |
teardown |
| 1301 |
setup |
| 1302 |
|
| 1303 |
# Border line below input faces the list; separator is hidden |
| 1304 |
tmux.send_keys %(seq 100 | #{FZF} --layout reverse --input-border bottom), :Enter |
| 1305 |
block = <<~BLOCK |
| 1306 |
> |
| 1307 |
100/100 |
| 1308 |
──────────── |
| 1309 |
> 1 |
| 1310 |
BLOCK |
| 1311 |
tmux.until { assert_block(block, it) } |
| 1312 |
end |
| 1313 |
|
| 1314 |
def test_separator_with_preview_next |
| 1315 |
# Preview window at 'next' position sits next to the input section, so the |
| 1316 |
# header border does not hide the separator |
| 1317 |
tmux.send_keys %(seq 100 | #{FZF} --header foo --header-border rounded --no-list-border --preview 'echo hi' --preview-window next,1,border-none), :Enter |
| 1318 |
block = <<~BLOCK |
| 1319 |
╰──────────── |
| 1320 |
hi |
| 1321 |
100/100 ─── |
| 1322 |
> |
| 1323 |
BLOCK |
| 1324 |
tmux.until { assert_block(block, it) } |
| 1325 |
teardown |
| 1326 |
setup |
| 1327 |
|
| 1328 |
# Same when 'next' position comes from a threshold alternative |
| 1329 |
tmux.send_keys %(seq 100 | #{FZF} --header foo --header-border rounded --no-list-border --preview 'echo hi' --preview-window 'up,40%,<9999(next,1,border-none)'), :Enter |
| 1330 |
tmux.until { assert_block(block, it) } |
| 1331 |
teardown |
| 1332 |
setup |
| 1333 |
|
| 1334 |
# A border of the preview window at 'next' position facing the input |
| 1335 |
# section hides the separator |
| 1336 |
tmux.send_keys %(seq 100 | #{FZF} --preview : --preview-window next,3), :Enter |
| 1337 |
block = <<~BLOCK |
| 1338 |
╰──────────── |
| 1339 |
100/100 |
| 1340 |
> |
| 1341 |
BLOCK |
| 1342 |
tmux.until { assert_block(block, it) } |
| 1343 |
teardown |
| 1344 |
setup |
| 1345 |
|
| 1346 |
# Same when every spec in the threshold chain is a bordered preview |
| 1347 |
# window at 'next' position |
| 1348 |
tmux.send_keys %(seq 100 | #{FZF} --preview : --preview-window 'next,3,<15(next,3)'), :Enter |
| 1349 |
tmux.until { assert_block(block, it) } |
| 1350 |
end |
| 1351 |
|
| 1352 |
def test_separator_with_preview_next_toggle |
| 1353 |
tmux.send_keys %(seq 100 | #{FZF} --preview 'echo hi' --preview-window next,3,hidden --bind space:toggle-preview), :Enter |
| 1354 |
hidden = <<~BLOCK |
| 1355 |
> 1 |
| 1356 |
100/100 ── |
| 1357 |
> |
| 1358 |
BLOCK |
| 1359 |
tmux.until { assert_block(hidden, it) } |
| 1360 |
|
| 1361 |
tmux.send_keys :Space |
| 1362 |
shown = <<~BLOCK |
| 1363 |
│ hi |
| 1364 |
│ |
| 1365 |
│ |
| 1366 |
╰──────────── |
| 1367 |
100/100 |
| 1368 |
> |
| 1369 |
BLOCK |
| 1370 |
tmux.until { assert_block(shown, it) } |
| 1371 |
|
| 1372 |
tmux.send_keys :Space |
| 1373 |
tmux.until { assert_block(hidden, it) } |
| 1374 |
end |
| 1375 |
|
| 1376 |
def test_separator_with_preview_next_alternative_only |
| 1377 |
# 'next' appears only in a threshold alternative and there is no |
| 1378 |
# previewer, so the input section stays embedded in the list window and |
| 1379 |
# needs the separator |
| 1380 |
tmux.send_keys %(seq 100 | #{FZF} --preview-window '<9999(next)' --list-border rounded), :Enter |
| 1381 |
block = <<~BLOCK |
| 1382 |
│ > 1 |
| 1383 |
│ 100/100 ── |
| 1384 |
│ > |
| 1385 |
╰───────────── |
| 1386 |
BLOCK |
| 1387 |
tmux.until { assert_block(block, it) } |
| 1388 |
end |
| 1389 |
|
| 1390 |
def test_separator_with_preview_action_at_next |
| 1391 |
# preview(...) action can display an ad-hoc preview window at 'next' |
| 1392 |
# position at any time; the list border must not hide the separator |
| 1393 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --preview-window 'next,border-left,5' --bind 'space:preview(echo hi)'), :Enter |
| 1394 |
block = <<~BLOCK |
| 1395 |
╰───────────── |
| 1396 |
100/100 ── |
| 1397 |
> |
| 1398 |
BLOCK |
| 1399 |
tmux.until { assert_block(block, it) } |
| 1400 |
|
| 1401 |
tmux.send_keys :Space |
| 1402 |
block = <<~BLOCK |
| 1403 |
│ hi |
| 1404 |
│ |
| 1405 |
│ |
| 1406 |
│ |
| 1407 |
│ |
| 1408 |
100/100 ── |
| 1409 |
> |
| 1410 |
BLOCK |
| 1411 |
tmux.until { assert_block(block, it) } |
| 1412 |
end |
| 1413 |
|
| 1414 |
def test_separator_change_preview_window_keeps_forced_preview |
| 1415 |
# Relayout triggered by the separator visibility change must not drop a |
| 1416 |
# preview window opened via the preview(...) action |
| 1417 |
tmux.send_keys %(seq 100 | #{FZF} --info hidden --input-border left --list-border --preview-window 'up,50%,<5(next)' --bind 'space:preview(echo AD-HOC)' --bind 'x:change-preview-window(up,50%,<5(up))'), :Enter |
| 1418 |
tmux.until { |lines| assert_includes lines.join, '│ ─' } |
| 1419 |
|
| 1420 |
tmux.send_keys :Space |
| 1421 |
tmux.until do |lines| |
| 1422 |
assert_includes lines.join, 'AD-HOC' |
| 1423 |
assert_includes lines.join, '│ ─' |
| 1424 |
end |
| 1425 |
|
| 1426 |
# Only the inactive threshold alternative changes; separator is hidden |
| 1427 |
# by the list border, and the forced preview window must survive |
| 1428 |
tmux.send_keys :x |
| 1429 |
tmux.until do |lines| |
| 1430 |
assert_includes lines.join, 'AD-HOC' |
| 1431 |
refute_includes lines.join, '│ ─' |
| 1432 |
end |
| 1433 |
end |
| 1434 |
|
| 1435 |
def test_separator_with_change_preview_window_chain |
| 1436 |
# change-preview-window that only alters a non-active spec must still |
| 1437 |
# trigger a relayout when it changes the separator visibility |
| 1438 |
tmux.send_keys %(seq 100 | #{FZF} --info hidden --layout reverse --preview 'echo hi' --preview-window 'next,3,border-none,<100(next,3,border-top)' --bind 'space:change-preview-window(next,3,border-top,<100(next,3,border-top))'), :Enter |
| 1439 |
block = <<~BLOCK |
| 1440 |
> |
| 1441 |
────────── |
| 1442 |
────────── |
| 1443 |
hi |
| 1444 |
BLOCK |
| 1445 |
tmux.until { assert_block(block, it) } |
| 1446 |
|
| 1447 |
tmux.send_keys :Space |
| 1448 |
block = <<~BLOCK |
| 1449 |
> |
| 1450 |
────────── |
| 1451 |
hi |
| 1452 |
BLOCK |
| 1453 |
tmux.until { assert_block(block, it) } |
| 1454 |
teardown |
| 1455 |
setup |
| 1456 |
|
| 1457 |
# Also when only the drawn bar changes; the info line row count is |
| 1458 |
# constant with the default info style |
| 1459 |
tmux.send_keys %(seq 100 | #{FZF} --layout reverse --preview 'echo hi' --preview-window 'next,3,border-none,<100(next,3,border-top)' --bind 'space:change-preview-window(next,3,border-top,<100(next,3,border-top))'), :Enter |
| 1460 |
block = <<~BLOCK |
| 1461 |
> |
| 1462 |
100/100 ── |
| 1463 |
BLOCK |
| 1464 |
tmux.until { assert_block(block, it) } |
| 1465 |
|
| 1466 |
tmux.send_keys :Space |
| 1467 |
block = <<~BLOCK |
| 1468 |
> |
| 1469 |
100/100 |
| 1470 |
──────────── |
| 1471 |
BLOCK |
| 1472 |
tmux.until { assert_block(block, it) } |
| 1473 |
teardown |
| 1474 |
setup |
| 1475 |
|
| 1476 |
# Also when compare finds a content-layout difference (scroll offset) |
| 1477 |
tmux.send_keys %(seq 100 | #{FZF} --info hidden --preview 'echo hi' --preview-window 'next,3,<2(up,3)' --bind 'space:change-preview-window(next,3,+1,<2(next,3))'), :Enter |
| 1478 |
block = <<~BLOCK |
| 1479 |
╰──────────── |
| 1480 |
───────────── |
| 1481 |
> |
| 1482 |
BLOCK |
| 1483 |
tmux.until { assert_block(block, it) } |
| 1484 |
|
| 1485 |
tmux.send_keys :Space |
| 1486 |
block = <<~BLOCK |
| 1487 |
╰──────────── |
| 1488 |
> |
| 1489 |
BLOCK |
| 1490 |
tmux.until { assert_block(block, it) } |
| 1491 |
end |
| 1492 |
|
| 1493 |
def test_separator_with_inline_header_border |
| 1494 |
# Inline header is drawn inside the list border; bare header lines sit |
| 1495 |
# next to the input section, so the separator is shown |
| 1496 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header foo --header-lines 2 --header-border inline --header-lines-border none), :Enter |
| 1497 |
block = <<~BLOCK |
| 1498 |
╰──────────── |
| 1499 |
2 |
| 1500 |
1 |
| 1501 |
98/98 ─── |
| 1502 |
> |
| 1503 |
BLOCK |
| 1504 |
tmux.until { assert_block(block, it) } |
| 1505 |
teardown |
| 1506 |
setup |
| 1507 |
|
| 1508 |
# Header lines are embedded in the list border along with the inline |
| 1509 |
# header; the list border faces the input section and hides the separator |
| 1510 |
tmux.send_keys %(seq 100 | #{FZF} --list-border rounded --header foo --header-lines 2 --header-border inline), :Enter |
| 1511 |
block = <<~BLOCK |
| 1512 |
│ 2 |
| 1513 |
│ 1 |
| 1514 |
│ foo |
| 1515 |
╰──────────── |
| 1516 |
98/98 |
| 1517 |
> |
| 1518 |
BLOCK |
| 1519 |
tmux.until { assert_block(block, it) } |
| 1520 |
end |
| 1521 |
|
| 1522 |
def test_header_border_no_pointer_and_marker |
| 1523 |
tmux.send_keys %(seq 10 | #{FZF} --header-lines 1 --header-border sharp --no-list-border --pointer '' --marker ''), :Enter |
| 1524 |
block = <<~BLOCK |
| 1525 |
┌────── |
| 1526 |
│ 1 |
| 1527 |
└────── |
| 1528 |
9/9 |
| 1529 |
> |
| 1530 |
BLOCK |
| 1531 |
tmux.until { assert_block(block, it) } |
| 1532 |
end |
| 1533 |
|
| 1534 |
def test_gutter_default |
| 1535 |
tmux.send_keys %(seq 10 | fzf), :Enter |
| 1536 |
block = <<~BLOCK |
| 1537 |
▌ 3 |
| 1538 |
▌ 2 |
| 1539 |
> 1 |
| 1540 |
10/10 |
| 1541 |
> |
| 1542 |
BLOCK |
| 1543 |
tmux.until { assert_block(block, it) } |
| 1544 |
end |
| 1545 |
|
| 1546 |
def test_gutter_default_no_unicode |
| 1547 |
tmux.send_keys %(seq 10 | fzf --no-unicode), :Enter |
| 1548 |
block = <<~BLOCK |
| 1549 |
3 |
| 1550 |
2 |
| 1551 |
> 1 |
| 1552 |
10/10 |
| 1553 |
> |
| 1554 |
BLOCK |
| 1555 |
tmux.until { assert_block(block, it) } |
| 1556 |
end |
| 1557 |
|
| 1558 |
def test_gutter_custom |
| 1559 |
tmux.send_keys %(seq 10 | fzf --gutter x), :Enter |
| 1560 |
block = <<~BLOCK |
| 1561 |
x 3 |
| 1562 |
x 2 |
| 1563 |
> 1 |
| 1564 |
10/10 |
| 1565 |
> |
| 1566 |
BLOCK |
| 1567 |
tmux.until { assert_block(block, it) } |
| 1568 |
end |
| 1569 |
|
| 1570 |
# https://github.com/junegunn/fzf/issues/4537 |
| 1571 |
def test_no_scrollbar_preview_toggle |
| 1572 |
x = 'x' * 300 |
| 1573 |
y = 'y' * 300 |
| 1574 |
tmux.send_keys %(yes #{x} | head -1000 | fzf --bind 'tab:toggle-preview' --border --no-scrollbar --preview 'echo #{y}' --preview-window 'border-left'), :Enter |
| 1575 |
|
| 1576 |
# │ ▌ xxxxxxxx·· │ yyyyyyyy│ |
| 1577 |
tmux.until do |lines| |
| 1578 |
lines.any? { it.match?(/x·· │ y+│$/) } |
| 1579 |
end |
| 1580 |
tmux.send_keys :Tab |
| 1581 |
|
| 1582 |
# │ ▌ xxxxxxxx·· │ |
| 1583 |
tmux.until do |lines| |
| 1584 |
lines.none? { it.match?(/x··y│$/) } |
| 1585 |
end |
| 1586 |
|
| 1587 |
tmux.send_keys :Tab |
| 1588 |
tmux.until do |lines| |
| 1589 |
lines.any? { it.match?(/x·· │ y+│$/) } |
| 1590 |
end |
| 1591 |
end |
| 1592 |
|
| 1593 |
def test_header_and_footer_should_not_be_wider_than_list |
| 1594 |
tmux.send_keys %(WIDE=$(printf 'x%.0s' {1..1000}); (echo $WIDE; echo $WIDE) | fzf --header-lines 1 --style full --header-border bottom --header-lines-border top --ellipsis XX --header "$WIDE" --footer "$WIDE" --no-footer-border), :Enter |
| 1595 |
tmux.until do |lines| |
| 1596 |
matches = lines.filter_map { |line| line[/x+XX/] } |
| 1597 |
assert_equal 4, matches.length |
| 1598 |
assert_equal 1, matches.uniq.length |
| 1599 |
end |
| 1600 |
end |
| 1601 |
|
| 1602 |
def test_combinations |
| 1603 |
skip unless ENV['LONGTEST'] |
| 1604 |
|
| 1605 |
begin |
| 1606 |
base = [ |
| 1607 |
'--pointer=@', |
| 1608 |
'--exact', |
| 1609 |
'--query=123', |
| 1610 |
'--header="$(seq 101 103)"', |
| 1611 |
'--header-lines=3', |
| 1612 |
'--footer "$(seq 201 203)"', |
| 1613 |
'--preview "echo foobar"' |
| 1614 |
] |
| 1615 |
options = [ |
| 1616 |
['--separator==', '--no-separator'], |
| 1617 |
['--info=default', '--info=inline', '--info=inline-right'], |
| 1618 |
['--no-input-border', '--input-border'], |
| 1619 |
['--no-header-border', '--header-border=none', '--header-border'], |
| 1620 |
['--no-header-lines-border', '--header-lines-border'], |
| 1621 |
['--no-footer-border', '--footer-border'], |
| 1622 |
['--no-list-border', '--list-border'], |
| 1623 |
['--preview-window=right', '--preview-window=up', '--preview-window=down', '--preview-window=left', '--preview-window=next'], |
| 1624 |
['--header-first', '--no-header-first'], |
| 1625 |
['--layout=default', '--layout=reverse', '--layout=reverse-list'] |
| 1626 |
] |
| 1627 |
# Combination of all options |
| 1628 |
combinations = options[0].product(*options.drop(1)) |
| 1629 |
|
| 1630 |
# Run workers in parallel, each with its own pre-created tmux window. |
| 1631 |
# Tmux setup/teardown is serialized in the main thread to avoid racing |
| 1632 |
# `tmux new-window` and `tmux kill-window` calls on the tmux server. |
| 1633 |
workers = 10 |
| 1634 |
tmuxes = Array.new(workers) { Tmux.new } |
| 1635 |
failures = [] |
| 1636 |
mutex = Mutex.new |
| 1637 |
queue = Queue.new |
| 1638 |
index = 0 |
| 1639 |
threads = tmuxes.map do |local_tmux| |
| 1640 |
Thread.new do |
| 1641 |
command = nil |
| 1642 |
loop do |
| 1643 |
combination = queue.pop or break |
| 1644 |
|
| 1645 |
opts = base + combination |
| 1646 |
command = %(seq 1001 2000 | #{FZF} #{opts.join(' ')}) |
| 1647 |
mutex.synchronize do |
| 1648 |
print("\r#{index += 1}/#{combinations.length}") |
| 1649 |
end |
| 1650 |
local_tmux.send_keys command, :Enter |
| 1651 |
local_tmux.until do |lines| |
| 1652 |
layout = combination.find { it.start_with?('--layout=') }.split('=').last |
| 1653 |
header_first = combination.include?('--header-first') |
| 1654 |
|
| 1655 |
# Input |
| 1656 |
input = lines.index { it.include?('> 123') } |
| 1657 |
assert(input) |
| 1658 |
|
| 1659 |
# Info |
| 1660 |
info = lines.index { it.include?('11/997') } |
| 1661 |
assert(info) |
| 1662 |
|
| 1663 |
assert(layout == 'reverse' ? input <= info : input >= info) |
| 1664 |
|
| 1665 |
# List |
| 1666 |
item1 = lines.index { it.include?('1230') } |
| 1667 |
item2 = lines.index { it.include?('1231') } |
| 1668 |
assert_equal(item1, layout == 'default' ? item2 + 1 : item2 - 1) |
| 1669 |
|
| 1670 |
# Preview |
| 1671 |
assert(lines.any? { it.include?('foobar') }) |
| 1672 |
|
| 1673 |
# Header |
| 1674 |
header1 = lines.index { it.include?('101') } |
| 1675 |
header2 = lines.index { it.include?('102') } |
| 1676 |
assert_equal(header2, header1 + 1) |
| 1677 |
assert((layout == 'reverse') == header_first ? input > header1 : input < header1) |
| 1678 |
|
| 1679 |
# Footer |
| 1680 |
footer1 = lines.index { it.include?('201') } |
| 1681 |
footer2 = lines.index { it.include?('202') } |
| 1682 |
assert_equal(footer2, footer1 + 1) |
| 1683 |
assert(layout == 'reverse' ? footer1 > item2 : footer1 < item2) |
| 1684 |
|
| 1685 |
# Header lines |
| 1686 |
hline1 = lines.index { it.include?('1001') } |
| 1687 |
hline2 = lines.index { it.include?('1002') } |
| 1688 |
assert_equal(hline1, layout == 'default' ? hline2 + 1 : hline2 - 1) |
| 1689 |
assert(layout == 'reverse' ? hline1 > header1 : hline1 < header1) |
| 1690 |
end |
| 1691 |
local_tmux.send_keys :Enter |
| 1692 |
end |
| 1693 |
rescue StandardError, Minitest::Assertion => e |
| 1694 |
mutex.synchronize { failures << [command, e] } |
| 1695 |
end |
| 1696 |
end |
| 1697 |
combinations.each { queue << it } |
| 1698 |
queue.close |
| 1699 |
|
| 1700 |
threads.each(&:join) |
| 1701 |
raise failures.inspect unless failures.empty? |
| 1702 |
ensure |
| 1703 |
# Reverse so any tmux window renumbering does not leave stale indices behind. |
| 1704 |
tmuxes&.reverse_each(&:kill) |
| 1705 |
end |
| 1706 |
end |
| 1707 |
|
| 1708 |
# Locate a word in the currently captured screen and click its first character. |
| 1709 |
# tmux rows/columns are 1-based; capture indices are 0-based. |
| 1710 |
def click_word(word) |
| 1711 |
tmux.capture.each_with_index do |line, idx| |
| 1712 |
col = line.index(word) |
| 1713 |
return tmux.click(col + 1, idx + 1) if col |
| 1714 |
end |
| 1715 |
flunk("word #{word.inspect} not found on screen") |
| 1716 |
end |
| 1717 |
|
| 1718 |
# Launch fzf with a click-{header,footer} binding that echoes FZF_CLICK_* into the prompt, |
| 1719 |
# then click each word in `clicks` and assert the resulting L/W values. |
| 1720 |
# `clicks` is an array of [word_to_click, expected_line]. |
| 1721 |
def verify_clicks(kind:, opts:, input:, clicks:) |
| 1722 |
var = kind.to_s.upcase # HEADER or FOOTER |
| 1723 |
binding = "click-#{kind}:transform-prompt:" \ |
| 1724 |
"echo \"L=$FZF_CLICK_#{var}_LINE W=$FZF_CLICK_#{var}_WORD> \"" |
| 1725 |
# --multi makes the info line end in " (0)" so the wait regex is unambiguous. |
| 1726 |
tmux.send_keys %(#{input} | #{FZF} #{opts} --multi --bind '#{binding}'), :Enter |
| 1727 |
# Wait for fzf to fully render before inspecting the screen, otherwise the echoed |
| 1728 |
# command line can shadow click targets. |
| 1729 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+ \(0\)}) } |
| 1730 |
clicks.each do |word, line| |
| 1731 |
click_word(word) |
| 1732 |
tmux.until { |lines| assert lines.any_include?("L=#{line} W=#{word}>") } |
| 1733 |
end |
| 1734 |
tmux.send_keys 'Escape' |
| 1735 |
end |
| 1736 |
|
| 1737 |
# Header lines (--header-lines) are rendered in reverse display order only under |
| 1738 |
# layout=default; in layout=reverse and layout=reverse-list they keep the input order. |
| 1739 |
# FZF_CLICK_HEADER_LINE reflects the visual row, so the expected value flips. |
| 1740 |
HEADER_CLICKS = [%w[Aaa 1], %w[Bbb 2], %w[Ccc 3]].freeze |
| 1741 |
|
| 1742 |
%w[default reverse reverse-list].each do |layout| |
| 1743 |
slug = layout.tr('-', '_') |
| 1744 |
|
| 1745 |
# Plain --header with no border around the header section. |
| 1746 |
define_method(:"test_click_header_plain_#{slug}") do |
| 1747 |
verify_clicks(kind: :header, |
| 1748 |
opts: %(--layout=#{layout} --header $'Aaa\\nBbb\\nCcc'), |
| 1749 |
input: 'seq 5', |
| 1750 |
clicks: HEADER_CLICKS) |
| 1751 |
end |
| 1752 |
|
| 1753 |
# --header with a framing border (--style full gives --header-border=rounded by default). |
| 1754 |
define_method(:"test_click_header_border_rounded_#{slug}") do |
| 1755 |
verify_clicks(kind: :header, |
| 1756 |
opts: %(--layout=#{layout} --style full --header $'Aaa\\nBbb\\nCcc'), |
| 1757 |
input: 'seq 5', |
| 1758 |
clicks: HEADER_CLICKS) |
| 1759 |
end |
| 1760 |
|
| 1761 |
# --header-lines consumed from stdin, with its own framing border. |
| 1762 |
define_method(:"test_click_header_lines_border_rounded_#{slug}") do |
| 1763 |
clicks_hl = if layout == 'default' |
| 1764 |
[%w[Xaa 3], %w[Ybb 2], %w[Zcc 1]] |
| 1765 |
else |
| 1766 |
[%w[Xaa 1], %w[Ybb 2], %w[Zcc 3]] |
| 1767 |
end |
| 1768 |
verify_clicks(kind: :header, |
| 1769 |
opts: %(--layout=#{layout} --style full --header-lines 3), |
| 1770 |
input: "(printf 'Xaa\\nYbb\\nZcc\\n'; seq 5)", |
| 1771 |
clicks: clicks_hl) |
| 1772 |
end |
| 1773 |
|
| 1774 |
# --footer with a framing border. |
| 1775 |
define_method(:"test_click_footer_border_rounded_#{slug}") do |
| 1776 |
verify_clicks(kind: :footer, |
| 1777 |
opts: %(--layout=#{layout} --style full --footer $'Foo\\nBar\\nBaz'), |
| 1778 |
input: 'seq 5', |
| 1779 |
clicks: [%w[Foo 1], %w[Bar 2], %w[Baz 3]]) |
| 1780 |
end |
| 1781 |
|
| 1782 |
# --header and --header-lines combined. Click-header numbering concatenates the two |
| 1783 |
# sections, but the order depends on the layout: |
| 1784 |
# layoutReverse: custom header (1..N), then header-lines (N+1..N+M) |
| 1785 |
# layoutDefault: header-lines (1..M, reversed visually), then custom header (M+1..M+N) |
| 1786 |
# layoutReverseList: header-lines (1..M), then custom header (M+1..M+N) |
| 1787 |
define_method(:"test_click_header_combined_#{slug}") do |
| 1788 |
clicks = case layout |
| 1789 |
when 'reverse' |
| 1790 |
[%w[Aaa 1], %w[Bbb 2], %w[Ccc 3], %w[Xaa 4], %w[Ybb 5], %w[Zcc 6]] |
| 1791 |
when 'default' |
| 1792 |
[%w[Aaa 4], %w[Bbb 5], %w[Ccc 6], %w[Xaa 3], %w[Ybb 2], %w[Zcc 1]] |
| 1793 |
else # reverse-list |
| 1794 |
[%w[Aaa 4], %w[Bbb 5], %w[Ccc 6], %w[Xaa 1], %w[Ybb 2], %w[Zcc 3]] |
| 1795 |
end |
| 1796 |
verify_clicks(kind: :header, |
| 1797 |
opts: %(--layout=#{layout} --header $'Aaa\\nBbb\\nCcc' --header-lines 3), |
| 1798 |
input: "(printf 'Xaa\\nYbb\\nZcc\\n'; seq 5)", |
| 1799 |
clicks: clicks) |
| 1800 |
end |
| 1801 |
|
| 1802 |
# Inline header inside a rounded list border. |
| 1803 |
define_method(:"test_click_header_border_inline_#{slug}") do |
| 1804 |
opts = %(--layout=#{layout} --style full --header $'Aaa\\nBbb\\nCcc' --header-border=inline) |
| 1805 |
verify_clicks(kind: :header, opts: opts, input: 'seq 5', clicks: HEADER_CLICKS) |
| 1806 |
end |
| 1807 |
|
| 1808 |
# Inline header inside a horizontal list border (top+bottom only, no T-junctions). |
| 1809 |
define_method(:"test_click_header_border_inline_horizontal_list_#{slug}") do |
| 1810 |
opts = %(--layout=#{layout} --style full --list-border=horizontal --header $'Aaa\\nBbb\\nCcc' --header-border=inline) |
| 1811 |
verify_clicks(kind: :header, opts: opts, input: 'seq 5', clicks: HEADER_CLICKS) |
| 1812 |
end |
| 1813 |
|
| 1814 |
# Inline header-lines inside a rounded list border. |
| 1815 |
define_method(:"test_click_header_lines_border_inline_#{slug}") do |
| 1816 |
clicks_hl = if layout == 'default' |
| 1817 |
[%w[Xaa 3], %w[Ybb 2], %w[Zcc 1]] |
| 1818 |
else |
| 1819 |
[%w[Xaa 1], %w[Ybb 2], %w[Zcc 3]] |
| 1820 |
end |
| 1821 |
opts = %(--layout=#{layout} --style full --header-lines 3 --header-lines-border=inline) |
| 1822 |
verify_clicks(kind: :header, opts: opts, |
| 1823 |
input: "(printf 'Xaa\\nYbb\\nZcc\\n'; seq 5)", |
| 1824 |
clicks: clicks_hl) |
| 1825 |
end |
| 1826 |
|
| 1827 |
# Inline footer inside a rounded list border. |
| 1828 |
define_method(:"test_click_footer_border_inline_#{slug}") do |
| 1829 |
opts = %(--layout=#{layout} --style full --footer $'Foo\\nBar\\nBaz' --footer-border=inline) |
| 1830 |
verify_clicks(kind: :footer, opts: opts, input: 'seq 5', |
| 1831 |
clicks: [%w[Foo 1], %w[Bar 2], %w[Baz 3]]) |
| 1832 |
end |
| 1833 |
end |
| 1834 |
|
| 1835 |
# An inline section requesting far more rows than the terminal can fit must not |
| 1836 |
# break the layout. The list frame must still render inside the pane with both |
| 1837 |
# corners visible and the prompt line present. |
| 1838 |
def test_inline_header_lines_oversized |
| 1839 |
tmux.send_keys %(seq 10000 | #{FZF} --style full --header-border inline --header-lines 9999), :Enter |
| 1840 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 1841 |
lines = tmux.capture |
| 1842 |
# Rounded (light) and sharp (tcell) default border glyphs. |
| 1843 |
top_corners = /[╭┌]/ |
| 1844 |
bottom_corners = /[╰└]/ |
| 1845 |
assert(lines.any? { |l| l.match?(top_corners) }, "list frame top missing: #{lines.inspect}") |
| 1846 |
assert(lines.any? { |l| l.match?(bottom_corners) }, "list frame bottom missing: #{lines.inspect}") |
| 1847 |
assert(lines.any? { |l| l.include?('>') }, "prompt missing: #{lines.inspect}") |
| 1848 |
tmux.send_keys 'Escape' |
| 1849 |
end |
| 1850 |
|
| 1851 |
# A non-inline section that consumes all available rows must still render without |
| 1852 |
# crashing when another section is inline but has no budget. The inline section's |
| 1853 |
# content is clipped to 0 but the layout proceeds. |
| 1854 |
def test_inline_footer_starved_by_non_inline_header |
| 1855 |
tmux.send_keys %(seq 10000 | #{FZF} --style full --footer-border inline --footer "$(seq 1000)" --header "$(seq 1000)"), :Enter |
| 1856 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 1857 |
lines = tmux.capture |
| 1858 |
assert(lines.any? { |l| l.include?('>') }, "prompt missing: #{lines.inspect}") |
| 1859 |
tmux.send_keys 'Escape' |
| 1860 |
end |
| 1861 |
|
| 1862 |
# Without a line-drawing --list-border, --header-border=inline must silently |
| 1863 |
# fall back to the `line` style (documented behavior). |
| 1864 |
def test_inline_falls_back_without_list_border |
| 1865 |
tmux.send_keys %(seq 5 | #{FZF} --list-border=none --header HEADER --header-border=inline), :Enter |
| 1866 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 1867 |
lines = tmux.capture |
| 1868 |
assert(lines.any? { |l| l.include?('HEADER') }, "header missing: #{lines.inspect}") |
| 1869 |
# Neither list frame corners (rounded/sharp) nor T-junction runes appear, |
| 1870 |
# since we've fallen back to a plain line separator. |
| 1871 |
assert(lines.none? { |l| l.match?(/[╭╮╰╯┌┐└┘├┤]/) }, "unexpected frame glyphs: #{lines.inspect}") |
| 1872 |
tmux.send_keys 'Escape' |
| 1873 |
end |
| 1874 |
|
| 1875 |
# Regression: when --header-border=inline falls back to `line` because the |
| 1876 |
# list border can't host an inline separator, the header-border color must |
| 1877 |
# inherit from `border`, not `list-border`. The effective shape is `line`, |
| 1878 |
# so color inheritance must match what `line` rendering would use. |
| 1879 |
def test_inline_fallback_does_not_inherit_list_border_color |
| 1880 |
# Marker attribute (bold) on list-border. If HeaderBorder wrongly inherits |
| 1881 |
# from ListBorder, the header separator characters will carry the bold |
| 1882 |
# attribute. --info=hidden and --no-separator strip other separator lines |
| 1883 |
# so the only row of `─` chars is the header separator. |
| 1884 |
tmux.send_keys %(seq 5 | #{FZF} --list-border=none --header HEADER --header-border=inline --info=hidden --no-separator --color=bg:-1,list-border:red:bold), :Enter |
| 1885 |
sep_row = nil |
| 1886 |
tmux.until do |_| |
| 1887 |
sep_row = tmux.capture_ansi.find do |row| |
| 1888 |
stripped = row.gsub(/\e\[[\d;]*m/, '').rstrip |
| 1889 |
stripped.match?(/\A─+\z/) |
| 1890 |
end |
| 1891 |
!sep_row.nil? |
| 1892 |
end |
| 1893 |
# Bold (1) or red fg (31) on the header separator means it inherited from |
| 1894 |
# list-border even though the effective shape is `line` (non-inline). |
| 1895 |
refute_match(/\e\[(?:[\d;]*;)?(?:1|31)(?:;[\d;]*)?m─/, sep_row, |
| 1896 |
"header separator inherited list-border attr: #{sep_row.inspect}") |
| 1897 |
tmux.send_keys 'Escape' |
| 1898 |
end |
| 1899 |
|
| 1900 |
# Inline takes precedence over --header-first: the main header stays |
| 1901 |
# inside the list frame instead of moving below the input. |
| 1902 |
def test_inline_header_border_overrides_header_first |
| 1903 |
tmux.send_keys %(seq 5 | #{FZF} --style full --header foo --header-first --header-border inline), :Enter |
| 1904 |
tmux.until do |lines| |
| 1905 |
foo_idx = lines.index { |l| l.match?(/\A│\s+foo\s+│\z/) } |
| 1906 |
input_idx = lines.index { |l| l.match?(%r{\A│\s+>\s+\d+/\d+\s+│\z}) } |
| 1907 |
foo_idx && input_idx && foo_idx < input_idx |
| 1908 |
end |
| 1909 |
end |
| 1910 |
|
| 1911 |
# With both sections present, --header-first still moves the main --header |
| 1912 |
# below the input while --header-lines-border=inline keeps header-lines |
| 1913 |
# inside the list frame. |
| 1914 |
def test_inline_header_lines_with_header_first_and_main_header |
| 1915 |
tmux.send_keys %(seq 5 | #{FZF} --style full --header foo --header-lines 1 --header-first --header-lines-border inline), :Enter |
| 1916 |
tmux.until do |lines| |
| 1917 |
one_idx = lines.index { |l| l.match?(/\A│\s+1\s+│\z/) } |
| 1918 |
foo_idx = lines.index { |l| l.match?(/\A│\s+foo\s+│\z/) } |
| 1919 |
input_idx = lines.index { |l| l.match?(%r{\A│\s+>\s+\d+/\d+\s+│\z}) } |
| 1920 |
one_idx && foo_idx && input_idx && one_idx < input_idx && input_idx < foo_idx |
| 1921 |
end |
| 1922 |
end |
| 1923 |
|
| 1924 |
# With no main --header, --header-first previously repositioned |
| 1925 |
# header-lines. Inline now takes precedence: header-lines stays inside |
| 1926 |
# the list frame. |
| 1927 |
def test_inline_header_lines_with_header_first_no_main_header |
| 1928 |
tmux.send_keys %(seq 5 | #{FZF} --style full --header-lines 1 --header-first --header-lines-border inline), :Enter |
| 1929 |
tmux.until do |lines| |
| 1930 |
one_idx = lines.index { |l| l.match?(/\A│\s+1\s+│\z/) } |
| 1931 |
input_idx = lines.index { |l| l.match?(%r{\A│\s+>\s+\d+/\d+\s+│\z}) } |
| 1932 |
one_idx && input_idx && one_idx < input_idx |
| 1933 |
end |
| 1934 |
end |
| 1935 |
|
| 1936 |
# Regression: with --header-border=inline and --header-lines but no |
| 1937 |
# --header, the inline slot was sized for header-lines only. After |
| 1938 |
# change-header added a main header line, resizeIfNeeded tolerated the |
| 1939 |
# too-small slot, so the header-lines line got displaced and disappeared. |
| 1940 |
def test_inline_change_header_grows_slot |
| 1941 |
tmux.send_keys %(seq 5 | #{FZF} --style full --header-lines 1 --header-border inline --bind space:change-header:tada), :Enter |
| 1942 |
tmux.until { |lines| lines.any_include?(/\A│\s+1\s+│\z/) } |
| 1943 |
tmux.send_keys :Space |
| 1944 |
tmux.until do |lines| |
| 1945 |
lines.any_include?(/\A│\s+1\s+│\z/) && lines.any_include?(/\A│\s+tada\s+│\z/) |
| 1946 |
end |
| 1947 |
end |
| 1948 |
|
| 1949 |
# Regression: with --footer-border=inline, change-footer that grows the |
| 1950 |
# footer line count left the inline slot sized for the old length, so |
| 1951 |
# extra lines were clipped. |
| 1952 |
def test_inline_change_footer_grows_slot |
| 1953 |
tmux.send_keys %(seq 5 | #{FZF} --style full --footer-border inline --footer one --bind $'space:change-footer:one\\ntwo'), :Enter |
| 1954 |
tmux.until { |lines| lines.any_include?(/\A│\s+one\s+│\z/) } |
| 1955 |
tmux.send_keys :Space |
| 1956 |
tmux.until do |lines| |
| 1957 |
lines.any_include?(/\A│\s+one\s+│\z/) && lines.any_include?(/\A│\s+two\s+│\z/) |
| 1958 |
end |
| 1959 |
end |
| 1960 |
|
| 1961 |
# Invalid inline combinations must be rejected at startup. |
| 1962 |
def test_inline_rejected_on_unsupported_options |
| 1963 |
[ |
| 1964 |
['--border=inline', 'inline border is only supported'], |
| 1965 |
['--list-border=inline', 'inline border is only supported'], |
| 1966 |
['--input-border=inline', 'inline border is only supported'], |
| 1967 |
['--preview-window=border-inline --preview :', 'invalid preview window option: border-inline'], |
| 1968 |
['--header-border=inline --header-lines-border=sharp --header-lines=1', |
| 1969 |
'--header-border=inline requires --header-lines-border to be inline or unset'] |
| 1970 |
].each do |args, expected| |
| 1971 |
output = `#{FZF} #{args} < /dev/null 2>&1` |
| 1972 |
refute_equal 0, $CHILD_STATUS.exitstatus, "expected non-zero exit for: #{args}" |
| 1973 |
assert_includes output, expected, "wrong error for: #{args}" |
| 1974 |
end |
| 1975 |
end |
| 1976 |
|
| 1977 |
private |
| 1978 |
|
| 1979 |
# Count rows whose entire width is a single `color` range. |
| 1980 |
def count_full_rows(ranges_by_row, color) |
| 1981 |
ranges_by_row.count { |r| r.length == 1 && r[0][2] == color } |
| 1982 |
end |
| 1983 |
|
| 1984 |
# Wait until `tmux.bg_ranges` has at least `count` fully-`color` rows; return them. |
| 1985 |
def wait_for_full_rows(color, count) |
| 1986 |
ranges = nil |
| 1987 |
tmux.until do |_| |
| 1988 |
ranges = tmux.bg_ranges |
| 1989 |
count_full_rows(ranges, color) >= count |
| 1990 |
end |
| 1991 |
ranges |
| 1992 |
end |
| 1993 |
|
| 1994 |
public |
| 1995 |
|
| 1996 |
# Inline header's entire section (outer edge + content-row verticals + separator) |
| 1997 |
# carries the header-bg color; list rows below carry list-bg. |
| 1998 |
def test_inline_header_bg_color |
| 1999 |
tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header HEADER --header-border=inline --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green), :Enter |
| 2000 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 2001 |
# 3 fully-red rows: top edge, header content, separator. |
| 2002 |
ranges = wait_for_full_rows('red', 3) |
| 2003 |
assert_equal_org(3, count_full_rows(ranges, 'red')) |
| 2004 |
# List rows below (>=5) are fully green. |
| 2005 |
assert_operator count_full_rows(ranges, 'green'), :>=, 5 |
| 2006 |
tmux.send_keys 'Escape' |
| 2007 |
end |
| 2008 |
|
| 2009 |
# Regression: when --header-lines-border=inline is the only inline section |
| 2010 |
# (no --header-border), the section must still use header-bg, not list-bg. |
| 2011 |
def test_inline_header_lines_bg_without_main_header |
| 2012 |
tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header-lines 2 --header-lines-border=inline --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green), :Enter |
| 2013 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 2014 |
# Top edge + 2 content rows + separator = 4 fully-red rows. |
| 2015 |
ranges = wait_for_full_rows('red', 4) |
| 2016 |
assert_equal_org(4, count_full_rows(ranges, 'red')) |
| 2017 |
tmux.send_keys 'Escape' |
| 2018 |
end |
| 2019 |
|
| 2020 |
# Inline footer's entire section carries footer-bg; list rows above carry list-bg. |
| 2021 |
def test_inline_footer_bg_color |
| 2022 |
tmux.send_keys %(seq 5 | #{FZF} --list-border --footer FOOTER --footer-border=inline --color=bg:-1,footer-border:white,list-border:white,footer-bg:blue,list-bg:green), :Enter |
| 2023 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 2024 |
ranges = wait_for_full_rows('blue', 3) |
| 2025 |
assert_equal_org(3, count_full_rows(ranges, 'blue')) |
| 2026 |
tmux.send_keys 'Escape' |
| 2027 |
end |
| 2028 |
|
| 2029 |
# The list-label's bg is swapped to match the adjacent inline section so it reads as |
| 2030 |
# part of the section frame rather than a list-colored island on a section-colored edge. |
| 2031 |
def test_list_label_bg_on_inline_section_edge |
| 2032 |
tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header HEADER --header-border=inline --list-label=LL --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green,list-label:yellow:bold), :Enter |
| 2033 |
tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) } |
| 2034 |
# The label sits on the header-owned top edge, so the entire row must be a |
| 2035 |
# single red run (no green breaks where the label cells are). |
| 2036 |
ranges = wait_for_full_rows('red', 3) |
| 2037 |
assert_operator count_full_rows(ranges, 'red'), :>=, 3 |
| 2038 |
tmux.send_keys 'Escape' |
| 2039 |
end |
| 2040 |
end |