blob: a38499cca1f80de2a14ad0c2a8a98d4c2bff9cd9 [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 Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaar4facea32019-10-12 20:17:40 +02007
Bram Moolenaarae3150e2016-06-11 23:22:36 +02008func Test_complete_tab()
9 call writefile(['testfile'], 'Xtestfile')
10 call feedkeys(":e Xtest\t\r", "tx")
11 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020012
13 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
14 call feedkeys(":e %\t\r", "tx")
15 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020016 call delete('Xtestfile')
17endfunc
18
19func Test_complete_list()
20 " We can't see the output, but at least we check the code runs properly.
21 call feedkeys(":e test\<C-D>\r", "tx")
22 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010023
24 " If a command doesn't support completion, then CTRL-D should be literally
25 " used.
26 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
27 call assert_equal("\"chistory \<C-D>", @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020028endfunc
29
30func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010031 call mkdir('Xdir1/Xdir2', 'p')
32 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
33 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
34 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
35 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020036 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010037
38 " Pressing <Tab> completes, and moves to next files when pressing again.
39 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
40 call assert_equal('testfile1', getline(1))
41 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020042 call assert_equal('testfile2', getline(1))
43
Bram Moolenaar37db6422019-03-28 21:26:23 +010044 " <S-Tab> is like <Tab> but begin with the last match and then go to
45 " previous.
46 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
47 call assert_equal('testfile2', getline(1))
48 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
49 call assert_equal('testfile1', getline(1))
50
51 " <Left>/<Right> to move to previous/next file.
52 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
53 call assert_equal('testfile1', getline(1))
54 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
55 call assert_equal('testfile2', getline(1))
56 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
57 call assert_equal('testfile1', getline(1))
58
59 " <Up>/<Down> to go up/down directories.
60 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
61 call assert_equal('testfile3', getline(1))
62 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
63 call assert_equal('testfile1', getline(1))
64
Bram Moolenaar3e112ac2020-12-28 13:41:53 +010065 " this fails in some Unix GUIs, not sure why
66 if !has('unix') || !has('gui_running')
67 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
68 " different than 'wildchar'.
69 set wildcharm=<C-Z>
70 cnoremap <C-J> <Down><C-Z>
71 cnoremap <C-K> <Up><C-Z>
72 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx')
73 call assert_equal('testfile3', getline(1))
74 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
75 call assert_equal('testfile1', getline(1))
76 set wildcharm=0
77 cunmap <C-J>
78 cunmap <C-K>
79 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +010080
Bram Moolenaar578fe942020-02-27 21:32:51 +010081 " Test for canceling the wild menu by adding a character
82 redrawstatus
83 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
84 call assert_equal('"e Xdir1/Xdir2/x', @:)
85
Bram Moolenaar8d588cc2020-02-25 21:47:45 +010086 " Completion using a relative path
87 cd Xdir1/Xdir2
88 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
89 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
90 cd -
91
Bram Moolenaar0e05de42020-03-25 22:23:46 +010092 cnoremap <expr> <F2> wildmenumode()
93 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +000094 call assert_equal('"cd Xdir1/0', @:)
95 call feedkeys(":e Xdir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
96 call assert_equal('"e Xdir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +010097 cunmap <F2>
98
Bram Moolenaar37db6422019-03-28 21:26:23 +010099 " cleanup
100 %bwipe
101 call delete('Xdir1/Xdir2/Xtestfile4')
102 call delete('Xdir1/Xdir2/Xtestfile3')
103 call delete('Xdir1/Xtestfile2')
104 call delete('Xdir1/Xtestfile1')
105 call delete('Xdir1/Xdir2', 'd')
106 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200107 set nowildmenu
108endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100109
Bram Moolenaara60053b2020-09-03 16:50:13 +0200110func Test_wildmenu_screendump()
111 CheckScreendump
112
113 let lines =<< trim [SCRIPT]
114 set wildmenu hlsearch
115 [SCRIPT]
116 call writefile(lines, 'XTest_wildmenu')
117
118 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
119 call term_sendkeys(buf, ":vim\<Tab>")
120 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
121
122 call term_sendkeys(buf, "\<Tab>")
123 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
124
125 call term_sendkeys(buf, "\<Tab>")
126 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
127
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100128 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200129 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
130 call term_sendkeys(buf, "\<Esc>")
131
132 " clean up
133 call StopVimInTerminal(buf)
134 call delete('XTest_wildmenu')
135endfunc
136
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100137func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100138 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
139 call assert_equal('"map <unique> <silent>', getreg(':'))
140 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
141 call assert_equal('"map <script> <unique>', getreg(':'))
142 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
143 call assert_equal('"map <expr> <script>', getreg(':'))
144 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
145 call assert_equal('"map <buffer> <expr>', getreg(':'))
146 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
147 call assert_equal('"map <nowait> <buffer>', getreg(':'))
148 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
149 call assert_equal('"map <special> <nowait>', getreg(':'))
150 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
151 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200152
Bram Moolenaar1776a282019-05-03 16:05:41 +0200153 map <Middle>x middle
154
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200155 map ,f commaf
156 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200157 map <Left> left
158 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200159 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
160 call assert_equal('"map ,f', getreg(':'))
161 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
162 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200163 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
164 call assert_equal('"map <Left>', getreg(':'))
165 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200166 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200167 unmap ,f
168 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200169 unmap <Left>
170 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200171
172 set cpo-=< cpo-=B cpo-=k
173 map <Left> left
174 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
175 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200176 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200177 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200178 unmap <Left>
179
180 set cpo+=<
181 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200182 exe "set t_k6=\<Esc>[17~"
183 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200184 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
185 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200186 if !has('gui_running')
187 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
188 call assert_equal("\"map <F6>x", getreg(':'))
189 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200190 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200191 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200192 set cpo-=<
193
194 set cpo+=B
195 map <Left> left
196 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
197 call assert_equal('"map <Left>', getreg(':'))
198 unmap <Left>
199 set cpo-=B
200
201 set cpo+=k
202 map <Left> left
203 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
204 call assert_equal('"map <Left>', getreg(':'))
205 unmap <Left>
206 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200207
Bram Moolenaar531be472020-09-23 22:38:05 +0200208 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
209
Bram Moolenaar1776a282019-05-03 16:05:41 +0200210 unmap <Middle>x
211 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100212endfunc
213
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100214func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100215 hi Aardig ctermfg=green
216 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
217 call assert_equal('"match Aardig', getreg(':'))
218 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
219 call assert_equal('"match none', getreg(':'))
220endfunc
221
222func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100223 hi Aardig ctermfg=green
224 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
225 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200226 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
227 call assert_equal('"hi default Aardig', getreg(':'))
228 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
229 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100230 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
231 call assert_equal('"hi link', getreg(':'))
232 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
233 call assert_equal('"hi default', getreg(':'))
234 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
235 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200236 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
237 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
238 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
239 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200240
241 " A cleared group does not show up in completions.
242 hi Anders ctermfg=green
243 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
244 hi clear Aardig
245 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
246 hi clear Anders
247 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100248endfunc
249
Bram Moolenaar75e15672020-06-28 13:10:22 +0200250" Test for command-line expansion of "hi Ni " (easter egg)
251func Test_highlight_easter_egg()
252 call test_override('ui_delay', 1)
253 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
254 call assert_equal("\"hi Ni \<Tab>", @:)
255 call test_override('ALL', 0)
256endfunc
257
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200258func Test_getcompletion()
259 let groupcount = len(getcompletion('', 'event'))
260 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200261 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200262 call assert_true(matchcount > 0)
263 call assert_true(groupcount > matchcount)
264
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200265 if has('menu')
266 source $VIMRUNTIME/menu.vim
267 let matchcount = len(getcompletion('', 'menu'))
268 call assert_true(matchcount > 0)
269 call assert_equal(['File.'], getcompletion('File', 'menu'))
270 call assert_true(matchcount > 0)
271 let matchcount = len(getcompletion('File.', 'menu'))
272 call assert_true(matchcount > 0)
273 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200274
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200275 let l = getcompletion('v:n', 'var')
276 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200277 let l = getcompletion('v:notexists', 'var')
278 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200279
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200280 args a.c b.c
281 let l = getcompletion('', 'arglist')
282 call assert_equal(['a.c', 'b.c'], l)
283 %argdelete
284
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200285 let l = getcompletion('', 'augroup')
286 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200287 let l = getcompletion('blahblah', 'augroup')
288 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200289
290 let l = getcompletion('', 'behave')
291 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200292 let l = getcompletion('not', 'behave')
293 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200294
295 let l = getcompletion('', 'color')
296 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200297 let l = getcompletion('dirty', 'color')
298 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200299
300 let l = getcompletion('', 'command')
301 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200302 let l = getcompletion('awake', 'command')
303 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200304
305 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200306 call assert_true(index(l, 'samples/') >= 0)
307 let l = getcompletion('NoMatch', 'dir')
308 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200309
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100310 if glob('~/*') !=# ''
311 let l = getcompletion('~/', 'dir')
312 call assert_true(l[0][0] ==# '~')
313 endif
314
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200315 let l = getcompletion('exe', 'expression')
316 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200317 let l = getcompletion('kill', 'expression')
318 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200319
320 let l = getcompletion('tag', 'function')
321 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200322 let l = getcompletion('paint', 'function')
323 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200324
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200325 let Flambda = {-> 'hello'}
326 let l = getcompletion('', 'function')
327 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200328 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200329
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200330 let l = getcompletion('run', 'file')
331 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200332 let l = getcompletion('walk', 'file')
333 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200334 set wildignore=*.vim
335 let l = getcompletion('run', 'file', 1)
336 call assert_true(index(l, 'runtest.vim') < 0)
337 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200338
339 let l = getcompletion('ha', 'filetype')
340 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200341 let l = getcompletion('horse', 'filetype')
342 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200343
344 let l = getcompletion('z', 'syntax')
345 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200346 let l = getcompletion('emacs', 'syntax')
347 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200348
349 let l = getcompletion('jikes', 'compiler')
350 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200351 let l = getcompletion('break', 'compiler')
352 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200353
354 let l = getcompletion('last', 'help')
355 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200356 let l = getcompletion('giveup', 'help')
357 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200358
359 let l = getcompletion('time', 'option')
360 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200361 let l = getcompletion('space', 'option')
362 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200363
364 let l = getcompletion('er', 'highlight')
365 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200366 let l = getcompletion('dark', 'highlight')
367 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200368
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200369 let l = getcompletion('', 'messages')
370 call assert_true(index(l, 'clear') >= 0)
371 let l = getcompletion('not', 'messages')
372 call assert_equal([], l)
373
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200374 let l = getcompletion('', 'mapclear')
375 call assert_true(index(l, '<buffer>') >= 0)
376 let l = getcompletion('not', 'mapclear')
377 call assert_equal([], l)
378
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200379 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200380 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200381 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
382 let root = has('win32') ? 'C:\\' : '/'
383 let l = getcompletion(root, 'shellcmd')
384 let expected = map(filter(glob(root . '*', 0, 1),
385 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
386 call assert_equal(expected, l)
387
Bram Moolenaarb650b982016-08-05 20:35:13 +0200388 if has('cscope')
389 let l = getcompletion('', 'cscope')
390 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
391 call assert_equal(cmds, l)
392 " using cmdline completion must not change the result
393 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
394 let l = getcompletion('', 'cscope')
395 call assert_equal(cmds, l)
396 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
397 let l = getcompletion('find ', 'cscope')
398 call assert_equal(keys, l)
399 endif
400
Bram Moolenaar7522f692016-08-06 14:12:50 +0200401 if has('signs')
402 sign define Testing linehl=Comment
403 let l = getcompletion('', 'sign')
404 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
405 call assert_equal(cmds, l)
406 " using cmdline completion must not change the result
407 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
408 let l = getcompletion('', 'sign')
409 call assert_equal(cmds, l)
410 let l = getcompletion('list ', 'sign')
411 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000412 let l = getcompletion('de*', 'sign')
413 call assert_equal(['define'], l)
414 let l = getcompletion('p?', 'sign')
415 call assert_equal(['place'], l)
416 let l = getcompletion('j.', 'sign')
417 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200418 endif
419
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200420 " Command line completion tests
421 let l = getcompletion('cd ', 'cmdline')
422 call assert_true(index(l, 'samples/') >= 0)
423 let l = getcompletion('cd NoMatch', 'cmdline')
424 call assert_equal([], l)
425 let l = getcompletion('let v:n', 'cmdline')
426 call assert_true(index(l, 'v:null') >= 0)
427 let l = getcompletion('let v:notexists', 'cmdline')
428 call assert_equal([], l)
429 let l = getcompletion('call tag', 'cmdline')
430 call assert_true(index(l, 'taglist(') >= 0)
431 let l = getcompletion('call paint', 'cmdline')
432 call assert_equal([], l)
433
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100434 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000435 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100436 return "oneA\noneB\noneC"
437 endfunc
438 command -nargs=1 -complete=custom,T MyCmd
439 let l = getcompletion('MyCmd ', 'cmdline')
440 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000441 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100442
443 delcommand MyCmd
444 delfunc T
ii144785fe02021-11-21 12:13:56 +0000445 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100446
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200447 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200448 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200449 if has('cmdline_hist')
450 call add(names, 'history')
451 endif
452 if has('gettext')
453 call add(names, 'locale')
454 endif
455 if has('profile')
456 call add(names, 'syntime')
457 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200458
459 set tags=Xtags
460 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
461
462 for name in names
463 let matchcount = len(getcompletion('', name))
464 call assert_true(matchcount >= 0, 'No matches for ' . name)
465 endfor
466
467 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200468 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200469
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000470 edit a~b
471 enew
472 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
473 bw a~b
474
475 if has('unix')
476 edit Xtest\
477 enew
478 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
479 bw Xtest\
480 endif
481
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200482 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200483 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200484 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200485endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200486
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100487func Test_fullcommand()
488 let tests = {
489 \ '': '',
490 \ ':': '',
491 \ ':::': '',
492 \ ':::5': '',
493 \ 'not_a_cmd': '',
494 \ 'Check': '',
495 \ 'syntax': 'syntax',
496 \ ':syntax': 'syntax',
497 \ '::::syntax': 'syntax',
498 \ 'sy': 'syntax',
499 \ 'syn': 'syntax',
500 \ 'synt': 'syntax',
501 \ ':sy': 'syntax',
502 \ '::::sy': 'syntax',
503 \ 'match': 'match',
504 \ '2match': 'match',
505 \ '3match': 'match',
506 \ 'aboveleft': 'aboveleft',
507 \ 'abo': 'aboveleft',
508 \ 's': 'substitute',
509 \ '5s': 'substitute',
510 \ ':5s': 'substitute',
511 \ "'<,'>s": 'substitute',
512 \ ":'<,'>s": 'substitute',
513 \ 'CheckUni': 'CheckUnix',
514 \ 'CheckUnix': 'CheckUnix',
515 \ }
516
517 for [in, want] in items(tests)
518 call assert_equal(want, fullcommand(in))
519 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200520 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100521
522 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200523
524 command -buffer BufferLocalCommand :
525 command GlobalCommand :
526 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
527 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
528 delcommand BufferLocalCommand
529 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100530endfunc
531
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200532func Test_shellcmd_completion()
533 let save_path = $PATH
534
535 call mkdir('Xpathdir/Xpathsubdir', 'p')
536 call writefile([''], 'Xpathdir/Xfile.exe')
537 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
538
539 " Set PATH to example directory without trailing slash.
540 let $PATH = getcwd() . '/Xpathdir'
541
542 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
543 " dirs in the PATH, even though they won't be executed. We check that only
544 " subdirs of the PWD and executables from the PATH are included in the
545 " suggestions.
546 let actual = getcompletion('X', 'shellcmd')
547 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
548 call insert(expected, 'Xfile.exe')
549 call assert_equal(expected, actual)
550
551 call delete('Xpathdir', 'rf')
552 let $PATH = save_path
553endfunc
554
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200555func Test_expand_star_star()
556 call mkdir('a/b', 'p')
557 call writefile(['asdfasdf'], 'a/b/fileXname')
558 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
559 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200560 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200561 call delete('a', 'rf')
562endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100563
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100564func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100565 let @a = "def"
566 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
567 call assert_equal('"abc def ghi', @:)
568
569 new
570 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
571
572 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
573 call assert_equal('"aaa asdf bbb', @:)
574
575 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
576 call assert_equal('"aaa /tmp/some bbb', @:)
577
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200578 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
579 call assert_equal('"aaa '.getline(1).' bbb', @:)
580
Bram Moolenaar21efc362016-12-03 14:05:49 +0100581 set incsearch
582 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
583 call assert_equal('"aaa verylongword bbb', @:)
584
585 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
586 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100587
588 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
589 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100590 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200591
592 " Error while typing a command used to cause that it was not executed
593 " in the end.
594 new
595 try
596 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
597 catch /^Vim\%((\a\+)\)\=:E32/
598 " ignore error E32
599 endtry
600 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100601
Bram Moolenaar578fe942020-02-27 21:32:51 +0100602 " Try to paste an invalid register using <C-R>
603 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
604 call assert_equal('"onetwo', @:)
605
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100606 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100607 let @a = "xy\<C-H>z"
608 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
609 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100610 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
611 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100612 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
613 call assert_equal("\"xy\<C-H>z", @:)
614
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100615 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
616 let @a = "xy\<C-V>z"
617 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
618 call assert_equal('"xyz', @:)
619 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
620 call assert_equal("\"xy\<C-V>z", @:)
621
Bram Moolenaar578fe942020-02-27 21:32:51 +0100622 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
623
Bram Moolenaar72532d32018-04-07 19:09:09 +0200624 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100625endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100626
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100627func Test_cmdline_remove_char()
628 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100629
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100630 for e in ['utf8', 'latin1']
631 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100632
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100633 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
634 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100635
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100636 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
637 call assert_equal('"abcdef', @:)
638
639 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
640 call assert_equal('"abc ghi', @:, e)
641
642 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
643 call assert_equal('"def', @:, e)
644 endfor
645
646 let &encoding = encoding_save
647endfunc
648
649func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200650 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100651
652 set keymap=esperanto
653 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
654 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
655 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100656endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100657
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100658func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100659 new
660 2;'(
661 2;')
662 quit
663endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100664
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100665func Test_illegal_address2()
666 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
667 new
668 source Xtest.vim
669 " Trigger calling validate_cursor()
670 diffsp Xtest.vim
671 quit!
672 bwipe!
673 call delete('Xtest.vim')
674endfunc
675
Bram Moolenaarba47b512017-01-24 21:18:19 +0100676func Test_cmdline_complete_wildoptions()
677 help
678 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
679 let a = join(sort(split(@:)),' ')
680 set wildoptions=tagfile
681 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
682 let b = join(sort(split(@:)),' ')
683 call assert_equal(a, b)
684 bw!
685endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100686
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200687func Test_cmdline_complete_user_cmd()
688 command! -complete=color -nargs=1 Foo :
689 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
690 call assert_equal('"Foo blue', @:)
691 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
692 call assert_equal('"Foo blue', @:)
693 delcommand Foo
694endfunc
695
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100696func s:ScriptLocalFunction()
697 echo 'yes'
698endfunc
699
700func Test_cmdline_complete_user_func()
701 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200702 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100703 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
704 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100705
706 " g: prefix also works
707 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
708 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200709
710 " using g: prefix does not result in just "g:" matches from a lambda
711 let Fx = { a -> a }
712 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
713 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200714
715 " existence of script-local dict function does not break user function name
716 " completion
717 function s:a_dict_func() dict
718 endfunction
719 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
720 call assert_match('"call Test_cmdline_complete_user_', @:)
721 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100722endfunc
723
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200724func Test_cmdline_complete_user_names()
725 if has('unix') && executable('whoami')
726 let whoami = systemlist('whoami')[0]
727 let first_letter = whoami[0]
728 if len(first_letter) > 0
729 " Trying completion of :e ~x where x is the first letter of
730 " the user name should complete to at least the user name.
731 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
732 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
733 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200734 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200735 " Just in case: check that the system has an Administrator account.
736 let names = system('net user')
737 if names =~ 'Administrator'
738 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100739 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200740 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100741 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200742 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200743 else
744 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200745 endif
746endfunc
747
Bram Moolenaar297610b2019-12-27 17:20:55 +0100748func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200749 CheckExecutable whoami
750 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
751 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100752endfunc
753
Bram Moolenaar8b633132020-03-20 18:20:51 +0100754func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200755 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
756 call assert_equal(lang, v:lc_time)
757
758 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
759 call assert_equal(lang, v:ctype)
760
761 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
762 call assert_equal(lang, v:collate)
763
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200764 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200765 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200766
767 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200768 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200769
Bram Moolenaarec680282020-06-12 19:35:32 +0200770 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200771
Bram Moolenaarec680282020-06-12 19:35:32 +0200772 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
773 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200774
Bram Moolenaarec680282020-06-12 19:35:32 +0200775 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
776 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200777
Bram Moolenaarec680282020-06-12 19:35:32 +0200778 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
779 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200780
781 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
782 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200783endfunc
784
Bram Moolenaar297610b2019-12-27 17:20:55 +0100785func Test_cmdline_complete_env_variable()
786 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100787 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
788 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100789 unlet $X_VIM_TEST_COMPLETE_ENV
790endfunc
791
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100792func Test_cmdline_complete_expression()
793 let g:SomeVar = 'blah'
794 for cmd in ['exe', 'echo', 'echon', 'echomsg']
795 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
796 call assert_match('"' .. cmd .. ' SomeVar', @:)
797 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
798 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
799 endfor
800 unlet g:SomeVar
801endfunc
802
Bram Moolenaar47016f52021-08-26 16:39:58 +0200803" Unique function name for completion below
804func s:WeirdFunc()
805 echo 'weird'
806endfunc
807
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100808" Test for various command-line completion
809func Test_cmdline_complete_various()
810 " completion for a command starting with a comment
811 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
812 call assert_equal("\" :|\"\<C-A>", @:)
813
814 " completion for a range followed by a comment
815 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
816 call assert_equal("\"1,2\"\<C-A>", @:)
817
818 " completion for :k command
819 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
820 call assert_equal("\"ka\<C-A>", @:)
821
822 " completion for short version of the :s command
823 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
824 call assert_equal("\"sI \<C-A>", @:)
825
826 " completion for :write command
827 call mkdir('Xdir')
828 call writefile(['one'], 'Xdir/Xfile1')
829 let save_cwd = getcwd()
830 cd Xdir
831 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
832 call assert_equal("\"w >> Xfile1", @:)
833 call chdir(save_cwd)
834 call delete('Xdir', 'rf')
835
836 " completion for :w ! and :r ! commands
837 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
838 call assert_equal("\"w !invalid_xyz_cmd", @:)
839 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
840 call assert_equal("\"r !invalid_xyz_cmd", @:)
841
842 " completion for :>> and :<< commands
843 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
844 call assert_equal("\">>>\<C-A>", @:)
845 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
846 call assert_equal("\"<<<\<C-A>", @:)
847
848 " completion for command with +cmd argument
849 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
850 call assert_equal("\"buffer +/pat Xabc", @:)
851 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
852 call assert_equal("\"buffer +/pat\<C-A>", @:)
853
854 " completion for a command with a trailing comment
855 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
856 call assert_equal("\"ls \" comment\<C-A>", @:)
857
858 " completion for a command with a trailing command
859 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
860 call assert_equal("\"ls | ls", @:)
861
862 " completion for a command with an CTRL-V escaped argument
863 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
864 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
865
866 " completion for a command that doesn't take additional arguments
867 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
868 call assert_equal("\"all abc\<C-A>", @:)
869
870 " completion for a command with a command modifier
871 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
872 call assert_equal("\"topleft new", @:)
873
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200874 " completion for vim9 and legacy commands
875 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
876 call assert_equal("\"vim9 call strlen(", @:)
877 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
878 call assert_equal("\"legac call strlen(", @:)
879
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200880 " completion for the :disassemble command
881 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
882 call assert_equal("\"disas debug", @:)
883 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
884 call assert_equal("\"disas profile", @:)
885 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
886 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
887 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
888 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +0200889 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
890 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200891
Bram Moolenaar47016f52021-08-26 16:39:58 +0200892 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +0200893 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +0200894
naohiro onodfe04db2021-09-12 15:45:10 +0200895 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
896 call assert_match('"disas <SNR>\d\+_', @:)
897 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
898 call assert_match('"disas debug <SNR>\d\+_', @:)
899
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100900 " completion for the :match command
901 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
902 call assert_equal("\"match Search /pat/\<C-A>", @:)
903
904 " completion for the :s command
905 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
906 call assert_equal("\"s/from/to/g\<C-A>", @:)
907
908 " completion for the :dlist command
909 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
910 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
911
912 " completion for the :doautocmd command
913 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
914 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
915
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200916 " completion of autocmd group after comma
917 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
918 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
919
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200920 " completion of file name in :doautocmd
921 call writefile([], 'Xfile1')
922 call writefile([], 'Xfile2')
923 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
924 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
925 call delete('Xfile1')
926 call delete('Xfile2')
927
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100928 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200929 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100930 augroup END
931 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200932 call assert_equal("\"augroup XTest.test", @:)
933 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
934 call assert_equal("\"au XTest.test", @:)
935 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100936
937 " completion for the :unlet command
938 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
939 call assert_equal("\"unlet one two", @:)
940
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +0100941 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +0100942 " FIXME: what should happen on MS-Windows?
943 if !has('win32')
944 edit \{someFile}
945 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
946 call assert_equal("\"buf {someFile}", @:)
947 bwipe {someFile}
948 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +0100949
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100950 " completion for the :bdelete command
951 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
952 call assert_equal("\"bdel a b c", @:)
953
954 " completion for the :mapclear command
955 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
956 call assert_equal("\"mapclear <buffer>", @:)
957
958 " completion for user defined commands with menu names
959 menu Test.foo :ls<CR>
960 com -nargs=* -complete=menu MyCmd
961 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
962 call assert_equal('"MyCmd Test.', @:)
963 delcom MyCmd
964 unmenu Test
965
966 " completion for user defined commands with mappings
967 mapclear
968 map <F3> :ls<CR>
969 com -nargs=* -complete=mapping MyCmd
970 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
971 call assert_equal('"MyCmd <F3>', @:)
972 mapclear
973 delcom MyCmd
974
975 " completion for :set path= with multiple backslashes
976 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
977 call assert_equal('"set path=a\\\ b', @:)
978
979 " completion for :set dir= with a backslash
980 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
981 call assert_equal('"set dir=a\ b', @:)
982
983 " completion for the :py3 commands
984 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
985 call assert_equal('"py3 py3do py3file', @:)
986
Bram Moolenaardf749a22021-03-28 15:29:43 +0200987 " completion for the :vim9 commands
988 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
989 call assert_equal('"vim9cmd vim9script', @:)
990
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100991 " redir @" is not the start of a comment. So complete after that
992 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
993 call assert_equal('"redir @" | cwindow', @:)
994
995 " completion after a backtick
996 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
997 call assert_equal('"e `a1b2c', @:)
998
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100999 " completion for :language command with an invalid argument
1000 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1001 call assert_equal("\"language dummy \t", @:)
1002
1003 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001004 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1005 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001006
1007 " completion with ambiguous user defined commands
1008 com TCmd1 echo 'TCmd1'
1009 com TCmd2 echo 'TCmd2'
1010 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1011 call assert_equal('"TCmd ', @:)
1012 delcom TCmd1
1013 delcom TCmd2
1014
1015 " completion after a range followed by a pipe (|) character
1016 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1017 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001018
1019 " use <Esc> as the 'wildchar' for completion
1020 set wildchar=<Esc>
1021 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1022 call assert_equal('"g/a\xb/clearjumps', @:)
1023 " pressing <esc> twice should cancel the command
1024 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1025 call assert_equal('"g/a\xb/clearjumps', @:)
1026 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001027
1028 " should be able to complete a file name that starts with a '~'.
1029 if has('unix')
1030 call writefile([], '~Xtest')
1031 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1032 call assert_equal('"e \~Xtest', @:)
1033 call delete('~Xtest')
1034 endif
1035endfunc
1036
1037" Test for 'wildignorecase'
1038func Test_cmdline_wildignorecase()
1039 CheckUnix
1040 call writefile([], 'XTEST')
1041 set wildignorecase
1042 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1043 call assert_equal('"e XTEST', @:)
1044 set wildignorecase&
1045 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001046endfunc
1047
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001048func Test_cmdline_write_alternatefile()
1049 new
1050 call setline('.', ['one', 'two'])
1051 f foo.txt
1052 new
1053 f #-A
1054 call assert_equal('foo.txt-A', expand('%'))
1055 f #<-B.txt
1056 call assert_equal('foo-B.txt', expand('%'))
1057 f %<
1058 call assert_equal('foo-B', expand('%'))
1059 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001060 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001061 bw!
1062 f foo-B.txt
1063 f %<-A
1064 call assert_equal('foo-B-A', expand('%'))
1065 bw!
1066 bw!
1067endfunc
1068
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001069" using a leading backslash here
1070set cpo+=C
1071
1072func Test_cmdline_search_range()
1073 new
1074 call setline(1, ['a', 'b', 'c', 'd'])
1075 /d
1076 1,\/s/b/B/
1077 call assert_equal('B', getline(2))
1078
1079 /a
1080 $
1081 \?,4s/c/C/
1082 call assert_equal('C', getline(3))
1083
1084 call setline(1, ['a', 'b', 'c', 'd'])
1085 %s/c/c/
1086 1,\&s/b/B/
1087 call assert_equal('B', getline(2))
1088
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001089 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001090 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001091
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001092 bwipe!
1093endfunc
1094
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001095" Test for the tick mark (') in an excmd range
1096func Test_tick_mark_in_range()
1097 " If only the tick is passed as a range and no command is specified, there
1098 " should not be an error
1099 call feedkeys(":'\<CR>", 'xt')
1100 call assert_equal("'", getreg(':'))
1101 call assert_fails("',print", 'E78:')
1102endfunc
1103
1104" Test for using a line number followed by a search pattern as range
1105func Test_lnum_and_pattern_as_range()
1106 new
1107 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1108 let @" = ''
1109 2/foo/yank
1110 call assert_equal("foo 3\n", @")
1111 call assert_equal(1, line('.'))
1112 close!
1113endfunc
1114
Bram Moolenaar65189a12017-02-06 22:22:17 +01001115" Tests for getcmdline(), getcmdpos() and getcmdtype()
1116func Check_cmdline(cmdtype)
1117 call assert_equal('MyCmd a', getcmdline())
1118 call assert_equal(8, getcmdpos())
1119 call assert_equal(a:cmdtype, getcmdtype())
1120 return ''
1121endfunc
1122
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001123set cpo&
1124
Bram Moolenaar65189a12017-02-06 22:22:17 +01001125func Test_getcmdtype()
1126 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1127
1128 let cmdtype = ''
1129 debuggreedy
1130 call feedkeys(":debug echo 'test'\<CR>", "t")
1131 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1132 call feedkeys("cont\<CR>", "xt")
1133 0debuggreedy
1134 call assert_equal('>', cmdtype)
1135
1136 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1137 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1138
1139 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001140 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001141
1142 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1143
1144 cnoremap <expr> <F6> Check_cmdline('=')
1145 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1146 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001147
1148 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001149endfunc
1150
Bram Moolenaar81612b72018-06-23 14:55:03 +02001151func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001152 CheckFeature cmdwin
1153
Bram Moolenaar81612b72018-06-23 14:55:03 +02001154 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1155 call assert_equal('/', a)
1156
1157 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1158 call assert_equal('?', a)
1159
1160 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1161 call assert_equal(':', a)
1162
1163 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1164 call assert_equal(':', a)
1165
1166 call assert_equal('', getcmdwintype())
1167endfunc
1168
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001169func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001170 CheckFeature cmdwin
1171
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001172 let s:seq = []
1173 augroup CmdWin
1174 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1175 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1176 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1177 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1178 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1179 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1180
1181 let org_winid = win_getid()
1182 let org_bufnr = bufnr()
1183 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1184 call assert_equal(':', a)
1185 call assert_equal([
1186 \ 'WinLeave ' .. org_winid,
1187 \ 'WinEnter ' .. s:cmd_winid,
1188 \ 'BufLeave ' .. org_bufnr,
1189 \ 'BufEnter ' .. s:cmd_bufnr,
1190 \ 'CmdWinEnter ' .. s:cmd_winid,
1191 \ 'CmdWinLeave ' .. s:cmd_winid,
1192 \ 'BufLeave ' .. s:cmd_bufnr,
1193 \ 'WinLeave ' .. s:cmd_winid,
1194 \ 'WinEnter ' .. org_winid,
1195 \ 'BufEnter ' .. org_bufnr,
1196 \ ], s:seq)
1197
1198 au!
1199 augroup END
1200endfunc
1201
Bram Moolenaar52604f22017-04-07 16:17:39 +02001202func Test_verbosefile()
1203 set verbosefile=Xlog
1204 echomsg 'foo'
1205 echomsg 'bar'
1206 set verbosefile=
1207 let log = readfile('Xlog')
1208 call assert_match("foo\nbar", join(log, "\n"))
1209 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001210 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001211 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001212 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001213endfunc
1214
Bram Moolenaar4facea32019-10-12 20:17:40 +02001215func Test_verbose_option()
1216 CheckScreendump
1217
1218 let lines =<< trim [SCRIPT]
1219 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1220 call feedkeys("\r", 't') " for the hit-enter prompt
1221 set verbose=20
1222 [SCRIPT]
1223 call writefile(lines, 'XTest_verbose')
1224
1225 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001226 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001227 call term_sendkeys(buf, ":DoSomething\<CR>")
1228 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1229
1230 " clean up
1231 call StopVimInTerminal(buf)
1232 call delete('XTest_verbose')
1233endfunc
1234
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001235func Test_setcmdpos()
1236 func InsertTextAtPos(text, pos)
1237 call assert_equal(0, setcmdpos(a:pos))
1238 return a:text
1239 endfunc
1240
1241 " setcmdpos() with position in the middle of the command line.
1242 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1243 call assert_equal('"1ab2', @:)
1244
1245 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1246 call assert_equal('"1b2a', @:)
1247
1248 " setcmdpos() with position beyond the end of the command line.
1249 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1250 call assert_equal('"12ab', @:)
1251
1252 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001253 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001254endfunc
1255
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001256func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001257 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001258 let encoding_save = &encoding
1259
1260 for e in encodings
1261 exe 'set encoding=' . e
1262
1263 " Test overstrike in the middle of the command line.
1264 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001265 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001266
1267 " Test overstrike going beyond end of command line.
1268 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001269 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001270
1271 " Test toggling insert/overstrike a few times.
1272 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001273 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001274 endfor
1275
Bram Moolenaar30276f22019-01-24 17:59:39 +01001276 " Test overstrike with multi-byte characters.
1277 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001278 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001279
1280 let &encoding = encoding_save
1281endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001282
1283func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001284 CheckFeature cmdwin
1285
Bram Moolenaara046b372019-09-15 17:26:07 +02001286 let winid = win_getid()
1287 sp
1288 try
1289 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1290 catch /^Vim\%((\a\+)\)\=:E11/
1291 endtry
1292 bw!
1293endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001294
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001295func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001296 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001297 CheckScreendump
1298
1299 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001300 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001301 call setline(1, range(30))
1302 2split
1303 [SCRIPT]
1304 call writefile(lines, 'XTest_restore')
1305
1306 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001307 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001308 call term_sendkeys(buf, "q:")
1309 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1310
1311 " normal restore
1312 call term_sendkeys(buf, ":q\<CR>")
1313 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1314
1315 " restore after setting 'lines' with one window
1316 call term_sendkeys(buf, ":close\<CR>")
1317 call term_sendkeys(buf, "q:")
1318 call term_sendkeys(buf, ":set lines=18\<CR>")
1319 call term_sendkeys(buf, ":q\<CR>")
1320 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1321
1322 " clean up
1323 call StopVimInTerminal(buf)
1324 call delete('XTest_restore')
1325endfunc
1326
Bram Moolenaare5b44862021-05-30 13:54:03 +02001327func Test_cmdwin_no_terminal()
1328 CheckFeature cmdwin
1329 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001330 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001331
1332 let buf = RunVimInTerminal('', {'rows': 12})
1333 call TermWait(buf, 50)
1334 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1335 call term_sendkeys(buf, "q:")
1336 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1337 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1338 call term_sendkeys(buf, ":q\<CR>")
1339 call StopVimInTerminal(buf)
1340endfunc
1341
Bram Moolenaar52410572019-10-27 05:12:45 +01001342func Test_buffers_lastused()
1343 " check that buffers are sorted by time when wildmode has lastused
1344 call test_settime(1550020000) " middle
1345 edit bufa
1346 enew
1347 call test_settime(1550030000) " newest
1348 edit bufb
1349 enew
1350 call test_settime(1550010000) " oldest
1351 edit bufc
1352 enew
1353 call test_settime(0)
1354 enew
1355
1356 call assert_equal(['bufa', 'bufb', 'bufc'],
1357 \ getcompletion('', 'buffer'))
1358
1359 let save_wildmode = &wildmode
1360 set wildmode=full:lastused
1361
1362 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1363 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1364 call assert_equal('b bufb', X)
1365 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1366 call assert_equal('b bufa', X)
1367 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1368 call assert_equal('b bufc', X)
1369 enew
1370
1371 edit other
1372 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1373 call assert_equal('b bufb', X)
1374 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1375 call assert_equal('b bufa', X)
1376 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1377 call assert_equal('b bufc', X)
1378 enew
1379
1380 let &wildmode = save_wildmode
1381
1382 bwipeout bufa
1383 bwipeout bufb
1384 bwipeout bufc
1385endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001386
1387func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001388 CheckFeature cmdwin
1389
Bram Moolenaar85db5472019-12-04 15:11:08 +01001390 " This should not generate E488
1391 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001392 " Using feedkeys with q: only should automatically close the cmd window
1393 call feedkeys('q:', 'xt')
1394 call assert_equal(1, winnr('$'))
1395 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001396endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001397
1398" Tests for the issues fixed in 7.4.441.
1399" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1400func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001401 CheckFeature cmdwin
1402
Bram Moolenaar309976e2019-12-05 18:16:33 +01001403 exe "set cedit=\<C-c>"
1404 normal! :
1405 call assert_equal(1, winnr('$'))
1406
1407 let g:cmd_wintype = ''
1408 func CmdWinType()
1409 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001410 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001411 return ''
1412 endfunc
1413
1414 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1415 echo input('')
1416 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001417 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001418
1419 set cedit&vim
1420 delfunc CmdWinType
1421endfunc
1422
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001423" Test for CmdwinEnter autocmd
1424func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001425 CheckFeature cmdwin
1426
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001427 augroup CmdWin
1428 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001429 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001430 autocmd CmdwinEnter * startinsert
1431 augroup END
1432
1433 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1434 call assert_equal('xyz', @:)
1435
1436 augroup CmdWin
1437 au!
1438 augroup END
1439 augroup! CmdWin
1440endfunc
1441
Bram Moolenaar479950f2020-01-19 15:45:17 +01001442func Test_cmdlineclear_tabenter()
1443 CheckScreendump
1444
1445 let lines =<< trim [SCRIPT]
1446 call setline(1, range(30))
1447 [SCRIPT]
1448
1449 call writefile(lines, 'XtestCmdlineClearTabenter')
1450 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001451 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001452 " in one tab make the command line higher with CTRL-W -
1453 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1454 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1455
1456 call StopVimInTerminal(buf)
1457 call delete('XtestCmdlineClearTabenter')
1458endfunc
1459
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001460" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001461func Test_cmdline_expand_special()
1462 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001463 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001464 call assert_fails('e <afile>', 'E495:')
1465 call assert_fails('e <abuf>', 'E496:')
1466 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001467
1468 call writefile([], 'Xfile.cpp')
1469 call writefile([], 'Xfile.java')
1470 new Xfile.cpp
1471 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1472 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1473 close
1474 call delete('Xfile.cpp')
1475 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001476endfunc
1477
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001478func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001479 CheckFeature cmdwin
1480
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001481 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1482 new
1483 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001484 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001485 close!
1486 call feedkeys("q/:close\<CR>", "xt")
1487 call assert_equal(1, winnr('$'))
1488 call feedkeys("q/:exit\<CR>", "xt")
1489 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001490
1491 " opening command window twice should fail
1492 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1493 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001494endfunc
1495
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001496func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001497 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001498 CheckScreendump
1499
1500 " aborting the :smile output caused the cmdline window to use the current
1501 " buffer.
1502 let lines =<< trim [SCRIPT]
1503 au WinNew * smile
1504 [SCRIPT]
1505 call writefile(lines, 'XTest_cmdwin')
1506
1507 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001508 " open cmdwin
1509 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001510 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001511 " quit more prompt for :smile command
1512 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001513 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001514 " execute a simple command
1515 call term_sendkeys(buf, "aecho 'done'\<CR>")
1516 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1517
1518 " clean up
1519 call StopVimInTerminal(buf)
1520 call delete('XTest_cmdwin')
1521endfunc
1522
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001523" Test for backtick expression in the command line
1524func Test_cmd_backtick()
1525 %argd
1526 argadd `=['a', 'b', 'c']`
1527 call assert_equal(['a', 'b', 'c'], argv())
1528 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001529
1530 argadd `echo abc def`
1531 call assert_equal(['abc def'], argv())
1532 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001533endfunc
1534
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001535" Test for the :! command
1536func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001537 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001538
1539 let lines =<< trim [SCRIPT]
1540 " Test for no previous command
1541 call assert_fails('!!', 'E34:')
1542 set nomore
1543 " Test for cmdline expansion with :!
1544 call setline(1, 'foo!')
1545 silent !echo <cWORD> > Xfile.out
1546 call assert_equal(['foo!'], readfile('Xfile.out'))
1547 " Test for using previous command
1548 silent !echo \! !
1549 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1550 call writefile(v:errors, 'Xresult')
1551 call delete('Xfile.out')
1552 qall!
1553 [SCRIPT]
1554 call writefile(lines, 'Xscript')
1555 if RunVim([], [], '--clean -S Xscript')
1556 call assert_equal([], readfile('Xresult'))
1557 endif
1558 call delete('Xscript')
1559 call delete('Xresult')
1560endfunc
1561
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001562" Test error: "E135: *Filter* Autocommands must not change current buffer"
1563func Test_cmd_bang_E135()
1564 new
1565 call setline(1, ['a', 'b', 'c', 'd'])
1566 augroup test_cmd_filter_E135
1567 au!
1568 autocmd FilterReadPost * help
1569 augroup END
1570 call assert_fails('2,3!echo "x"', 'E135:')
1571
1572 augroup test_cmd_filter_E135
1573 au!
1574 augroup END
1575 %bwipe!
1576endfunc
1577
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001578" Test for using ~ for home directory in cmdline completion matches
1579func Test_cmdline_expand_home()
1580 call mkdir('Xdir')
1581 call writefile([], 'Xdir/Xfile1')
1582 call writefile([], 'Xdir/Xfile2')
1583 cd Xdir
1584 let save_HOME = $HOME
1585 let $HOME = getcwd()
1586 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1587 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1588 let $HOME = save_HOME
1589 cd ..
1590 call delete('Xdir', 'rf')
1591endfunc
1592
Bram Moolenaar578fe942020-02-27 21:32:51 +01001593" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1594" or insert mode (when 'insertmode' is set)
1595func Test_cmdline_ctrl_g()
1596 new
1597 call setline(1, 'abc')
1598 call cursor(1, 3)
1599 " If command line is entered from insert mode, using C-\ C-G should back to
1600 " insert mode
1601 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1602 call assert_equal('abxyc', getline(1))
1603 call assert_equal(4, col('.'))
1604
1605 " If command line is entered in 'insertmode', using C-\ C-G should back to
1606 " 'insertmode'
1607 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1608 call assert_equal('ab12xyc', getline(1))
1609 close!
1610endfunc
1611
Bram Moolenaar578fe942020-02-27 21:32:51 +01001612" Test for 'wildmode'
1613func Test_wildmode()
1614 func T(a, c, p)
1615 return "oneA\noneB\noneC"
1616 endfunc
1617 command -nargs=1 -complete=custom,T MyCmd
1618
1619 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001620 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001621 return ''
1622 endfunc
1623 cnoremap <expr> <F2> SaveScreenLine()
1624
1625 set nowildmenu
1626 set wildmode=full,list
1627 let g:Sline = ''
1628 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001629 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001630 call assert_equal('"MyCmd oneA', @:)
1631
1632 set wildmode=longest,full
1633 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1634 call assert_equal('"MyCmd one', @:)
1635 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1636 call assert_equal('"MyCmd oneC', @:)
1637
1638 set wildmode=longest
1639 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1640 call assert_equal('"MyCmd one', @:)
1641
1642 set wildmode=list:longest
1643 let g:Sline = ''
1644 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001645 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001646 call assert_equal('"MyCmd one', @:)
1647
1648 set wildmode=""
1649 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1650 call assert_equal('"MyCmd oneA', @:)
1651
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001652 " Test for wildmode=longest with 'fileignorecase' set
1653 set wildmode=longest
1654 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001655 argadd AAA AAAA AAAAA
1656 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1657 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001658 set fileignorecase&
1659
1660 " Test for listing files with wildmode=list
1661 set wildmode=list
1662 let g:Sline = ''
1663 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001664 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001665 call assert_equal('"b A', @:)
1666
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001667 " when using longest completion match, matches shorter than the argument
1668 " should be ignored (happens with :help)
1669 set wildmode=longest,full
1670 set wildmenu
1671 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1672 call assert_equal('"help a', @:)
1673 set wildmenu&
1674
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001675 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001676 delcommand MyCmd
1677 delfunc T
1678 delfunc SaveScreenLine
1679 cunmap <F2>
1680 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001681 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001682endfunc
1683
1684" Test for interrupting the command-line completion
1685func Test_interrupt_compl()
1686 func F(lead, cmdl, p)
1687 if a:lead =~ 'tw'
1688 call interrupt()
1689 return
1690 endif
1691 return "one\ntwo\nthree"
1692 endfunc
1693 command -nargs=1 -complete=custom,F Tcmd
1694
1695 set nowildmenu
1696 set wildmode=full
1697 let interrupted = 0
1698 try
1699 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1700 catch /^Vim:Interrupt$/
1701 let interrupted = 1
1702 endtry
1703 call assert_equal(1, interrupted)
1704
1705 delcommand Tcmd
1706 delfunc F
1707 set wildmode&
1708endfunc
1709
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001710" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001711func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001712 let str = ":one two\<C-U>"
1713 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001714 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001715 let str ..= "\<Left>five\<Right>"
1716 let str ..= "\<Home>two "
1717 let str ..= "\<C-Left>one "
1718 let str ..= "\<C-Right> three"
1719 let str ..= "\<End>\<S-Left>four "
1720 let str ..= "\<S-Right> six"
1721 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1722 call feedkeys(str, 'xt')
1723 call assert_equal("\"one two three four five six seven", @:)
1724endfunc
1725
1726" Test for moving the cursor on the / command line in 'rightleft' mode
1727func Test_cmdline_edit_rightleft()
1728 CheckFeature rightleft
1729 set rightleft
1730 set rightleftcmd=search
1731 let str = "/one two\<C-U>"
1732 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001733 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001734 let str ..= "\<Right>five\<Left>"
1735 let str ..= "\<Home>two "
1736 let str ..= "\<C-Right>one "
1737 let str ..= "\<C-Left> three"
1738 let str ..= "\<End>\<S-Right>four "
1739 let str ..= "\<S-Left> six"
1740 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1741 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1742 call assert_equal("\"one two three four five six seven", @/)
1743 set rightleftcmd&
1744 set rightleft&
1745endfunc
1746
1747" Test for using <C-\>e in the command line to evaluate an expression
1748func Test_cmdline_expr()
1749 " Evaluate an expression from the beginning of a command line
1750 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1751 call assert_equal('"hello', @:)
1752
1753 " Use an invalid expression for <C-\>e
1754 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1755
1756 " Insert literal <CTRL-\> in the command line
1757 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1758 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001759endfunc
1760
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001761" Test for 'imcmdline' and 'imsearch'
1762" This test doesn't actually test the input method functionality.
1763func Test_cmdline_inputmethod()
1764 new
1765 call setline(1, ['', 'abc', ''])
1766 set imcmdline
1767
1768 call feedkeys(":\"abc\<CR>", 'xt')
1769 call assert_equal("\"abc", @:)
1770 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1771 call assert_equal("\"abc", @:)
1772 call feedkeys("/abc\<CR>", 'xt')
1773 call assert_equal([2, 1], [line('.'), col('.')])
1774 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1775 call assert_equal([2, 1], [line('.'), col('.')])
1776
1777 set imsearch=2
1778 call cursor(1, 1)
1779 call feedkeys("/abc\<CR>", 'xt')
1780 call assert_equal([2, 1], [line('.'), col('.')])
1781 call cursor(1, 1)
1782 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1783 call assert_equal([2, 1], [line('.'), col('.')])
1784 set imdisable
1785 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1786 call assert_equal([2, 1], [line('.'), col('.')])
1787 set imdisable&
1788 set imsearch&
1789
1790 set imcmdline&
1791 %bwipe!
1792endfunc
1793
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001794" Test for recursively getting multiple command line inputs
1795func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001796 CheckFeature cmdwin
1797
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001798 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1799 call assert_equal('"cyan', @:)
1800endfunc
1801
1802" Test for using CTRL-_ in the command line with 'allowrevins'
1803func Test_cmdline_revins()
1804 CheckNotMSWindows
1805 CheckFeature rightleft
1806 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1807 call assert_equal("\"abc\<c-_>", @:)
1808 set allowrevins
1809 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1810 call assert_equal('"abcñèæ', @:)
1811 set allowrevins&
1812endfunc
1813
1814" Test for typing UTF-8 composing characters in the command line
1815func Test_cmdline_composing_chars()
1816 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1817 call assert_equal('"ゔ', @:)
1818endfunc
1819
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001820" Test for normal mode commands not supported in the cmd window
1821func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001822 CheckFeature cmdwin
1823
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001824 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1825 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1826 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1827 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1828 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1829 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001830 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1831 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1832 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1833 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1834 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1835 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1836 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1837 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1838 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1839 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1840 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1841 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1842 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1843 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1844 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1845 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1846 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1847 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1848 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1849 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1850 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001851endfunc
1852
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001853" Close the Cmd-line window in insert mode using CTRL-C
1854func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001855 CheckFeature cmdwin
1856
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001857 %bw!
1858 let s = ''
1859 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1860 call assert_equal('Hello', s)
1861 call assert_equal(1, winnr('$'))
1862endfunc
1863
Bram Moolenaar0e717042020-04-27 19:29:01 +02001864" test that ";" works to find a match at the start of the first line
1865func Test_zero_line_search()
1866 new
1867 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1868 call cursor(1,1)
1869 0;/pattern/d
1870 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1871 q!
1872endfunc
1873
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001874func Test_read_shellcmd()
1875 CheckUnix
1876 if executable('ls')
1877 " There should be ls in the $PATH
1878 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1879 call assert_match('^"r! .*\<ls\>', @:)
1880 endif
1881
1882 if executable('rm')
1883 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1884 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1885 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001886
1887 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1888 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1889 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001890 endif
1891endfunc
1892
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001893" Test for going up and down the directory tree using 'wildmenu'
1894func Test_wildmenu_dirstack()
1895 CheckUnix
1896 %bw!
1897 call mkdir('Xdir1/dir2/dir3', 'p')
1898 call writefile([], 'Xdir1/file1_1.txt')
1899 call writefile([], 'Xdir1/file1_2.txt')
1900 call writefile([], 'Xdir1/dir2/file2_1.txt')
1901 call writefile([], 'Xdir1/dir2/file2_2.txt')
1902 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
1903 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
1904 cd Xdir1/dir2/dir3
1905 set wildmenu
1906
1907 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
1908 call assert_equal('"e file3_1.txt', @:)
1909 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
1910 call assert_equal('"e ../dir3/', @:)
1911 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1912 call assert_equal('"e ../../dir2/', @:)
1913 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
1914 call assert_equal('"e ../../dir2/dir3/', @:)
1915 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1916 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:)
1917
1918 cd -
1919 call delete('Xdir1', 'rf')
1920 set wildmenu&
1921endfunc
1922
obcat71c6f7a2021-05-13 20:23:10 +02001923" Test for recalling newer or older cmdline from history with <Up>, <Down>,
1924" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
1925func Test_recalling_cmdline()
1926 CheckFeature cmdline_hist
1927
1928 let g:cmdlines = []
1929 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1930
1931 let histories = [
1932 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
1933 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
1934 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
1935 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
1936 "\ TODO: {'name': 'debug', ...}
1937 \]
1938 let keypairs = [
1939 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
1940 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
1941 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
1942 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
1943 \]
1944 let prefix = 'vi'
1945 for h in histories
1946 call histadd(h.name, 'vim')
1947 call histadd(h.name, 'virtue')
1948 call histadd(h.name, 'Virgo')
1949 call histadd(h.name, 'vogue')
1950 call histadd(h.name, 'emacs')
1951 for k in keypairs
1952 let g:cmdlines = []
1953 let keyseqs = h.enter
1954 \ .. prefix
1955 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
1956 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
1957 \ .. h.exit
1958 call feedkeys(keyseqs, 'xt')
1959 call histdel(h.name, -1) " delete the history added by feedkeys above
1960 let expect = k.prefixmatch
1961 \ ? ['virtue', 'vim', 'virtue', prefix]
1962 \ : ['emacs', 'vogue', 'emacs', prefix]
1963 call assert_equal(expect, g:cmdlines)
1964 endfor
1965 endfor
1966
1967 unlet g:cmdlines
1968 cunmap <Plug>(save-cmdline)
1969endfunc
1970
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001971func Test_cmd_map_cmdlineChanged()
1972 let g:log = []
1973 cnoremap <F1> l<Cmd><CR>s
1974 augroup test
1975 autocmd!
1976 autocmd CmdlineChanged : let g:log += [getcmdline()]
1977 augroup END
1978
1979 call feedkeys(":\<F1>\<CR>", 'xt')
1980 call assert_equal(['l', 'ls'], g:log)
1981
Bram Moolenaar796139a2021-05-18 21:38:45 +02001982 let @b = 'b'
1983 cnoremap <F1> a<C-R>b
1984 let g:log = []
1985 call feedkeys(":\<F1>\<CR>", 'xt')
1986 call assert_equal(['a', 'ab'], g:log)
1987
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001988 unlet g:log
1989 cunmap <F1>
1990 augroup test
1991 autocmd!
1992 augroup END
1993endfunc
1994
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001995" Test for the 'suffixes' option
1996func Test_suffixes_opt()
1997 call writefile([], 'Xfile')
1998 call writefile([], 'Xfile.c')
1999 call writefile([], 'Xfile.o')
2000 set suffixes=
2001 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2002 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
2003 set suffixes=.c
2004 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2005 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
2006 set suffixes=,,
2007 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2008 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
2009 set suffixes&
2010 call delete('Xfile')
2011 call delete('Xfile.c')
2012 call delete('Xfile.o')
2013endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002014
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002015" Test for using a popup menu for the command line completion matches
2016" (wildoptions=pum)
2017func Test_wildmenu_pum()
2018 CheckRunVimInTerminal
2019
2020 let commands =<< trim [CODE]
2021 set wildmenu
2022 set wildoptions=pum
2023 set shm+=I
2024 set noruler
2025 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002026
2027 func CmdCompl(a, b, c)
2028 return repeat(['aaaa'], 120)
2029 endfunc
2030 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002031
2032 func MyStatusLine() abort
2033 return 'status'
2034 endfunc
2035 func SetupStatusline()
2036 set statusline=%!MyStatusLine()
2037 set laststatus=2
2038 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002039 [CODE]
2040 call writefile(commands, 'Xtest')
2041
2042 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2043
2044 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002045 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2046
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002047 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002048 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002049 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2050
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002051 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002052 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002053 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2054
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002055 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002056 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002057 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2058
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002059 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002060 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002061 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2062
2063 " pressing <C-E> should end completion and go back to the original match
2064 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002065 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2066
2067 " pressing <C-Y> should select the current match and end completion
2068 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002069 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2070
2071 " With 'wildmode' set to 'longest,full', completing a match should display
2072 " the longest match, the wildmenu should not be displayed.
2073 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2074 call TermWait(buf)
2075 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002076 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2077
2078 " pressing <Tab> should display the wildmenu
2079 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002080 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2081
2082 " pressing <Tab> second time should select the next entry in the menu
2083 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002084 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2085
2086 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002087 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002088 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002089 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2090
2091 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002092 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2093
2094 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002095 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2096
2097 " Directory name completion
2098 call mkdir('Xdir/XdirA/XdirB', 'p')
2099 call writefile([], 'Xdir/XfileA')
2100 call writefile([], 'Xdir/XdirA/XfileB')
2101 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2102
2103 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002104 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2105
2106 " Pressing <Right> on a directory name should go into that directory
2107 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002108 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2109
2110 " Pressing <Left> on a directory name should go to the parent directory
2111 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002112 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2113
2114 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002115 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002116 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002117 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2118
2119 " Pressing <C-D> when the popup menu is displayed should remove the popup
2120 " menu
2121 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002122 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2123
2124 " Pressing <S-Tab> should open the popup menu with the last entry selected
2125 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002126 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2127
2128 " Pressing <Esc> should close the popup menu and cancel the cmd line
2129 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002130 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2131
2132 " Typing a character when the popup is open, should close the popup
2133 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002134 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2135
2136 " When the popup is open, entering the cmdline window should close the popup
2137 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002138 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2139 call term_sendkeys(buf, ":q\<CR>")
2140
2141 " After the last popup menu item, <C-N> should show the original string
2142 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002143 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2144
2145 " Use the popup menu for the command name
2146 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002147 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2148
2149 " Pressing the left arrow should remove the popup menu
2150 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002151 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2152
2153 " Pressing <BS> should remove the popup menu and erase the last character
2154 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002155 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2156
2157 " Pressing <C-W> should remove the popup menu and erase the previous word
2158 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002159 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2160
2161 " Pressing <C-U> should remove the popup menu and erase the entire line
2162 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002163 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2164
2165 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2166 " the cmdline from history
2167 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002168 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2169
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002170 " Check "list" still works
2171 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2172 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002173 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2174 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002175 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2176
rbtnn68cc2b82022-02-09 11:55:47 +00002177 " Tests a directory name contained full-width characters.
2178 call mkdir('Xdir/あいう', 'p')
2179 call writefile([], 'Xdir/あいう/abc')
2180 call writefile([], 'Xdir/あいう/xyz')
2181 call writefile([], 'Xdir/あいう/123')
2182
2183 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2184 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002185 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2186
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002187 " Pressing <C-A> when the popup menu is displayed should list all the
2188 " matches and pressing a key after that should remove the popup menu
2189 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2190 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2191 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2192
2193 " Pressing <C-A> when the popup menu is displayed should list all the
2194 " matches and pressing <Left> after that should move the cursor
2195 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2196 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2197 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2198
2199 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2200 " should be displayed correctly on the screen.
2201 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2202 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2203
2204 " After using <C-A> to expand all the filename matches, pressing <Up>
2205 " should not open the popup menu again.
2206 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2207 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2208 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2209 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2210
2211 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2212 " crash Vim
2213 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2214 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2215
Bram Moolenaar414acd32022-02-10 21:09:45 +00002216 " After removing the pum the command line is redrawn
2217 call term_sendkeys(buf, ":edit foo\<CR>")
2218 call term_sendkeys(buf, ":edit bar\<CR>")
2219 call term_sendkeys(buf, ":ls\<CR>")
2220 call term_sendkeys(buf, ":com\<Tab> ")
2221 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002222 call term_sendkeys(buf, "\<C-U>\<CR>")
2223
2224 " Esc still works to abort the command when 'statusline' is set
2225 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2226 call term_sendkeys(buf, ":si\<Tab>")
2227 call term_sendkeys(buf, "\<Esc>")
2228 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002229
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002230 call term_sendkeys(buf, "\<C-U>\<CR>")
2231 call StopVimInTerminal(buf)
2232 call delete('Xtest')
2233 call delete('Xdir', 'rf')
2234endfunc
2235
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002236" Test for wildmenumode() with the cmdline popup menu
2237func Test_wildmenumode_with_pum()
2238 set wildmenu
2239 set wildoptions=pum
2240 cnoremap <expr> <F2> wildmenumode()
2241 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2242 call assert_equal('"sign define10', @:)
2243 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2244 call assert_equal('"sign define jump list place undefine unplace0', @:)
2245 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2246 call assert_equal('"sign 0', @:)
2247 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2248 call assert_equal('"sign define0', @:)
2249 set nowildmenu wildoptions&
2250 cunmap <F2>
2251endfunc
2252
Bram Moolenaar309976e2019-12-05 18:16:33 +01002253" vim: shiftwidth=2 sts=2 expandtab