summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2017-10-07 21:32:15 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2017-10-07 21:32:42 -0700
commitca1fb61f4894580e2ceef9cd0394137826aa0173 (patch)
treed3c4eb7ebda5cd29e0ebc39dc54dddca30ae1453
parent99fb33f60e7ae4cfdb7a887f9b1596b291643fbf (diff)
Add acceptance test for moving text cursor
-rw-r--r--test/acceptance/acceptance_test.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb
index 53090ff..4a11cac 100644
--- a/test/acceptance/acceptance_test.rb
+++ b/test/acceptance/acceptance_test.rb
@@ -5,12 +5,6 @@ require 'ttytest'
class FzyTest < Minitest::Test
FZY_PATH = File.expand_path('../../../fzy', __FILE__)
- def setup
- # fzy is fast.
- # This is never hit in a (passing) test suite, but helps speed up development
- TTYtest.default_max_wait_time = 0.2
- end
-
def test_empty_list
@tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
@tty.assert_cursor_position(y: 1, x: 2)
@@ -288,6 +282,34 @@ class FzyTest < Minitest::Test
@tty.assert_matches "before\nfoo\nafter"
end
+ def test_moving_text_cursor
+ @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}; echo after})
+ @tty.send_keys("br")
+ @tty.assert_matches "> br\nbar"
+ @tty.assert_cursor_position(y: 0, x: 4)
+
+ @tty.send_keys("\e[D") # left
+ @tty.assert_cursor_position(y: 0, x: 3)
+ @tty.assert_matches "> br\nbar"
+ @tty.send_keys("a")
+ @tty.assert_cursor_position(y: 0, x: 4)
+ @tty.assert_matches "> bar\nbar"
+
+ @tty.send_keys(ctrl("A")) # Ctrl-A
+ @tty.assert_cursor_position(y: 0, x: 2)
+ @tty.assert_matches "> bar\nbar"
+ @tty.send_keys("foo")
+ @tty.assert_cursor_position(y: 0, x: 5)
+ @tty.assert_matches "> foobar"
+
+ @tty.send_keys(ctrl("E")) # Ctrl-E
+ @tty.assert_cursor_position(y: 0, x: 8)
+ @tty.assert_matches "> foobar"
+ @tty.send_keys("baz") # Ctrl-E
+ @tty.assert_cursor_position(y: 0, x: 11)
+ @tty.assert_matches "> foobarbaz"
+ end
+
# More info;
# https://github.com/jhawthorn/fzy/issues/42
# https://cirw.in/blog/bracketed-paste