blob: fa3446ad1a77a94d28b9a0f94dd76cd3f4951a37 [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
Bram Moolenaar8d588cc2020-02-25 21:47:45 +010054 " Completion using a relative path
55 cd Xdir1/Xdir2
56 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
57 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
58 cd -
59
Bram Moolenaar37db6422019-03-28 21:26:23 +010060 " cleanup
61 %bwipe
62 call delete('Xdir1/Xdir2/Xtestfile4')
63 call delete('Xdir1/Xdir2/Xtestfile3')
64 call delete('Xdir1/Xtestfile2')
65 call delete('Xdir1/Xtestfile1')
66 call delete('Xdir1/Xdir2', 'd')
67 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020068 set nowildmenu
69endfunc
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020070
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +010071func Test_map_completion()
72 if !has('cmdline_compl')
73 return
74 endif
75 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
76 call assert_equal('"map <unique> <silent>', getreg(':'))
77 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
78 call assert_equal('"map <script> <unique>', getreg(':'))
79 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
80 call assert_equal('"map <expr> <script>', getreg(':'))
81 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
82 call assert_equal('"map <buffer> <expr>', getreg(':'))
83 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
84 call assert_equal('"map <nowait> <buffer>', getreg(':'))
85 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
86 call assert_equal('"map <special> <nowait>', getreg(':'))
87 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
88 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020089
Bram Moolenaar1776a282019-05-03 16:05:41 +020090 map <Middle>x middle
91
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020092 map ,f commaf
93 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +020094 map <Left> left
95 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +020096 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
97 call assert_equal('"map ,f', getreg(':'))
98 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
99 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200100 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
101 call assert_equal('"map <Left>', getreg(':'))
102 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200103 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200104 unmap ,f
105 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200106 unmap <Left>
107 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200108
109 set cpo-=< cpo-=B cpo-=k
110 map <Left> left
111 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
112 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200113 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200114 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200115 unmap <Left>
116
117 set cpo+=<
118 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200119 exe "set t_k6=\<Esc>[17~"
120 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200121 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
122 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200123 if !has('gui_running')
124 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
125 call assert_equal("\"map <F6>x", getreg(':'))
126 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200127 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200128 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200129 set cpo-=<
130
131 set cpo+=B
132 map <Left> left
133 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
134 call assert_equal('"map <Left>', getreg(':'))
135 unmap <Left>
136 set cpo-=B
137
138 set cpo+=k
139 map <Left> left
140 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
141 call assert_equal('"map <Left>', getreg(':'))
142 unmap <Left>
143 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200144
145 unmap <Middle>x
146 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100147endfunc
148
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100149func Test_match_completion()
150 if !has('cmdline_compl')
151 return
152 endif
153 hi Aardig ctermfg=green
154 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
155 call assert_equal('"match Aardig', getreg(':'))
156 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
157 call assert_equal('"match none', getreg(':'))
158endfunc
159
160func Test_highlight_completion()
161 if !has('cmdline_compl')
162 return
163 endif
164 hi Aardig ctermfg=green
165 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
166 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200167 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
168 call assert_equal('"hi default Aardig', getreg(':'))
169 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
170 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100171 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
172 call assert_equal('"hi link', getreg(':'))
173 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
174 call assert_equal('"hi default', getreg(':'))
175 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
176 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200177
178 " A cleared group does not show up in completions.
179 hi Anders ctermfg=green
180 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
181 hi clear Aardig
182 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
183 hi clear Anders
184 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100185endfunc
186
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100187func Test_expr_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100188 if !has('cmdline_compl')
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100189 return
190 endif
191 for cmd in [
192 \ 'let a = ',
Bram Moolenaar8f76e6b2019-11-26 16:50:30 +0100193 \ 'const a = ',
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100194 \ 'if',
195 \ 'elseif',
196 \ 'while',
197 \ 'for',
198 \ 'echo',
199 \ 'echon',
200 \ 'execute',
201 \ 'echomsg',
202 \ 'echoerr',
203 \ 'call',
204 \ 'return',
205 \ 'cexpr',
206 \ 'caddexpr',
207 \ 'cgetexpr',
208 \ 'lexpr',
209 \ 'laddexpr',
210 \ 'lgetexpr']
211 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt')
212 call assert_equal('"' . cmd . ' getline(', getreg(':'))
213 endfor
214endfunc
215
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200216func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200217 if !has('cmdline_compl')
218 return
219 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200220 let groupcount = len(getcompletion('', 'event'))
221 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200222 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200223 call assert_true(matchcount > 0)
224 call assert_true(groupcount > matchcount)
225
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200226 if has('menu')
227 source $VIMRUNTIME/menu.vim
228 let matchcount = len(getcompletion('', 'menu'))
229 call assert_true(matchcount > 0)
230 call assert_equal(['File.'], getcompletion('File', 'menu'))
231 call assert_true(matchcount > 0)
232 let matchcount = len(getcompletion('File.', 'menu'))
233 call assert_true(matchcount > 0)
234 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200235
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200236 let l = getcompletion('v:n', 'var')
237 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200238 let l = getcompletion('v:notexists', 'var')
239 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200240
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200241 args a.c b.c
242 let l = getcompletion('', 'arglist')
243 call assert_equal(['a.c', 'b.c'], l)
244 %argdelete
245
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200246 let l = getcompletion('', 'augroup')
247 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200248 let l = getcompletion('blahblah', 'augroup')
249 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200250
251 let l = getcompletion('', 'behave')
252 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200253 let l = getcompletion('not', 'behave')
254 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200255
256 let l = getcompletion('', 'color')
257 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200258 let l = getcompletion('dirty', 'color')
259 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200260
261 let l = getcompletion('', 'command')
262 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200263 let l = getcompletion('awake', 'command')
264 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200265
266 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200267 call assert_true(index(l, 'samples/') >= 0)
268 let l = getcompletion('NoMatch', 'dir')
269 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200270
271 let l = getcompletion('exe', 'expression')
272 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200273 let l = getcompletion('kill', 'expression')
274 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200275
276 let l = getcompletion('tag', 'function')
277 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200278 let l = getcompletion('paint', 'function')
279 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200280
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200281 let Flambda = {-> 'hello'}
282 let l = getcompletion('', 'function')
283 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200284 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200285
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200286 let l = getcompletion('run', 'file')
287 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200288 let l = getcompletion('walk', 'file')
289 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200290 set wildignore=*.vim
291 let l = getcompletion('run', 'file', 1)
292 call assert_true(index(l, 'runtest.vim') < 0)
293 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200294
295 let l = getcompletion('ha', 'filetype')
296 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200297 let l = getcompletion('horse', 'filetype')
298 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200299
300 let l = getcompletion('z', 'syntax')
301 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200302 let l = getcompletion('emacs', 'syntax')
303 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200304
305 let l = getcompletion('jikes', 'compiler')
306 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200307 let l = getcompletion('break', 'compiler')
308 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200309
310 let l = getcompletion('last', 'help')
311 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200312 let l = getcompletion('giveup', 'help')
313 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200314
315 let l = getcompletion('time', 'option')
316 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200317 let l = getcompletion('space', 'option')
318 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200319
320 let l = getcompletion('er', 'highlight')
321 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200322 let l = getcompletion('dark', 'highlight')
323 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200324
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200325 let l = getcompletion('', 'messages')
326 call assert_true(index(l, 'clear') >= 0)
327 let l = getcompletion('not', 'messages')
328 call assert_equal([], l)
329
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200330 let l = getcompletion('', 'mapclear')
331 call assert_true(index(l, '<buffer>') >= 0)
332 let l = getcompletion('not', 'mapclear')
333 call assert_equal([], l)
334
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200335 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200336 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200337 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
338 let root = has('win32') ? 'C:\\' : '/'
339 let l = getcompletion(root, 'shellcmd')
340 let expected = map(filter(glob(root . '*', 0, 1),
341 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
342 call assert_equal(expected, l)
343
Bram Moolenaarb650b982016-08-05 20:35:13 +0200344 if has('cscope')
345 let l = getcompletion('', 'cscope')
346 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
347 call assert_equal(cmds, l)
348 " using cmdline completion must not change the result
349 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
350 let l = getcompletion('', 'cscope')
351 call assert_equal(cmds, l)
352 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
353 let l = getcompletion('find ', 'cscope')
354 call assert_equal(keys, l)
355 endif
356
Bram Moolenaar7522f692016-08-06 14:12:50 +0200357 if has('signs')
358 sign define Testing linehl=Comment
359 let l = getcompletion('', 'sign')
360 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
361 call assert_equal(cmds, l)
362 " using cmdline completion must not change the result
363 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
364 let l = getcompletion('', 'sign')
365 call assert_equal(cmds, l)
366 let l = getcompletion('list ', 'sign')
367 call assert_equal(['Testing'], l)
368 endif
369
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200370 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200371 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200372 if has('cmdline_hist')
373 call add(names, 'history')
374 endif
375 if has('gettext')
376 call add(names, 'locale')
377 endif
378 if has('profile')
379 call add(names, 'syntime')
380 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200381
382 set tags=Xtags
383 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
384
385 for name in names
386 let matchcount = len(getcompletion('', name))
387 call assert_true(matchcount >= 0, 'No matches for ' . name)
388 endfor
389
390 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200391 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200392
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200393 call assert_fails('call getcompletion("", "burp")', 'E475:')
394endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200395
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200396func Test_shellcmd_completion()
397 let save_path = $PATH
398
399 call mkdir('Xpathdir/Xpathsubdir', 'p')
400 call writefile([''], 'Xpathdir/Xfile.exe')
401 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
402
403 " Set PATH to example directory without trailing slash.
404 let $PATH = getcwd() . '/Xpathdir'
405
406 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
407 " dirs in the PATH, even though they won't be executed. We check that only
408 " subdirs of the PWD and executables from the PATH are included in the
409 " suggestions.
410 let actual = getcompletion('X', 'shellcmd')
411 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
412 call insert(expected, 'Xfile.exe')
413 call assert_equal(expected, actual)
414
415 call delete('Xpathdir', 'rf')
416 let $PATH = save_path
417endfunc
418
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200419func Test_expand_star_star()
420 call mkdir('a/b', 'p')
421 call writefile(['asdfasdf'], 'a/b/fileXname')
422 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
423 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200424 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200425 call delete('a', 'rf')
426endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100427
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100428func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100429 let @a = "def"
430 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
431 call assert_equal('"abc def ghi', @:)
432
433 new
434 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
435
436 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
437 call assert_equal('"aaa asdf bbb', @:)
438
439 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
440 call assert_equal('"aaa /tmp/some bbb', @:)
441
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200442 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
443 call assert_equal('"aaa '.getline(1).' bbb', @:)
444
Bram Moolenaar21efc362016-12-03 14:05:49 +0100445 set incsearch
446 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
447 call assert_equal('"aaa verylongword bbb', @:)
448
449 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
450 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100451
452 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
453 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100454 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200455
456 " Error while typing a command used to cause that it was not executed
457 " in the end.
458 new
459 try
460 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
461 catch /^Vim\%((\a\+)\)\=:E32/
462 " ignore error E32
463 endtry
464 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100465
466 " Use an invalid expression for <C-\>e
467 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
468
Bram Moolenaar72532d32018-04-07 19:09:09 +0200469 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100470endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100471
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100472func Test_cmdline_remove_char()
473 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100474
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100475 for e in ['utf8', 'latin1']
476 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100477
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100478 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
479 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100480
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100481 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
482 call assert_equal('"abcdef', @:)
483
484 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
485 call assert_equal('"abc ghi', @:, e)
486
487 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
488 call assert_equal('"def', @:, e)
489 endfor
490
491 let &encoding = encoding_save
492endfunc
493
494func Test_cmdline_keymap_ctrl_hat()
495 if !has('keymap')
496 return
497 endif
498
499 set keymap=esperanto
500 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
501 call assert_equal('"Jxauxdo Ä´aÅ­do Jxauxdo', @:)
502 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100503endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100504
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100505func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100506 new
507 2;'(
508 2;')
509 quit
510endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100511
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100512func Test_illegal_address2()
513 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
514 new
515 source Xtest.vim
516 " Trigger calling validate_cursor()
517 diffsp Xtest.vim
518 quit!
519 bwipe!
520 call delete('Xtest.vim')
521endfunc
522
Bram Moolenaarba47b512017-01-24 21:18:19 +0100523func Test_cmdline_complete_wildoptions()
524 help
525 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
526 let a = join(sort(split(@:)),' ')
527 set wildoptions=tagfile
528 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
529 let b = join(sort(split(@:)),' ')
530 call assert_equal(a, b)
531 bw!
532endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100533
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200534func Test_cmdline_complete_user_cmd()
535 command! -complete=color -nargs=1 Foo :
536 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
537 call assert_equal('"Foo blue', @:)
538 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
539 call assert_equal('"Foo blue', @:)
540 delcommand Foo
541endfunc
542
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200543func Test_cmdline_complete_user_names()
544 if has('unix') && executable('whoami')
545 let whoami = systemlist('whoami')[0]
546 let first_letter = whoami[0]
547 if len(first_letter) > 0
548 " Trying completion of :e ~x where x is the first letter of
549 " the user name should complete to at least the user name.
550 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
551 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
552 endif
553 endif
554 if has('win32')
555 " Just in case: check that the system has an Administrator account.
556 let names = system('net user')
557 if names =~ 'Administrator'
558 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100559 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200560 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100561 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200562 endif
563 endif
564endfunc
565
Bram Moolenaar297610b2019-12-27 17:20:55 +0100566func Test_cmdline_complete_bang()
567 if executable('whoami')
Bram Moolenaar731a7992019-12-28 14:06:50 +0100568 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
569 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100570 endif
Bram Moolenaar297610b2019-12-27 17:20:55 +0100571endfunc
572
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200573funct Test_cmdline_complete_languages()
574 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
575
576 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
577 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
578
579 if has('unix')
580 " TODO: these tests don't work on Windows. lang appears to be 'C'
581 " but C does not appear in the completion. Why?
582 call assert_match('^"language .*\<' . lang . '\>', @:)
583
584 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
585 call assert_match('^"language .*\<' . lang . '\>', @:)
586
587 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
588 call assert_match('^"language .*\<' . lang . '\>', @:)
589
590 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
591 call assert_match('^"language .*\<' . lang . '\>', @:)
592 endif
593endfunc
594
Bram Moolenaar297610b2019-12-27 17:20:55 +0100595func Test_cmdline_complete_env_variable()
596 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
597
598 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
599 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
600
601 unlet $X_VIM_TEST_COMPLETE_ENV
602endfunc
603
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200604func Test_cmdline_write_alternatefile()
605 new
606 call setline('.', ['one', 'two'])
607 f foo.txt
608 new
609 f #-A
610 call assert_equal('foo.txt-A', expand('%'))
611 f #<-B.txt
612 call assert_equal('foo-B.txt', expand('%'))
613 f %<
614 call assert_equal('foo-B', expand('%'))
615 new
616 call assert_fails('f #<', 'E95')
617 bw!
618 f foo-B.txt
619 f %<-A
620 call assert_equal('foo-B-A', expand('%'))
621 bw!
622 bw!
623endfunc
624
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100625" using a leading backslash here
626set cpo+=C
627
628func Test_cmdline_search_range()
629 new
630 call setline(1, ['a', 'b', 'c', 'd'])
631 /d
632 1,\/s/b/B/
633 call assert_equal('B', getline(2))
634
635 /a
636 $
637 \?,4s/c/C/
638 call assert_equal('C', getline(3))
639
640 call setline(1, ['a', 'b', 'c', 'd'])
641 %s/c/c/
642 1,\&s/b/B/
643 call assert_equal('B', getline(2))
644
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100645 let @/ = 'apple'
646 call assert_fails('\/print', 'E486:')
647
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100648 bwipe!
649endfunc
650
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100651" Test for the tick mark (') in an excmd range
652func Test_tick_mark_in_range()
653 " If only the tick is passed as a range and no command is specified, there
654 " should not be an error
655 call feedkeys(":'\<CR>", 'xt')
656 call assert_equal("'", getreg(':'))
657 call assert_fails("',print", 'E78:')
658endfunc
659
660" Test for using a line number followed by a search pattern as range
661func Test_lnum_and_pattern_as_range()
662 new
663 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
664 let @" = ''
665 2/foo/yank
666 call assert_equal("foo 3\n", @")
667 call assert_equal(1, line('.'))
668 close!
669endfunc
670
Bram Moolenaar65189a12017-02-06 22:22:17 +0100671" Tests for getcmdline(), getcmdpos() and getcmdtype()
672func Check_cmdline(cmdtype)
673 call assert_equal('MyCmd a', getcmdline())
674 call assert_equal(8, getcmdpos())
675 call assert_equal(a:cmdtype, getcmdtype())
676 return ''
677endfunc
678
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200679set cpo&
680
Bram Moolenaar65189a12017-02-06 22:22:17 +0100681func Test_getcmdtype()
682 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
683
684 let cmdtype = ''
685 debuggreedy
686 call feedkeys(":debug echo 'test'\<CR>", "t")
687 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
688 call feedkeys("cont\<CR>", "xt")
689 0debuggreedy
690 call assert_equal('>', cmdtype)
691
692 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
693 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
694
695 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +0100696 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +0100697
698 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
699
700 cnoremap <expr> <F6> Check_cmdline('=')
701 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
702 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100703
704 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +0100705endfunc
706
Bram Moolenaar81612b72018-06-23 14:55:03 +0200707func Test_getcmdwintype()
708 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
709 call assert_equal('/', a)
710
711 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
712 call assert_equal('?', a)
713
714 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
715 call assert_equal(':', a)
716
717 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
718 call assert_equal(':', a)
719
720 call assert_equal('', getcmdwintype())
721endfunc
722
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200723func Test_getcmdwin_autocmd()
724 let s:seq = []
725 augroup CmdWin
726 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
727 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
728 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
729 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
730 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
731 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
732
733 let org_winid = win_getid()
734 let org_bufnr = bufnr()
735 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
736 call assert_equal(':', a)
737 call assert_equal([
738 \ 'WinLeave ' .. org_winid,
739 \ 'WinEnter ' .. s:cmd_winid,
740 \ 'BufLeave ' .. org_bufnr,
741 \ 'BufEnter ' .. s:cmd_bufnr,
742 \ 'CmdWinEnter ' .. s:cmd_winid,
743 \ 'CmdWinLeave ' .. s:cmd_winid,
744 \ 'BufLeave ' .. s:cmd_bufnr,
745 \ 'WinLeave ' .. s:cmd_winid,
746 \ 'WinEnter ' .. org_winid,
747 \ 'BufEnter ' .. org_bufnr,
748 \ ], s:seq)
749
750 au!
751 augroup END
752endfunc
753
Bram Moolenaar52604f22017-04-07 16:17:39 +0200754func Test_verbosefile()
755 set verbosefile=Xlog
756 echomsg 'foo'
757 echomsg 'bar'
758 set verbosefile=
759 let log = readfile('Xlog')
760 call assert_match("foo\nbar", join(log, "\n"))
761 call delete('Xlog')
762endfunc
763
Bram Moolenaar4facea32019-10-12 20:17:40 +0200764func Test_verbose_option()
765 CheckScreendump
766
767 let lines =<< trim [SCRIPT]
768 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
769 call feedkeys("\r", 't') " for the hit-enter prompt
770 set verbose=20
771 [SCRIPT]
772 call writefile(lines, 'XTest_verbose')
773
774 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
775 call term_wait(buf, 100)
776 call term_sendkeys(buf, ":DoSomething\<CR>")
777 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
778
779 " clean up
780 call StopVimInTerminal(buf)
781 call delete('XTest_verbose')
782endfunc
783
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200784func Test_setcmdpos()
785 func InsertTextAtPos(text, pos)
786 call assert_equal(0, setcmdpos(a:pos))
787 return a:text
788 endfunc
789
790 " setcmdpos() with position in the middle of the command line.
791 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
792 call assert_equal('"1ab2', @:)
793
794 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
795 call assert_equal('"1b2a', @:)
796
797 " setcmdpos() with position beyond the end of the command line.
798 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
799 call assert_equal('"12ab', @:)
800
801 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +0200802 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200803endfunc
804
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100805func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100806 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100807 let encoding_save = &encoding
808
809 for e in encodings
810 exe 'set encoding=' . e
811
812 " Test overstrike in the middle of the command line.
813 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100814 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100815
816 " Test overstrike going beyond end of command line.
817 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100818 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100819
820 " Test toggling insert/overstrike a few times.
821 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100822 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100823 endfor
824
Bram Moolenaar30276f22019-01-24 17:59:39 +0100825 " Test overstrike with multi-byte characters.
826 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100827 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100828
829 let &encoding = encoding_save
830endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +0200831
832func Test_cmdwin_bug()
833 let winid = win_getid()
834 sp
835 try
836 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
837 catch /^Vim\%((\a\+)\)\=:E11/
838 endtry
839 bw!
840endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +0100841
Bram Moolenaar1c329c02019-10-27 20:37:35 +0100842func Test_cmdwin_restore()
843 CheckScreendump
844
845 let lines =<< trim [SCRIPT]
846 call setline(1, range(30))
847 2split
848 [SCRIPT]
849 call writefile(lines, 'XTest_restore')
850
851 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
852 call term_wait(buf, 100)
853 call term_sendkeys(buf, "q:")
854 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
855
856 " normal restore
857 call term_sendkeys(buf, ":q\<CR>")
858 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
859
860 " restore after setting 'lines' with one window
861 call term_sendkeys(buf, ":close\<CR>")
862 call term_sendkeys(buf, "q:")
863 call term_sendkeys(buf, ":set lines=18\<CR>")
864 call term_sendkeys(buf, ":q\<CR>")
865 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
866
867 " clean up
868 call StopVimInTerminal(buf)
869 call delete('XTest_restore')
870endfunc
871
Bram Moolenaar52410572019-10-27 05:12:45 +0100872func Test_buffers_lastused()
873 " check that buffers are sorted by time when wildmode has lastused
874 call test_settime(1550020000) " middle
875 edit bufa
876 enew
877 call test_settime(1550030000) " newest
878 edit bufb
879 enew
880 call test_settime(1550010000) " oldest
881 edit bufc
882 enew
883 call test_settime(0)
884 enew
885
886 call assert_equal(['bufa', 'bufb', 'bufc'],
887 \ getcompletion('', 'buffer'))
888
889 let save_wildmode = &wildmode
890 set wildmode=full:lastused
891
892 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
893 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
894 call assert_equal('b bufb', X)
895 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
896 call assert_equal('b bufa', X)
897 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
898 call assert_equal('b bufc', X)
899 enew
900
901 edit other
902 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
903 call assert_equal('b bufb', X)
904 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
905 call assert_equal('b bufa', X)
906 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
907 call assert_equal('b bufc', X)
908 enew
909
910 let &wildmode = save_wildmode
911
912 bwipeout bufa
913 bwipeout bufb
914 bwipeout bufc
915endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +0100916
917func Test_cmdwin_feedkeys()
918 " This should not generate E488
919 call feedkeys("q:\<CR>", 'x')
920endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +0100921
922" Tests for the issues fixed in 7.4.441.
923" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
924func Test_cmdwin_cedit()
925 exe "set cedit=\<C-c>"
926 normal! :
927 call assert_equal(1, winnr('$'))
928
929 let g:cmd_wintype = ''
930 func CmdWinType()
931 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +0100932 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +0100933 return ''
934 endfunc
935
936 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
937 echo input('')
938 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +0100939 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +0100940
941 set cedit&vim
942 delfunc CmdWinType
943endfunc
944
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100945" Test for CmdwinEnter autocmd
946func Test_cmdwin_autocmd()
947 augroup CmdWin
948 au!
949 autocmd CmdwinEnter * startinsert
950 augroup END
951
952 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
953 call assert_equal('xyz', @:)
954
955 augroup CmdWin
956 au!
957 augroup END
958 augroup! CmdWin
959endfunc
960
Bram Moolenaar479950f2020-01-19 15:45:17 +0100961func Test_cmdlineclear_tabenter()
962 CheckScreendump
963
964 let lines =<< trim [SCRIPT]
965 call setline(1, range(30))
966 [SCRIPT]
967
968 call writefile(lines, 'XtestCmdlineClearTabenter')
969 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
970 call term_wait(buf, 50)
971 " in one tab make the command line higher with CTRL-W -
972 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
973 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
974
975 call StopVimInTerminal(buf)
976 call delete('XtestCmdlineClearTabenter')
977endfunc
978
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100979" Test for failure in expanding special keywords in cmdline
980func Test_cmdline_expand_special()
981 %bwipe!
982 call assert_fails('e #', 'E499:')
983 call assert_fails('e <afile>', 'E495:')
984 call assert_fails('e <abuf>', 'E496:')
985 call assert_fails('e <amatch>', 'E497:')
986endfunc
987
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100988func Test_cmdwin_jump_to_win()
989 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
990 new
991 set modified
992 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
993 close!
994 call feedkeys("q/:close\<CR>", "xt")
995 call assert_equal(1, winnr('$'))
996 call feedkeys("q/:exit\<CR>", "xt")
997 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100998
999 " opening command window twice should fail
1000 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1001 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001002endfunc
1003
1004" Test for backtick expression in the command line
1005func Test_cmd_backtick()
1006 %argd
1007 argadd `=['a', 'b', 'c']`
1008 call assert_equal(['a', 'b', 'c'], argv())
1009 %argd
1010endfunc
1011
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001012" Test for the :! command
1013func Test_cmd_bang()
1014 if !has('unix')
1015 return
1016 endif
1017
1018 let lines =<< trim [SCRIPT]
1019 " Test for no previous command
1020 call assert_fails('!!', 'E34:')
1021 set nomore
1022 " Test for cmdline expansion with :!
1023 call setline(1, 'foo!')
1024 silent !echo <cWORD> > Xfile.out
1025 call assert_equal(['foo!'], readfile('Xfile.out'))
1026 " Test for using previous command
1027 silent !echo \! !
1028 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1029 call writefile(v:errors, 'Xresult')
1030 call delete('Xfile.out')
1031 qall!
1032 [SCRIPT]
1033 call writefile(lines, 'Xscript')
1034 if RunVim([], [], '--clean -S Xscript')
1035 call assert_equal([], readfile('Xresult'))
1036 endif
1037 call delete('Xscript')
1038 call delete('Xresult')
1039endfunc
1040
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001041" Test for using ~ for home directory in cmdline completion matches
1042func Test_cmdline_expand_home()
1043 call mkdir('Xdir')
1044 call writefile([], 'Xdir/Xfile1')
1045 call writefile([], 'Xdir/Xfile2')
1046 cd Xdir
1047 let save_HOME = $HOME
1048 let $HOME = getcwd()
1049 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1050 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1051 let $HOME = save_HOME
1052 cd ..
1053 call delete('Xdir', 'rf')
1054endfunc
1055
Bram Moolenaar309976e2019-12-05 18:16:33 +01001056" vim: shiftwidth=2 sts=2 expandtab