aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bind.expect
blob: 6c80b8f116893f63ae150e8b3620873d7b8460a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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
}