aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bind.expect
blob: 155571638c8bc255636a1d11bf32260a2d4abc29 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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). These initial tests assume the
# default escape timeout of 500ms is in effect.

send "set -g fish_key_bindings fish_vi_key_bindings\r"
expect_prompt
send "echo fail: default escape timeout"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.510
send "ddi"
send "echo success: default escape timeout\r"
expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
    puts "vi replace line: default escape timeout"
} -nounmatched -re {\r\nfail} {
    puts stderr "vi replace line fail: default escape timeout"
} unmatched {
    puts stderr "couldn't find expected output: replace line, default escape timeout"
}

# 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"
send "\033"
# Fish should still be in vi insert mode after this delay to simulate a slow
# typist.
sleep 0.400
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
    puts "vi transpose words: default escape timeout"
} unmatched {
    puts stderr "vi transpose words fail: default escape timeout"
}

# Test replacing a single character.
send "echo TEXT"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.510
send "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
    puts "vi mode replace: default escape timeout"
} -nounmatched -re {\r\nfail} {
    puts stderr "vi mode replace fail: default escape timeout"
} unmatched {
    puts stderr "couldn't find expected output 'TAXT': default escape timeout"
}

# Verify that changing the escape timeout has an effect. The vi key bindings
# should still be in effect.
send "set -g fish_escape_delay_ms 100\r"
expect_prompt
send "echo fail: shortened escape timeout"
send "\033"
sleep 0.110
send "ddi"
send "echo success: shortened escape timeout\r"
expect_prompt -re {\r\nsuccess: shortened escape timeout\r\n} {
    puts "vi replace line: shortened escape timeout"
} -nounmatched -re {\r\nfail} {
    puts stderr "vi replace line fail: shortened escape timeout"
} unmatched {
    puts stderr "couldn't find expected output: replace_line, shortened escape timeout"
}

# Verify that we don't switch to vi normal mode if we don't wait long enough
# after sending escape. The vi key bindings should still be in effect.
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 normal mode: shortened escape timeout"
} unmatched {
    puts stderr "couldn't find expected output: no normal mode"
}

# Switch back to regular (emacs mode) key bindings.
send "set -g fish_key_bindings fish_default_key_bindings\r"
expect_prompt

# 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: no escape delay"
} unmatched {
    puts stderr "emacs transpose words fail: no escape delay"
}

# Now test with a delay > 0 and < the escape timeout. This should transpose
# the words.
send "set -g fish_escape_delay_ms 100\r"
expect_prompt
send "echo ghi jkl"
send "\033"
sleep 0.050
send "t\r"
expect_prompt -re {\r\njkl ghi\r\n} {
    puts "emacs transpose words: short escape delay"
} unmatched {
    puts stderr "emacs transpose words fail: short escape 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.110
send "t\r"
expect_prompt -re {\r\nmno pqrt\r\n} {
    puts "emacs transpose words: long escape delay"
} unmatched {
    puts stderr "emacs transpose words fail: long escape delay"
}