blob: 7960a9efb4d78de96bae6d670eee9ea28c139e4b [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 Moolenaar37db6422019-03-28 21:26:23 +010071 " cleanup
72 %bwipe
73 call delete('Xdir1/Xdir2/Xtestfile4')
74 call delete('Xdir1/Xdir2/Xtestfile3')
75 call delete('Xdir1/Xtestfile2')
76 call delete('Xdir1/Xtestfile1')
77 call delete('Xdir1/Xdir2', 'd')
78 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020079 set nowildmenu
80endfunc
Bram Moolenaaraa4d7322016-07-09 18:50:29 +020081
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +010082func Test_map_completion()
83 if !has('cmdline_compl')
84 return
85 endif
86 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
87 call assert_equal('"map <unique> <silent>', getreg(':'))
88 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
89 call assert_equal('"map <script> <unique>', getreg(':'))
90 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
91 call assert_equal('"map <expr> <script>', getreg(':'))
92 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
93 call assert_equal('"map <buffer> <expr>', getreg(':'))
94 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
95 call assert_equal('"map <nowait> <buffer>', getreg(':'))
96 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
97 call assert_equal('"map <special> <nowait>', getreg(':'))
98 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
99 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200100
Bram Moolenaar1776a282019-05-03 16:05:41 +0200101 map <Middle>x middle
102
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200103 map ,f commaf
104 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200105 map <Left> left
106 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200107 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
108 call assert_equal('"map ,f', getreg(':'))
109 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
110 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200111 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
112 call assert_equal('"map <Left>', getreg(':'))
113 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200114 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200115 unmap ,f
116 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200117 unmap <Left>
118 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200119
120 set cpo-=< cpo-=B cpo-=k
121 map <Left> left
122 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
123 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200124 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200125 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200126 unmap <Left>
127
128 set cpo+=<
129 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200130 exe "set t_k6=\<Esc>[17~"
131 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200132 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
133 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200134 if !has('gui_running')
135 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
136 call assert_equal("\"map <F6>x", getreg(':'))
137 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200138 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200139 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200140 set cpo-=<
141
142 set cpo+=B
143 map <Left> left
144 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
145 call assert_equal('"map <Left>', getreg(':'))
146 unmap <Left>
147 set cpo-=B
148
149 set cpo+=k
150 map <Left> left
151 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
152 call assert_equal('"map <Left>', getreg(':'))
153 unmap <Left>
154 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200155
156 unmap <Middle>x
157 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100158endfunc
159
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100160func Test_match_completion()
161 if !has('cmdline_compl')
162 return
163 endif
164 hi Aardig ctermfg=green
165 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
166 call assert_equal('"match Aardig', getreg(':'))
167 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
168 call assert_equal('"match none', getreg(':'))
169endfunc
170
171func Test_highlight_completion()
172 if !has('cmdline_compl')
173 return
174 endif
175 hi Aardig ctermfg=green
176 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
177 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200178 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
179 call assert_equal('"hi default Aardig', getreg(':'))
180 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
181 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100182 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
183 call assert_equal('"hi link', getreg(':'))
184 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
185 call assert_equal('"hi default', getreg(':'))
186 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
187 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200188
189 " A cleared group does not show up in completions.
190 hi Anders ctermfg=green
191 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
192 hi clear Aardig
193 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
194 hi clear Anders
195 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100196endfunc
197
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100198func Test_expr_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100199 if !has('cmdline_compl')
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100200 return
201 endif
202 for cmd in [
203 \ 'let a = ',
Bram Moolenaar8f76e6b2019-11-26 16:50:30 +0100204 \ 'const a = ',
Bram Moolenaar2b2207b2017-01-22 16:46:56 +0100205 \ 'if',
206 \ 'elseif',
207 \ 'while',
208 \ 'for',
209 \ 'echo',
210 \ 'echon',
211 \ 'execute',
212 \ 'echomsg',
213 \ 'echoerr',
214 \ 'call',
215 \ 'return',
216 \ 'cexpr',
217 \ 'caddexpr',
218 \ 'cgetexpr',
219 \ 'lexpr',
220 \ 'laddexpr',
221 \ 'lgetexpr']
222 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt')
223 call assert_equal('"' . cmd . ' getline(', getreg(':'))
224 endfor
225endfunc
226
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200227func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200228 if !has('cmdline_compl')
229 return
230 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200231 let groupcount = len(getcompletion('', 'event'))
232 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200233 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200234 call assert_true(matchcount > 0)
235 call assert_true(groupcount > matchcount)
236
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200237 if has('menu')
238 source $VIMRUNTIME/menu.vim
239 let matchcount = len(getcompletion('', 'menu'))
240 call assert_true(matchcount > 0)
241 call assert_equal(['File.'], getcompletion('File', 'menu'))
242 call assert_true(matchcount > 0)
243 let matchcount = len(getcompletion('File.', 'menu'))
244 call assert_true(matchcount > 0)
245 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200246
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200247 let l = getcompletion('v:n', 'var')
248 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200249 let l = getcompletion('v:notexists', 'var')
250 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200251
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200252 args a.c b.c
253 let l = getcompletion('', 'arglist')
254 call assert_equal(['a.c', 'b.c'], l)
255 %argdelete
256
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200257 let l = getcompletion('', 'augroup')
258 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200259 let l = getcompletion('blahblah', 'augroup')
260 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200261
262 let l = getcompletion('', 'behave')
263 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200264 let l = getcompletion('not', 'behave')
265 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200266
267 let l = getcompletion('', 'color')
268 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200269 let l = getcompletion('dirty', 'color')
270 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200271
272 let l = getcompletion('', 'command')
273 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200274 let l = getcompletion('awake', 'command')
275 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200276
277 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200278 call assert_true(index(l, 'samples/') >= 0)
279 let l = getcompletion('NoMatch', 'dir')
280 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200281
282 let l = getcompletion('exe', 'expression')
283 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200284 let l = getcompletion('kill', 'expression')
285 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200286
287 let l = getcompletion('tag', 'function')
288 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200289 let l = getcompletion('paint', 'function')
290 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200291
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200292 let Flambda = {-> 'hello'}
293 let l = getcompletion('', 'function')
294 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200295 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200296
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200297 let l = getcompletion('run', 'file')
298 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200299 let l = getcompletion('walk', 'file')
300 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200301 set wildignore=*.vim
302 let l = getcompletion('run', 'file', 1)
303 call assert_true(index(l, 'runtest.vim') < 0)
304 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200305
306 let l = getcompletion('ha', 'filetype')
307 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200308 let l = getcompletion('horse', 'filetype')
309 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200310
311 let l = getcompletion('z', 'syntax')
312 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200313 let l = getcompletion('emacs', 'syntax')
314 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200315
316 let l = getcompletion('jikes', 'compiler')
317 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200318 let l = getcompletion('break', 'compiler')
319 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200320
321 let l = getcompletion('last', 'help')
322 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200323 let l = getcompletion('giveup', 'help')
324 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200325
326 let l = getcompletion('time', 'option')
327 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200328 let l = getcompletion('space', 'option')
329 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200330
331 let l = getcompletion('er', 'highlight')
332 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200333 let l = getcompletion('dark', 'highlight')
334 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200335
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200336 let l = getcompletion('', 'messages')
337 call assert_true(index(l, 'clear') >= 0)
338 let l = getcompletion('not', 'messages')
339 call assert_equal([], l)
340
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200341 let l = getcompletion('', 'mapclear')
342 call assert_true(index(l, '<buffer>') >= 0)
343 let l = getcompletion('not', 'mapclear')
344 call assert_equal([], l)
345
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200346 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200347 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200348 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
349 let root = has('win32') ? 'C:\\' : '/'
350 let l = getcompletion(root, 'shellcmd')
351 let expected = map(filter(glob(root . '*', 0, 1),
352 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
353 call assert_equal(expected, l)
354
Bram Moolenaarb650b982016-08-05 20:35:13 +0200355 if has('cscope')
356 let l = getcompletion('', 'cscope')
357 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
358 call assert_equal(cmds, l)
359 " using cmdline completion must not change the result
360 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
361 let l = getcompletion('', 'cscope')
362 call assert_equal(cmds, l)
363 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
364 let l = getcompletion('find ', 'cscope')
365 call assert_equal(keys, l)
366 endif
367
Bram Moolenaar7522f692016-08-06 14:12:50 +0200368 if has('signs')
369 sign define Testing linehl=Comment
370 let l = getcompletion('', 'sign')
371 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
372 call assert_equal(cmds, l)
373 " using cmdline completion must not change the result
374 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
375 let l = getcompletion('', 'sign')
376 call assert_equal(cmds, l)
377 let l = getcompletion('list ', 'sign')
378 call assert_equal(['Testing'], l)
379 endif
380
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200381 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200382 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200383 if has('cmdline_hist')
384 call add(names, 'history')
385 endif
386 if has('gettext')
387 call add(names, 'locale')
388 endif
389 if has('profile')
390 call add(names, 'syntime')
391 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200392
393 set tags=Xtags
394 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
395
396 for name in names
397 let matchcount = len(getcompletion('', name))
398 call assert_true(matchcount >= 0, 'No matches for ' . name)
399 endfor
400
401 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200402 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200403
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200404 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100405 call assert_fails('call getcompletion("abc", [])', 'E474:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200406endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200407
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200408func Test_shellcmd_completion()
409 let save_path = $PATH
410
411 call mkdir('Xpathdir/Xpathsubdir', 'p')
412 call writefile([''], 'Xpathdir/Xfile.exe')
413 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
414
415 " Set PATH to example directory without trailing slash.
416 let $PATH = getcwd() . '/Xpathdir'
417
418 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
419 " dirs in the PATH, even though they won't be executed. We check that only
420 " subdirs of the PWD and executables from the PATH are included in the
421 " suggestions.
422 let actual = getcompletion('X', 'shellcmd')
423 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
424 call insert(expected, 'Xfile.exe')
425 call assert_equal(expected, actual)
426
427 call delete('Xpathdir', 'rf')
428 let $PATH = save_path
429endfunc
430
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200431func Test_expand_star_star()
432 call mkdir('a/b', 'p')
433 call writefile(['asdfasdf'], 'a/b/fileXname')
434 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
435 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200436 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200437 call delete('a', 'rf')
438endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100439
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100440func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100441 let @a = "def"
442 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
443 call assert_equal('"abc def ghi', @:)
444
445 new
446 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
447
448 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
449 call assert_equal('"aaa asdf bbb', @:)
450
451 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
452 call assert_equal('"aaa /tmp/some bbb', @:)
453
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200454 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
455 call assert_equal('"aaa '.getline(1).' bbb', @:)
456
Bram Moolenaar21efc362016-12-03 14:05:49 +0100457 set incsearch
458 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
459 call assert_equal('"aaa verylongword bbb', @:)
460
461 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
462 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100463
464 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
465 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100466 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200467
468 " Error while typing a command used to cause that it was not executed
469 " in the end.
470 new
471 try
472 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
473 catch /^Vim\%((\a\+)\)\=:E32/
474 " ignore error E32
475 endtry
476 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100477
Bram Moolenaar578fe942020-02-27 21:32:51 +0100478 " Try to paste an invalid register using <C-R>
479 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
480 call assert_equal('"onetwo', @:)
481
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100482 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100483 let @a = "xy\<C-H>z"
484 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
485 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100486 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
487 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100488 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
489 call assert_equal("\"xy\<C-H>z", @:)
490
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100491 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
492 let @a = "xy\<C-V>z"
493 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
494 call assert_equal('"xyz', @:)
495 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
496 call assert_equal("\"xy\<C-V>z", @:)
497
Bram Moolenaar578fe942020-02-27 21:32:51 +0100498 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
499
Bram Moolenaar72532d32018-04-07 19:09:09 +0200500 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100501endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100502
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100503func Test_cmdline_remove_char()
504 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100505
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100506 for e in ['utf8', 'latin1']
507 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100508
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100509 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
510 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100511
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100512 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
513 call assert_equal('"abcdef', @:)
514
515 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
516 call assert_equal('"abc ghi', @:, e)
517
518 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
519 call assert_equal('"def', @:, e)
520 endfor
521
522 let &encoding = encoding_save
523endfunc
524
525func Test_cmdline_keymap_ctrl_hat()
526 if !has('keymap')
527 return
528 endif
529
530 set keymap=esperanto
531 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
532 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
533 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100534endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100535
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100536func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100537 new
538 2;'(
539 2;')
540 quit
541endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100542
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100543func Test_illegal_address2()
544 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
545 new
546 source Xtest.vim
547 " Trigger calling validate_cursor()
548 diffsp Xtest.vim
549 quit!
550 bwipe!
551 call delete('Xtest.vim')
552endfunc
553
Bram Moolenaarba47b512017-01-24 21:18:19 +0100554func Test_cmdline_complete_wildoptions()
555 help
556 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
557 let a = join(sort(split(@:)),' ')
558 set wildoptions=tagfile
559 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
560 let b = join(sort(split(@:)),' ')
561 call assert_equal(a, b)
562 bw!
563endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100564
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200565func Test_cmdline_complete_user_cmd()
566 command! -complete=color -nargs=1 Foo :
567 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
568 call assert_equal('"Foo blue', @:)
569 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
570 call assert_equal('"Foo blue', @:)
571 delcommand Foo
572endfunc
573
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100574func s:ScriptLocalFunction()
575 echo 'yes'
576endfunc
577
578func Test_cmdline_complete_user_func()
579 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
580 call assert_match('"func Test_cmdline_complete_user', @:)
581 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
582 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
583endfunc
584
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200585func Test_cmdline_complete_user_names()
586 if has('unix') && executable('whoami')
587 let whoami = systemlist('whoami')[0]
588 let first_letter = whoami[0]
589 if len(first_letter) > 0
590 " Trying completion of :e ~x where x is the first letter of
591 " the user name should complete to at least the user name.
592 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
593 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
594 endif
595 endif
596 if has('win32')
597 " Just in case: check that the system has an Administrator account.
598 let names = system('net user')
599 if names =~ 'Administrator'
600 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100601 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200602 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100603 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200604 endif
605 endif
606endfunc
607
Bram Moolenaar297610b2019-12-27 17:20:55 +0100608func Test_cmdline_complete_bang()
609 if executable('whoami')
Bram Moolenaar731a7992019-12-28 14:06:50 +0100610 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
611 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100612 endif
Bram Moolenaar297610b2019-12-27 17:20:55 +0100613endfunc
614
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200615funct Test_cmdline_complete_languages()
616 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
617
618 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
619 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
620
621 if has('unix')
622 " TODO: these tests don't work on Windows. lang appears to be 'C'
623 " but C does not appear in the completion. Why?
624 call assert_match('^"language .*\<' . lang . '\>', @:)
625
626 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
627 call assert_match('^"language .*\<' . lang . '\>', @:)
628
629 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
630 call assert_match('^"language .*\<' . lang . '\>', @:)
631
632 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
633 call assert_match('^"language .*\<' . lang . '\>', @:)
634 endif
635endfunc
636
Bram Moolenaar297610b2019-12-27 17:20:55 +0100637func Test_cmdline_complete_env_variable()
638 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
639
640 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
641 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
642
643 unlet $X_VIM_TEST_COMPLETE_ENV
644endfunc
645
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100646" Test for various command-line completion
647func Test_cmdline_complete_various()
648 " completion for a command starting with a comment
649 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
650 call assert_equal("\" :|\"\<C-A>", @:)
651
652 " completion for a range followed by a comment
653 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
654 call assert_equal("\"1,2\"\<C-A>", @:)
655
656 " completion for :k command
657 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
658 call assert_equal("\"ka\<C-A>", @:)
659
660 " completion for short version of the :s command
661 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
662 call assert_equal("\"sI \<C-A>", @:)
663
664 " completion for :write command
665 call mkdir('Xdir')
666 call writefile(['one'], 'Xdir/Xfile1')
667 let save_cwd = getcwd()
668 cd Xdir
669 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
670 call assert_equal("\"w >> Xfile1", @:)
671 call chdir(save_cwd)
672 call delete('Xdir', 'rf')
673
674 " completion for :w ! and :r ! commands
675 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
676 call assert_equal("\"w !invalid_xyz_cmd", @:)
677 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
678 call assert_equal("\"r !invalid_xyz_cmd", @:)
679
680 " completion for :>> and :<< commands
681 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
682 call assert_equal("\">>>\<C-A>", @:)
683 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
684 call assert_equal("\"<<<\<C-A>", @:)
685
686 " completion for command with +cmd argument
687 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
688 call assert_equal("\"buffer +/pat Xabc", @:)
689 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
690 call assert_equal("\"buffer +/pat\<C-A>", @:)
691
692 " completion for a command with a trailing comment
693 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
694 call assert_equal("\"ls \" comment\<C-A>", @:)
695
696 " completion for a command with a trailing command
697 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
698 call assert_equal("\"ls | ls", @:)
699
700 " completion for a command with an CTRL-V escaped argument
701 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
702 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
703
704 " completion for a command that doesn't take additional arguments
705 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
706 call assert_equal("\"all abc\<C-A>", @:)
707
708 " completion for a command with a command modifier
709 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
710 call assert_equal("\"topleft new", @:)
711
712 " completion for the :match command
713 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
714 call assert_equal("\"match Search /pat/\<C-A>", @:)
715
716 " completion for the :s command
717 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
718 call assert_equal("\"s/from/to/g\<C-A>", @:)
719
720 " completion for the :dlist command
721 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
722 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
723
724 " completion for the :doautocmd command
725 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
726 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
727
728 " completion for the :augroup command
729 augroup XTest
730 augroup END
731 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
732 call assert_equal("\"augroup XTest", @:)
733 augroup! XTest
734
735 " completion for the :unlet command
736 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
737 call assert_equal("\"unlet one two", @:)
738
739 " completion for the :bdelete command
740 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
741 call assert_equal("\"bdel a b c", @:)
742
743 " completion for the :mapclear command
744 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
745 call assert_equal("\"mapclear <buffer>", @:)
746
747 " completion for user defined commands with menu names
748 menu Test.foo :ls<CR>
749 com -nargs=* -complete=menu MyCmd
750 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
751 call assert_equal('"MyCmd Test.', @:)
752 delcom MyCmd
753 unmenu Test
754
755 " completion for user defined commands with mappings
756 mapclear
757 map <F3> :ls<CR>
758 com -nargs=* -complete=mapping MyCmd
759 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
760 call assert_equal('"MyCmd <F3>', @:)
761 mapclear
762 delcom MyCmd
763
764 " completion for :set path= with multiple backslashes
765 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
766 call assert_equal('"set path=a\\\ b', @:)
767
768 " completion for :set dir= with a backslash
769 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
770 call assert_equal('"set dir=a\ b', @:)
771
772 " completion for the :py3 commands
773 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
774 call assert_equal('"py3 py3do py3file', @:)
775
776 " redir @" is not the start of a comment. So complete after that
777 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
778 call assert_equal('"redir @" | cwindow', @:)
779
780 " completion after a backtick
781 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
782 call assert_equal('"e `a1b2c', @:)
783
784 " completion for the expression register
785 call feedkeys(":\"\<C-R>=float2\t\"\<C-B>\"\<CR>", 'xt')
786 call assert_equal('"float2nr("', @=)
787endfunc
788
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200789func Test_cmdline_write_alternatefile()
790 new
791 call setline('.', ['one', 'two'])
792 f foo.txt
793 new
794 f #-A
795 call assert_equal('foo.txt-A', expand('%'))
796 f #<-B.txt
797 call assert_equal('foo-B.txt', expand('%'))
798 f %<
799 call assert_equal('foo-B', expand('%'))
800 new
801 call assert_fails('f #<', 'E95')
802 bw!
803 f foo-B.txt
804 f %<-A
805 call assert_equal('foo-B-A', expand('%'))
806 bw!
807 bw!
808endfunc
809
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100810" using a leading backslash here
811set cpo+=C
812
813func Test_cmdline_search_range()
814 new
815 call setline(1, ['a', 'b', 'c', 'd'])
816 /d
817 1,\/s/b/B/
818 call assert_equal('B', getline(2))
819
820 /a
821 $
822 \?,4s/c/C/
823 call assert_equal('C', getline(3))
824
825 call setline(1, ['a', 'b', 'c', 'd'])
826 %s/c/c/
827 1,\&s/b/B/
828 call assert_equal('B', getline(2))
829
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100830 let @/ = 'apple'
831 call assert_fails('\/print', 'E486:')
832
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100833 bwipe!
834endfunc
835
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100836" Test for the tick mark (') in an excmd range
837func Test_tick_mark_in_range()
838 " If only the tick is passed as a range and no command is specified, there
839 " should not be an error
840 call feedkeys(":'\<CR>", 'xt')
841 call assert_equal("'", getreg(':'))
842 call assert_fails("',print", 'E78:')
843endfunc
844
845" Test for using a line number followed by a search pattern as range
846func Test_lnum_and_pattern_as_range()
847 new
848 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
849 let @" = ''
850 2/foo/yank
851 call assert_equal("foo 3\n", @")
852 call assert_equal(1, line('.'))
853 close!
854endfunc
855
Bram Moolenaar65189a12017-02-06 22:22:17 +0100856" Tests for getcmdline(), getcmdpos() and getcmdtype()
857func Check_cmdline(cmdtype)
858 call assert_equal('MyCmd a', getcmdline())
859 call assert_equal(8, getcmdpos())
860 call assert_equal(a:cmdtype, getcmdtype())
861 return ''
862endfunc
863
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200864set cpo&
865
Bram Moolenaar65189a12017-02-06 22:22:17 +0100866func Test_getcmdtype()
867 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
868
869 let cmdtype = ''
870 debuggreedy
871 call feedkeys(":debug echo 'test'\<CR>", "t")
872 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
873 call feedkeys("cont\<CR>", "xt")
874 0debuggreedy
875 call assert_equal('>', cmdtype)
876
877 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
878 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
879
880 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +0100881 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +0100882
883 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
884
885 cnoremap <expr> <F6> Check_cmdline('=')
886 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
887 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100888
889 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +0100890endfunc
891
Bram Moolenaar81612b72018-06-23 14:55:03 +0200892func Test_getcmdwintype()
893 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
894 call assert_equal('/', a)
895
896 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
897 call assert_equal('?', a)
898
899 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
900 call assert_equal(':', a)
901
902 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
903 call assert_equal(':', a)
904
905 call assert_equal('', getcmdwintype())
906endfunc
907
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200908func Test_getcmdwin_autocmd()
909 let s:seq = []
910 augroup CmdWin
911 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
912 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
913 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
914 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
915 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
916 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
917
918 let org_winid = win_getid()
919 let org_bufnr = bufnr()
920 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
921 call assert_equal(':', a)
922 call assert_equal([
923 \ 'WinLeave ' .. org_winid,
924 \ 'WinEnter ' .. s:cmd_winid,
925 \ 'BufLeave ' .. org_bufnr,
926 \ 'BufEnter ' .. s:cmd_bufnr,
927 \ 'CmdWinEnter ' .. s:cmd_winid,
928 \ 'CmdWinLeave ' .. s:cmd_winid,
929 \ 'BufLeave ' .. s:cmd_bufnr,
930 \ 'WinLeave ' .. s:cmd_winid,
931 \ 'WinEnter ' .. org_winid,
932 \ 'BufEnter ' .. org_bufnr,
933 \ ], s:seq)
934
935 au!
936 augroup END
937endfunc
938
Bram Moolenaar52604f22017-04-07 16:17:39 +0200939func Test_verbosefile()
940 set verbosefile=Xlog
941 echomsg 'foo'
942 echomsg 'bar'
943 set verbosefile=
944 let log = readfile('Xlog')
945 call assert_match("foo\nbar", join(log, "\n"))
946 call delete('Xlog')
947endfunc
948
Bram Moolenaar4facea32019-10-12 20:17:40 +0200949func Test_verbose_option()
950 CheckScreendump
951
952 let lines =<< trim [SCRIPT]
953 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
954 call feedkeys("\r", 't') " for the hit-enter prompt
955 set verbose=20
956 [SCRIPT]
957 call writefile(lines, 'XTest_verbose')
958
959 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
960 call term_wait(buf, 100)
961 call term_sendkeys(buf, ":DoSomething\<CR>")
962 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
963
964 " clean up
965 call StopVimInTerminal(buf)
966 call delete('XTest_verbose')
967endfunc
968
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200969func Test_setcmdpos()
970 func InsertTextAtPos(text, pos)
971 call assert_equal(0, setcmdpos(a:pos))
972 return a:text
973 endfunc
974
975 " setcmdpos() with position in the middle of the command line.
976 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
977 call assert_equal('"1ab2', @:)
978
979 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
980 call assert_equal('"1b2a', @:)
981
982 " setcmdpos() with position beyond the end of the command line.
983 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
984 call assert_equal('"12ab', @:)
985
986 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +0200987 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200988endfunc
989
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100990func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100991 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100992 let encoding_save = &encoding
993
994 for e in encodings
995 exe 'set encoding=' . e
996
997 " Test overstrike in the middle of the command line.
998 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100999 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001000
1001 " Test overstrike going beyond end of command line.
1002 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001003 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001004
1005 " Test toggling insert/overstrike a few times.
1006 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001007 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001008 endfor
1009
Bram Moolenaar30276f22019-01-24 17:59:39 +01001010 " Test overstrike with multi-byte characters.
1011 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001012 call assert_equal('"abcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001013
1014 let &encoding = encoding_save
1015endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001016
1017func Test_cmdwin_bug()
1018 let winid = win_getid()
1019 sp
1020 try
1021 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1022 catch /^Vim\%((\a\+)\)\=:E11/
1023 endtry
1024 bw!
1025endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001026
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001027func Test_cmdwin_restore()
1028 CheckScreendump
1029
1030 let lines =<< trim [SCRIPT]
1031 call setline(1, range(30))
1032 2split
1033 [SCRIPT]
1034 call writefile(lines, 'XTest_restore')
1035
1036 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
1037 call term_wait(buf, 100)
1038 call term_sendkeys(buf, "q:")
1039 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1040
1041 " normal restore
1042 call term_sendkeys(buf, ":q\<CR>")
1043 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1044
1045 " restore after setting 'lines' with one window
1046 call term_sendkeys(buf, ":close\<CR>")
1047 call term_sendkeys(buf, "q:")
1048 call term_sendkeys(buf, ":set lines=18\<CR>")
1049 call term_sendkeys(buf, ":q\<CR>")
1050 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1051
1052 " clean up
1053 call StopVimInTerminal(buf)
1054 call delete('XTest_restore')
1055endfunc
1056
Bram Moolenaar52410572019-10-27 05:12:45 +01001057func Test_buffers_lastused()
1058 " check that buffers are sorted by time when wildmode has lastused
1059 call test_settime(1550020000) " middle
1060 edit bufa
1061 enew
1062 call test_settime(1550030000) " newest
1063 edit bufb
1064 enew
1065 call test_settime(1550010000) " oldest
1066 edit bufc
1067 enew
1068 call test_settime(0)
1069 enew
1070
1071 call assert_equal(['bufa', 'bufb', 'bufc'],
1072 \ getcompletion('', 'buffer'))
1073
1074 let save_wildmode = &wildmode
1075 set wildmode=full:lastused
1076
1077 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1078 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1079 call assert_equal('b bufb', X)
1080 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1081 call assert_equal('b bufa', X)
1082 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1083 call assert_equal('b bufc', X)
1084 enew
1085
1086 edit other
1087 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1088 call assert_equal('b bufb', X)
1089 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1090 call assert_equal('b bufa', X)
1091 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1092 call assert_equal('b bufc', X)
1093 enew
1094
1095 let &wildmode = save_wildmode
1096
1097 bwipeout bufa
1098 bwipeout bufb
1099 bwipeout bufc
1100endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001101
1102func Test_cmdwin_feedkeys()
1103 " This should not generate E488
1104 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001105 " Using feedkeys with q: only should automatically close the cmd window
1106 call feedkeys('q:', 'xt')
1107 call assert_equal(1, winnr('$'))
1108 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001109endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001110
1111" Tests for the issues fixed in 7.4.441.
1112" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1113func Test_cmdwin_cedit()
1114 exe "set cedit=\<C-c>"
1115 normal! :
1116 call assert_equal(1, winnr('$'))
1117
1118 let g:cmd_wintype = ''
1119 func CmdWinType()
1120 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001121 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001122 return ''
1123 endfunc
1124
1125 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1126 echo input('')
1127 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001128 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001129
1130 set cedit&vim
1131 delfunc CmdWinType
1132endfunc
1133
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001134" Test for CmdwinEnter autocmd
1135func Test_cmdwin_autocmd()
1136 augroup CmdWin
1137 au!
1138 autocmd CmdwinEnter * startinsert
1139 augroup END
1140
1141 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1142 call assert_equal('xyz', @:)
1143
1144 augroup CmdWin
1145 au!
1146 augroup END
1147 augroup! CmdWin
1148endfunc
1149
Bram Moolenaar479950f2020-01-19 15:45:17 +01001150func Test_cmdlineclear_tabenter()
1151 CheckScreendump
1152
1153 let lines =<< trim [SCRIPT]
1154 call setline(1, range(30))
1155 [SCRIPT]
1156
1157 call writefile(lines, 'XtestCmdlineClearTabenter')
1158 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
1159 call term_wait(buf, 50)
1160 " in one tab make the command line higher with CTRL-W -
1161 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1162 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1163
1164 call StopVimInTerminal(buf)
1165 call delete('XtestCmdlineClearTabenter')
1166endfunc
1167
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001168" Test for failure in expanding special keywords in cmdline
1169func Test_cmdline_expand_special()
1170 %bwipe!
1171 call assert_fails('e #', 'E499:')
1172 call assert_fails('e <afile>', 'E495:')
1173 call assert_fails('e <abuf>', 'E496:')
1174 call assert_fails('e <amatch>', 'E497:')
1175endfunc
1176
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001177func Test_cmdwin_jump_to_win()
1178 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1179 new
1180 set modified
1181 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
1182 close!
1183 call feedkeys("q/:close\<CR>", "xt")
1184 call assert_equal(1, winnr('$'))
1185 call feedkeys("q/:exit\<CR>", "xt")
1186 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001187
1188 " opening command window twice should fail
1189 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1190 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001191endfunc
1192
1193" Test for backtick expression in the command line
1194func Test_cmd_backtick()
1195 %argd
1196 argadd `=['a', 'b', 'c']`
1197 call assert_equal(['a', 'b', 'c'], argv())
1198 %argd
1199endfunc
1200
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001201" Test for the :! command
1202func Test_cmd_bang()
1203 if !has('unix')
1204 return
1205 endif
1206
1207 let lines =<< trim [SCRIPT]
1208 " Test for no previous command
1209 call assert_fails('!!', 'E34:')
1210 set nomore
1211 " Test for cmdline expansion with :!
1212 call setline(1, 'foo!')
1213 silent !echo <cWORD> > Xfile.out
1214 call assert_equal(['foo!'], readfile('Xfile.out'))
1215 " Test for using previous command
1216 silent !echo \! !
1217 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1218 call writefile(v:errors, 'Xresult')
1219 call delete('Xfile.out')
1220 qall!
1221 [SCRIPT]
1222 call writefile(lines, 'Xscript')
1223 if RunVim([], [], '--clean -S Xscript')
1224 call assert_equal([], readfile('Xresult'))
1225 endif
1226 call delete('Xscript')
1227 call delete('Xresult')
1228endfunc
1229
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001230" Test for using ~ for home directory in cmdline completion matches
1231func Test_cmdline_expand_home()
1232 call mkdir('Xdir')
1233 call writefile([], 'Xdir/Xfile1')
1234 call writefile([], 'Xdir/Xfile2')
1235 cd Xdir
1236 let save_HOME = $HOME
1237 let $HOME = getcwd()
1238 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1239 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1240 let $HOME = save_HOME
1241 cd ..
1242 call delete('Xdir', 'rf')
1243endfunc
1244
Bram Moolenaar578fe942020-02-27 21:32:51 +01001245" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1246" or insert mode (when 'insertmode' is set)
1247func Test_cmdline_ctrl_g()
1248 new
1249 call setline(1, 'abc')
1250 call cursor(1, 3)
1251 " If command line is entered from insert mode, using C-\ C-G should back to
1252 " insert mode
1253 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1254 call assert_equal('abxyc', getline(1))
1255 call assert_equal(4, col('.'))
1256
1257 " If command line is entered in 'insertmode', using C-\ C-G should back to
1258 " 'insertmode'
1259 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1260 call assert_equal('ab12xyc', getline(1))
1261 close!
1262endfunc
1263
Bram Moolenaar578fe942020-02-27 21:32:51 +01001264" Test for 'wildmode'
1265func Test_wildmode()
1266 func T(a, c, p)
1267 return "oneA\noneB\noneC"
1268 endfunc
1269 command -nargs=1 -complete=custom,T MyCmd
1270
1271 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001272 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001273 return ''
1274 endfunc
1275 cnoremap <expr> <F2> SaveScreenLine()
1276
1277 set nowildmenu
1278 set wildmode=full,list
1279 let g:Sline = ''
1280 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001281 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001282 call assert_equal('"MyCmd oneA', @:)
1283
1284 set wildmode=longest,full
1285 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1286 call assert_equal('"MyCmd one', @:)
1287 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1288 call assert_equal('"MyCmd oneC', @:)
1289
1290 set wildmode=longest
1291 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1292 call assert_equal('"MyCmd one', @:)
1293
1294 set wildmode=list:longest
1295 let g:Sline = ''
1296 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001297 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001298 call assert_equal('"MyCmd one', @:)
1299
1300 set wildmode=""
1301 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1302 call assert_equal('"MyCmd oneA', @:)
1303
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001304 " Test for wildmode=longest with 'fileignorecase' set
1305 set wildmode=longest
1306 set fileignorecase
1307 argadd AA AAA AAAA
1308 call feedkeys(":buffer \t\<C-B>\"\<CR>", 'xt')
1309 call assert_equal('"buffer AA', @:)
1310 set fileignorecase&
1311
1312 " Test for listing files with wildmode=list
1313 set wildmode=list
1314 let g:Sline = ''
1315 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal('AA AAA AAAA', g:Sline)
1317 call assert_equal('"b A', @:)
1318
1319 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001320 delcommand MyCmd
1321 delfunc T
1322 delfunc SaveScreenLine
1323 cunmap <F2>
1324 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001325 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001326endfunc
1327
1328" Test for interrupting the command-line completion
1329func Test_interrupt_compl()
1330 func F(lead, cmdl, p)
1331 if a:lead =~ 'tw'
1332 call interrupt()
1333 return
1334 endif
1335 return "one\ntwo\nthree"
1336 endfunc
1337 command -nargs=1 -complete=custom,F Tcmd
1338
1339 set nowildmenu
1340 set wildmode=full
1341 let interrupted = 0
1342 try
1343 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1344 catch /^Vim:Interrupt$/
1345 let interrupted = 1
1346 endtry
1347 call assert_equal(1, interrupted)
1348
1349 delcommand Tcmd
1350 delfunc F
1351 set wildmode&
1352endfunc
1353
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001354" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001355func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001356 let str = ":one two\<C-U>"
1357 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001358 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001359 let str ..= "\<Left>five\<Right>"
1360 let str ..= "\<Home>two "
1361 let str ..= "\<C-Left>one "
1362 let str ..= "\<C-Right> three"
1363 let str ..= "\<End>\<S-Left>four "
1364 let str ..= "\<S-Right> six"
1365 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1366 call feedkeys(str, 'xt')
1367 call assert_equal("\"one two three four five six seven", @:)
1368endfunc
1369
1370" Test for moving the cursor on the / command line in 'rightleft' mode
1371func Test_cmdline_edit_rightleft()
1372 CheckFeature rightleft
1373 set rightleft
1374 set rightleftcmd=search
1375 let str = "/one two\<C-U>"
1376 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001377 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001378 let str ..= "\<Right>five\<Left>"
1379 let str ..= "\<Home>two "
1380 let str ..= "\<C-Right>one "
1381 let str ..= "\<C-Left> three"
1382 let str ..= "\<End>\<S-Right>four "
1383 let str ..= "\<S-Left> six"
1384 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1385 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1386 call assert_equal("\"one two three four five six seven", @/)
1387 set rightleftcmd&
1388 set rightleft&
1389endfunc
1390
1391" Test for using <C-\>e in the command line to evaluate an expression
1392func Test_cmdline_expr()
1393 " Evaluate an expression from the beginning of a command line
1394 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1395 call assert_equal('"hello', @:)
1396
1397 " Use an invalid expression for <C-\>e
1398 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1399
1400 " Insert literal <CTRL-\> in the command line
1401 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1402 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001403endfunc
1404
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001405" Test for 'imcmdline' and 'imsearch'
1406" This test doesn't actually test the input method functionality.
1407func Test_cmdline_inputmethod()
1408 new
1409 call setline(1, ['', 'abc', ''])
1410 set imcmdline
1411
1412 call feedkeys(":\"abc\<CR>", 'xt')
1413 call assert_equal("\"abc", @:)
1414 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1415 call assert_equal("\"abc", @:)
1416 call feedkeys("/abc\<CR>", 'xt')
1417 call assert_equal([2, 1], [line('.'), col('.')])
1418 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1419 call assert_equal([2, 1], [line('.'), col('.')])
1420
1421 set imsearch=2
1422 call cursor(1, 1)
1423 call feedkeys("/abc\<CR>", 'xt')
1424 call assert_equal([2, 1], [line('.'), col('.')])
1425 call cursor(1, 1)
1426 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1427 call assert_equal([2, 1], [line('.'), col('.')])
1428 set imdisable
1429 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1430 call assert_equal([2, 1], [line('.'), col('.')])
1431 set imdisable&
1432 set imsearch&
1433
1434 set imcmdline&
1435 %bwipe!
1436endfunc
1437
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001438" Test for opening the command-line window when too many windows are present
1439func Test_cmdwin_fail_to_open()
1440 " Open as many windows as possible
1441 for i in range(100)
1442 try
1443 new
1444 catch /E36:/
1445 break
1446 endtry
1447 endfor
1448 call assert_beeps('call feedkeys("q:\<CR>", "xt")')
1449 only
1450endfunc
1451
1452" Test for recursively getting multiple command line inputs
1453func Test_cmdwin_multi_input()
1454 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1455 call assert_equal('"cyan', @:)
1456endfunc
1457
1458" Test for using CTRL-_ in the command line with 'allowrevins'
1459func Test_cmdline_revins()
1460 CheckNotMSWindows
1461 CheckFeature rightleft
1462 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1463 call assert_equal("\"abc\<c-_>", @:)
1464 set allowrevins
1465 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1466 call assert_equal('"abcñèæ', @:)
1467 set allowrevins&
1468endfunc
1469
1470" Test for typing UTF-8 composing characters in the command line
1471func Test_cmdline_composing_chars()
1472 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1473 call assert_equal('"ゔ', @:)
1474endfunc
1475
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001476" Test for normal mode commands not supported in the cmd window
1477func Test_cmdwin_blocked_commands()
1478 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1479 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1480 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1481 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1482 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1483 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
1484endfunc
1485
Bram Moolenaar309976e2019-12-05 18:16:33 +01001486" vim: shiftwidth=2 sts=2 expandtab