blob: 7d3c0c87d09680e0a2d3cab96a3174fac4493c4a [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaar4facea32019-10-12 20:17:40 +02006
Bram Moolenaarae3150e2016-06-11 23:22:36 +02007func Test_complete_tab()
8 call writefile(['testfile'], 'Xtestfile')
9 call feedkeys(":e Xtest\t\r", "tx")
10 call assert_equal('testfile', getline(1))
11 call delete('Xtestfile')
12endfunc
13
14func Test_complete_list()
15 " We can't see the output, but at least we check the code runs properly.
16 call feedkeys(":e test\<C-D>\r", "tx")
17 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010018
19 " If a command doesn't support completion, then CTRL-D should be literally
20 " used.
21 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
22 call assert_equal("\"chistory \<C-D>", @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020023endfunc
24
25func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010026 call mkdir('Xdir1/Xdir2', 'p')
27 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
28 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
29 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
30 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020031 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010032
33 " Pressing <Tab> completes, and moves to next files when pressing again.
34 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
35 call assert_equal('testfile1', getline(1))
36 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020037 call assert_equal('testfile2', getline(1))
38
Bram Moolenaar37db6422019-03-28 21:26:23 +010039 " <S-Tab> is like <Tab> but begin with the last match and then go to
40 " previous.
41 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
42 call assert_equal('testfile2', getline(1))
43 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
44 call assert_equal('testfile1', getline(1))
45
46 " <Left>/<Right> to move to previous/next file.
47 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
48 call assert_equal('testfile1', getline(1))
49 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
50 call assert_equal('testfile2', getline(1))
51 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
52 call assert_equal('testfile1', getline(1))
53
54 " <Up>/<Down> to go up/down directories.
55 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
56 call assert_equal('testfile3', getline(1))
57 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
58 call assert_equal('testfile1', getline(1))
59
Bram Moolenaar578fe942020-02-27 21:32:51 +010060 " Test for canceling the wild menu by adding a character
61 redrawstatus
62 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
63 call assert_equal('"e Xdir1/Xdir2/x', @:)
64
Bram Moolenaar8d588cc2020-02-25 21:47:45 +010065 " Completion using a relative path
66 cd Xdir1/Xdir2
67 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
68 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
69 cd -
70
Bram Moolenaar0e05de42020-03-25 22:23:46 +010071 cnoremap <expr> <F2> wildmenumode()
72 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
73 call assert_equal('"cd Xdir1/1', @:)
74 cunmap <F2>
75
Bram Moolenaar37db6422019-03-28 21:26:23 +010076 " cleanup
77 %bwipe
78 call delete('Xdir1/Xdir2/Xtestfile4')
79 call delete('Xdir1/Xdir2/Xtestfile3')
80 call delete('Xdir1/Xtestfile2')
81 call delete('Xdir1/Xtestfile1')
82 call delete('Xdir1/Xdir2', 'd')
83 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020084 set nowildmenu
85endfunc
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020086
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +010087func Test_map_completion()
88 if !has('cmdline_compl')
89 return
90 endif
91 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
92 call assert_equal('"map <unique> <silent>', getreg(':'))
93 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
94 call assert_equal('"map <script> <unique>', getreg(':'))
95 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
96 call assert_equal('"map <expr> <script>', getreg(':'))
97 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
98 call assert_equal('"map <buffer> <expr>', getreg(':'))
99 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
100 call assert_equal('"map <nowait> <buffer>', getreg(':'))
101 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
102 call assert_equal('"map <special> <nowait>', getreg(':'))
103 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
104 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200105
Bram Moolenaar1776a282019-05-03 16:05:41 +0200106 map <Middle>x middle
107
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200108 map ,f commaf
109 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200110 map <Left> left
111 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200112 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
113 call assert_equal('"map ,f', getreg(':'))
114 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
115 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200116 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
117 call assert_equal('"map <Left>', getreg(':'))
118 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200119 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200120 unmap ,f
121 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200122 unmap <Left>
123 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200124
125 set cpo-=< cpo-=B cpo-=k
126 map <Left> left
127 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
128 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200129 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200130 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200131 unmap <Left>
132
133 set cpo+=<
134 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200135 exe "set t_k6=\<Esc>[17~"
136 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200137 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
138 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200139 if !has('gui_running')
140 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
141 call assert_equal("\"map <F6>x", getreg(':'))
142 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200143 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200144 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200145 set cpo-=<
146
147 set cpo+=B
148 map <Left> left
149 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
150 call assert_equal('"map <Left>', getreg(':'))
151 unmap <Left>
152 set cpo-=B
153
154 set cpo+=k
155 map <Left> left
156 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
157 call assert_equal('"map <Left>', getreg(':'))
158 unmap <Left>
159 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200160
161 unmap <Middle>x
162 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100163endfunc
164
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100165func Test_match_completion()
166 if !has('cmdline_compl')
167 return
168 endif
169 hi Aardig ctermfg=green
170 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
171 call assert_equal('"match Aardig', getreg(':'))
172 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
173 call assert_equal('"match none', getreg(':'))
174endfunc
175
176func Test_highlight_completion()
177 if !has('cmdline_compl')
178 return
179 endif
180 hi Aardig ctermfg=green
181 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
182 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200183 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
184 call assert_equal('"hi default Aardig', getreg(':'))
185 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
186 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100187 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
188 call assert_equal('"hi link', getreg(':'))
189 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
190 call assert_equal('"hi default', getreg(':'))
191 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
192 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200193
194 " A cleared group does not show up in completions.
195 hi Anders ctermfg=green
196 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
197 hi clear Aardig
198 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
199 hi clear Anders
200 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100201endfunc
202
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200203func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200204 if !has('cmdline_compl')
205 return
206 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200207 let groupcount = len(getcompletion('', 'event'))
208 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200209 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200210 call assert_true(matchcount > 0)
211 call assert_true(groupcount > matchcount)
212
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200213 if has('menu')
214 source $VIMRUNTIME/menu.vim
215 let matchcount = len(getcompletion('', 'menu'))
216 call assert_true(matchcount > 0)
217 call assert_equal(['File.'], getcompletion('File', 'menu'))
218 call assert_true(matchcount > 0)
219 let matchcount = len(getcompletion('File.', 'menu'))
220 call assert_true(matchcount > 0)
221 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200222
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200223 let l = getcompletion('v:n', 'var')
224 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200225 let l = getcompletion('v:notexists', 'var')
226 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200227
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200228 args a.c b.c
229 let l = getcompletion('', 'arglist')
230 call assert_equal(['a.c', 'b.c'], l)
231 %argdelete
232
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200233 let l = getcompletion('', 'augroup')
234 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200235 let l = getcompletion('blahblah', 'augroup')
236 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200237
238 let l = getcompletion('', 'behave')
239 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200240 let l = getcompletion('not', 'behave')
241 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200242
243 let l = getcompletion('', 'color')
244 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200245 let l = getcompletion('dirty', 'color')
246 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200247
248 let l = getcompletion('', 'command')
249 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200250 let l = getcompletion('awake', 'command')
251 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200252
253 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200254 call assert_true(index(l, 'samples/') >= 0)
255 let l = getcompletion('NoMatch', 'dir')
256 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200257
258 let l = getcompletion('exe', 'expression')
259 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200260 let l = getcompletion('kill', 'expression')
261 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200262
263 let l = getcompletion('tag', 'function')
264 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200265 let l = getcompletion('paint', 'function')
266 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200267
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200268 let Flambda = {-> 'hello'}
269 let l = getcompletion('', 'function')
270 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200271 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200272
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200273 let l = getcompletion('run', 'file')
274 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200275 let l = getcompletion('walk', 'file')
276 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200277 set wildignore=*.vim
278 let l = getcompletion('run', 'file', 1)
279 call assert_true(index(l, 'runtest.vim') < 0)
280 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200281
282 let l = getcompletion('ha', 'filetype')
283 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200284 let l = getcompletion('horse', 'filetype')
285 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200286
287 let l = getcompletion('z', 'syntax')
288 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200289 let l = getcompletion('emacs', 'syntax')
290 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200291
292 let l = getcompletion('jikes', 'compiler')
293 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200294 let l = getcompletion('break', 'compiler')
295 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200296
297 let l = getcompletion('last', 'help')
298 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200299 let l = getcompletion('giveup', 'help')
300 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200301
302 let l = getcompletion('time', 'option')
303 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200304 let l = getcompletion('space', 'option')
305 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200306
307 let l = getcompletion('er', 'highlight')
308 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200309 let l = getcompletion('dark', 'highlight')
310 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200311
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200312 let l = getcompletion('', 'messages')
313 call assert_true(index(l, 'clear') >= 0)
314 let l = getcompletion('not', 'messages')
315 call assert_equal([], l)
316
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200317 let l = getcompletion('', 'mapclear')
318 call assert_true(index(l, '<buffer>') >= 0)
319 let l = getcompletion('not', 'mapclear')
320 call assert_equal([], l)
321
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200322 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200323 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200324 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
325 let root = has('win32') ? 'C:\\' : '/'
326 let l = getcompletion(root, 'shellcmd')
327 let expected = map(filter(glob(root . '*', 0, 1),
328 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
329 call assert_equal(expected, l)
330
Bram Moolenaarb650b982016-08-05 20:35:13 +0200331 if has('cscope')
332 let l = getcompletion('', 'cscope')
333 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
334 call assert_equal(cmds, l)
335 " using cmdline completion must not change the result
336 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
337 let l = getcompletion('', 'cscope')
338 call assert_equal(cmds, l)
339 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
340 let l = getcompletion('find ', 'cscope')
341 call assert_equal(keys, l)
342 endif
343
Bram Moolenaar7522f692016-08-06 14:12:50 +0200344 if has('signs')
345 sign define Testing linehl=Comment
346 let l = getcompletion('', 'sign')
347 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
348 call assert_equal(cmds, l)
349 " using cmdline completion must not change the result
350 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
351 let l = getcompletion('', 'sign')
352 call assert_equal(cmds, l)
353 let l = getcompletion('list ', 'sign')
354 call assert_equal(['Testing'], l)
355 endif
356
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200357 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200358 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200359 if has('cmdline_hist')
360 call add(names, 'history')
361 endif
362 if has('gettext')
363 call add(names, 'locale')
364 endif
365 if has('profile')
366 call add(names, 'syntime')
367 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200368
369 set tags=Xtags
370 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
371
372 for name in names
373 let matchcount = len(getcompletion('', name))
374 call assert_true(matchcount >= 0, 'No matches for ' . name)
375 endfor
376
377 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200378 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200379
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200380 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100381 call assert_fails('call getcompletion("abc", [])', 'E474:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200382endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200383
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200384func Test_shellcmd_completion()
385 let save_path = $PATH
386
387 call mkdir('Xpathdir/Xpathsubdir', 'p')
388 call writefile([''], 'Xpathdir/Xfile.exe')
389 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
390
391 " Set PATH to example directory without trailing slash.
392 let $PATH = getcwd() . '/Xpathdir'
393
394 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
395 " dirs in the PATH, even though they won't be executed. We check that only
396 " subdirs of the PWD and executables from the PATH are included in the
397 " suggestions.
398 let actual = getcompletion('X', 'shellcmd')
399 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
400 call insert(expected, 'Xfile.exe')
401 call assert_equal(expected, actual)
402
403 call delete('Xpathdir', 'rf')
404 let $PATH = save_path
405endfunc
406
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200407func Test_expand_star_star()
408 call mkdir('a/b', 'p')
409 call writefile(['asdfasdf'], 'a/b/fileXname')
410 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
411 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200412 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200413 call delete('a', 'rf')
414endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100415
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100416func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100417 let @a = "def"
418 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
419 call assert_equal('"abc def ghi', @:)
420
421 new
422 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
423
424 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
425 call assert_equal('"aaa asdf bbb', @:)
426
427 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
428 call assert_equal('"aaa /tmp/some bbb', @:)
429
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200430 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
431 call assert_equal('"aaa '.getline(1).' bbb', @:)
432
Bram Moolenaar21efc362016-12-03 14:05:49 +0100433 set incsearch
434 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
435 call assert_equal('"aaa verylongword bbb', @:)
436
437 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
438 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100439
440 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
441 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100442 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200443
444 " Error while typing a command used to cause that it was not executed
445 " in the end.
446 new
447 try
448 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
449 catch /^Vim\%((\a\+)\)\=:E32/
450 " ignore error E32
451 endtry
452 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100453
Bram Moolenaar578fe942020-02-27 21:32:51 +0100454 " Try to paste an invalid register using <C-R>
455 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
456 call assert_equal('"onetwo', @:)
457
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100458 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100459 let @a = "xy\<C-H>z"
460 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
461 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100462 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
463 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100464 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
465 call assert_equal("\"xy\<C-H>z", @:)
466
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100467 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
468 let @a = "xy\<C-V>z"
469 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
470 call assert_equal('"xyz', @:)
471 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
472 call assert_equal("\"xy\<C-V>z", @:)
473
Bram Moolenaar578fe942020-02-27 21:32:51 +0100474 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
475
Bram Moolenaar72532d32018-04-07 19:09:09 +0200476 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100477endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100478
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100479func Test_cmdline_remove_char()
480 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100481
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100482 for e in ['utf8', 'latin1']
483 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100484
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100485 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
486 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100487
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100488 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
489 call assert_equal('"abcdef', @:)
490
491 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
492 call assert_equal('"abc ghi', @:, e)
493
494 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
495 call assert_equal('"def', @:, e)
496 endfor
497
498 let &encoding = encoding_save
499endfunc
500
501func Test_cmdline_keymap_ctrl_hat()
502 if !has('keymap')
503 return
504 endif
505
506 set keymap=esperanto
507 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
508 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
509 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100510endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100511
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100512func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100513 new
514 2;'(
515 2;')
516 quit
517endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100518
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100519func Test_illegal_address2()
520 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
521 new
522 source Xtest.vim
523 " Trigger calling validate_cursor()
524 diffsp Xtest.vim
525 quit!
526 bwipe!
527 call delete('Xtest.vim')
528endfunc
529
Bram Moolenaarba47b512017-01-24 21:18:19 +0100530func Test_cmdline_complete_wildoptions()
531 help
532 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
533 let a = join(sort(split(@:)),' ')
534 set wildoptions=tagfile
535 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
536 let b = join(sort(split(@:)),' ')
537 call assert_equal(a, b)
538 bw!
539endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100540
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200541func Test_cmdline_complete_user_cmd()
542 command! -complete=color -nargs=1 Foo :
543 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
544 call assert_equal('"Foo blue', @:)
545 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
546 call assert_equal('"Foo blue', @:)
547 delcommand Foo
548endfunc
549
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100550func s:ScriptLocalFunction()
551 echo 'yes'
552endfunc
553
554func Test_cmdline_complete_user_func()
555 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
556 call assert_match('"func Test_cmdline_complete_user', @:)
557 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
558 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
559endfunc
560
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200561func Test_cmdline_complete_user_names()
562 if has('unix') && executable('whoami')
563 let whoami = systemlist('whoami')[0]
564 let first_letter = whoami[0]
565 if len(first_letter) > 0
566 " Trying completion of :e ~x where x is the first letter of
567 " the user name should complete to at least the user name.
568 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
569 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
570 endif
571 endif
572 if has('win32')
573 " Just in case: check that the system has an Administrator account.
574 let names = system('net user')
575 if names =~ 'Administrator'
576 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100577 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200578 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100579 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200580 endif
581 endif
582endfunc
583
Bram Moolenaar297610b2019-12-27 17:20:55 +0100584func Test_cmdline_complete_bang()
585 if executable('whoami')
Bram Moolenaar731a7992019-12-28 14:06:50 +0100586 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
587 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100588 endif
Bram Moolenaar297610b2019-12-27 17:20:55 +0100589endfunc
590
Bram Moolenaar8b633132020-03-20 18:20:51 +0100591func Test_cmdline_complete_languages()
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200592 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
593
594 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
595 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
596
597 if has('unix')
598 " TODO: these tests don't work on Windows. lang appears to be 'C'
599 " but C does not appear in the completion. Why?
600 call assert_match('^"language .*\<' . lang . '\>', @:)
601
602 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
603 call assert_match('^"language .*\<' . lang . '\>', @:)
604
605 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
606 call assert_match('^"language .*\<' . lang . '\>', @:)
607
608 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
609 call assert_match('^"language .*\<' . lang . '\>', @:)
610 endif
611endfunc
612
Bram Moolenaar297610b2019-12-27 17:20:55 +0100613func Test_cmdline_complete_env_variable()
614 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100615 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
616 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100617 unlet $X_VIM_TEST_COMPLETE_ENV
618endfunc
619
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100620" Test for various command-line completion
621func Test_cmdline_complete_various()
622 " completion for a command starting with a comment
623 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
624 call assert_equal("\" :|\"\<C-A>", @:)
625
626 " completion for a range followed by a comment
627 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
628 call assert_equal("\"1,2\"\<C-A>", @:)
629
630 " completion for :k command
631 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
632 call assert_equal("\"ka\<C-A>", @:)
633
634 " completion for short version of the :s command
635 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
636 call assert_equal("\"sI \<C-A>", @:)
637
638 " completion for :write command
639 call mkdir('Xdir')
640 call writefile(['one'], 'Xdir/Xfile1')
641 let save_cwd = getcwd()
642 cd Xdir
643 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
644 call assert_equal("\"w >> Xfile1", @:)
645 call chdir(save_cwd)
646 call delete('Xdir', 'rf')
647
648 " completion for :w ! and :r ! commands
649 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
650 call assert_equal("\"w !invalid_xyz_cmd", @:)
651 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
652 call assert_equal("\"r !invalid_xyz_cmd", @:)
653
654 " completion for :>> and :<< commands
655 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
656 call assert_equal("\">>>\<C-A>", @:)
657 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
658 call assert_equal("\"<<<\<C-A>", @:)
659
660 " completion for command with +cmd argument
661 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
662 call assert_equal("\"buffer +/pat Xabc", @:)
663 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
664 call assert_equal("\"buffer +/pat\<C-A>", @:)
665
666 " completion for a command with a trailing comment
667 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
668 call assert_equal("\"ls \" comment\<C-A>", @:)
669
670 " completion for a command with a trailing command
671 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
672 call assert_equal("\"ls | ls", @:)
673
674 " completion for a command with an CTRL-V escaped argument
675 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
676 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
677
678 " completion for a command that doesn't take additional arguments
679 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
680 call assert_equal("\"all abc\<C-A>", @:)
681
682 " completion for a command with a command modifier
683 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
684 call assert_equal("\"topleft new", @:)
685
686 " completion for the :match command
687 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
688 call assert_equal("\"match Search /pat/\<C-A>", @:)
689
690 " completion for the :s command
691 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
692 call assert_equal("\"s/from/to/g\<C-A>", @:)
693
694 " completion for the :dlist command
695 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
696 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
697
698 " completion for the :doautocmd command
699 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
700 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
701
702 " completion for the :augroup command
703 augroup XTest
704 augroup END
705 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
706 call assert_equal("\"augroup XTest", @:)
707 augroup! XTest
708
709 " completion for the :unlet command
710 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
711 call assert_equal("\"unlet one two", @:)
712
713 " completion for the :bdelete command
714 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
715 call assert_equal("\"bdel a b c", @:)
716
717 " completion for the :mapclear command
718 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
719 call assert_equal("\"mapclear <buffer>", @:)
720
721 " completion for user defined commands with menu names
722 menu Test.foo :ls<CR>
723 com -nargs=* -complete=menu MyCmd
724 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
725 call assert_equal('"MyCmd Test.', @:)
726 delcom MyCmd
727 unmenu Test
728
729 " completion for user defined commands with mappings
730 mapclear
731 map <F3> :ls<CR>
732 com -nargs=* -complete=mapping MyCmd
733 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
734 call assert_equal('"MyCmd <F3>', @:)
735 mapclear
736 delcom MyCmd
737
738 " completion for :set path= with multiple backslashes
739 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
740 call assert_equal('"set path=a\\\ b', @:)
741
742 " completion for :set dir= with a backslash
743 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
744 call assert_equal('"set dir=a\ b', @:)
745
746 " completion for the :py3 commands
747 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
748 call assert_equal('"py3 py3do py3file', @:)
749
750 " redir @" is not the start of a comment. So complete after that
751 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
752 call assert_equal('"redir @" | cwindow', @:)
753
754 " completion after a backtick
755 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
756 call assert_equal('"e `a1b2c', @:)
757
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100758 " completion for :language command with an invalid argument
759 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
760 call assert_equal("\"language dummy \t", @:)
761
762 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +0100763 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
764 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100765
766 " completion with ambiguous user defined commands
767 com TCmd1 echo 'TCmd1'
768 com TCmd2 echo 'TCmd2'
769 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
770 call assert_equal('"TCmd ', @:)
771 delcom TCmd1
772 delcom TCmd2
773
774 " completion after a range followed by a pipe (|) character
775 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
776 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100777endfunc
778
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200779func Test_cmdline_write_alternatefile()
780 new
781 call setline('.', ['one', 'two'])
782 f foo.txt
783 new
784 f #-A
785 call assert_equal('foo.txt-A', expand('%'))
786 f #<-B.txt
787 call assert_equal('foo-B.txt', expand('%'))
788 f %<
789 call assert_equal('foo-B', expand('%'))
790 new
791 call assert_fails('f #<', 'E95')
792 bw!
793 f foo-B.txt
794 f %<-A
795 call assert_equal('foo-B-A', expand('%'))
796 bw!
797 bw!
798endfunc
799
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100800" using a leading backslash here
801set cpo+=C
802
803func Test_cmdline_search_range()
804 new
805 call setline(1, ['a', 'b', 'c', 'd'])
806 /d
807 1,\/s/b/B/
808 call assert_equal('B', getline(2))
809
810 /a
811 $
812 \?,4s/c/C/
813 call assert_equal('C', getline(3))
814
815 call setline(1, ['a', 'b', 'c', 'd'])
816 %s/c/c/
817 1,\&s/b/B/
818 call assert_equal('B', getline(2))
819
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100820 let @/ = 'apple'
821 call assert_fails('\/print', 'E486:')
822
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100823 bwipe!
824endfunc
825
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100826" Test for the tick mark (') in an excmd range
827func Test_tick_mark_in_range()
828 " If only the tick is passed as a range and no command is specified, there
829 " should not be an error
830 call feedkeys(":'\<CR>", 'xt')
831 call assert_equal("'", getreg(':'))
832 call assert_fails("',print", 'E78:')
833endfunc
834
835" Test for using a line number followed by a search pattern as range
836func Test_lnum_and_pattern_as_range()
837 new
838 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
839 let @" = ''
840 2/foo/yank
841 call assert_equal("foo 3\n", @")
842 call assert_equal(1, line('.'))
843 close!
844endfunc
845
Bram Moolenaar65189a12017-02-06 22:22:17 +0100846" Tests for getcmdline(), getcmdpos() and getcmdtype()
847func Check_cmdline(cmdtype)
848 call assert_equal('MyCmd a', getcmdline())
849 call assert_equal(8, getcmdpos())
850 call assert_equal(a:cmdtype, getcmdtype())
851 return ''
852endfunc
853
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200854set cpo&
855
Bram Moolenaar65189a12017-02-06 22:22:17 +0100856func Test_getcmdtype()
857 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
858
859 let cmdtype = ''
860 debuggreedy
861 call feedkeys(":debug echo 'test'\<CR>", "t")
862 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
863 call feedkeys("cont\<CR>", "xt")
864 0debuggreedy
865 call assert_equal('>', cmdtype)
866
867 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
868 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
869
870 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +0100871 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +0100872
873 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
874
875 cnoremap <expr> <F6> Check_cmdline('=')
876 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
877 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100878
879 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +0100880endfunc
881
Bram Moolenaar81612b72018-06-23 14:55:03 +0200882func Test_getcmdwintype()
883 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
884 call assert_equal('/', a)
885
886 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
887 call assert_equal('?', a)
888
889 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
890 call assert_equal(':', a)
891
892 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
893 call assert_equal(':', a)
894
895 call assert_equal('', getcmdwintype())
896endfunc
897
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200898func Test_getcmdwin_autocmd()
899 let s:seq = []
900 augroup CmdWin
901 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
902 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
903 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
904 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
905 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
906 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
907
908 let org_winid = win_getid()
909 let org_bufnr = bufnr()
910 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
911 call assert_equal(':', a)
912 call assert_equal([
913 \ 'WinLeave ' .. org_winid,
914 \ 'WinEnter ' .. s:cmd_winid,
915 \ 'BufLeave ' .. org_bufnr,
916 \ 'BufEnter ' .. s:cmd_bufnr,
917 \ 'CmdWinEnter ' .. s:cmd_winid,
918 \ 'CmdWinLeave ' .. s:cmd_winid,
919 \ 'BufLeave ' .. s:cmd_bufnr,
920 \ 'WinLeave ' .. s:cmd_winid,
921 \ 'WinEnter ' .. org_winid,
922 \ 'BufEnter ' .. org_bufnr,
923 \ ], s:seq)
924
925 au!
926 augroup END
927endfunc
928
Bram Moolenaar52604f22017-04-07 16:17:39 +0200929func Test_verbosefile()
930 set verbosefile=Xlog
931 echomsg 'foo'
932 echomsg 'bar'
933 set verbosefile=
934 let log = readfile('Xlog')
935 call assert_match("foo\nbar", join(log, "\n"))
936 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200937 call mkdir('Xdir')
938 call assert_fails('set verbosefile=Xdir', 'E474:')
939 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +0200940endfunc
941
Bram Moolenaar4facea32019-10-12 20:17:40 +0200942func Test_verbose_option()
943 CheckScreendump
944
945 let lines =<< trim [SCRIPT]
946 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
947 call feedkeys("\r", 't') " for the hit-enter prompt
948 set verbose=20
949 [SCRIPT]
950 call writefile(lines, 'XTest_verbose')
951
952 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200953 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +0200954 call term_sendkeys(buf, ":DoSomething\<CR>")
955 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
956
957 " clean up
958 call StopVimInTerminal(buf)
959 call delete('XTest_verbose')
960endfunc
961
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200962func Test_setcmdpos()
963 func InsertTextAtPos(text, pos)
964 call assert_equal(0, setcmdpos(a:pos))
965 return a:text
966 endfunc
967
968 " setcmdpos() with position in the middle of the command line.
969 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
970 call assert_equal('"1ab2', @:)
971
972 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
973 call assert_equal('"1b2a', @:)
974
975 " setcmdpos() with position beyond the end of the command line.
976 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
977 call assert_equal('"12ab', @:)
978
979 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +0200980 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200981endfunc
982
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100983func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100984 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100985 let encoding_save = &encoding
986
987 for e in encodings
988 exe 'set encoding=' . e
989
990 " Test overstrike in the middle of the command line.
991 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100992 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100993
994 " Test overstrike going beyond end of command line.
995 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100996 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100997
998 " Test toggling insert/overstrike a few times.
999 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001000 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001001 endfor
1002
Bram Moolenaar30276f22019-01-24 17:59:39 +01001003 " Test overstrike with multi-byte characters.
1004 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001005 call assert_equal('"abcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001006
1007 let &encoding = encoding_save
1008endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001009
1010func Test_cmdwin_bug()
1011 let winid = win_getid()
1012 sp
1013 try
1014 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1015 catch /^Vim\%((\a\+)\)\=:E11/
1016 endtry
1017 bw!
1018endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001019
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001020func Test_cmdwin_restore()
1021 CheckScreendump
1022
1023 let lines =<< trim [SCRIPT]
1024 call setline(1, range(30))
1025 2split
1026 [SCRIPT]
1027 call writefile(lines, 'XTest_restore')
1028
1029 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001030 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001031 call term_sendkeys(buf, "q:")
1032 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1033
1034 " normal restore
1035 call term_sendkeys(buf, ":q\<CR>")
1036 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1037
1038 " restore after setting 'lines' with one window
1039 call term_sendkeys(buf, ":close\<CR>")
1040 call term_sendkeys(buf, "q:")
1041 call term_sendkeys(buf, ":set lines=18\<CR>")
1042 call term_sendkeys(buf, ":q\<CR>")
1043 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1044
1045 " clean up
1046 call StopVimInTerminal(buf)
1047 call delete('XTest_restore')
1048endfunc
1049
Bram Moolenaar52410572019-10-27 05:12:45 +01001050func Test_buffers_lastused()
1051 " check that buffers are sorted by time when wildmode has lastused
1052 call test_settime(1550020000) " middle
1053 edit bufa
1054 enew
1055 call test_settime(1550030000) " newest
1056 edit bufb
1057 enew
1058 call test_settime(1550010000) " oldest
1059 edit bufc
1060 enew
1061 call test_settime(0)
1062 enew
1063
1064 call assert_equal(['bufa', 'bufb', 'bufc'],
1065 \ getcompletion('', 'buffer'))
1066
1067 let save_wildmode = &wildmode
1068 set wildmode=full:lastused
1069
1070 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1071 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1072 call assert_equal('b bufb', X)
1073 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1074 call assert_equal('b bufa', X)
1075 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1076 call assert_equal('b bufc', X)
1077 enew
1078
1079 edit other
1080 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1081 call assert_equal('b bufb', X)
1082 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1083 call assert_equal('b bufa', X)
1084 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1085 call assert_equal('b bufc', X)
1086 enew
1087
1088 let &wildmode = save_wildmode
1089
1090 bwipeout bufa
1091 bwipeout bufb
1092 bwipeout bufc
1093endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001094
1095func Test_cmdwin_feedkeys()
1096 " This should not generate E488
1097 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001098 " Using feedkeys with q: only should automatically close the cmd window
1099 call feedkeys('q:', 'xt')
1100 call assert_equal(1, winnr('$'))
1101 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001102endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001103
1104" Tests for the issues fixed in 7.4.441.
1105" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1106func Test_cmdwin_cedit()
1107 exe "set cedit=\<C-c>"
1108 normal! :
1109 call assert_equal(1, winnr('$'))
1110
1111 let g:cmd_wintype = ''
1112 func CmdWinType()
1113 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001114 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001115 return ''
1116 endfunc
1117
1118 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1119 echo input('')
1120 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001121 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001122
1123 set cedit&vim
1124 delfunc CmdWinType
1125endfunc
1126
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001127" Test for CmdwinEnter autocmd
1128func Test_cmdwin_autocmd()
1129 augroup CmdWin
1130 au!
1131 autocmd CmdwinEnter * startinsert
1132 augroup END
1133
1134 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1135 call assert_equal('xyz', @:)
1136
1137 augroup CmdWin
1138 au!
1139 augroup END
1140 augroup! CmdWin
1141endfunc
1142
Bram Moolenaar479950f2020-01-19 15:45:17 +01001143func Test_cmdlineclear_tabenter()
1144 CheckScreendump
1145
1146 let lines =<< trim [SCRIPT]
1147 call setline(1, range(30))
1148 [SCRIPT]
1149
1150 call writefile(lines, 'XtestCmdlineClearTabenter')
1151 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001152 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001153 " in one tab make the command line higher with CTRL-W -
1154 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1155 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1156
1157 call StopVimInTerminal(buf)
1158 call delete('XtestCmdlineClearTabenter')
1159endfunc
1160
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001161" Test for failure in expanding special keywords in cmdline
1162func Test_cmdline_expand_special()
1163 %bwipe!
1164 call assert_fails('e #', 'E499:')
1165 call assert_fails('e <afile>', 'E495:')
1166 call assert_fails('e <abuf>', 'E496:')
1167 call assert_fails('e <amatch>', 'E497:')
1168endfunc
1169
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001170func Test_cmdwin_jump_to_win()
1171 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1172 new
1173 set modified
1174 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
1175 close!
1176 call feedkeys("q/:close\<CR>", "xt")
1177 call assert_equal(1, winnr('$'))
1178 call feedkeys("q/:exit\<CR>", "xt")
1179 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001180
1181 " opening command window twice should fail
1182 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1183 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001184endfunc
1185
1186" Test for backtick expression in the command line
1187func Test_cmd_backtick()
1188 %argd
1189 argadd `=['a', 'b', 'c']`
1190 call assert_equal(['a', 'b', 'c'], argv())
1191 %argd
1192endfunc
1193
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001194" Test for the :! command
1195func Test_cmd_bang()
1196 if !has('unix')
1197 return
1198 endif
1199
1200 let lines =<< trim [SCRIPT]
1201 " Test for no previous command
1202 call assert_fails('!!', 'E34:')
1203 set nomore
1204 " Test for cmdline expansion with :!
1205 call setline(1, 'foo!')
1206 silent !echo <cWORD> > Xfile.out
1207 call assert_equal(['foo!'], readfile('Xfile.out'))
1208 " Test for using previous command
1209 silent !echo \! !
1210 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1211 call writefile(v:errors, 'Xresult')
1212 call delete('Xfile.out')
1213 qall!
1214 [SCRIPT]
1215 call writefile(lines, 'Xscript')
1216 if RunVim([], [], '--clean -S Xscript')
1217 call assert_equal([], readfile('Xresult'))
1218 endif
1219 call delete('Xscript')
1220 call delete('Xresult')
1221endfunc
1222
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001223" Test for using ~ for home directory in cmdline completion matches
1224func Test_cmdline_expand_home()
1225 call mkdir('Xdir')
1226 call writefile([], 'Xdir/Xfile1')
1227 call writefile([], 'Xdir/Xfile2')
1228 cd Xdir
1229 let save_HOME = $HOME
1230 let $HOME = getcwd()
1231 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1232 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1233 let $HOME = save_HOME
1234 cd ..
1235 call delete('Xdir', 'rf')
1236endfunc
1237
Bram Moolenaar578fe942020-02-27 21:32:51 +01001238" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1239" or insert mode (when 'insertmode' is set)
1240func Test_cmdline_ctrl_g()
1241 new
1242 call setline(1, 'abc')
1243 call cursor(1, 3)
1244 " If command line is entered from insert mode, using C-\ C-G should back to
1245 " insert mode
1246 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1247 call assert_equal('abxyc', getline(1))
1248 call assert_equal(4, col('.'))
1249
1250 " If command line is entered in 'insertmode', using C-\ C-G should back to
1251 " 'insertmode'
1252 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1253 call assert_equal('ab12xyc', getline(1))
1254 close!
1255endfunc
1256
Bram Moolenaar578fe942020-02-27 21:32:51 +01001257" Test for 'wildmode'
1258func Test_wildmode()
1259 func T(a, c, p)
1260 return "oneA\noneB\noneC"
1261 endfunc
1262 command -nargs=1 -complete=custom,T MyCmd
1263
1264 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001265 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001266 return ''
1267 endfunc
1268 cnoremap <expr> <F2> SaveScreenLine()
1269
1270 set nowildmenu
1271 set wildmode=full,list
1272 let g:Sline = ''
1273 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001274 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001275 call assert_equal('"MyCmd oneA', @:)
1276
1277 set wildmode=longest,full
1278 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1279 call assert_equal('"MyCmd one', @:)
1280 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1281 call assert_equal('"MyCmd oneC', @:)
1282
1283 set wildmode=longest
1284 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1285 call assert_equal('"MyCmd one', @:)
1286
1287 set wildmode=list:longest
1288 let g:Sline = ''
1289 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001290 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001291 call assert_equal('"MyCmd one', @:)
1292
1293 set wildmode=""
1294 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1295 call assert_equal('"MyCmd oneA', @:)
1296
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001297 " Test for wildmode=longest with 'fileignorecase' set
1298 set wildmode=longest
1299 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001300 argadd AAA AAAA AAAAA
1301 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1302 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001303 set fileignorecase&
1304
1305 " Test for listing files with wildmode=list
1306 set wildmode=list
1307 let g:Sline = ''
1308 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001309 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001310 call assert_equal('"b A', @:)
1311
1312 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001313 delcommand MyCmd
1314 delfunc T
1315 delfunc SaveScreenLine
1316 cunmap <F2>
1317 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001318 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001319endfunc
1320
1321" Test for interrupting the command-line completion
1322func Test_interrupt_compl()
1323 func F(lead, cmdl, p)
1324 if a:lead =~ 'tw'
1325 call interrupt()
1326 return
1327 endif
1328 return "one\ntwo\nthree"
1329 endfunc
1330 command -nargs=1 -complete=custom,F Tcmd
1331
1332 set nowildmenu
1333 set wildmode=full
1334 let interrupted = 0
1335 try
1336 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1337 catch /^Vim:Interrupt$/
1338 let interrupted = 1
1339 endtry
1340 call assert_equal(1, interrupted)
1341
1342 delcommand Tcmd
1343 delfunc F
1344 set wildmode&
1345endfunc
1346
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001347" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001348func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001349 let str = ":one two\<C-U>"
1350 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001351 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001352 let str ..= "\<Left>five\<Right>"
1353 let str ..= "\<Home>two "
1354 let str ..= "\<C-Left>one "
1355 let str ..= "\<C-Right> three"
1356 let str ..= "\<End>\<S-Left>four "
1357 let str ..= "\<S-Right> six"
1358 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1359 call feedkeys(str, 'xt')
1360 call assert_equal("\"one two three four five six seven", @:)
1361endfunc
1362
1363" Test for moving the cursor on the / command line in 'rightleft' mode
1364func Test_cmdline_edit_rightleft()
1365 CheckFeature rightleft
1366 set rightleft
1367 set rightleftcmd=search
1368 let str = "/one two\<C-U>"
1369 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001370 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001371 let str ..= "\<Right>five\<Left>"
1372 let str ..= "\<Home>two "
1373 let str ..= "\<C-Right>one "
1374 let str ..= "\<C-Left> three"
1375 let str ..= "\<End>\<S-Right>four "
1376 let str ..= "\<S-Left> six"
1377 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1378 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1379 call assert_equal("\"one two three four five six seven", @/)
1380 set rightleftcmd&
1381 set rightleft&
1382endfunc
1383
1384" Test for using <C-\>e in the command line to evaluate an expression
1385func Test_cmdline_expr()
1386 " Evaluate an expression from the beginning of a command line
1387 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1388 call assert_equal('"hello', @:)
1389
1390 " Use an invalid expression for <C-\>e
1391 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1392
1393 " Insert literal <CTRL-\> in the command line
1394 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1395 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001396endfunc
1397
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001398" Test for 'imcmdline' and 'imsearch'
1399" This test doesn't actually test the input method functionality.
1400func Test_cmdline_inputmethod()
1401 new
1402 call setline(1, ['', 'abc', ''])
1403 set imcmdline
1404
1405 call feedkeys(":\"abc\<CR>", 'xt')
1406 call assert_equal("\"abc", @:)
1407 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1408 call assert_equal("\"abc", @:)
1409 call feedkeys("/abc\<CR>", 'xt')
1410 call assert_equal([2, 1], [line('.'), col('.')])
1411 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1412 call assert_equal([2, 1], [line('.'), col('.')])
1413
1414 set imsearch=2
1415 call cursor(1, 1)
1416 call feedkeys("/abc\<CR>", 'xt')
1417 call assert_equal([2, 1], [line('.'), col('.')])
1418 call cursor(1, 1)
1419 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1420 call assert_equal([2, 1], [line('.'), col('.')])
1421 set imdisable
1422 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1423 call assert_equal([2, 1], [line('.'), col('.')])
1424 set imdisable&
1425 set imsearch&
1426
1427 set imcmdline&
1428 %bwipe!
1429endfunc
1430
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001431" Test for recursively getting multiple command line inputs
1432func Test_cmdwin_multi_input()
1433 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1434 call assert_equal('"cyan', @:)
1435endfunc
1436
1437" Test for using CTRL-_ in the command line with 'allowrevins'
1438func Test_cmdline_revins()
1439 CheckNotMSWindows
1440 CheckFeature rightleft
1441 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1442 call assert_equal("\"abc\<c-_>", @:)
1443 set allowrevins
1444 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1445 call assert_equal('"abcñèæ', @:)
1446 set allowrevins&
1447endfunc
1448
1449" Test for typing UTF-8 composing characters in the command line
1450func Test_cmdline_composing_chars()
1451 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1452 call assert_equal('"ゔ', @:)
1453endfunc
1454
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001455" Test for normal mode commands not supported in the cmd window
1456func Test_cmdwin_blocked_commands()
1457 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1458 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1459 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1460 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1461 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1462 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
1463endfunc
1464
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001465" Close the Cmd-line window in insert mode using CTRL-C
1466func Test_cmdwin_insert_mode_close()
1467 %bw!
1468 let s = ''
1469 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1470 call assert_equal('Hello', s)
1471 call assert_equal(1, winnr('$'))
1472endfunc
1473
Bram Moolenaar309976e2019-12-05 18:16:33 +01001474" vim: shiftwidth=2 sts=2 expandtab