summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2018-09-09 13:08:46 -0700
committerJohn Hawthorn <john@hawthorn.email>2018-09-09 13:08:46 -0700
commit03ccaaf3392712370274df5d39ec9cfad9ef39c2 (patch)
treeff7491e9f95e7c715a92381e3fca2932ab4a749e
parent244912dd26cd42f44fa0425b0bc15ff442805d38 (diff)
Add acceptance tests for unicode chars
-rw-r--r--test/acceptance/acceptance_test.rb102
1 files changed, 101 insertions, 1 deletions
diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb
index 6440b75..6123b2d 100644
--- a/test/acceptance/acceptance_test.rb
+++ b/test/acceptance/acceptance_test.rb
@@ -5,6 +5,9 @@ require 'ttytest'
class FzyTest < Minitest::Test
FZY_PATH = File.expand_path('../../../fzy', __FILE__)
+ LEFT = "\e[D"
+ RIGHT = "\e[C"
+
def test_empty_list
@tty = interactive_fzy(input: %w[], before: "placeholder")
@tty.assert_cursor_position(y: 1, x: 2)
@@ -291,7 +294,7 @@ class FzyTest < Minitest::Test
@tty.assert_matches "> br\nbar"
@tty.assert_cursor_position(y: 0, x: 4)
- @tty.send_keys("\e[D") # left
+ @tty.send_keys(LEFT)
@tty.assert_cursor_position(y: 0, x: 3)
@tty.assert_matches "> br\nbar"
@tty.send_keys("a")
@@ -330,6 +333,103 @@ class FzyTest < Minitest::Test
@tty.assert_matches "bc"
end
+ def test_unicode
+ @tty = interactive_fzy(input: %w[English Français 日本語])
+ @tty.assert_matches <<~TTY
+ >
+ English
+ Français
+ 日本語
+ TTY
+ @tty.assert_cursor_position(y: 0, x: 2)
+
+ @tty.send_keys("ç")
+ @tty.assert_matches <<~TTY
+ > ç
+ Français
+ TTY
+ @tty.assert_cursor_position(y: 0, x: 3)
+
+ @tty.send_keys("\r")
+ @tty.assert_matches "Français"
+ end
+
+ def test_unicode_backspace
+ @tty = interactive_fzy
+ @tty.send_keys "Français"
+ @tty.assert_matches "> Français"
+ @tty.assert_cursor_position(y: 0, x: 10)
+
+ @tty.send_keys(ctrl('H') * 3)
+ @tty.assert_matches "> Franç"
+ @tty.assert_cursor_position(y: 0, x: 7)
+
+ @tty.send_keys(ctrl('H'))
+ @tty.assert_matches "> Fran"
+ @tty.assert_cursor_position(y: 0, x: 6)
+
+ @tty.send_keys('ce')
+ @tty.assert_matches "> France"
+
+ @tty = interactive_fzy
+ @tty.send_keys "日本語"
+ @tty.assert_matches "> 日本語"
+ @tty.send_keys(ctrl('H'))
+ @tty.assert_matches "> 日本"
+ @tty.send_keys(ctrl('H'))
+ @tty.assert_matches "> 日"
+ @tty.send_keys(ctrl('H'))
+ @tty.assert_matches "> "
+ @tty.assert_cursor_position(y: 0, x: 2)
+ end
+
+ def test_unicode_delete_word
+ @tty = interactive_fzy
+ @tty.send_keys "Je parle Français"
+ @tty.assert_matches "> Je parle Français"
+ @tty.assert_cursor_position(y: 0, x: 19)
+
+ @tty.send_keys(ctrl('W'))
+ @tty.assert_matches "> Je parle"
+ @tty.assert_cursor_position(y: 0, x: 11)
+
+ @tty = interactive_fzy
+ @tty.send_keys "日本語"
+ @tty.assert_matches "> 日本語"
+ @tty.send_keys(ctrl('W'))
+ @tty.assert_matches "> "
+ @tty.assert_cursor_position(y: 0, x: 2)
+ end
+
+ def test_unicode_cursor_movement
+ @tty = interactive_fzy
+ @tty.send_keys "Français"
+ @tty.assert_cursor_position(y: 0, x: 10)
+
+ @tty.send_keys(LEFT*5)
+ @tty.assert_cursor_position(y: 0, x: 5)
+
+ @tty.send_keys(RIGHT*3)
+ @tty.assert_cursor_position(y: 0, x: 8)
+
+ @tty = interactive_fzy
+ @tty.send_keys "日本語"
+ @tty.assert_matches "> 日本語"
+ @tty.assert_cursor_position(y: 0, x: 8)
+ @tty.send_keys(LEFT)
+ @tty.assert_cursor_position(y: 0, x: 6)
+ @tty.send_keys(LEFT)
+ @tty.assert_cursor_position(y: 0, x: 4)
+ @tty.send_keys(LEFT)
+ @tty.assert_cursor_position(y: 0, x: 2)
+ @tty.send_keys(LEFT)
+ @tty.assert_cursor_position(y: 0, x: 2)
+ @tty.send_keys(RIGHT*3)
+ @tty.assert_cursor_position(y: 0, x: 8)
+ @tty.send_keys(RIGHT)
+ @tty.assert_cursor_position(y: 0, x: 8)
+ end
+
def test_help
@tty = TTYtest.new_terminal(%{#{FZY_PATH} --help})
@tty.assert_matches <<TTY