blob: 545f09b16f605b236bc3d9d195f19f5f1923baf1 [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
5
Bram Moolenaarae3150e2016-06-11 23:22:36 +02006func Test_complete_tab()
7 call writefile(['testfile'], 'Xtestfile')
8 call feedkeys(":e Xtest\t\r", "tx")
9 call assert_equal('testfile', getline(1))
10 call delete('Xtestfile')
11endfunc
12
13func Test_complete_list()
14 " We can't see the output, but at least we check the code runs properly.
15 call feedkeys(":e test\<C-D>\r", "tx")
16 call assert_equal('test', expand('%:t'))
17endfunc
18
19func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010020 call mkdir('Xdir1/Xdir2', 'p')
21 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
22 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
23 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
24 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020025 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010026
27 " Pressing <Tab> completes, and moves to next files when pressing again.
28 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
29 call assert_equal('testfile1', getline(1))
30 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020031 call assert_equal('testfile2', getline(1))
32
Bram Moolenaar37db6422019-03-28 21:26:23 +010033 " <S-Tab> is like <Tab> but begin with the last match and then go to
34 " previous.
35 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
36 call assert_equal('testfile2', getline(1))
37 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
38 call assert_equal('testfile1', getline(1))
39
40 " <Left>/<Right> to move to previous/next file.
41 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
42 call assert_equal('testfile1', getline(1))
43 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
44 call assert_equal('testfile2', getline(1))
45 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
46 call assert_equal('testfile1', getline(1))
47
48 " <Up>/<Down> to go up/down directories.
49 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
50 call assert_equal('testfile3', getline(1))
51 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
52 call assert_equal('testfile1', getline(1))
53
54 " cleanup
55 %bwipe
56 call delete('Xdir1/Xdir2/Xtestfile4')
57 call delete('Xdir1/Xdir2/Xtestfile3')
58 call delete('Xdir1/Xtestfile2')
59 call delete('Xdir1/Xtestfile1')
60 call delete('Xdir1/Xdir2', 'd')
61 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020062 set nowildmenu
63endfunc
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020064
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +010065func Test_map_completion()
66 if !has('cmdline_compl')
67 return
68 endif
69 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
70 call assert_equal('"map <unique> <silent>', getreg(':'))
71 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
72 call assert_equal('"map <script> <unique>', getreg(':'))
73 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
74 call assert_equal('"map <expr> <script>', getreg(':'))
75 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
76 call assert_equal('"map <buffer> <expr>', getreg(':'))
77 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
78 call assert_equal('"map <nowait> <buffer>', getreg(':'))
79 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
80 call assert_equal('"map <special> <nowait>', getreg(':'))
81 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
82 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020083
Bram Moolenaar1776a282019-05-03 16:05:41 +020084 map <Middle>x middle
85
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020086 map ,f commaf
87 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +020088 map <Left> left
89 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020090 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
91 call assert_equal('"map ,f', getreg(':'))
92 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
93 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +020094 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
95 call assert_equal('"map <Left>', getreg(':'))
96 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +020097 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020098 unmap ,f
99 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200100 unmap <Left>
101 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200102
103 set cpo-=< cpo-=B cpo-=k
104 map <Left> left
105 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
106 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200107 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200108 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200109 unmap <Left>
110
111 set cpo+=<
112 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200113 exe "set t_k6=\<Esc>[17~"
114 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200115 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
116 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200117 if !has('gui_running')
118 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
119 call assert_equal("\"map <F6>x", getreg(':'))
120 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200121 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200122 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200123 set cpo-=<
124
125 set cpo+=B
126 map <Left> left
127 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
128 call assert_equal('"map <Left>', getreg(':'))
129 unmap <Left>
130 set cpo-=B
131
132 set cpo+=k
133 map <Left> left
134 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
135 call assert_equal('"map <Left>', getreg(':'))
136 unmap <Left>
137 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200138
139 unmap <Middle>x
140 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100141endfunc
142
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100143func Test_match_completion()
144 if !has('cmdline_compl')
145 return
146 endif
147 hi Aardig ctermfg=green
148 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
149 call assert_equal('"match Aardig', getreg(':'))
150 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
151 call assert_equal('"match none', getreg(':'))
152endfunc
153
154func Test_highlight_completion()
155 if !has('cmdline_compl')
156 return
157 endif
158 hi Aardig ctermfg=green
159 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
160 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200161 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
162 call assert_equal('"hi default Aardig', getreg(':'))
163 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
164 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100165 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
166 call assert_equal('"hi link', getreg(':'))
167 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
168 call assert_equal('"hi default', getreg(':'))
169 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
170 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200171
172 " A cleared group does not show up in completions.
173 hi Anders ctermfg=green
174 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
175 hi clear Aardig
176 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
177 hi clear Anders
178 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100179endfunc
180
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100181func Test_expr_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100182 if !has('cmdline_compl')
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100183 return
184 endif
185 for cmd in [
186 \ 'let a = ',
Bram Moolenaar8f76e6b2019-11-26 16:50:30 +0100187 \ 'const a = ',
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100188 \ 'if',
189 \ 'elseif',
190 \ 'while',
191 \ 'for',
192 \ 'echo',
193 \ 'echon',
194 \ 'execute',
195 \ 'echomsg',
196 \ 'echoerr',
197 \ 'call',
198 \ 'return',
199 \ 'cexpr',
200 \ 'caddexpr',
201 \ 'cgetexpr',
202 \ 'lexpr',
203 \ 'laddexpr',
204 \ 'lgetexpr']
205 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt')
206 call assert_equal('"' . cmd . ' getline(', getreg(':'))
207 endfor
208endfunc
209
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200210func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200211 if !has('cmdline_compl')
212 return
213 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200214 let groupcount = len(getcompletion('', 'event'))
215 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200216 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200217 call assert_true(matchcount > 0)
218 call assert_true(groupcount > matchcount)
219
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200220 if has('menu')
221 source $VIMRUNTIME/menu.vim
222 let matchcount = len(getcompletion('', 'menu'))
223 call assert_true(matchcount > 0)
224 call assert_equal(['File.'], getcompletion('File', 'menu'))
225 call assert_true(matchcount > 0)
226 let matchcount = len(getcompletion('File.', 'menu'))
227 call assert_true(matchcount > 0)
228 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200229
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200230 let l = getcompletion('v:n', 'var')
231 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200232 let l = getcompletion('v:notexists', 'var')
233 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200234
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200235 args a.c b.c
236 let l = getcompletion('', 'arglist')
237 call assert_equal(['a.c', 'b.c'], l)
238 %argdelete
239
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200240 let l = getcompletion('', 'augroup')
241 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200242 let l = getcompletion('blahblah', 'augroup')
243 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200244
245 let l = getcompletion('', 'behave')
246 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200247 let l = getcompletion('not', 'behave')
248 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200249
250 let l = getcompletion('', 'color')
251 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200252 let l = getcompletion('dirty', 'color')
253 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200254
255 let l = getcompletion('', 'command')
256 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200257 let l = getcompletion('awake', 'command')
258 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200259
260 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200261 call assert_true(index(l, 'samples/') >= 0)
262 let l = getcompletion('NoMatch', 'dir')
263 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200264
265 let l = getcompletion('exe', 'expression')
266 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200267 let l = getcompletion('kill', 'expression')
268 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200269
270 let l = getcompletion('tag', 'function')
271 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200272 let l = getcompletion('paint', 'function')
273 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200274
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200275 let Flambda = {-> 'hello'}
276 let l = getcompletion('', 'function')
277 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200278 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200279
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200280 let l = getcompletion('run', 'file')
281 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200282 let l = getcompletion('walk', 'file')
283 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200284 set wildignore=*.vim
285 let l = getcompletion('run', 'file', 1)
286 call assert_true(index(l, 'runtest.vim') < 0)
287 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200288
289 let l = getcompletion('ha', 'filetype')
290 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200291 let l = getcompletion('horse', 'filetype')
292 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200293
294 let l = getcompletion('z', 'syntax')
295 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200296 let l = getcompletion('emacs', 'syntax')
297 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200298
299 let l = getcompletion('jikes', 'compiler')
300 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200301 let l = getcompletion('break', 'compiler')
302 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200303
304 let l = getcompletion('last', 'help')
305 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200306 let l = getcompletion('giveup', 'help')
307 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200308
309 let l = getcompletion('time', 'option')
310 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200311 let l = getcompletion('space', 'option')
312 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200313
314 let l = getcompletion('er', 'highlight')
315 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200316 let l = getcompletion('dark', 'highlight')
317 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200318
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200319 let l = getcompletion('', 'messages')
320 call assert_true(index(l, 'clear') >= 0)
321 let l = getcompletion('not', 'messages')
322 call assert_equal([], l)
323
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200324 let l = getcompletion('', 'mapclear')
325 call assert_true(index(l, '<buffer>') >= 0)
326 let l = getcompletion('not', 'mapclear')
327 call assert_equal([], l)
328
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200329 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200330 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200331 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
332 let root = has('win32') ? 'C:\\' : '/'
333 let l = getcompletion(root, 'shellcmd')
334 let expected = map(filter(glob(root . '*', 0, 1),
335 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
336 call assert_equal(expected, l)
337
Bram Moolenaarb650b982016-08-05 20:35:13 +0200338 if has('cscope')
339 let l = getcompletion('', 'cscope')
340 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
341 call assert_equal(cmds, l)
342 " using cmdline completion must not change the result
343 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
344 let l = getcompletion('', 'cscope')
345 call assert_equal(cmds, l)
346 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
347 let l = getcompletion('find ', 'cscope')
348 call assert_equal(keys, l)
349 endif
350
Bram Moolenaar7522f692016-08-06 14:12:50 +0200351 if has('signs')
352 sign define Testing linehl=Comment
353 let l = getcompletion('', 'sign')
354 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
355 call assert_equal(cmds, l)
356 " using cmdline completion must not change the result
357 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
358 let l = getcompletion('', 'sign')
359 call assert_equal(cmds, l)
360 let l = getcompletion('list ', 'sign')
361 call assert_equal(['Testing'], l)
362 endif
363
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200364 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200365 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200366 if has('cmdline_hist')
367 call add(names, 'history')
368 endif
369 if has('gettext')
370 call add(names, 'locale')
371 endif
372 if has('profile')
373 call add(names, 'syntime')
374 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200375
376 set tags=Xtags
377 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
378
379 for name in names
380 let matchcount = len(getcompletion('', name))
381 call assert_true(matchcount >= 0, 'No matches for ' . name)
382 endfor
383
384 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200385 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200386
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200387 call assert_fails('call getcompletion("", "burp")', 'E475:')
388endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200389
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200390func Test_shellcmd_completion()
391 let save_path = $PATH
392
393 call mkdir('Xpathdir/Xpathsubdir', 'p')
394 call writefile([''], 'Xpathdir/Xfile.exe')
395 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
396
397 " Set PATH to example directory without trailing slash.
398 let $PATH = getcwd() . '/Xpathdir'
399
400 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
401 " dirs in the PATH, even though they won't be executed. We check that only
402 " subdirs of the PWD and executables from the PATH are included in the
403 " suggestions.
404 let actual = getcompletion('X', 'shellcmd')
405 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
406 call insert(expected, 'Xfile.exe')
407 call assert_equal(expected, actual)
408
409 call delete('Xpathdir', 'rf')
410 let $PATH = save_path
411endfunc
412
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200413func Test_expand_star_star()
414 call mkdir('a/b', 'p')
415 call writefile(['asdfasdf'], 'a/b/fileXname')
416 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
417 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200418 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200419 call delete('a', 'rf')
420endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100421
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100422func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100423 let @a = "def"
424 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
425 call assert_equal('"abc def ghi', @:)
426
427 new
428 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
429
430 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
431 call assert_equal('"aaa asdf bbb', @:)
432
433 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
434 call assert_equal('"aaa /tmp/some bbb', @:)
435
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200436 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
437 call assert_equal('"aaa '.getline(1).' bbb', @:)
438
Bram Moolenaar21efc362016-12-03 14:05:49 +0100439 set incsearch
440 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
441 call assert_equal('"aaa verylongword bbb', @:)
442
443 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
444 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100445
446 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
447 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100448 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200449
450 " Error while typing a command used to cause that it was not executed
451 " in the end.
452 new
453 try
454 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
455 catch /^Vim\%((\a\+)\)\=:E32/
456 " ignore error E32
457 endtry
458 call assert_equal("Xtestfile", bufname("%"))
459 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100460endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100461
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100462func Test_cmdline_remove_char()
463 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100464
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100465 for e in ['utf8', 'latin1']
466 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100467
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100468 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
469 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100470
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100471 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
472 call assert_equal('"abcdef', @:)
473
474 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
475 call assert_equal('"abc ghi', @:, e)
476
477 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
478 call assert_equal('"def', @:, e)
479 endfor
480
481 let &encoding = encoding_save
482endfunc
483
484func Test_cmdline_keymap_ctrl_hat()
485 if !has('keymap')
486 return
487 endif
488
489 set keymap=esperanto
490 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
491 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
492 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100493endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100494
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100495func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100496 new
497 2;'(
498 2;')
499 quit
500endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100501
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100502func Test_illegal_address2()
503 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
504 new
505 source Xtest.vim
506 " Trigger calling validate_cursor()
507 diffsp Xtest.vim
508 quit!
509 bwipe!
510 call delete('Xtest.vim')
511endfunc
512
Bram Moolenaarba47b512017-01-24 21:18:19 +0100513func Test_cmdline_complete_wildoptions()
514 help
515 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
516 let a = join(sort(split(@:)),' ')
517 set wildoptions=tagfile
518 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
519 let b = join(sort(split(@:)),' ')
520 call assert_equal(a, b)
521 bw!
522endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100523
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200524func Test_cmdline_complete_user_cmd()
525 command! -complete=color -nargs=1 Foo :
526 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
527 call assert_equal('"Foo blue', @:)
528 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
529 call assert_equal('"Foo blue', @:)
530 delcommand Foo
531endfunc
532
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200533func Test_cmdline_complete_user_names()
534 if has('unix') && executable('whoami')
535 let whoami = systemlist('whoami')[0]
536 let first_letter = whoami[0]
537 if len(first_letter) > 0
538 " Trying completion of :e ~x where x is the first letter of
539 " the user name should complete to at least the user name.
540 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
541 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
542 endif
543 endif
544 if has('win32')
545 " Just in case: check that the system has an Administrator account.
546 let names = system('net user')
547 if names =~ 'Administrator'
548 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100549 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200550 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100551 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200552 endif
553 endif
554endfunc
555
Bram Moolenaar297610b2019-12-27 17:20:55 +0100556func Test_cmdline_complete_bang()
557 if executable('whoami')
Bram Moolenaar731a7992019-12-28 14:06:50 +0100558 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
559 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100560 endif
Bram Moolenaar297610b2019-12-27 17:20:55 +0100561endfunc
562
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200563funct Test_cmdline_complete_languages()
564 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
565
566 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
567 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
568
569 if has('unix')
570 " TODO: these tests don't work on Windows. lang appears to be 'C'
571 " but C does not appear in the completion. Why?
572 call assert_match('^"language .*\<' . lang . '\>', @:)
573
574 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
575 call assert_match('^"language .*\<' . lang . '\>', @:)
576
577 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
578 call assert_match('^"language .*\<' . lang . '\>', @:)
579
580 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
581 call assert_match('^"language .*\<' . lang . '\>', @:)
582 endif
583endfunc
584
Bram Moolenaar297610b2019-12-27 17:20:55 +0100585func Test_cmdline_complete_env_variable()
586 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
587
588 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
589 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
590
591 unlet $X_VIM_TEST_COMPLETE_ENV
592endfunc
593
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200594func Test_cmdline_write_alternatefile()
595 new
596 call setline('.', ['one', 'two'])
597 f foo.txt
598 new
599 f #-A
600 call assert_equal('foo.txt-A', expand('%'))
601 f #<-B.txt
602 call assert_equal('foo-B.txt', expand('%'))
603 f %<
604 call assert_equal('foo-B', expand('%'))
605 new
606 call assert_fails('f #<', 'E95')
607 bw!
608 f foo-B.txt
609 f %<-A
610 call assert_equal('foo-B-A', expand('%'))
611 bw!
612 bw!
613endfunc
614
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100615" using a leading backslash here
616set cpo+=C
617
618func Test_cmdline_search_range()
619 new
620 call setline(1, ['a', 'b', 'c', 'd'])
621 /d
622 1,\/s/b/B/
623 call assert_equal('B', getline(2))
624
625 /a
626 $
627 \?,4s/c/C/
628 call assert_equal('C', getline(3))
629
630 call setline(1, ['a', 'b', 'c', 'd'])
631 %s/c/c/
632 1,\&s/b/B/
633 call assert_equal('B', getline(2))
634
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100635 let @/ = 'apple'
636 call assert_fails('\/print', 'E486:')
637
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100638 bwipe!
639endfunc
640
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100641" Test for the tick mark (') in an excmd range
642func Test_tick_mark_in_range()
643 " If only the tick is passed as a range and no command is specified, there
644 " should not be an error
645 call feedkeys(":'\<CR>", 'xt')
646 call assert_equal("'", getreg(':'))
647 call assert_fails("',print", 'E78:')
648endfunc
649
650" Test for using a line number followed by a search pattern as range
651func Test_lnum_and_pattern_as_range()
652 new
653 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
654 let @" = ''
655 2/foo/yank
656 call assert_equal("foo 3\n", @")
657 call assert_equal(1, line('.'))
658 close!
659endfunc
660
Bram Moolenaar65189a12017-02-06 22:22:17 +0100661" Tests for getcmdline(), getcmdpos() and getcmdtype()
662func Check_cmdline(cmdtype)
663 call assert_equal('MyCmd a', getcmdline())
664 call assert_equal(8, getcmdpos())
665 call assert_equal(a:cmdtype, getcmdtype())
666 return ''
667endfunc
668
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200669set cpo&
670
Bram Moolenaar65189a12017-02-06 22:22:17 +0100671func Test_getcmdtype()
672 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
673
674 let cmdtype = ''
675 debuggreedy
676 call feedkeys(":debug echo 'test'\<CR>", "t")
677 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
678 call feedkeys("cont\<CR>", "xt")
679 0debuggreedy
680 call assert_equal('>', cmdtype)
681
682 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
683 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
684
685 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +0100686 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +0100687
688 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
689
690 cnoremap <expr> <F6> Check_cmdline('=')
691 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
692 cunmap <F6>
693endfunc
694
Bram Moolenaar81612b72018-06-23 14:55:03 +0200695func Test_getcmdwintype()
696 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
697 call assert_equal('/', a)
698
699 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
700 call assert_equal('?', a)
701
702 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
703 call assert_equal(':', a)
704
705 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
706 call assert_equal(':', a)
707
708 call assert_equal('', getcmdwintype())
709endfunc
710
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200711func Test_getcmdwin_autocmd()
712 let s:seq = []
713 augroup CmdWin
714 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
715 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
716 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
717 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
718 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
719 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
720
721 let org_winid = win_getid()
722 let org_bufnr = bufnr()
723 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
724 call assert_equal(':', a)
725 call assert_equal([
726 \ 'WinLeave ' .. org_winid,
727 \ 'WinEnter ' .. s:cmd_winid,
728 \ 'BufLeave ' .. org_bufnr,
729 \ 'BufEnter ' .. s:cmd_bufnr,
730 \ 'CmdWinEnter ' .. s:cmd_winid,
731 \ 'CmdWinLeave ' .. s:cmd_winid,
732 \ 'BufLeave ' .. s:cmd_bufnr,
733 \ 'WinLeave ' .. s:cmd_winid,
734 \ 'WinEnter ' .. org_winid,
735 \ 'BufEnter ' .. org_bufnr,
736 \ ], s:seq)
737
738 au!
739 augroup END
740endfunc
741
Bram Moolenaar52604f22017-04-07 16:17:39 +0200742func Test_verbosefile()
743 set verbosefile=Xlog
744 echomsg 'foo'
745 echomsg 'bar'
746 set verbosefile=
747 let log = readfile('Xlog')
748 call assert_match("foo\nbar", join(log, "\n"))
749 call delete('Xlog')
750endfunc
751
Bram Moolenaar4facea32019-10-12 20:17:40 +0200752func Test_verbose_option()
753 CheckScreendump
754
755 let lines =<< trim [SCRIPT]
756 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
757 call feedkeys("\r", 't') " for the hit-enter prompt
758 set verbose=20
759 [SCRIPT]
760 call writefile(lines, 'XTest_verbose')
761
762 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
763 call term_wait(buf, 100)
764 call term_sendkeys(buf, ":DoSomething\<CR>")
765 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
766
767 " clean up
768 call StopVimInTerminal(buf)
769 call delete('XTest_verbose')
770endfunc
771
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200772func Test_setcmdpos()
773 func InsertTextAtPos(text, pos)
774 call assert_equal(0, setcmdpos(a:pos))
775 return a:text
776 endfunc
777
778 " setcmdpos() with position in the middle of the command line.
779 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
780 call assert_equal('"1ab2', @:)
781
782 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
783 call assert_equal('"1b2a', @:)
784
785 " setcmdpos() with position beyond the end of the command line.
786 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
787 call assert_equal('"12ab', @:)
788
789 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +0200790 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200791endfunc
792
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100793func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100794 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100795 let encoding_save = &encoding
796
797 for e in encodings
798 exe 'set encoding=' . e
799
800 " Test overstrike in the middle of the command line.
801 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100802 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100803
804 " Test overstrike going beyond end of command line.
805 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100806 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100807
808 " Test toggling insert/overstrike a few times.
809 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100810 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100811 endfor
812
Bram Moolenaar30276f22019-01-24 17:59:39 +0100813 " Test overstrike with multi-byte characters.
814 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100815 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100816
817 let &encoding = encoding_save
818endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +0200819
820func Test_cmdwin_bug()
821 let winid = win_getid()
822 sp
823 try
824 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
825 catch /^Vim\%((\a\+)\)\=:E11/
826 endtry
827 bw!
828endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +0100829
Bram Moolenaar1c329c02019-10-27 20:37:35 +0100830func Test_cmdwin_restore()
831 CheckScreendump
832
833 let lines =<< trim [SCRIPT]
834 call setline(1, range(30))
835 2split
836 [SCRIPT]
837 call writefile(lines, 'XTest_restore')
838
839 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
840 call term_wait(buf, 100)
841 call term_sendkeys(buf, "q:")
842 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
843
844 " normal restore
845 call term_sendkeys(buf, ":q\<CR>")
846 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
847
848 " restore after setting 'lines' with one window
849 call term_sendkeys(buf, ":close\<CR>")
850 call term_sendkeys(buf, "q:")
851 call term_sendkeys(buf, ":set lines=18\<CR>")
852 call term_sendkeys(buf, ":q\<CR>")
853 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
854
855 " clean up
856 call StopVimInTerminal(buf)
857 call delete('XTest_restore')
858endfunc
859
Bram Moolenaar52410572019-10-27 05:12:45 +0100860func Test_buffers_lastused()
861 " check that buffers are sorted by time when wildmode has lastused
862 call test_settime(1550020000) " middle
863 edit bufa
864 enew
865 call test_settime(1550030000) " newest
866 edit bufb
867 enew
868 call test_settime(1550010000) " oldest
869 edit bufc
870 enew
871 call test_settime(0)
872 enew
873
874 call assert_equal(['bufa', 'bufb', 'bufc'],
875 \ getcompletion('', 'buffer'))
876
877 let save_wildmode = &wildmode
878 set wildmode=full:lastused
879
880 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
881 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
882 call assert_equal('b bufb', X)
883 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
884 call assert_equal('b bufa', X)
885 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
886 call assert_equal('b bufc', X)
887 enew
888
889 edit other
890 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
891 call assert_equal('b bufb', X)
892 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
893 call assert_equal('b bufa', X)
894 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
895 call assert_equal('b bufc', X)
896 enew
897
898 let &wildmode = save_wildmode
899
900 bwipeout bufa
901 bwipeout bufb
902 bwipeout bufc
903endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +0100904
905func Test_cmdwin_feedkeys()
906 " This should not generate E488
907 call feedkeys("q:\<CR>", 'x')
908endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +0100909
910" Tests for the issues fixed in 7.4.441.
911" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
912func Test_cmdwin_cedit()
913 exe "set cedit=\<C-c>"
914 normal! :
915 call assert_equal(1, winnr('$'))
916
917 let g:cmd_wintype = ''
918 func CmdWinType()
919 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +0100920 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +0100921 return ''
922 endfunc
923
924 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
925 echo input('')
926 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +0100927 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +0100928
929 set cedit&vim
930 delfunc CmdWinType
931endfunc
932
Bram Moolenaar479950f2020-01-19 15:45:17 +0100933func Test_cmdlineclear_tabenter()
934 CheckScreendump
935
936 let lines =<< trim [SCRIPT]
937 call setline(1, range(30))
938 [SCRIPT]
939
940 call writefile(lines, 'XtestCmdlineClearTabenter')
941 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
942 call term_wait(buf, 50)
943 " in one tab make the command line higher with CTRL-W -
944 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
945 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
946
947 call StopVimInTerminal(buf)
948 call delete('XtestCmdlineClearTabenter')
949endfunc
950
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100951" Test for failure in expanding special keywords in cmdline
952func Test_cmdline_expand_special()
953 %bwipe!
954 call assert_fails('e #', 'E499:')
955 call assert_fails('e <afile>', 'E495:')
956 call assert_fails('e <abuf>', 'E496:')
957 call assert_fails('e <amatch>', 'E497:')
958endfunc
959
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100960func Test_cmdwin_jump_to_win()
961 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
962 new
963 set modified
964 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
965 close!
966 call feedkeys("q/:close\<CR>", "xt")
967 call assert_equal(1, winnr('$'))
968 call feedkeys("q/:exit\<CR>", "xt")
969 call assert_equal(1, winnr('$'))
970endfunc
971
972" Test for backtick expression in the command line
973func Test_cmd_backtick()
974 %argd
975 argadd `=['a', 'b', 'c']`
976 call assert_equal(['a', 'b', 'c'], argv())
977 %argd
978endfunc
979
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100980" Test for the :! command
981func Test_cmd_bang()
982 if !has('unix')
983 return
984 endif
985
986 let lines =<< trim [SCRIPT]
987 " Test for no previous command
988 call assert_fails('!!', 'E34:')
989 set nomore
990 " Test for cmdline expansion with :!
991 call setline(1, 'foo!')
992 silent !echo <cWORD> > Xfile.out
993 call assert_equal(['foo!'], readfile('Xfile.out'))
994 " Test for using previous command
995 silent !echo \! !
996 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
997 call writefile(v:errors, 'Xresult')
998 call delete('Xfile.out')
999 qall!
1000 [SCRIPT]
1001 call writefile(lines, 'Xscript')
1002 if RunVim([], [], '--clean -S Xscript')
1003 call assert_equal([], readfile('Xresult'))
1004 endif
1005 call delete('Xscript')
1006 call delete('Xresult')
1007endfunc
1008
Bram Moolenaar309976e2019-12-05 18:16:33 +01001009" vim: shiftwidth=2 sts=2 expandtab