| ... | ... |
@@ -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 |