fish-shell/tests/bind.expect

61 lines
1.8 KiB
Plaintext
Raw Normal View History

# vim: set filetype=expect:
spawn $fish
expect_prompt
# Test switching key bindings to vi mode.
# This should leave the mode in the appropriate state (i.e., insert mode).
send "set -g fish_key_bindings fish_vi_key_bindings\r"
expect_prompt
send -h "echo fail\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.510
send -h "ddiecho success\r"
expect_prompt -re {\r\nsuccess\r\n} {
puts "vi replace line success"
} -nounmatched -re {\r\nfail} {
puts stderr "vi replace line fail"
} unmatched {
puts stderr "Couldn't find expected output 'success'"
}
# Verify that a human can transpose words using \et (which is an emacs default
# binding but should be valid while in vi insert mode).
send "echo abc def\033"
# Fish should still be in vi "insert" mode after this delay.
sleep 0.400
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
puts "vi transpose words success"
} unmatched {
puts stderr "vi transpose words fail"
}
# Test replacing a single character.
send -h "echo TEXT\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.510
send -h "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
puts "vi mode replace success"
} -nounmatched -re {\r\nfail} {
puts stderr "vi mode replace fail"
} unmatched {
puts stderr "Couldn't find expected output 'TAXT'"
}
# Switch back to regular (emacs mode) key bindings.
send -h "set -g fish_key_bindings fish_default_key_bindings\r"
expect_prompt
send "echo success\r"
expect_prompt -re {\r\nsuccess\r\n} {
puts "emacs success"
} 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
}