blob: c41effe077fd1cbebf3b4db201d68f81a6dfd800 [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 Moolenaaraa4d7322016-07-09 18:50:29 +0200198func Test_getcompletion()
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200199 if !has('cmdline_compl')
200 return
201 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200202 let groupcount = len(getcompletion('', 'event'))
203 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200204 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200205 call assert_true(matchcount > 0)
206 call assert_true(groupcount > matchcount)
207
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200208 if has('menu')
209 source $VIMRUNTIME/menu.vim
210 let matchcount = len(getcompletion('', 'menu'))
211 call assert_true(matchcount > 0)
212 call assert_equal(['File.'], getcompletion('File', 'menu'))
213 call assert_true(matchcount > 0)
214 let matchcount = len(getcompletion('File.', 'menu'))
215 call assert_true(matchcount > 0)
216 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200217
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200218 let l = getcompletion('v:n', 'var')
219 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200220 let l = getcompletion('v:notexists', 'var')
221 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200222
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200223 args a.c b.c
224 let l = getcompletion('', 'arglist')
225 call assert_equal(['a.c', 'b.c'], l)
226 %argdelete
227
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200228 let l = getcompletion('', 'augroup')
229 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200230 let l = getcompletion('blahblah', 'augroup')
231 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200232
233 let l = getcompletion('', 'behave')
234 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200235 let l = getcompletion('not', 'behave')
236 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200237
238 let l = getcompletion('', 'color')
239 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200240 let l = getcompletion('dirty', 'color')
241 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200242
243 let l = getcompletion('', 'command')
244 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200245 let l = getcompletion('awake', 'command')
246 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200247
248 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200249 call assert_true(index(l, 'samples/') >= 0)
250 let l = getcompletion('NoMatch', 'dir')
251 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200252
253 let l = getcompletion('exe', 'expression')
254 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200255 let l = getcompletion('kill', 'expression')
256 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200257
258 let l = getcompletion('tag', 'function')
259 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200260 let l = getcompletion('paint', 'function')
261 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200262
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200263 let Flambda = {-> 'hello'}
264 let l = getcompletion('', 'function')
265 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200266 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200267
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200268 let l = getcompletion('run', 'file')
269 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200270 let l = getcompletion('walk', 'file')
271 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200272 set wildignore=*.vim
273 let l = getcompletion('run', 'file', 1)
274 call assert_true(index(l, 'runtest.vim') < 0)
275 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200276
277 let l = getcompletion('ha', 'filetype')
278 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200279 let l = getcompletion('horse', 'filetype')
280 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200281
282 let l = getcompletion('z', 'syntax')
283 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200284 let l = getcompletion('emacs', 'syntax')
285 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200286
287 let l = getcompletion('jikes', 'compiler')
288 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200289 let l = getcompletion('break', 'compiler')
290 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200291
292 let l = getcompletion('last', 'help')
293 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200294 let l = getcompletion('giveup', 'help')
295 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200296
297 let l = getcompletion('time', 'option')
298 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200299 let l = getcompletion('space', 'option')
300 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200301
302 let l = getcompletion('er', 'highlight')
303 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200304 let l = getcompletion('dark', 'highlight')
305 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200306
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200307 let l = getcompletion('', 'messages')
308 call assert_true(index(l, 'clear') >= 0)
309 let l = getcompletion('not', 'messages')
310 call assert_equal([], l)
311
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200312 let l = getcompletion('', 'mapclear')
313 call assert_true(index(l, '<buffer>') >= 0)
314 let l = getcompletion('not', 'mapclear')
315 call assert_equal([], l)
316
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200317 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200318 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200319 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
320 let root = has('win32') ? 'C:\\' : '/'
321 let l = getcompletion(root, 'shellcmd')
322 let expected = map(filter(glob(root . '*', 0, 1),
323 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
324 call assert_equal(expected, l)
325
Bram Moolenaarb650b982016-08-05 20:35:13 +0200326 if has('cscope')
327 let l = getcompletion('', 'cscope')
328 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
329 call assert_equal(cmds, l)
330 " using cmdline completion must not change the result
331 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
332 let l = getcompletion('', 'cscope')
333 call assert_equal(cmds, l)
334 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
335 let l = getcompletion('find ', 'cscope')
336 call assert_equal(keys, l)
337 endif
338
Bram Moolenaar7522f692016-08-06 14:12:50 +0200339 if has('signs')
340 sign define Testing linehl=Comment
341 let l = getcompletion('', 'sign')
342 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
343 call assert_equal(cmds, l)
344 " using cmdline completion must not change the result
345 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
346 let l = getcompletion('', 'sign')
347 call assert_equal(cmds, l)
348 let l = getcompletion('list ', 'sign')
349 call assert_equal(['Testing'], l)
350 endif
351
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200352 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200353 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200354 if has('cmdline_hist')
355 call add(names, 'history')
356 endif
357 if has('gettext')
358 call add(names, 'locale')
359 endif
360 if has('profile')
361 call add(names, 'syntime')
362 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200363
364 set tags=Xtags
365 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
366
367 for name in names
368 let matchcount = len(getcompletion('', name))
369 call assert_true(matchcount >= 0, 'No matches for ' . name)
370 endfor
371
372 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200373 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200374
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200375 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100376 call assert_fails('call getcompletion("abc", [])', 'E474:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200377endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200378
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200379func Test_shellcmd_completion()
380 let save_path = $PATH
381
382 call mkdir('Xpathdir/Xpathsubdir', 'p')
383 call writefile([''], 'Xpathdir/Xfile.exe')
384 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
385
386 " Set PATH to example directory without trailing slash.
387 let $PATH = getcwd() . '/Xpathdir'
388
389 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
390 " dirs in the PATH, even though they won't be executed. We check that only
391 " subdirs of the PWD and executables from the PATH are included in the
392 " suggestions.
393 let actual = getcompletion('X', 'shellcmd')
394 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
395 call insert(expected, 'Xfile.exe')
396 call assert_equal(expected, actual)
397
398 call delete('Xpathdir', 'rf')
399 let $PATH = save_path
400endfunc
401
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200402func Test_expand_star_star()
403 call mkdir('a/b', 'p')
404 call writefile(['asdfasdf'], 'a/b/fileXname')
405 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
406 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200407 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200408 call delete('a', 'rf')
409endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100410
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100411func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100412 let @a = "def"
413 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
414 call assert_equal('"abc def ghi', @:)
415
416 new
417 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
418
419 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
420 call assert_equal('"aaa asdf bbb', @:)
421
422 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
423 call assert_equal('"aaa /tmp/some bbb', @:)
424
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200425 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
426 call assert_equal('"aaa '.getline(1).' bbb', @:)
427
Bram Moolenaar21efc362016-12-03 14:05:49 +0100428 set incsearch
429 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
430 call assert_equal('"aaa verylongword bbb', @:)
431
432 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
433 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100434
435 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
436 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100437 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200438
439 " Error while typing a command used to cause that it was not executed
440 " in the end.
441 new
442 try
443 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
444 catch /^Vim\%((\a\+)\)\=:E32/
445 " ignore error E32
446 endtry
447 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100448
Bram Moolenaar578fe942020-02-27 21:32:51 +0100449 " Try to paste an invalid register using <C-R>
450 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
451 call assert_equal('"onetwo', @:)
452
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100453 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100454 let @a = "xy\<C-H>z"
455 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
456 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100457 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
458 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100459 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
460 call assert_equal("\"xy\<C-H>z", @:)
461
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100462 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
463 let @a = "xy\<C-V>z"
464 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
465 call assert_equal('"xyz', @:)
466 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
467 call assert_equal("\"xy\<C-V>z", @:)
468
Bram Moolenaar578fe942020-02-27 21:32:51 +0100469 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
470
Bram Moolenaar72532d32018-04-07 19:09:09 +0200471 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100472endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100473
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100474func Test_cmdline_remove_char()
475 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100476
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100477 for e in ['utf8', 'latin1']
478 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100479
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100480 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
481 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100482
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100483 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
484 call assert_equal('"abcdef', @:)
485
486 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
487 call assert_equal('"abc ghi', @:, e)
488
489 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
490 call assert_equal('"def', @:, e)
491 endfor
492
493 let &encoding = encoding_save
494endfunc
495
496func Test_cmdline_keymap_ctrl_hat()
497 if !has('keymap')
498 return
499 endif
500
501 set keymap=esperanto
502 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
503 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
504 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100505endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100506
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100507func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100508 new
509 2;'(
510 2;')
511 quit
512endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100513
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100514func Test_illegal_address2()
515 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
516 new
517 source Xtest.vim
518 " Trigger calling validate_cursor()
519 diffsp Xtest.vim
520 quit!
521 bwipe!
522 call delete('Xtest.vim')
523endfunc
524
Bram Moolenaarba47b512017-01-24 21:18:19 +0100525func Test_cmdline_complete_wildoptions()
526 help
527 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
528 let a = join(sort(split(@:)),' ')
529 set wildoptions=tagfile
530 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
531 let b = join(sort(split(@:)),' ')
532 call assert_equal(a, b)
533 bw!
534endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100535
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200536func Test_cmdline_complete_user_cmd()
537 command! -complete=color -nargs=1 Foo :
538 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
539 call assert_equal('"Foo blue', @:)
540 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
541 call assert_equal('"Foo blue', @:)
542 delcommand Foo
543endfunc
544
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100545func s:ScriptLocalFunction()
546 echo 'yes'
547endfunc
548
549func Test_cmdline_complete_user_func()
550 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
551 call assert_match('"func Test_cmdline_complete_user', @:)
552 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
553 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
554endfunc
555
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200556func Test_cmdline_complete_user_names()
557 if has('unix') && executable('whoami')
558 let whoami = systemlist('whoami')[0]
559 let first_letter = whoami[0]
560 if len(first_letter) > 0
561 " Trying completion of :e ~x where x is the first letter of
562 " the user name should complete to at least the user name.
563 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
564 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
565 endif
566 endif
567 if has('win32')
568 " Just in case: check that the system has an Administrator account.
569 let names = system('net user')
570 if names =~ 'Administrator'
571 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100572 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200573 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100574 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200575 endif
576 endif
577endfunc
578
Bram Moolenaar297610b2019-12-27 17:20:55 +0100579func Test_cmdline_complete_bang()
580 if executable('whoami')
Bram Moolenaar731a7992019-12-28 14:06:50 +0100581 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
582 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100583 endif
Bram Moolenaar297610b2019-12-27 17:20:55 +0100584endfunc
585
Bram Moolenaar8b633132020-03-20 18:20:51 +0100586func Test_cmdline_complete_languages()
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200587 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
588
589 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
590 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
591
592 if has('unix')
593 " TODO: these tests don't work on Windows. lang appears to be 'C'
594 " but C does not appear in the completion. Why?
595 call assert_match('^"language .*\<' . lang . '\>', @:)
596
597 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
598 call assert_match('^"language .*\<' . lang . '\>', @:)
599
600 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
601 call assert_match('^"language .*\<' . lang . '\>', @:)
602
603 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
604 call assert_match('^"language .*\<' . lang . '\>', @:)
605 endif
606endfunc
607
Bram Moolenaar297610b2019-12-27 17:20:55 +0100608func Test_cmdline_complete_env_variable()
609 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100610 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
611 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100612 unlet $X_VIM_TEST_COMPLETE_ENV
613endfunc
614
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100615" Test for various command-line completion
616func Test_cmdline_complete_various()
617 " completion for a command starting with a comment
618 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
619 call assert_equal("\" :|\"\<C-A>", @:)
620
621 " completion for a range followed by a comment
622 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
623 call assert_equal("\"1,2\"\<C-A>", @:)
624
625 " completion for :k command
626 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
627 call assert_equal("\"ka\<C-A>", @:)
628
629 " completion for short version of the :s command
630 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
631 call assert_equal("\"sI \<C-A>", @:)
632
633 " completion for :write command
634 call mkdir('Xdir')
635 call writefile(['one'], 'Xdir/Xfile1')
636 let save_cwd = getcwd()
637 cd Xdir
638 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
639 call assert_equal("\"w >> Xfile1", @:)
640 call chdir(save_cwd)
641 call delete('Xdir', 'rf')
642
643 " completion for :w ! and :r ! commands
644 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
645 call assert_equal("\"w !invalid_xyz_cmd", @:)
646 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
647 call assert_equal("\"r !invalid_xyz_cmd", @:)
648
649 " completion for :>> and :<< commands
650 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
651 call assert_equal("\">>>\<C-A>", @:)
652 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
653 call assert_equal("\"<<<\<C-A>", @:)
654
655 " completion for command with +cmd argument
656 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
657 call assert_equal("\"buffer +/pat Xabc", @:)
658 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
659 call assert_equal("\"buffer +/pat\<C-A>", @:)
660
661 " completion for a command with a trailing comment
662 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
663 call assert_equal("\"ls \" comment\<C-A>", @:)
664
665 " completion for a command with a trailing command
666 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
667 call assert_equal("\"ls | ls", @:)
668
669 " completion for a command with an CTRL-V escaped argument
670 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
671 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
672
673 " completion for a command that doesn't take additional arguments
674 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
675 call assert_equal("\"all abc\<C-A>", @:)
676
677 " completion for a command with a command modifier
678 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
679 call assert_equal("\"topleft new", @:)
680
681 " completion for the :match command
682 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
683 call assert_equal("\"match Search /pat/\<C-A>", @:)
684
685 " completion for the :s command
686 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
687 call assert_equal("\"s/from/to/g\<C-A>", @:)
688
689 " completion for the :dlist command
690 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
691 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
692
693 " completion for the :doautocmd command
694 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
695 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
696
697 " completion for the :augroup command
698 augroup XTest
699 augroup END
700 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
701 call assert_equal("\"augroup XTest", @:)
702 augroup! XTest
703
704 " completion for the :unlet command
705 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
706 call assert_equal("\"unlet one two", @:)
707
708 " completion for the :bdelete command
709 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
710 call assert_equal("\"bdel a b c", @:)
711
712 " completion for the :mapclear command
713 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
714 call assert_equal("\"mapclear <buffer>", @:)
715
716 " completion for user defined commands with menu names
717 menu Test.foo :ls<CR>
718 com -nargs=* -complete=menu MyCmd
719 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
720 call assert_equal('"MyCmd Test.', @:)
721 delcom MyCmd
722 unmenu Test
723
724 " completion for user defined commands with mappings
725 mapclear
726 map <F3> :ls<CR>
727 com -nargs=* -complete=mapping MyCmd
728 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
729 call assert_equal('"MyCmd <F3>', @:)
730 mapclear
731 delcom MyCmd
732
733 " completion for :set path= with multiple backslashes
734 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
735 call assert_equal('"set path=a\\\ b', @:)
736
737 " completion for :set dir= with a backslash
738 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
739 call assert_equal('"set dir=a\ b', @:)
740
741 " completion for the :py3 commands
742 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
743 call assert_equal('"py3 py3do py3file', @:)
744
745 " redir @" is not the start of a comment. So complete after that
746 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
747 call assert_equal('"redir @" | cwindow', @:)
748
749 " completion after a backtick
750 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
751 call assert_equal('"e `a1b2c', @:)
752
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100753 " completion for :language command with an invalid argument
754 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
755 call assert_equal("\"language dummy \t", @:)
756
757 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +0100758 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
759 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100760
761 " completion with ambiguous user defined commands
762 com TCmd1 echo 'TCmd1'
763 com TCmd2 echo 'TCmd2'
764 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
765 call assert_equal('"TCmd ', @:)
766 delcom TCmd1
767 delcom TCmd2
768
769 " completion after a range followed by a pipe (|) character
770 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
771 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100772endfunc
773
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200774func Test_cmdline_write_alternatefile()
775 new
776 call setline('.', ['one', 'two'])
777 f foo.txt
778 new
779 f #-A
780 call assert_equal('foo.txt-A', expand('%'))
781 f #<-B.txt
782 call assert_equal('foo-B.txt', expand('%'))
783 f %<
784 call assert_equal('foo-B', expand('%'))
785 new
786 call assert_fails('f #<', 'E95')
787 bw!
788 f foo-B.txt
789 f %<-A
790 call assert_equal('foo-B-A', expand('%'))
791 bw!
792 bw!
793endfunc
794
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100795" using a leading backslash here
796set cpo+=C
797
798func Test_cmdline_search_range()
799 new
800 call setline(1, ['a', 'b', 'c', 'd'])
801 /d
802 1,\/s/b/B/
803 call assert_equal('B', getline(2))
804
805 /a
806 $
807 \?,4s/c/C/
808 call assert_equal('C', getline(3))
809
810 call setline(1, ['a', 'b', 'c', 'd'])
811 %s/c/c/
812 1,\&s/b/B/
813 call assert_equal('B', getline(2))
814
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100815 let @/ = 'apple'
816 call assert_fails('\/print', 'E486:')
817
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100818 bwipe!
819endfunc
820
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100821" Test for the tick mark (') in an excmd range
822func Test_tick_mark_in_range()
823 " If only the tick is passed as a range and no command is specified, there
824 " should not be an error
825 call feedkeys(":'\<CR>", 'xt')
826 call assert_equal("'", getreg(':'))
827 call assert_fails("',print", 'E78:')
828endfunc
829
830" Test for using a line number followed by a search pattern as range
831func Test_lnum_and_pattern_as_range()
832 new
833 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
834 let @" = ''
835 2/foo/yank
836 call assert_equal("foo 3\n", @")
837 call assert_equal(1, line('.'))
838 close!
839endfunc
840
Bram Moolenaar65189a12017-02-06 22:22:17 +0100841" Tests for getcmdline(), getcmdpos() and getcmdtype()
842func Check_cmdline(cmdtype)
843 call assert_equal('MyCmd a', getcmdline())
844 call assert_equal(8, getcmdpos())
845 call assert_equal(a:cmdtype, getcmdtype())
846 return ''
847endfunc
848
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200849set cpo&
850
Bram Moolenaar65189a12017-02-06 22:22:17 +0100851func Test_getcmdtype()
852 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
853
854 let cmdtype = ''
855 debuggreedy
856 call feedkeys(":debug echo 'test'\<CR>", "t")
857 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
858 call feedkeys("cont\<CR>", "xt")
859 0debuggreedy
860 call assert_equal('>', cmdtype)
861
862 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
863 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
864
865 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +0100866 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +0100867
868 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
869
870 cnoremap <expr> <F6> Check_cmdline('=')
871 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
872 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100873
874 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +0100875endfunc
876
Bram Moolenaar81612b72018-06-23 14:55:03 +0200877func Test_getcmdwintype()
878 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
879 call assert_equal('/', a)
880
881 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
882 call assert_equal('?', a)
883
884 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
885 call assert_equal(':', a)
886
887 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
888 call assert_equal(':', a)
889
890 call assert_equal('', getcmdwintype())
891endfunc
892
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200893func Test_getcmdwin_autocmd()
894 let s:seq = []
895 augroup CmdWin
896 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
897 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
898 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
899 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
900 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
901 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
902
903 let org_winid = win_getid()
904 let org_bufnr = bufnr()
905 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
906 call assert_equal(':', a)
907 call assert_equal([
908 \ 'WinLeave ' .. org_winid,
909 \ 'WinEnter ' .. s:cmd_winid,
910 \ 'BufLeave ' .. org_bufnr,
911 \ 'BufEnter ' .. s:cmd_bufnr,
912 \ 'CmdWinEnter ' .. s:cmd_winid,
913 \ 'CmdWinLeave ' .. s:cmd_winid,
914 \ 'BufLeave ' .. s:cmd_bufnr,
915 \ 'WinLeave ' .. s:cmd_winid,
916 \ 'WinEnter ' .. org_winid,
917 \ 'BufEnter ' .. org_bufnr,
918 \ ], s:seq)
919
920 au!
921 augroup END
922endfunc
923
Bram Moolenaar52604f22017-04-07 16:17:39 +0200924func Test_verbosefile()
925 set verbosefile=Xlog
926 echomsg 'foo'
927 echomsg 'bar'
928 set verbosefile=
929 let log = readfile('Xlog')
930 call assert_match("foo\nbar", join(log, "\n"))
931 call delete('Xlog')
932endfunc
933
Bram Moolenaar4facea32019-10-12 20:17:40 +0200934func Test_verbose_option()
935 CheckScreendump
936
937 let lines =<< trim [SCRIPT]
938 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
939 call feedkeys("\r", 't') " for the hit-enter prompt
940 set verbose=20
941 [SCRIPT]
942 call writefile(lines, 'XTest_verbose')
943
944 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
945 call term_wait(buf, 100)
946 call term_sendkeys(buf, ":DoSomething\<CR>")
947 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
948
949 " clean up
950 call StopVimInTerminal(buf)
951 call delete('XTest_verbose')
952endfunc
953
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200954func Test_setcmdpos()
955 func InsertTextAtPos(text, pos)
956 call assert_equal(0, setcmdpos(a:pos))
957 return a:text
958 endfunc
959
960 " setcmdpos() with position in the middle of the command line.
961 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
962 call assert_equal('"1ab2', @:)
963
964 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
965 call assert_equal('"1b2a', @:)
966
967 " setcmdpos() with position beyond the end of the command line.
968 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
969 call assert_equal('"12ab', @:)
970
971 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +0200972 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +0200973endfunc
974
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100975func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100976 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100977 let encoding_save = &encoding
978
979 for e in encodings
980 exe 'set encoding=' . e
981
982 " Test overstrike in the middle of the command line.
983 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100984 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100985
986 " Test overstrike going beyond end of command line.
987 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100988 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100989
990 " Test toggling insert/overstrike a few times.
991 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100992 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100993 endfor
994
Bram Moolenaar30276f22019-01-24 17:59:39 +0100995 " Test overstrike with multi-byte characters.
996 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100997 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +0100998
999 let &encoding = encoding_save
1000endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001001
1002func Test_cmdwin_bug()
1003 let winid = win_getid()
1004 sp
1005 try
1006 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1007 catch /^Vim\%((\a\+)\)\=:E11/
1008 endtry
1009 bw!
1010endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001011
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001012func Test_cmdwin_restore()
1013 CheckScreendump
1014
1015 let lines =<< trim [SCRIPT]
1016 call setline(1, range(30))
1017 2split
1018 [SCRIPT]
1019 call writefile(lines, 'XTest_restore')
1020
1021 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
1022 call term_wait(buf, 100)
1023 call term_sendkeys(buf, "q:")
1024 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1025
1026 " normal restore
1027 call term_sendkeys(buf, ":q\<CR>")
1028 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1029
1030 " restore after setting 'lines' with one window
1031 call term_sendkeys(buf, ":close\<CR>")
1032 call term_sendkeys(buf, "q:")
1033 call term_sendkeys(buf, ":set lines=18\<CR>")
1034 call term_sendkeys(buf, ":q\<CR>")
1035 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1036
1037 " clean up
1038 call StopVimInTerminal(buf)
1039 call delete('XTest_restore')
1040endfunc
1041
Bram Moolenaar52410572019-10-27 05:12:45 +01001042func Test_buffers_lastused()
1043 " check that buffers are sorted by time when wildmode has lastused
1044 call test_settime(1550020000) " middle
1045 edit bufa
1046 enew
1047 call test_settime(1550030000) " newest
1048 edit bufb
1049 enew
1050 call test_settime(1550010000) " oldest
1051 edit bufc
1052 enew
1053 call test_settime(0)
1054 enew
1055
1056 call assert_equal(['bufa', 'bufb', 'bufc'],
1057 \ getcompletion('', 'buffer'))
1058
1059 let save_wildmode = &wildmode
1060 set wildmode=full:lastused
1061
1062 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1063 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1064 call assert_equal('b bufb', X)
1065 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1066 call assert_equal('b bufa', X)
1067 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1068 call assert_equal('b bufc', X)
1069 enew
1070
1071 edit other
1072 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1073 call assert_equal('b bufb', X)
1074 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1075 call assert_equal('b bufa', X)
1076 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1077 call assert_equal('b bufc', X)
1078 enew
1079
1080 let &wildmode = save_wildmode
1081
1082 bwipeout bufa
1083 bwipeout bufb
1084 bwipeout bufc
1085endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001086
1087func Test_cmdwin_feedkeys()
1088 " This should not generate E488
1089 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001090 " Using feedkeys with q: only should automatically close the cmd window
1091 call feedkeys('q:', 'xt')
1092 call assert_equal(1, winnr('$'))
1093 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001094endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001095
1096" Tests for the issues fixed in 7.4.441.
1097" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1098func Test_cmdwin_cedit()
1099 exe "set cedit=\<C-c>"
1100 normal! :
1101 call assert_equal(1, winnr('$'))
1102
1103 let g:cmd_wintype = ''
1104 func CmdWinType()
1105 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001106 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001107 return ''
1108 endfunc
1109
1110 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1111 echo input('')
1112 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001113 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001114
1115 set cedit&vim
1116 delfunc CmdWinType
1117endfunc
1118
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001119" Test for CmdwinEnter autocmd
1120func Test_cmdwin_autocmd()
1121 augroup CmdWin
1122 au!
1123 autocmd CmdwinEnter * startinsert
1124 augroup END
1125
1126 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1127 call assert_equal('xyz', @:)
1128
1129 augroup CmdWin
1130 au!
1131 augroup END
1132 augroup! CmdWin
1133endfunc
1134
Bram Moolenaar479950f2020-01-19 15:45:17 +01001135func Test_cmdlineclear_tabenter()
1136 CheckScreendump
1137
1138 let lines =<< trim [SCRIPT]
1139 call setline(1, range(30))
1140 [SCRIPT]
1141
1142 call writefile(lines, 'XtestCmdlineClearTabenter')
1143 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
1144 call term_wait(buf, 50)
1145 " in one tab make the command line higher with CTRL-W -
1146 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1147 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1148
1149 call StopVimInTerminal(buf)
1150 call delete('XtestCmdlineClearTabenter')
1151endfunc
1152
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001153" Test for failure in expanding special keywords in cmdline
1154func Test_cmdline_expand_special()
1155 %bwipe!
1156 call assert_fails('e #', 'E499:')
1157 call assert_fails('e <afile>', 'E495:')
1158 call assert_fails('e <abuf>', 'E496:')
1159 call assert_fails('e <amatch>', 'E497:')
1160endfunc
1161
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001162func Test_cmdwin_jump_to_win()
1163 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1164 new
1165 set modified
1166 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
1167 close!
1168 call feedkeys("q/:close\<CR>", "xt")
1169 call assert_equal(1, winnr('$'))
1170 call feedkeys("q/:exit\<CR>", "xt")
1171 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001172
1173 " opening command window twice should fail
1174 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1175 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001176endfunc
1177
1178" Test for backtick expression in the command line
1179func Test_cmd_backtick()
1180 %argd
1181 argadd `=['a', 'b', 'c']`
1182 call assert_equal(['a', 'b', 'c'], argv())
1183 %argd
1184endfunc
1185
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001186" Test for the :! command
1187func Test_cmd_bang()
1188 if !has('unix')
1189 return
1190 endif
1191
1192 let lines =<< trim [SCRIPT]
1193 " Test for no previous command
1194 call assert_fails('!!', 'E34:')
1195 set nomore
1196 " Test for cmdline expansion with :!
1197 call setline(1, 'foo!')
1198 silent !echo <cWORD> > Xfile.out
1199 call assert_equal(['foo!'], readfile('Xfile.out'))
1200 " Test for using previous command
1201 silent !echo \! !
1202 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1203 call writefile(v:errors, 'Xresult')
1204 call delete('Xfile.out')
1205 qall!
1206 [SCRIPT]
1207 call writefile(lines, 'Xscript')
1208 if RunVim([], [], '--clean -S Xscript')
1209 call assert_equal([], readfile('Xresult'))
1210 endif
1211 call delete('Xscript')
1212 call delete('Xresult')
1213endfunc
1214
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001215" Test for using ~ for home directory in cmdline completion matches
1216func Test_cmdline_expand_home()
1217 call mkdir('Xdir')
1218 call writefile([], 'Xdir/Xfile1')
1219 call writefile([], 'Xdir/Xfile2')
1220 cd Xdir
1221 let save_HOME = $HOME
1222 let $HOME = getcwd()
1223 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1225 let $HOME = save_HOME
1226 cd ..
1227 call delete('Xdir', 'rf')
1228endfunc
1229
Bram Moolenaar578fe942020-02-27 21:32:51 +01001230" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1231" or insert mode (when 'insertmode' is set)
1232func Test_cmdline_ctrl_g()
1233 new
1234 call setline(1, 'abc')
1235 call cursor(1, 3)
1236 " If command line is entered from insert mode, using C-\ C-G should back to
1237 " insert mode
1238 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1239 call assert_equal('abxyc', getline(1))
1240 call assert_equal(4, col('.'))
1241
1242 " If command line is entered in 'insertmode', using C-\ C-G should back to
1243 " 'insertmode'
1244 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1245 call assert_equal('ab12xyc', getline(1))
1246 close!
1247endfunc
1248
Bram Moolenaar578fe942020-02-27 21:32:51 +01001249" Test for 'wildmode'
1250func Test_wildmode()
1251 func T(a, c, p)
1252 return "oneA\noneB\noneC"
1253 endfunc
1254 command -nargs=1 -complete=custom,T MyCmd
1255
1256 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001257 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001258 return ''
1259 endfunc
1260 cnoremap <expr> <F2> SaveScreenLine()
1261
1262 set nowildmenu
1263 set wildmode=full,list
1264 let g:Sline = ''
1265 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001266 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001267 call assert_equal('"MyCmd oneA', @:)
1268
1269 set wildmode=longest,full
1270 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1271 call assert_equal('"MyCmd one', @:)
1272 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1273 call assert_equal('"MyCmd oneC', @:)
1274
1275 set wildmode=longest
1276 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1277 call assert_equal('"MyCmd one', @:)
1278
1279 set wildmode=list:longest
1280 let g:Sline = ''
1281 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001282 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001283 call assert_equal('"MyCmd one', @:)
1284
1285 set wildmode=""
1286 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1287 call assert_equal('"MyCmd oneA', @:)
1288
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001289 " Test for wildmode=longest with 'fileignorecase' set
1290 set wildmode=longest
1291 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001292 argadd AAA AAAA AAAAA
1293 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1294 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001295 set fileignorecase&
1296
1297 " Test for listing files with wildmode=list
1298 set wildmode=list
1299 let g:Sline = ''
1300 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001301 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001302 call assert_equal('"b A', @:)
1303
1304 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001305 delcommand MyCmd
1306 delfunc T
1307 delfunc SaveScreenLine
1308 cunmap <F2>
1309 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001310 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001311endfunc
1312
1313" Test for interrupting the command-line completion
1314func Test_interrupt_compl()
1315 func F(lead, cmdl, p)
1316 if a:lead =~ 'tw'
1317 call interrupt()
1318 return
1319 endif
1320 return "one\ntwo\nthree"
1321 endfunc
1322 command -nargs=1 -complete=custom,F Tcmd
1323
1324 set nowildmenu
1325 set wildmode=full
1326 let interrupted = 0
1327 try
1328 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1329 catch /^Vim:Interrupt$/
1330 let interrupted = 1
1331 endtry
1332 call assert_equal(1, interrupted)
1333
1334 delcommand Tcmd
1335 delfunc F
1336 set wildmode&
1337endfunc
1338
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001339" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001340func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001341 let str = ":one two\<C-U>"
1342 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001343 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001344 let str ..= "\<Left>five\<Right>"
1345 let str ..= "\<Home>two "
1346 let str ..= "\<C-Left>one "
1347 let str ..= "\<C-Right> three"
1348 let str ..= "\<End>\<S-Left>four "
1349 let str ..= "\<S-Right> six"
1350 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1351 call feedkeys(str, 'xt')
1352 call assert_equal("\"one two three four five six seven", @:)
1353endfunc
1354
1355" Test for moving the cursor on the / command line in 'rightleft' mode
1356func Test_cmdline_edit_rightleft()
1357 CheckFeature rightleft
1358 set rightleft
1359 set rightleftcmd=search
1360 let str = "/one two\<C-U>"
1361 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001362 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001363 let str ..= "\<Right>five\<Left>"
1364 let str ..= "\<Home>two "
1365 let str ..= "\<C-Right>one "
1366 let str ..= "\<C-Left> three"
1367 let str ..= "\<End>\<S-Right>four "
1368 let str ..= "\<S-Left> six"
1369 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1370 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1371 call assert_equal("\"one two three four five six seven", @/)
1372 set rightleftcmd&
1373 set rightleft&
1374endfunc
1375
1376" Test for using <C-\>e in the command line to evaluate an expression
1377func Test_cmdline_expr()
1378 " Evaluate an expression from the beginning of a command line
1379 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1380 call assert_equal('"hello', @:)
1381
1382 " Use an invalid expression for <C-\>e
1383 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1384
1385 " Insert literal <CTRL-\> in the command line
1386 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1387 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001388endfunc
1389
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001390" Test for 'imcmdline' and 'imsearch'
1391" This test doesn't actually test the input method functionality.
1392func Test_cmdline_inputmethod()
1393 new
1394 call setline(1, ['', 'abc', ''])
1395 set imcmdline
1396
1397 call feedkeys(":\"abc\<CR>", 'xt')
1398 call assert_equal("\"abc", @:)
1399 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1400 call assert_equal("\"abc", @:)
1401 call feedkeys("/abc\<CR>", 'xt')
1402 call assert_equal([2, 1], [line('.'), col('.')])
1403 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1404 call assert_equal([2, 1], [line('.'), col('.')])
1405
1406 set imsearch=2
1407 call cursor(1, 1)
1408 call feedkeys("/abc\<CR>", 'xt')
1409 call assert_equal([2, 1], [line('.'), col('.')])
1410 call cursor(1, 1)
1411 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1412 call assert_equal([2, 1], [line('.'), col('.')])
1413 set imdisable
1414 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1415 call assert_equal([2, 1], [line('.'), col('.')])
1416 set imdisable&
1417 set imsearch&
1418
1419 set imcmdline&
1420 %bwipe!
1421endfunc
1422
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001423" Test for recursively getting multiple command line inputs
1424func Test_cmdwin_multi_input()
1425 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1426 call assert_equal('"cyan', @:)
1427endfunc
1428
1429" Test for using CTRL-_ in the command line with 'allowrevins'
1430func Test_cmdline_revins()
1431 CheckNotMSWindows
1432 CheckFeature rightleft
1433 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1434 call assert_equal("\"abc\<c-_>", @:)
1435 set allowrevins
1436 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1437 call assert_equal('"abcñèæ', @:)
1438 set allowrevins&
1439endfunc
1440
1441" Test for typing UTF-8 composing characters in the command line
1442func Test_cmdline_composing_chars()
1443 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1444 call assert_equal('"ゔ', @:)
1445endfunc
1446
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001447" Test for normal mode commands not supported in the cmd window
1448func Test_cmdwin_blocked_commands()
1449 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1450 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1451 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1452 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1453 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1454 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
1455endfunc
1456
Bram Moolenaar309976e2019-12-05 18:16:33 +01001457" vim: shiftwidth=2 sts=2 expandtab