aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bind.expect
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-04 13:56:06 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-04 13:56:49 -0800
commit25ad8866c97b242911b1e52298c8cfeed4530097 (patch)
tree8043d99a119ecef9bef288d9c77be9324898af80 /tests/bind.expect
parent1d446b74ffb563ee18c298417b802458aad9ca84 (diff)
parent2646d51a0bb2551e1d53d164cea2a6a15be44b6e (diff)
Merge change for lengthened and configurable escape key timeout
Diffstat (limited to 'tests/bind.expect')
-rw-r--r--tests/bind.expect187
1 files changed, 150 insertions, 37 deletions
diff --git a/tests/bind.expect b/tests/bind.expect
index 8af3ddab..5ad4fc9c 100644
--- a/tests/bind.expect
+++ b/tests/bind.expect
@@ -1,48 +1,134 @@
# vim: set filetype=expect:
-
spawn $fish
-
expect_prompt
-# test switching key bindings
-# this should leave the mode in the appropriate state
+# Fish should start in default-mode (i.e., emacs) bindings. The default escape
+# timeout is 300ms.
+
+# Verify the emacs transpose word (\et) behavior using various delays,
+# including none, after the escape character.
+
+# Start by testing with no delay. This should transpose the words.
+send "echo abc def"
+send "\033t\r"
+expect_prompt -re {\r\ndef abc\r\n} {
+ puts "emacs transpose words, default timeout: no delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: no delay"
+}
+
+# Now test with a delay > 0 and < the escape timeout. This should transpose
+# the words.
+send "echo ghi jkl"
+send "\033"
+sleep 0.200
+send "t\r"
+expect_prompt -re {\r\njkl ghi\r\n} {
+ puts "emacs transpose words, default timeout: short delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: short delay"
+}
+
+# Now test with a delay > the escape timeout. The transposition should not
+# occur and the "t" should become part of the text that is echoed.
+send "echo mno pqr"
+send "\033"
+sleep 0.400
+send "t\r"
+expect_prompt -re {\r\nmno pqrt\r\n} {
+ puts "emacs transpose words, default timeout: long delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: long delay"
+}
-send_line "set -g fish_key_bindings fish_vi_key_bindings"
+# Test vi key bindings.
+# This should leave vi mode in the insert state.
+send "set -g fish_key_bindings fish_vi_key_bindings\r"
expect_prompt
-send_line -h "echo fail\033ddiecho success"
-expect_prompt -re {\r\nsuccess\r\n} {
- puts "success"
-} -nounmatched -re {\r\nfail} {
- puts stderr "fail"
+
+# These vi tests assume the fish_vi_key_bindings default escape timeout of
+# 10ms is in effect; not the 300ms timeout for the default-mode.
+#
+# This test is only present to make the Travis-CI framework succeed
+# consistently. It's not clear why the subsequent tests succeed without this
+# test when executed on a local machine but not in the Travis-CI framework.
+send "echo success: default escape timeout\r"
+expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
+ puts "prime vi mode, default timeout"
} unmatched {
- puts stderr "Couldn't find expected output 'success'"
+ puts stderr "prime vi mode, default timeout"
}
-# try again without the human typing
-send_line -h "echo fail\033ddiecho success"
-expect_prompt -re {\r\nsuccess\r\n} {
- puts "success"
-} -nounmatched -re {\r\nfail} {
- puts stderr "fail"
+
+send "echo fail: default escape timeout"
+send "\033"
+# Delay needed to allow fish to transition to vi "normal" mode.
+sleep 0.020
+send "ddi"
+send "echo success: default escape timeout\r"
+expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
+ puts "vi replace line, default timeout: long delay"
+} unmatched {
+ puts stderr "vi replace line, default timeout: long delay"
+}
+
+# Verify that a human can transpose words using \et (which is an emacs default
+# binding but should be valid while in vi insert or normal mode).
+send "echo abc def"
+send "\033"
+sleep 0.005
+send "t\r"
+expect_prompt -re {\r\ndef abc\r\n} {
+ puts "vi transpose words, default timeout: short delay"
} unmatched {
- puts stderr "Couldn't find expected output 'success'"
+ puts stderr "vi transpose words, default timeout: short delay"
}
-# Test lowercase-r replace
-send_line -h "\033ddiecho TEXT\033hhrAi"
+# Test replacing a single character.
+send "echo TEXT"
+send "\033"
+# Delay needed to allow fish to transition to vi "normal" mode.
+sleep 0.020
+send "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
- puts "replace success"
-} -nounmatched -re {\r\nfail} {
- puts stderr "replace fail"
+ puts "vi mode replace char, default timeout: long delay"
+} unmatched {
+ puts stderr "vi mode replace char, default timeout: long delay"
+}
+
+# Verify that changing the escape timeout has an effect.
+send "set -g fish_escape_delay_ms 100\r"
+
+expect_prompt
+send "echo fail: lengthened escape timeout"
+send "\033"
+sleep 0.150
+send "ddi"
+send "echo success: lengthened escape timeout\r"
+expect_prompt -re {\r\nsuccess: lengthened escape timeout\r\n} {
+ puts "vi replace line, 100ms timeout: long delay"
+} unmatched {
+ puts stderr "vi replace line, 100ms timeout: long delay"
+}
+
+# Verify that we don't switch to vi normal mode if we don't wait long enough
+# after sending escape.
+send "echo fail: no normal mode"
+send "\033"
+sleep 0.050
+send "ddi"
+send "inserted\r"
+expect_prompt -re {\r\nfail: no normal modediinserted\r\n} {
+ puts "vi replace line, 100ms timeout: short delay"
} unmatched {
- puts stderr "Couldn't find expected output 'TAXT'"
+ puts stderr "vi replace line, 100ms timeout: short delay"
}
# Test 't' binding that contains non-zero arity function (forward-jump) followed
# by another function (and) https://github.com/fish-shell/fish-shell/issues/2357
send "\033"
-sleep 0.500
+sleep 0.510
send "ddiecho TEXT\033"
-sleep 0.500
+sleep 0.510
send "hhtTrN\r"
expect_prompt -re {\r\nTENT\r\n} {
puts "t-binding success"
@@ -52,17 +138,44 @@ expect_prompt -re {\r\nTENT\r\n} {
puts stderr "Couldn't find expected output 'TENT'"
}
-# still in insert mode, switch back to regular key bindings
-send_line -h "set -g fish_key_bindings fish_default_key_bindings"
+# Switch back to regular (emacs mode) key bindings.
+# The custom escape timeout of 100ms set earlier should still be in effect.
+send "set -g fish_key_bindings fish_default_key_bindings\r"
expect_prompt
-send_line "echo success"
-expect_prompt -re {\r\nsuccess\r\n} {
- puts "success"
+
+# Verify the emacs transpose word (\et) behavior using various delays,
+# including none, after the escape character.
+
+# Start by testing with no delay. This should transpose the words.
+send "echo abc def"
+send "\033"
+send "t\r"
+expect_prompt -re {\r\ndef abc\r\n} {
+ puts "emacs transpose words, 100ms timeout: no delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, 100ms timeout: no delay"
+}
+
+
+# Same test as above but with a slight delay less than the escape timeout.
+send "echo ghi jkl"
+send "\033"
+sleep 0.080
+send "t\r"
+expect_prompt -re {\r\njkl ghi\r\n} {
+ puts "emacs transpose words, 100ms timeout: short delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, 100ms timeout: short delay"
+}
+
+# Now test with a delay > the escape timeout. The transposition should not
+# occur and the "t" should become part of the text that is echoed.
+send "echo mno pqr"
+send "\033"
+sleep 0.120
+send "t\r"
+expect_prompt -re {\r\nmno pqrt\r\n} {
+ puts "emacs transpose words, 100ms timeout: long delay"
} unmatched {
- puts stderr "Couldn't find expected output 'success'"
-} timeout {
- set msg ""
- append msg "Timeout after setting fish_key_bindings to fish_default_key_bindings\n" \
- "\$fish_bind_mode is most likely still set to 'insert'"
- abort $msg
+ puts stderr "emacs transpose words fail, 100ms timeout: long delay"
}