| ... | ... |
@@ -447,6 +447,15 @@ class FzyTest < Minitest::Test |
| 447 | 447 |
TTY |
| 448 | 448 |
end |
| 449 | 449 |
|
| 450 |
+ def test_show_info |
|
| 451 |
+ @tty = interactive_fzy(input: %w[foo bar baz], args: "-i") |
|
| 452 |
+ @tty.assert_matches ">\n[3/3]\nfoo\nbar\nbaz" |
|
| 453 |
+ @tty.send_keys("ba")
|
|
| 454 |
+ @tty.assert_matches "> ba\n[2/3]\nbar\nbaz" |
|
| 455 |
+ @tty.send_keys("q")
|
|
| 456 |
+ @tty.assert_matches "> baq\n[0/3]" |
|
| 457 |
+ end |
|
| 458 |
+ |
|
| 450 | 459 |
def test_help |
| 451 | 460 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 452 | 461 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -1,3 +1,4 @@ |
| 1 |
+# coding: utf-8 |
|
| 1 | 2 |
require 'minitest' |
| 2 | 3 |
require 'minitest/autorun' |
| 3 | 4 |
require 'ttytest' |
| ... | ... |
@@ -458,6 +459,7 @@ Usage: fzy [OPTION]... |
| 458 | 459 |
-s, --show-scores Show the scores of each match |
| 459 | 460 |
-0, --read-null Read input delimited by ASCII NUL characters |
| 460 | 461 |
-j, --workers NUM Use NUM workers for searching. (default is # of CPUs) |
| 462 |
+ -i, --show-info Show selection info line |
|
| 461 | 463 |
-h, --help Display this help and exit |
| 462 | 464 |
-v, --version Output version information and exit |
| 463 | 465 |
TTY |
Update tty to print newline as space
Add tty_putc
| ... | ... |
@@ -456,6 +456,7 @@ Usage: fzy [OPTION]... |
| 456 | 456 |
-e, --show-matches=QUERY Output the sorted matches of QUERY |
| 457 | 457 |
-t, --tty=TTY Specify file to use as TTY device (default /dev/tty) |
| 458 | 458 |
-s, --show-scores Show the scores of each match |
| 459 |
+ -0, --read-null Read input delimited by ASCII NUL characters |
|
| 459 | 460 |
-j, --workers NUM Use NUM workers for searching. (default is # of CPUs) |
| 460 | 461 |
-h, --help Display this help and exit |
| 461 | 462 |
-v, --version Output version information and exit |
| ... | ... |
@@ -328,7 +328,11 @@ class FzyTest < Minitest::Test |
| 328 | 328 |
|
| 329 | 329 |
# https://github.com/jhawthorn/fzy/issues/81 |
| 330 | 330 |
def test_slow_stdin_fast_user |
| 331 |
- @tty = TTYtest.new_terminal(%{(echo aa; echo bc; echo bd; sleep 0.5) | #{FZY_PATH}})
|
|
| 331 |
+ @tty = TTYtest.new_terminal(%{(sleep 0.5; echo aa; echo bc; echo bd) | #{FZY_PATH}})
|
|
| 332 |
+ |
|
| 333 |
+ # Before input has all come in, but wait for fzy to at least start |
|
| 334 |
+ sleep 0.1 |
|
| 335 |
+ |
|
| 332 | 336 |
@tty.send_keys("b\r")
|
| 333 | 337 |
@tty.assert_matches "bc" |
| 334 | 338 |
end |
| ... | ... |
@@ -463,7 +467,7 @@ TTY |
| 463 | 467 |
def interactive_fzy(input: [], before: nil, after: nil, args: "") |
| 464 | 468 |
cmd = [] |
| 465 | 469 |
cmd << %{echo "#{before}"} if before
|
| 466 |
- cmd << %{echo -n "#{input.join("\\n")}" | #{FZY_PATH} #{args}}
|
|
| 470 |
+ cmd << %{printf "#{input.join("\\n")}" | #{FZY_PATH} #{args}}
|
|
| 467 | 471 |
cmd << %{echo "#{after}"} if after
|
| 468 | 472 |
cmd = cmd.join("; ")
|
| 469 | 473 |
TTYtest.new_terminal(cmd) |
This solves the line wrapping issue with much simpler code, which also
works better with Unicode characters and when the terminal is resized.
| ... | ... |
@@ -430,6 +430,18 @@ class FzyTest < Minitest::Test |
| 430 | 430 |
@tty.assert_cursor_position(y: 0, x: 8) |
| 431 | 431 |
end |
| 432 | 432 |
|
| 433 |
+ def test_long_strings |
|
| 434 |
+ ascii = "LongStringOfText" * 6 |
|
| 435 |
+ unicode = "LongStringOfText" * 3 |
|
| 436 |
+ |
|
| 437 |
+ @tty = interactive_fzy(input: [ascii, unicode]) |
|
| 438 |
+ @tty.assert_matches <<~TTY |
|
| 439 |
+ > |
|
| 440 |
+ LongStringOfTextLongStringOfTextLongStringOfTextLongStringOfTextLongStringOfText |
|
| 441 |
+ LongStringOfTextLongStringOfTextLongStri |
|
| 442 |
+ TTY |
|
| 443 |
+ end |
|
| 444 |
+ |
|
| 433 | 445 |
def test_help |
| 434 | 446 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 435 | 447 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -5,6 +5,9 @@ require 'ttytest' |
| 5 | 5 |
class FzyTest < Minitest::Test |
| 6 | 6 |
FZY_PATH = File.expand_path('../../../fzy', __FILE__)
|
| 7 | 7 |
|
| 8 |
+ LEFT = "\e[D" |
|
| 9 |
+ RIGHT = "\e[C" |
|
| 10 |
+ |
|
| 8 | 11 |
def test_empty_list |
| 9 | 12 |
@tty = interactive_fzy(input: %w[], before: "placeholder") |
| 10 | 13 |
@tty.assert_cursor_position(y: 1, x: 2) |
| ... | ... |
@@ -291,7 +294,7 @@ class FzyTest < Minitest::Test |
| 291 | 294 |
@tty.assert_matches "> br\nbar" |
| 292 | 295 |
@tty.assert_cursor_position(y: 0, x: 4) |
| 293 | 296 |
|
| 294 |
- @tty.send_keys("\e[D") # left
|
|
| 297 |
+ @tty.send_keys(LEFT) |
|
| 295 | 298 |
@tty.assert_cursor_position(y: 0, x: 3) |
| 296 | 299 |
@tty.assert_matches "> br\nbar" |
| 297 | 300 |
@tty.send_keys("a")
|
| ... | ... |
@@ -330,6 +333,103 @@ class FzyTest < Minitest::Test |
| 330 | 333 |
@tty.assert_matches "bc" |
| 331 | 334 |
end |
| 332 | 335 |
|
| 336 |
+ def test_unicode |
|
| 337 |
+ @tty = interactive_fzy(input: %w[English Français 日本語]) |
|
| 338 |
+ @tty.assert_matches <<~TTY |
|
| 339 |
+ > |
|
| 340 |
+ English |
|
| 341 |
+ Français |
|
| 342 |
+ 日本語 |
|
| 343 |
+ TTY |
|
| 344 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 345 |
+ |
|
| 346 |
+ @tty.send_keys("ç")
|
|
| 347 |
+ @tty.assert_matches <<~TTY |
|
| 348 |
+ > ç |
|
| 349 |
+ Français |
|
| 350 |
+ TTY |
|
| 351 |
+ @tty.assert_cursor_position(y: 0, x: 3) |
|
| 352 |
+ |
|
| 353 |
+ @tty.send_keys("\r")
|
|
| 354 |
+ @tty.assert_matches "Français" |
|
| 355 |
+ end |
|
| 356 |
+ |
|
| 357 |
+ def test_unicode_backspace |
|
| 358 |
+ @tty = interactive_fzy |
|
| 359 |
+ @tty.send_keys "Français" |
|
| 360 |
+ @tty.assert_matches "> Français" |
|
| 361 |
+ @tty.assert_cursor_position(y: 0, x: 10) |
|
| 362 |
+ |
|
| 363 |
+ @tty.send_keys(ctrl('H') * 3)
|
|
| 364 |
+ @tty.assert_matches "> Franç" |
|
| 365 |
+ @tty.assert_cursor_position(y: 0, x: 7) |
|
| 366 |
+ |
|
| 367 |
+ @tty.send_keys(ctrl('H'))
|
|
| 368 |
+ @tty.assert_matches "> Fran" |
|
| 369 |
+ @tty.assert_cursor_position(y: 0, x: 6) |
|
| 370 |
+ |
|
| 371 |
+ @tty.send_keys('ce')
|
|
| 372 |
+ @tty.assert_matches "> France" |
|
| 373 |
+ |
|
| 374 |
+ @tty = interactive_fzy |
|
| 375 |
+ @tty.send_keys "日本語" |
|
| 376 |
+ @tty.assert_matches "> 日本語" |
|
| 377 |
+ @tty.send_keys(ctrl('H'))
|
|
| 378 |
+ @tty.assert_matches "> 日本" |
|
| 379 |
+ @tty.send_keys(ctrl('H'))
|
|
| 380 |
+ @tty.assert_matches "> 日" |
|
| 381 |
+ @tty.send_keys(ctrl('H'))
|
|
| 382 |
+ @tty.assert_matches "> " |
|
| 383 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 384 |
+ end |
|
| 385 |
+ |
|
| 386 |
+ def test_unicode_delete_word |
|
| 387 |
+ @tty = interactive_fzy |
|
| 388 |
+ @tty.send_keys "Je parle Français" |
|
| 389 |
+ @tty.assert_matches "> Je parle Français" |
|
| 390 |
+ @tty.assert_cursor_position(y: 0, x: 19) |
|
| 391 |
+ |
|
| 392 |
+ @tty.send_keys(ctrl('W'))
|
|
| 393 |
+ @tty.assert_matches "> Je parle" |
|
| 394 |
+ @tty.assert_cursor_position(y: 0, x: 11) |
|
| 395 |
+ |
|
| 396 |
+ @tty = interactive_fzy |
|
| 397 |
+ @tty.send_keys "日本語" |
|
| 398 |
+ @tty.assert_matches "> 日本語" |
|
| 399 |
+ @tty.send_keys(ctrl('W'))
|
|
| 400 |
+ @tty.assert_matches "> " |
|
| 401 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 402 |
+ end |
|
| 403 |
+ |
|
| 404 |
+ def test_unicode_cursor_movement |
|
| 405 |
+ @tty = interactive_fzy |
|
| 406 |
+ @tty.send_keys "Français" |
|
| 407 |
+ @tty.assert_cursor_position(y: 0, x: 10) |
|
| 408 |
+ |
|
| 409 |
+ @tty.send_keys(LEFT*5) |
|
| 410 |
+ @tty.assert_cursor_position(y: 0, x: 5) |
|
| 411 |
+ |
|
| 412 |
+ @tty.send_keys(RIGHT*3) |
|
| 413 |
+ @tty.assert_cursor_position(y: 0, x: 8) |
|
| 414 |
+ |
|
| 415 |
+ @tty = interactive_fzy |
|
| 416 |
+ @tty.send_keys "日本語" |
|
| 417 |
+ @tty.assert_matches "> 日本語" |
|
| 418 |
+ @tty.assert_cursor_position(y: 0, x: 8) |
|
| 419 |
+ @tty.send_keys(LEFT) |
|
| 420 |
+ @tty.assert_cursor_position(y: 0, x: 6) |
|
| 421 |
+ @tty.send_keys(LEFT) |
|
| 422 |
+ @tty.assert_cursor_position(y: 0, x: 4) |
|
| 423 |
+ @tty.send_keys(LEFT) |
|
| 424 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 425 |
+ @tty.send_keys(LEFT) |
|
| 426 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 427 |
+ @tty.send_keys(RIGHT*3) |
|
| 428 |
+ @tty.assert_cursor_position(y: 0, x: 8) |
|
| 429 |
+ @tty.send_keys(RIGHT) |
|
| 430 |
+ @tty.assert_cursor_position(y: 0, x: 8) |
|
| 431 |
+ end |
|
| 432 |
+ |
|
| 333 | 433 |
def test_help |
| 334 | 434 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 335 | 435 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -6,7 +6,7 @@ class FzyTest < Minitest::Test |
| 6 | 6 |
FZY_PATH = File.expand_path('../../../fzy', __FILE__)
|
| 7 | 7 |
|
| 8 | 8 |
def test_empty_list |
| 9 |
- @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
|
|
| 9 |
+ @tty = interactive_fzy(input: %w[], before: "placeholder") |
|
| 10 | 10 |
@tty.assert_cursor_position(y: 1, x: 2) |
| 11 | 11 |
@tty.assert_matches <<~TTY |
| 12 | 12 |
placeholder |
| ... | ... |
@@ -36,7 +36,7 @@ class FzyTest < Minitest::Test |
| 36 | 36 |
end |
| 37 | 37 |
|
| 38 | 38 |
def test_one_item |
| 39 |
- @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
|
|
| 39 |
+ @tty = interactive_fzy(input: %w[test], before: "placeholder") |
|
| 40 | 40 |
@tty.assert_matches <<~TTY |
| 41 | 41 |
placeholder |
| 42 | 42 |
> |
| ... | ... |
@@ -68,7 +68,7 @@ class FzyTest < Minitest::Test |
| 68 | 68 |
end |
| 69 | 69 |
|
| 70 | 70 |
def test_two_items |
| 71 |
- @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
|
|
| 71 |
+ @tty = interactive_fzy(input: %w[test foo], before: "placeholder") |
|
| 72 | 72 |
@tty.assert_cursor_position(y: 1, x: 2) |
| 73 | 73 |
@tty.assert_matches <<~TTY |
| 74 | 74 |
placeholder |
| ... | ... |
@@ -105,7 +105,7 @@ class FzyTest < Minitest::Test |
| 105 | 105 |
end |
| 106 | 106 |
|
| 107 | 107 |
def test_editing |
| 108 |
- @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
|
|
| 108 |
+ @tty = interactive_fzy(input: %w[test foo], before: "placeholder") |
|
| 109 | 109 |
@tty.assert_cursor_position(y: 1, x: 2) |
| 110 | 110 |
@tty.assert_matches <<~TTY |
| 111 | 111 |
placeholder |
| ... | ... |
@@ -146,7 +146,7 @@ class FzyTest < Minitest::Test |
| 146 | 146 |
end |
| 147 | 147 |
|
| 148 | 148 |
def test_ctrl_d |
| 149 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 149 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 150 | 150 |
@tty.assert_matches ">\nfoo\nbar" |
| 151 | 151 |
|
| 152 | 152 |
@tty.send_keys('foo')
|
| ... | ... |
@@ -158,7 +158,7 @@ class FzyTest < Minitest::Test |
| 158 | 158 |
end |
| 159 | 159 |
|
| 160 | 160 |
def test_ctrl_c |
| 161 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 161 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 162 | 162 |
@tty.assert_matches ">\nfoo\nbar" |
| 163 | 163 |
|
| 164 | 164 |
@tty.send_keys('foo')
|
| ... | ... |
@@ -170,25 +170,25 @@ class FzyTest < Minitest::Test |
| 170 | 170 |
end |
| 171 | 171 |
|
| 172 | 172 |
def test_down_arrow |
| 173 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 173 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 174 | 174 |
@tty.assert_matches ">\nfoo\nbar" |
| 175 | 175 |
@tty.send_keys("\e[A\r")
|
| 176 | 176 |
@tty.assert_matches "bar" |
| 177 | 177 |
|
| 178 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 178 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 179 | 179 |
@tty.assert_matches ">\nfoo\nbar" |
| 180 | 180 |
@tty.send_keys("\eOA\r")
|
| 181 | 181 |
@tty.assert_matches "bar" |
| 182 | 182 |
end |
| 183 | 183 |
|
| 184 | 184 |
def test_up_arrow |
| 185 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 185 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 186 | 186 |
@tty.assert_matches ">\nfoo\nbar" |
| 187 | 187 |
@tty.send_keys("\e[A") # first down
|
| 188 | 188 |
@tty.send_keys("\e[B\r") # and back up
|
| 189 | 189 |
@tty.assert_matches "foo" |
| 190 | 190 |
|
| 191 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 191 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 192 | 192 |
@tty.assert_matches ">\nfoo\nbar" |
| 193 | 193 |
@tty.send_keys("\eOA") # first down
|
| 194 | 194 |
@tty.send_keys("\e[B\r") # and back up
|
| ... | ... |
@@ -196,45 +196,48 @@ class FzyTest < Minitest::Test |
| 196 | 196 |
end |
| 197 | 197 |
|
| 198 | 198 |
def test_lines |
| 199 |
- @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH}})
|
|
| 199 |
+ input10 = (1..10).map(&:to_s) |
|
| 200 |
+ input20 = (1..20).map(&:to_s) |
|
| 201 |
+ |
|
| 202 |
+ @tty = interactive_fzy(input: input10) |
|
| 200 | 203 |
@tty.assert_matches ">\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10" |
| 201 | 204 |
|
| 202 |
- @tty = TTYtest.new_terminal(%{seq 20 | #{FZY_PATH}})
|
|
| 205 |
+ @tty = interactive_fzy(input: input20) |
|
| 203 | 206 |
@tty.assert_matches ">\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10" |
| 204 | 207 |
|
| 205 |
- @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH} -l 5})
|
|
| 208 |
+ @tty = interactive_fzy(input: input10, args: "-l 5") |
|
| 206 | 209 |
@tty.assert_matches ">\n1\n2\n3\n4\n5" |
| 207 | 210 |
|
| 208 |
- @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH} --lines=5})
|
|
| 211 |
+ @tty = interactive_fzy(input: input10, args: "--lines=5") |
|
| 209 | 212 |
@tty.assert_matches ">\n1\n2\n3\n4\n5" |
| 210 | 213 |
end |
| 211 | 214 |
|
| 212 | 215 |
def test_prompt |
| 213 |
- @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH}})
|
|
| 216 |
+ @tty = interactive_fzy |
|
| 214 | 217 |
@tty.send_keys("foo")
|
| 215 | 218 |
@tty.assert_matches '> foo' |
| 216 | 219 |
|
| 217 |
- @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH} -p 'C:\\'})
|
|
| 220 |
+ @tty = interactive_fzy(args: "-p 'C:\\'") |
|
| 218 | 221 |
@tty.send_keys("foo")
|
| 219 | 222 |
@tty.assert_matches 'C:\foo' |
| 220 | 223 |
|
| 221 |
- @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH} --prompt="foo bar "})
|
|
| 224 |
+ @tty = interactive_fzy(args: "--prompt=\"foo bar \"") |
|
| 222 | 225 |
@tty.send_keys("baz")
|
| 223 | 226 |
@tty.assert_matches "foo bar baz" |
| 224 | 227 |
end |
| 225 | 228 |
|
| 226 | 229 |
def test_show_scores |
| 227 | 230 |
expected_score = '( inf)' |
| 228 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -s})
|
|
| 231 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-s") |
|
| 229 | 232 |
@tty.send_keys('foo')
|
| 230 | 233 |
@tty.assert_matches "> foo\n#{expected_score} foo"
|
| 231 | 234 |
|
| 232 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} --show-scores})
|
|
| 235 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "--show-scores") |
|
| 233 | 236 |
@tty.send_keys('foo')
|
| 234 | 237 |
@tty.assert_matches "> foo\n#{expected_score} foo"
|
| 235 | 238 |
|
| 236 | 239 |
expected_score = '( 0.89)' |
| 237 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -s})
|
|
| 240 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-s") |
|
| 238 | 241 |
@tty.send_keys('f')
|
| 239 | 242 |
@tty.assert_matches "> f\n#{expected_score} foo"
|
| 240 | 243 |
end |
| ... | ... |
@@ -252,7 +255,7 @@ class FzyTest < Minitest::Test |
| 252 | 255 |
end |
| 253 | 256 |
|
| 254 | 257 |
def test_worker_count |
| 255 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -j1})
|
|
| 258 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-j1") |
|
| 256 | 259 |
@tty.send_keys('foo')
|
| 257 | 260 |
@tty.assert_matches "> foo\nfoo" |
| 258 | 261 |
|
| ... | ... |
@@ -266,24 +269,24 @@ class FzyTest < Minitest::Test |
| 266 | 269 |
end |
| 267 | 270 |
|
| 268 | 271 |
def test_initial_query |
| 269 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -q fo})
|
|
| 272 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-q fo") |
|
| 270 | 273 |
@tty.assert_matches "> fo\nfoo" |
| 271 | 274 |
@tty.send_keys("o")
|
| 272 | 275 |
@tty.assert_matches "> foo\nfoo" |
| 273 | 276 |
@tty.send_keys("o")
|
| 274 | 277 |
@tty.assert_matches "> fooo" |
| 275 | 278 |
|
| 276 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -q asdf})
|
|
| 279 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-q asdf") |
|
| 277 | 280 |
@tty.assert_matches "> asdf" |
| 278 | 281 |
end |
| 279 | 282 |
|
| 280 | 283 |
def test_non_interactive |
| 281 |
- @tty = TTYtest.new_terminal(%{echo before; echo -n "foo\nbar" | #{FZY_PATH} -e foo; echo after})
|
|
| 284 |
+ @tty = interactive_fzy(input: %w[foo bar], args: "-e foo", before: "before", after: "after") |
|
| 282 | 285 |
@tty.assert_matches "before\nfoo\nafter" |
| 283 | 286 |
end |
| 284 | 287 |
|
| 285 | 288 |
def test_moving_text_cursor |
| 286 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}; echo after})
|
|
| 289 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 287 | 290 |
@tty.send_keys("br")
|
| 288 | 291 |
@tty.assert_matches "> br\nbar" |
| 289 | 292 |
@tty.assert_cursor_position(y: 0, x: 4) |
| ... | ... |
@@ -314,7 +317,7 @@ class FzyTest < Minitest::Test |
| 314 | 317 |
# https://github.com/jhawthorn/fzy/issues/42 |
| 315 | 318 |
# https://cirw.in/blog/bracketed-paste |
| 316 | 319 |
def test_bracketed_paste_characters |
| 317 |
- @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 320 |
+ @tty = interactive_fzy(input: %w[foo bar]) |
|
| 318 | 321 |
@tty.assert_matches ">\nfoo\nbar" |
| 319 | 322 |
@tty.send_keys("\e[200~foo\e[201~")
|
| 320 | 323 |
@tty.assert_matches "> foo\nfoo" |
| ... | ... |
@@ -342,4 +345,15 @@ Usage: fzy [OPTION]... |
| 342 | 345 |
-v, --version Output version information and exit |
| 343 | 346 |
TTY |
| 344 | 347 |
end |
| 348 |
+ |
|
| 349 |
+ private |
|
| 350 |
+ |
|
| 351 |
+ def interactive_fzy(input: [], before: nil, after: nil, args: "") |
|
| 352 |
+ cmd = [] |
|
| 353 |
+ cmd << %{echo "#{before}"} if before
|
|
| 354 |
+ cmd << %{echo -n "#{input.join("\\n")}" | #{FZY_PATH} #{args}}
|
|
| 355 |
+ cmd << %{echo "#{after}"} if after
|
|
| 356 |
+ cmd = cmd.join("; ")
|
|
| 357 |
+ TTYtest.new_terminal(cmd) |
|
| 358 |
+ end |
|
| 345 | 359 |
end |
| ... | ... |
@@ -320,6 +320,13 @@ class FzyTest < Minitest::Test |
| 320 | 320 |
@tty.assert_matches "> foo\nfoo" |
| 321 | 321 |
end |
| 322 | 322 |
|
| 323 |
+ # https://github.com/jhawthorn/fzy/issues/81 |
|
| 324 |
+ def test_slow_stdin_fast_user |
|
| 325 |
+ @tty = TTYtest.new_terminal(%{(echo aa; echo bc; echo bd; sleep 0.5) | #{FZY_PATH}})
|
|
| 326 |
+ @tty.send_keys("b\r")
|
|
| 327 |
+ @tty.assert_matches "bc" |
|
| 328 |
+ end |
|
| 329 |
+ |
|
| 323 | 330 |
def test_help |
| 324 | 331 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 325 | 332 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -5,12 +5,6 @@ require 'ttytest' |
| 5 | 5 |
class FzyTest < Minitest::Test |
| 6 | 6 |
FZY_PATH = File.expand_path('../../../fzy', __FILE__)
|
| 7 | 7 |
|
| 8 |
- def setup |
|
| 9 |
- # fzy is fast. |
|
| 10 |
- # This is never hit in a (passing) test suite, but helps speed up development |
|
| 11 |
- TTYtest.default_max_wait_time = 0.2 |
|
| 12 |
- end |
|
| 13 |
- |
|
| 14 | 8 |
def test_empty_list |
| 15 | 9 |
@tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
|
| 16 | 10 |
@tty.assert_cursor_position(y: 1, x: 2) |
| ... | ... |
@@ -288,6 +282,34 @@ class FzyTest < Minitest::Test |
| 288 | 282 |
@tty.assert_matches "before\nfoo\nafter" |
| 289 | 283 |
end |
| 290 | 284 |
|
| 285 |
+ def test_moving_text_cursor |
|
| 286 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}; echo after})
|
|
| 287 |
+ @tty.send_keys("br")
|
|
| 288 |
+ @tty.assert_matches "> br\nbar" |
|
| 289 |
+ @tty.assert_cursor_position(y: 0, x: 4) |
|
| 290 |
+ |
|
| 291 |
+ @tty.send_keys("\e[D") # left
|
|
| 292 |
+ @tty.assert_cursor_position(y: 0, x: 3) |
|
| 293 |
+ @tty.assert_matches "> br\nbar" |
|
| 294 |
+ @tty.send_keys("a")
|
|
| 295 |
+ @tty.assert_cursor_position(y: 0, x: 4) |
|
| 296 |
+ @tty.assert_matches "> bar\nbar" |
|
| 297 |
+ |
|
| 298 |
+ @tty.send_keys(ctrl("A")) # Ctrl-A
|
|
| 299 |
+ @tty.assert_cursor_position(y: 0, x: 2) |
|
| 300 |
+ @tty.assert_matches "> bar\nbar" |
|
| 301 |
+ @tty.send_keys("foo")
|
|
| 302 |
+ @tty.assert_cursor_position(y: 0, x: 5) |
|
| 303 |
+ @tty.assert_matches "> foobar" |
|
| 304 |
+ |
|
| 305 |
+ @tty.send_keys(ctrl("E")) # Ctrl-E
|
|
| 306 |
+ @tty.assert_cursor_position(y: 0, x: 8) |
|
| 307 |
+ @tty.assert_matches "> foobar" |
|
| 308 |
+ @tty.send_keys("baz") # Ctrl-E
|
|
| 309 |
+ @tty.assert_cursor_position(y: 0, x: 11) |
|
| 310 |
+ @tty.assert_matches "> foobarbaz" |
|
| 311 |
+ end |
|
| 312 |
+ |
|
| 291 | 313 |
# More info; |
| 292 | 314 |
# https://github.com/jhawthorn/fzy/issues/42 |
| 293 | 315 |
# https://cirw.in/blog/bracketed-paste |
| ... | ... |
@@ -288,6 +288,16 @@ class FzyTest < Minitest::Test |
| 288 | 288 |
@tty.assert_matches "before\nfoo\nafter" |
| 289 | 289 |
end |
| 290 | 290 |
|
| 291 |
+ # More info; |
|
| 292 |
+ # https://github.com/jhawthorn/fzy/issues/42 |
|
| 293 |
+ # https://cirw.in/blog/bracketed-paste |
|
| 294 |
+ def test_bracketed_paste_characters |
|
| 295 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 296 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 297 |
+ @tty.send_keys("\e[200~foo\e[201~")
|
|
| 298 |
+ @tty.assert_matches "> foo\nfoo" |
|
| 299 |
+ end |
|
| 300 |
+ |
|
| 291 | 301 |
def test_help |
| 292 | 302 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 293 | 303 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -283,6 +283,11 @@ class FzyTest < Minitest::Test |
| 283 | 283 |
@tty.assert_matches "> asdf" |
| 284 | 284 |
end |
| 285 | 285 |
|
| 286 |
+ def test_non_interactive |
|
| 287 |
+ @tty = TTYtest.new_terminal(%{echo before; echo -n "foo\nbar" | #{FZY_PATH} -e foo; echo after})
|
|
| 288 |
+ @tty.assert_matches "before\nfoo\nafter" |
|
| 289 |
+ end |
|
| 290 |
+ |
|
| 286 | 291 |
def test_help |
| 287 | 292 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 288 | 293 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -271,6 +271,18 @@ class FzyTest < Minitest::Test |
| 271 | 271 |
@tty.assert_matches "> 34\n34\n340\n341" |
| 272 | 272 |
end |
| 273 | 273 |
|
| 274 |
+ def test_initial_query |
|
| 275 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -q fo})
|
|
| 276 |
+ @tty.assert_matches "> fo\nfoo" |
|
| 277 |
+ @tty.send_keys("o")
|
|
| 278 |
+ @tty.assert_matches "> foo\nfoo" |
|
| 279 |
+ @tty.send_keys("o")
|
|
| 280 |
+ @tty.assert_matches "> fooo" |
|
| 281 |
+ |
|
| 282 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -q asdf})
|
|
| 283 |
+ @tty.assert_matches "> asdf" |
|
| 284 |
+ end |
|
| 285 |
+ |
|
| 274 | 286 |
def test_help |
| 275 | 287 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 276 | 288 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -245,6 +245,32 @@ class FzyTest < Minitest::Test |
| 245 | 245 |
@tty.assert_matches "> f\n#{expected_score} foo"
|
| 246 | 246 |
end |
| 247 | 247 |
|
| 248 |
+ def test_large_input |
|
| 249 |
+ @tty = TTYtest.new_terminal(%{seq 100000 | #{FZY_PATH} -l 3})
|
|
| 250 |
+ @tty.send_keys('34')
|
|
| 251 |
+ @tty.assert_matches "> 34\n34\n340\n341" |
|
| 252 |
+ |
|
| 253 |
+ @tty.send_keys('5')
|
|
| 254 |
+ @tty.assert_matches "> 345\n345\n3450\n3451" |
|
| 255 |
+ |
|
| 256 |
+ @tty.send_keys('z')
|
|
| 257 |
+ @tty.assert_matches "> 345z" |
|
| 258 |
+ end |
|
| 259 |
+ |
|
| 260 |
+ def test_worker_count |
|
| 261 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -j1})
|
|
| 262 |
+ @tty.send_keys('foo')
|
|
| 263 |
+ @tty.assert_matches "> foo\nfoo" |
|
| 264 |
+ |
|
| 265 |
+ @tty = TTYtest.new_terminal(%{seq 100000 | #{FZY_PATH} -j1 -l3})
|
|
| 266 |
+ @tty.send_keys('34')
|
|
| 267 |
+ @tty.assert_matches "> 34\n34\n340\n341" |
|
| 268 |
+ |
|
| 269 |
+ @tty = TTYtest.new_terminal(%{seq 100000 | #{FZY_PATH} -j200 -l3})
|
|
| 270 |
+ @tty.send_keys('34')
|
|
| 271 |
+ @tty.assert_matches "> 34\n34\n340\n341" |
|
| 272 |
+ end |
|
| 273 |
+ |
|
| 248 | 274 |
def test_help |
| 249 | 275 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 250 | 276 |
@tty.assert_matches <<TTY |
| ... | ... |
@@ -229,6 +229,22 @@ class FzyTest < Minitest::Test |
| 229 | 229 |
@tty.assert_matches "foo bar baz" |
| 230 | 230 |
end |
| 231 | 231 |
|
| 232 |
+ def test_show_scores |
|
| 233 |
+ expected_score = '( inf)' |
|
| 234 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -s})
|
|
| 235 |
+ @tty.send_keys('foo')
|
|
| 236 |
+ @tty.assert_matches "> foo\n#{expected_score} foo"
|
|
| 237 |
+ |
|
| 238 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} --show-scores})
|
|
| 239 |
+ @tty.send_keys('foo')
|
|
| 240 |
+ @tty.assert_matches "> foo\n#{expected_score} foo"
|
|
| 241 |
+ |
|
| 242 |
+ expected_score = '( 0.89)' |
|
| 243 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH} -s})
|
|
| 244 |
+ @tty.send_keys('f')
|
|
| 245 |
+ @tty.assert_matches "> f\n#{expected_score} foo"
|
|
| 246 |
+ end |
|
| 247 |
+ |
|
| 232 | 248 |
def test_help |
| 233 | 249 |
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
| 234 | 250 |
@tty.assert_matches <<TTY |
Also shorten help to fit 80 characters wide terminal.
| ... | ... |
@@ -228,4 +228,20 @@ class FzyTest < Minitest::Test |
| 228 | 228 |
@tty.send_keys("baz")
|
| 229 | 229 |
@tty.assert_matches "foo bar baz" |
| 230 | 230 |
end |
| 231 |
+ |
|
| 232 |
+ def test_help |
|
| 233 |
+ @tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
|
|
| 234 |
+ @tty.assert_matches <<TTY |
|
| 235 |
+Usage: fzy [OPTION]... |
|
| 236 |
+ -l, --lines=LINES Specify how many lines of results to show (default 10) |
|
| 237 |
+ -p, --prompt=PROMPT Input prompt (default '> ') |
|
| 238 |
+ -q, --query=QUERY Use QUERY as the initial search string |
|
| 239 |
+ -e, --show-matches=QUERY Output the sorted matches of QUERY |
|
| 240 |
+ -t, --tty=TTY Specify file to use as TTY device (default /dev/tty) |
|
| 241 |
+ -s, --show-scores Show the scores of each match |
|
| 242 |
+ -j, --workers NUM Use NUM workers for searching. (default is # of CPUs) |
|
| 243 |
+ -h, --help Display this help and exit |
|
| 244 |
+ -v, --version Output version information and exit |
|
| 245 |
+TTY |
|
| 246 |
+ end |
|
| 231 | 247 |
end |
| ... | ... |
@@ -200,4 +200,32 @@ class FzyTest < Minitest::Test |
| 200 | 200 |
@tty.send_keys("\e[B\r") # and back up
|
| 201 | 201 |
@tty.assert_matches "foo" |
| 202 | 202 |
end |
| 203 |
+ |
|
| 204 |
+ def test_lines |
|
| 205 |
+ @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH}})
|
|
| 206 |
+ @tty.assert_matches ">\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10" |
|
| 207 |
+ |
|
| 208 |
+ @tty = TTYtest.new_terminal(%{seq 20 | #{FZY_PATH}})
|
|
| 209 |
+ @tty.assert_matches ">\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10" |
|
| 210 |
+ |
|
| 211 |
+ @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH} -l 5})
|
|
| 212 |
+ @tty.assert_matches ">\n1\n2\n3\n4\n5" |
|
| 213 |
+ |
|
| 214 |
+ @tty = TTYtest.new_terminal(%{seq 10 | #{FZY_PATH} --lines=5})
|
|
| 215 |
+ @tty.assert_matches ">\n1\n2\n3\n4\n5" |
|
| 216 |
+ end |
|
| 217 |
+ |
|
| 218 |
+ def test_prompt |
|
| 219 |
+ @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH}})
|
|
| 220 |
+ @tty.send_keys("foo")
|
|
| 221 |
+ @tty.assert_matches '> foo' |
|
| 222 |
+ |
|
| 223 |
+ @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH} -p 'C:\\'})
|
|
| 224 |
+ @tty.send_keys("foo")
|
|
| 225 |
+ @tty.assert_matches 'C:\foo' |
|
| 226 |
+ |
|
| 227 |
+ @tty = TTYtest.new_terminal(%{echo -n "" | #{FZY_PATH} --prompt="foo bar "})
|
|
| 228 |
+ @tty.send_keys("baz")
|
|
| 229 |
+ @tty.assert_matches "foo bar baz" |
|
| 230 |
+ end |
|
| 203 | 231 |
end |
| ... | ... |
@@ -174,4 +174,30 @@ class FzyTest < Minitest::Test |
| 174 | 174 |
@tty.assert_matches '' |
| 175 | 175 |
@tty.assert_cursor_position(y: 0, x: 0) |
| 176 | 176 |
end |
| 177 |
+ |
|
| 178 |
+ def test_down_arrow |
|
| 179 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 180 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 181 |
+ @tty.send_keys("\e[A\r")
|
|
| 182 |
+ @tty.assert_matches "bar" |
|
| 183 |
+ |
|
| 184 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 185 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 186 |
+ @tty.send_keys("\eOA\r")
|
|
| 187 |
+ @tty.assert_matches "bar" |
|
| 188 |
+ end |
|
| 189 |
+ |
|
| 190 |
+ def test_up_arrow |
|
| 191 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 192 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 193 |
+ @tty.send_keys("\e[A") # first down
|
|
| 194 |
+ @tty.send_keys("\e[B\r") # and back up
|
|
| 195 |
+ @tty.assert_matches "foo" |
|
| 196 |
+ |
|
| 197 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 198 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 199 |
+ @tty.send_keys("\eOA") # first down
|
|
| 200 |
+ @tty.send_keys("\e[B\r") # and back up
|
|
| 201 |
+ @tty.assert_matches "foo" |
|
| 202 |
+ end |
|
| 177 | 203 |
end |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,177 @@ |
| 1 |
+require 'minitest' |
|
| 2 |
+require 'minitest/autorun' |
|
| 3 |
+require 'ttytest' |
|
| 4 |
+ |
|
| 5 |
+class FzyTest < Minitest::Test |
|
| 6 |
+ FZY_PATH = File.expand_path('../../../fzy', __FILE__)
|
|
| 7 |
+ |
|
| 8 |
+ def setup |
|
| 9 |
+ # fzy is fast. |
|
| 10 |
+ # This is never hit in a (passing) test suite, but helps speed up development |
|
| 11 |
+ TTYtest.default_max_wait_time = 0.2 |
|
| 12 |
+ end |
|
| 13 |
+ |
|
| 14 |
+ def test_empty_list |
|
| 15 |
+ @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
|
|
| 16 |
+ @tty.assert_cursor_position(y: 1, x: 2) |
|
| 17 |
+ @tty.assert_matches <<~TTY |
|
| 18 |
+ placeholder |
|
| 19 |
+ > |
|
| 20 |
+ TTY |
|
| 21 |
+ |
|
| 22 |
+ @tty.send_keys('t')
|
|
| 23 |
+ @tty.assert_cursor_position(y: 1, x: 3) |
|
| 24 |
+ @tty.assert_matches <<~TTY |
|
| 25 |
+ placeholder |
|
| 26 |
+ > t |
|
| 27 |
+ TTY |
|
| 28 |
+ |
|
| 29 |
+ @tty.send_keys('z')
|
|
| 30 |
+ @tty.assert_cursor_position(y: 1, x: 4) |
|
| 31 |
+ @tty.assert_matches <<~TTY |
|
| 32 |
+ placeholder |
|
| 33 |
+ > tz |
|
| 34 |
+ TTY |
|
| 35 |
+ |
|
| 36 |
+ @tty.send_keys("\r")
|
|
| 37 |
+ @tty.assert_cursor_position(y: 2, x: 0) |
|
| 38 |
+ @tty.assert_matches <<~TTY |
|
| 39 |
+ placeholder |
|
| 40 |
+ tz |
|
| 41 |
+ TTY |
|
| 42 |
+ end |
|
| 43 |
+ |
|
| 44 |
+ def test_one_item |
|
| 45 |
+ @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
|
|
| 46 |
+ @tty.assert_matches <<~TTY |
|
| 47 |
+ placeholder |
|
| 48 |
+ > |
|
| 49 |
+ test |
|
| 50 |
+ TTY |
|
| 51 |
+ @tty.assert_cursor_position(y: 1, x: 2) |
|
| 52 |
+ |
|
| 53 |
+ @tty.send_keys('t')
|
|
| 54 |
+ @tty.assert_cursor_position(y: 1, x: 3) |
|
| 55 |
+ @tty.assert_matches <<~TTY |
|
| 56 |
+ placeholder |
|
| 57 |
+ > t |
|
| 58 |
+ test |
|
| 59 |
+ TTY |
|
| 60 |
+ |
|
| 61 |
+ @tty.send_keys('z')
|
|
| 62 |
+ @tty.assert_cursor_position(y: 1, x: 4) |
|
| 63 |
+ @tty.assert_matches <<~TTY |
|
| 64 |
+ placeholder |
|
| 65 |
+ > tz |
|
| 66 |
+ TTY |
|
| 67 |
+ |
|
| 68 |
+ @tty.send_keys("\r")
|
|
| 69 |
+ @tty.assert_cursor_position(y: 2, x: 0) |
|
| 70 |
+ @tty.assert_matches <<~TTY |
|
| 71 |
+ placeholder |
|
| 72 |
+ tz |
|
| 73 |
+ TTY |
|
| 74 |
+ end |
|
| 75 |
+ |
|
| 76 |
+ def test_two_items |
|
| 77 |
+ @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
|
|
| 78 |
+ @tty.assert_cursor_position(y: 1, x: 2) |
|
| 79 |
+ @tty.assert_matches <<~TTY |
|
| 80 |
+ placeholder |
|
| 81 |
+ > |
|
| 82 |
+ test |
|
| 83 |
+ foo |
|
| 84 |
+ TTY |
|
| 85 |
+ |
|
| 86 |
+ @tty.send_keys('t')
|
|
| 87 |
+ @tty.assert_cursor_position(y: 1, x: 3) |
|
| 88 |
+ @tty.assert_matches <<~TTY |
|
| 89 |
+ placeholder |
|
| 90 |
+ > t |
|
| 91 |
+ test |
|
| 92 |
+ TTY |
|
| 93 |
+ |
|
| 94 |
+ @tty.send_keys('z')
|
|
| 95 |
+ @tty.assert_cursor_position(y: 1, x: 4) |
|
| 96 |
+ @tty.assert_matches <<~TTY |
|
| 97 |
+ placeholder |
|
| 98 |
+ > tz |
|
| 99 |
+ TTY |
|
| 100 |
+ |
|
| 101 |
+ @tty.send_keys("\r")
|
|
| 102 |
+ @tty.assert_matches <<~TTY |
|
| 103 |
+ placeholder |
|
| 104 |
+ tz |
|
| 105 |
+ TTY |
|
| 106 |
+ @tty.assert_cursor_position(y: 2, x: 0) |
|
| 107 |
+ end |
|
| 108 |
+ |
|
| 109 |
+ def ctrl(key) |
|
| 110 |
+ ((key.upcase.ord) - ('A'.ord) + 1).chr
|
|
| 111 |
+ end |
|
| 112 |
+ |
|
| 113 |
+ def test_editing |
|
| 114 |
+ @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
|
|
| 115 |
+ @tty.assert_cursor_position(y: 1, x: 2) |
|
| 116 |
+ @tty.assert_matches <<~TTY |
|
| 117 |
+ placeholder |
|
| 118 |
+ > |
|
| 119 |
+ test |
|
| 120 |
+ foo |
|
| 121 |
+ TTY |
|
| 122 |
+ |
|
| 123 |
+ @tty.send_keys("foo bar baz")
|
|
| 124 |
+ @tty.assert_cursor_position(y: 1, x: 13) |
|
| 125 |
+ @tty.assert_matches <<~TTY |
|
| 126 |
+ placeholder |
|
| 127 |
+ > foo bar baz |
|
| 128 |
+ TTY |
|
| 129 |
+ |
|
| 130 |
+ @tty.send_keys(ctrl('H'))
|
|
| 131 |
+ @tty.assert_cursor_position(y: 1, x: 12) |
|
| 132 |
+ @tty.assert_matches <<~TTY |
|
| 133 |
+ placeholder |
|
| 134 |
+ > foo bar ba |
|
| 135 |
+ TTY |
|
| 136 |
+ |
|
| 137 |
+ @tty.send_keys(ctrl('W'))
|
|
| 138 |
+ @tty.assert_cursor_position(y: 1, x: 10) |
|
| 139 |
+ @tty.assert_matches <<~TTY |
|
| 140 |
+ placeholder |
|
| 141 |
+ > foo bar |
|
| 142 |
+ TTY |
|
| 143 |
+ |
|
| 144 |
+ @tty.send_keys(ctrl('U'))
|
|
| 145 |
+ @tty.assert_cursor_position(y: 1, x: 2) |
|
| 146 |
+ @tty.assert_matches <<~TTY |
|
| 147 |
+ placeholder |
|
| 148 |
+ > |
|
| 149 |
+ test |
|
| 150 |
+ foo |
|
| 151 |
+ TTY |
|
| 152 |
+ end |
|
| 153 |
+ |
|
| 154 |
+ def test_ctrl_d |
|
| 155 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 156 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 157 |
+ |
|
| 158 |
+ @tty.send_keys('foo')
|
|
| 159 |
+ @tty.assert_matches "> foo\nfoo" |
|
| 160 |
+ |
|
| 161 |
+ @tty.send_keys(ctrl('D'))
|
|
| 162 |
+ @tty.assert_matches '' |
|
| 163 |
+ @tty.assert_cursor_position(y: 0, x: 0) |
|
| 164 |
+ end |
|
| 165 |
+ |
|
| 166 |
+ def test_ctrl_c |
|
| 167 |
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
|
|
| 168 |
+ @tty.assert_matches ">\nfoo\nbar" |
|
| 169 |
+ |
|
| 170 |
+ @tty.send_keys('foo')
|
|
| 171 |
+ @tty.assert_matches "> foo\nfoo" |
|
| 172 |
+ |
|
| 173 |
+ @tty.send_keys(ctrl('C'))
|
|
| 174 |
+ @tty.assert_matches '' |
|
| 175 |
+ @tty.assert_cursor_position(y: 0, x: 0) |
|
| 176 |
+ end |
|
| 177 |
+end |