aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bind.expect
blob: 7c594241043c5b471def1d303b0e01f21cf58433 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# vim: set filetype=expect:
spawn $fish
expect_prompt

# 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.250
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"
}

# 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

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

# Go through a prompt cycle to let fish catch up, it may be slow due to ASAN
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 "prime vi mode, default timeout"
}

# Verify the default timeout has been set to the expected value.
send "echo fish_escape_delay_ms=\$fish_escape_delay_ms\r"
expect_prompt -re {\r\nfish_escape_delay_ms=100\r\n} {
    puts "vi-mode default timeout set correctly"
} unmatched {
    puts stderr "vi-mode default timeout not set correctly"
}

send "echo fail: default escape timeout"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode. The delay is
# longer than strictly necessary to let fish catch up as it may be slow due to
# ASAN.
sleep 0.150
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.010
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
    puts "vi transpose words, default timeout: short delay"
} unmatched {
    puts stderr "vi transpose words, default timeout: short delay"
}

# Test replacing a single character.
send "echo TEXT"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.150
send "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
    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 200\r"
expect_prompt

send "echo fail: lengthened escape timeout"
send "\033"
sleep 0.250
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.100
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 "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.250
send "ddiecho TEXT\033"
sleep 0.250
send "hhtTrN\r"
expect_prompt -re {\r\nTENT\r\n} {
    puts "t-binding success"
} -nounmatched -re {\r\nfail} {
    puts stderr "t-binding fail"
} unmatched {
    puts stderr "Couldn't find expected output 'TENT'"
}

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

# Verify the custom escape timeout of 200ms set earlier is still in effect.
send "echo fish_escape_delay_ms=\$fish_escape_delay_ms\r"
expect_prompt -re {\r\nfish_escape_delay_ms=200\r\n} {
    puts "default-mode custom timeout set correctly"
} unmatched {
    puts stderr "default-mode custom timeout not set correctly"
}

# Reset it to 100ms.
send "set -g fish_escape_delay_ms 100\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 "\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.250
send "t\r"
expect_prompt -re {\r\nmno pqrt\r\n} {
    puts "emacs transpose words, 100ms timeout: long delay"
} unmatched {
    puts stderr "emacs transpose words fail, 100ms timeout: long delay"
}

# Verify special characters, such as \cV, are not intercepted by the kernel
# tty driver. Rather, they can be bound and handled by fish.
send "bind \\cV 'echo ctrl-v seen'\r"
expect_prompt
send "\026\r"
expect_prompt -re {ctrl-v seen} {
    puts "ctrl-v seen"
} unmatched {
    puts stderr "ctrl-v not seen"
}

send "bind \\cO 'echo ctrl-o seen'\r"
expect_prompt
send "\017\r"
expect_prompt -re {ctrl-o seen} {
    puts "ctrl-o seen"
} unmatched {
    puts stderr "ctrl-o not seen"
}