Browse code

Add acceptance test for moving text cursor

John Hawthorn authored on 08/10/2017 04:32:15
Showing 1 changed files

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