blob: 6d0dc5bef75e567ab7d1021fd1c1012a08582af9 [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)
412 endif
413
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200414 " Command line completion tests
415 let l = getcompletion('cd ', 'cmdline')
416 call assert_true(index(l, 'samples/') >= 0)
417 let l = getcompletion('cd NoMatch', 'cmdline')
418 call assert_equal([], l)
419 let l = getcompletion('let v:n', 'cmdline')
420 call assert_true(index(l, 'v:null') >= 0)
421 let l = getcompletion('let v:notexists', 'cmdline')
422 call assert_equal([], l)
423 let l = getcompletion('call tag', 'cmdline')
424 call assert_true(index(l, 'taglist(') >= 0)
425 let l = getcompletion('call paint', 'cmdline')
426 call assert_equal([], l)
427
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100428 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000429 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100430 return "oneA\noneB\noneC"
431 endfunc
432 command -nargs=1 -complete=custom,T MyCmd
433 let l = getcompletion('MyCmd ', 'cmdline')
434 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000435 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100436
437 delcommand MyCmd
438 delfunc T
ii144785fe02021-11-21 12:13:56 +0000439 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100440
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200441 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200442 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200443 if has('cmdline_hist')
444 call add(names, 'history')
445 endif
446 if has('gettext')
447 call add(names, 'locale')
448 endif
449 if has('profile')
450 call add(names, 'syntime')
451 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200452
453 set tags=Xtags
454 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
455
456 for name in names
457 let matchcount = len(getcompletion('', name))
458 call assert_true(matchcount >= 0, 'No matches for ' . name)
459 endfor
460
461 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200462 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200463
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200464 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200465 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200466 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200467endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200468
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100469func Test_fullcommand()
470 let tests = {
471 \ '': '',
472 \ ':': '',
473 \ ':::': '',
474 \ ':::5': '',
475 \ 'not_a_cmd': '',
476 \ 'Check': '',
477 \ 'syntax': 'syntax',
478 \ ':syntax': 'syntax',
479 \ '::::syntax': 'syntax',
480 \ 'sy': 'syntax',
481 \ 'syn': 'syntax',
482 \ 'synt': 'syntax',
483 \ ':sy': 'syntax',
484 \ '::::sy': 'syntax',
485 \ 'match': 'match',
486 \ '2match': 'match',
487 \ '3match': 'match',
488 \ 'aboveleft': 'aboveleft',
489 \ 'abo': 'aboveleft',
490 \ 's': 'substitute',
491 \ '5s': 'substitute',
492 \ ':5s': 'substitute',
493 \ "'<,'>s": 'substitute',
494 \ ":'<,'>s": 'substitute',
495 \ 'CheckUni': 'CheckUnix',
496 \ 'CheckUnix': 'CheckUnix',
497 \ }
498
499 for [in, want] in items(tests)
500 call assert_equal(want, fullcommand(in))
501 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200502 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100503
504 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200505
506 command -buffer BufferLocalCommand :
507 command GlobalCommand :
508 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
509 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
510 delcommand BufferLocalCommand
511 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100512endfunc
513
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200514func Test_shellcmd_completion()
515 let save_path = $PATH
516
517 call mkdir('Xpathdir/Xpathsubdir', 'p')
518 call writefile([''], 'Xpathdir/Xfile.exe')
519 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
520
521 " Set PATH to example directory without trailing slash.
522 let $PATH = getcwd() . '/Xpathdir'
523
524 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
525 " dirs in the PATH, even though they won't be executed. We check that only
526 " subdirs of the PWD and executables from the PATH are included in the
527 " suggestions.
528 let actual = getcompletion('X', 'shellcmd')
529 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
530 call insert(expected, 'Xfile.exe')
531 call assert_equal(expected, actual)
532
533 call delete('Xpathdir', 'rf')
534 let $PATH = save_path
535endfunc
536
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200537func Test_expand_star_star()
538 call mkdir('a/b', 'p')
539 call writefile(['asdfasdf'], 'a/b/fileXname')
540 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
541 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200542 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200543 call delete('a', 'rf')
544endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100545
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100546func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100547 let @a = "def"
548 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
549 call assert_equal('"abc def ghi', @:)
550
551 new
552 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
553
554 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
555 call assert_equal('"aaa asdf bbb', @:)
556
557 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
558 call assert_equal('"aaa /tmp/some bbb', @:)
559
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200560 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
561 call assert_equal('"aaa '.getline(1).' bbb', @:)
562
Bram Moolenaar21efc362016-12-03 14:05:49 +0100563 set incsearch
564 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
565 call assert_equal('"aaa verylongword bbb', @:)
566
567 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
568 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100569
570 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
571 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100572 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200573
574 " Error while typing a command used to cause that it was not executed
575 " in the end.
576 new
577 try
578 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
579 catch /^Vim\%((\a\+)\)\=:E32/
580 " ignore error E32
581 endtry
582 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100583
Bram Moolenaar578fe942020-02-27 21:32:51 +0100584 " Try to paste an invalid register using <C-R>
585 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
586 call assert_equal('"onetwo', @:)
587
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100588 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100589 let @a = "xy\<C-H>z"
590 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
591 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100592 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
593 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100594 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
595 call assert_equal("\"xy\<C-H>z", @:)
596
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100597 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
598 let @a = "xy\<C-V>z"
599 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
600 call assert_equal('"xyz', @:)
601 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
602 call assert_equal("\"xy\<C-V>z", @:)
603
Bram Moolenaar578fe942020-02-27 21:32:51 +0100604 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
605
Bram Moolenaar72532d32018-04-07 19:09:09 +0200606 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100607endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100608
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100609func Test_cmdline_remove_char()
610 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100611
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100612 for e in ['utf8', 'latin1']
613 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100614
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100615 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
616 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100617
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100618 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
619 call assert_equal('"abcdef', @:)
620
621 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
622 call assert_equal('"abc ghi', @:, e)
623
624 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
625 call assert_equal('"def', @:, e)
626 endfor
627
628 let &encoding = encoding_save
629endfunc
630
631func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200632 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100633
634 set keymap=esperanto
635 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
636 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
637 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100638endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100639
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100640func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100641 new
642 2;'(
643 2;')
644 quit
645endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100646
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100647func Test_illegal_address2()
648 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
649 new
650 source Xtest.vim
651 " Trigger calling validate_cursor()
652 diffsp Xtest.vim
653 quit!
654 bwipe!
655 call delete('Xtest.vim')
656endfunc
657
Bram Moolenaarba47b512017-01-24 21:18:19 +0100658func Test_cmdline_complete_wildoptions()
659 help
660 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
661 let a = join(sort(split(@:)),' ')
662 set wildoptions=tagfile
663 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
664 let b = join(sort(split(@:)),' ')
665 call assert_equal(a, b)
666 bw!
667endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100668
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200669func Test_cmdline_complete_user_cmd()
670 command! -complete=color -nargs=1 Foo :
671 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
672 call assert_equal('"Foo blue', @:)
673 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
674 call assert_equal('"Foo blue', @:)
675 delcommand Foo
676endfunc
677
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100678func s:ScriptLocalFunction()
679 echo 'yes'
680endfunc
681
682func Test_cmdline_complete_user_func()
683 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200684 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100685 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
686 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100687
688 " g: prefix also works
689 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
690 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200691
692 " using g: prefix does not result in just "g:" matches from a lambda
693 let Fx = { a -> a }
694 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
695 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200696
697 " existence of script-local dict function does not break user function name
698 " completion
699 function s:a_dict_func() dict
700 endfunction
701 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
702 call assert_match('"call Test_cmdline_complete_user_', @:)
703 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100704endfunc
705
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200706func Test_cmdline_complete_user_names()
707 if has('unix') && executable('whoami')
708 let whoami = systemlist('whoami')[0]
709 let first_letter = whoami[0]
710 if len(first_letter) > 0
711 " Trying completion of :e ~x where x is the first letter of
712 " the user name should complete to at least the user name.
713 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
714 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
715 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200716 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200717 " Just in case: check that the system has an Administrator account.
718 let names = system('net user')
719 if names =~ 'Administrator'
720 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100721 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200722 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100723 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200724 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200725 else
726 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200727 endif
728endfunc
729
Bram Moolenaar297610b2019-12-27 17:20:55 +0100730func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200731 CheckExecutable whoami
732 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
733 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100734endfunc
735
Bram Moolenaar8b633132020-03-20 18:20:51 +0100736func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200737 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
738 call assert_equal(lang, v:lc_time)
739
740 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
741 call assert_equal(lang, v:ctype)
742
743 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
744 call assert_equal(lang, v:collate)
745
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200746 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200747 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200748
749 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200750 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200751
Bram Moolenaarec680282020-06-12 19:35:32 +0200752 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200753
Bram Moolenaarec680282020-06-12 19:35:32 +0200754 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
755 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200756
Bram Moolenaarec680282020-06-12 19:35:32 +0200757 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
758 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200759
Bram Moolenaarec680282020-06-12 19:35:32 +0200760 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
761 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200762
763 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
764 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200765endfunc
766
Bram Moolenaar297610b2019-12-27 17:20:55 +0100767func Test_cmdline_complete_env_variable()
768 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100769 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
770 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100771 unlet $X_VIM_TEST_COMPLETE_ENV
772endfunc
773
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100774func Test_cmdline_complete_expression()
775 let g:SomeVar = 'blah'
776 for cmd in ['exe', 'echo', 'echon', 'echomsg']
777 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
778 call assert_match('"' .. cmd .. ' SomeVar', @:)
779 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
780 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
781 endfor
782 unlet g:SomeVar
783endfunc
784
Bram Moolenaar47016f52021-08-26 16:39:58 +0200785" Unique function name for completion below
786func s:WeirdFunc()
787 echo 'weird'
788endfunc
789
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100790" Test for various command-line completion
791func Test_cmdline_complete_various()
792 " completion for a command starting with a comment
793 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
794 call assert_equal("\" :|\"\<C-A>", @:)
795
796 " completion for a range followed by a comment
797 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
798 call assert_equal("\"1,2\"\<C-A>", @:)
799
800 " completion for :k command
801 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
802 call assert_equal("\"ka\<C-A>", @:)
803
804 " completion for short version of the :s command
805 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
806 call assert_equal("\"sI \<C-A>", @:)
807
808 " completion for :write command
809 call mkdir('Xdir')
810 call writefile(['one'], 'Xdir/Xfile1')
811 let save_cwd = getcwd()
812 cd Xdir
813 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
814 call assert_equal("\"w >> Xfile1", @:)
815 call chdir(save_cwd)
816 call delete('Xdir', 'rf')
817
818 " completion for :w ! and :r ! commands
819 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
820 call assert_equal("\"w !invalid_xyz_cmd", @:)
821 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
822 call assert_equal("\"r !invalid_xyz_cmd", @:)
823
824 " completion for :>> and :<< commands
825 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
826 call assert_equal("\">>>\<C-A>", @:)
827 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
828 call assert_equal("\"<<<\<C-A>", @:)
829
830 " completion for command with +cmd argument
831 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
832 call assert_equal("\"buffer +/pat Xabc", @:)
833 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
834 call assert_equal("\"buffer +/pat\<C-A>", @:)
835
836 " completion for a command with a trailing comment
837 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
838 call assert_equal("\"ls \" comment\<C-A>", @:)
839
840 " completion for a command with a trailing command
841 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
842 call assert_equal("\"ls | ls", @:)
843
844 " completion for a command with an CTRL-V escaped argument
845 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
846 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
847
848 " completion for a command that doesn't take additional arguments
849 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
850 call assert_equal("\"all abc\<C-A>", @:)
851
852 " completion for a command with a command modifier
853 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
854 call assert_equal("\"topleft new", @:)
855
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200856 " completion for vim9 and legacy commands
857 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
858 call assert_equal("\"vim9 call strlen(", @:)
859 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
860 call assert_equal("\"legac call strlen(", @:)
861
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200862 " completion for the :disassemble command
863 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
864 call assert_equal("\"disas debug", @:)
865 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
866 call assert_equal("\"disas profile", @:)
867 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
868 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
869 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
870 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +0200871 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
872 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200873
Bram Moolenaar47016f52021-08-26 16:39:58 +0200874 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +0200875 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +0200876
naohiro onodfe04db2021-09-12 15:45:10 +0200877 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
878 call assert_match('"disas <SNR>\d\+_', @:)
879 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
880 call assert_match('"disas debug <SNR>\d\+_', @:)
881
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100882 " completion for the :match command
883 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
884 call assert_equal("\"match Search /pat/\<C-A>", @:)
885
886 " completion for the :s command
887 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
888 call assert_equal("\"s/from/to/g\<C-A>", @:)
889
890 " completion for the :dlist command
891 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
892 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
893
894 " completion for the :doautocmd command
895 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
896 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
897
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200898 " completion of autocmd group after comma
899 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
900 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
901
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200902 " completion of file name in :doautocmd
903 call writefile([], 'Xfile1')
904 call writefile([], 'Xfile2')
905 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
906 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
907 call delete('Xfile1')
908 call delete('Xfile2')
909
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100910 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200911 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100912 augroup END
913 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200914 call assert_equal("\"augroup XTest.test", @:)
915 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
916 call assert_equal("\"au XTest.test", @:)
917 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100918
919 " completion for the :unlet command
920 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
921 call assert_equal("\"unlet one two", @:)
922
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +0100923 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +0100924 " FIXME: what should happen on MS-Windows?
925 if !has('win32')
926 edit \{someFile}
927 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
928 call assert_equal("\"buf {someFile}", @:)
929 bwipe {someFile}
930 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +0100931
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100932 " completion for the :bdelete command
933 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
934 call assert_equal("\"bdel a b c", @:)
935
936 " completion for the :mapclear command
937 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
938 call assert_equal("\"mapclear <buffer>", @:)
939
940 " completion for user defined commands with menu names
941 menu Test.foo :ls<CR>
942 com -nargs=* -complete=menu MyCmd
943 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
944 call assert_equal('"MyCmd Test.', @:)
945 delcom MyCmd
946 unmenu Test
947
948 " completion for user defined commands with mappings
949 mapclear
950 map <F3> :ls<CR>
951 com -nargs=* -complete=mapping MyCmd
952 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
953 call assert_equal('"MyCmd <F3>', @:)
954 mapclear
955 delcom MyCmd
956
957 " completion for :set path= with multiple backslashes
958 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
959 call assert_equal('"set path=a\\\ b', @:)
960
961 " completion for :set dir= with a backslash
962 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
963 call assert_equal('"set dir=a\ b', @:)
964
965 " completion for the :py3 commands
966 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
967 call assert_equal('"py3 py3do py3file', @:)
968
Bram Moolenaardf749a22021-03-28 15:29:43 +0200969 " completion for the :vim9 commands
970 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
971 call assert_equal('"vim9cmd vim9script', @:)
972
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100973 " redir @" is not the start of a comment. So complete after that
974 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
975 call assert_equal('"redir @" | cwindow', @:)
976
977 " completion after a backtick
978 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
979 call assert_equal('"e `a1b2c', @:)
980
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100981 " completion for :language command with an invalid argument
982 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
983 call assert_equal("\"language dummy \t", @:)
984
985 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +0100986 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
987 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100988
989 " completion with ambiguous user defined commands
990 com TCmd1 echo 'TCmd1'
991 com TCmd2 echo 'TCmd2'
992 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
993 call assert_equal('"TCmd ', @:)
994 delcom TCmd1
995 delcom TCmd2
996
997 " completion after a range followed by a pipe (|) character
998 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
999 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001000
1001 " use <Esc> as the 'wildchar' for completion
1002 set wildchar=<Esc>
1003 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1004 call assert_equal('"g/a\xb/clearjumps', @:)
1005 " pressing <esc> twice should cancel the command
1006 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1007 call assert_equal('"g/a\xb/clearjumps', @:)
1008 set wildchar&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001009endfunc
1010
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001011func Test_cmdline_write_alternatefile()
1012 new
1013 call setline('.', ['one', 'two'])
1014 f foo.txt
1015 new
1016 f #-A
1017 call assert_equal('foo.txt-A', expand('%'))
1018 f #<-B.txt
1019 call assert_equal('foo-B.txt', expand('%'))
1020 f %<
1021 call assert_equal('foo-B', expand('%'))
1022 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001023 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001024 bw!
1025 f foo-B.txt
1026 f %<-A
1027 call assert_equal('foo-B-A', expand('%'))
1028 bw!
1029 bw!
1030endfunc
1031
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001032" using a leading backslash here
1033set cpo+=C
1034
1035func Test_cmdline_search_range()
1036 new
1037 call setline(1, ['a', 'b', 'c', 'd'])
1038 /d
1039 1,\/s/b/B/
1040 call assert_equal('B', getline(2))
1041
1042 /a
1043 $
1044 \?,4s/c/C/
1045 call assert_equal('C', getline(3))
1046
1047 call setline(1, ['a', 'b', 'c', 'd'])
1048 %s/c/c/
1049 1,\&s/b/B/
1050 call assert_equal('B', getline(2))
1051
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001052 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001053 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001054
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001055 bwipe!
1056endfunc
1057
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001058" Test for the tick mark (') in an excmd range
1059func Test_tick_mark_in_range()
1060 " If only the tick is passed as a range and no command is specified, there
1061 " should not be an error
1062 call feedkeys(":'\<CR>", 'xt')
1063 call assert_equal("'", getreg(':'))
1064 call assert_fails("',print", 'E78:')
1065endfunc
1066
1067" Test for using a line number followed by a search pattern as range
1068func Test_lnum_and_pattern_as_range()
1069 new
1070 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1071 let @" = ''
1072 2/foo/yank
1073 call assert_equal("foo 3\n", @")
1074 call assert_equal(1, line('.'))
1075 close!
1076endfunc
1077
Bram Moolenaar65189a12017-02-06 22:22:17 +01001078" Tests for getcmdline(), getcmdpos() and getcmdtype()
1079func Check_cmdline(cmdtype)
1080 call assert_equal('MyCmd a', getcmdline())
1081 call assert_equal(8, getcmdpos())
1082 call assert_equal(a:cmdtype, getcmdtype())
1083 return ''
1084endfunc
1085
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001086set cpo&
1087
Bram Moolenaar65189a12017-02-06 22:22:17 +01001088func Test_getcmdtype()
1089 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1090
1091 let cmdtype = ''
1092 debuggreedy
1093 call feedkeys(":debug echo 'test'\<CR>", "t")
1094 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1095 call feedkeys("cont\<CR>", "xt")
1096 0debuggreedy
1097 call assert_equal('>', cmdtype)
1098
1099 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1100 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1101
1102 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001103 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001104
1105 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1106
1107 cnoremap <expr> <F6> Check_cmdline('=')
1108 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1109 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001110
1111 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001112endfunc
1113
Bram Moolenaar81612b72018-06-23 14:55:03 +02001114func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001115 CheckFeature cmdwin
1116
Bram Moolenaar81612b72018-06-23 14:55:03 +02001117 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1118 call assert_equal('/', a)
1119
1120 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1121 call assert_equal('?', a)
1122
1123 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1124 call assert_equal(':', a)
1125
1126 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1127 call assert_equal(':', a)
1128
1129 call assert_equal('', getcmdwintype())
1130endfunc
1131
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001132func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001133 CheckFeature cmdwin
1134
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001135 let s:seq = []
1136 augroup CmdWin
1137 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1138 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1139 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1140 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1141 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1142 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1143
1144 let org_winid = win_getid()
1145 let org_bufnr = bufnr()
1146 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1147 call assert_equal(':', a)
1148 call assert_equal([
1149 \ 'WinLeave ' .. org_winid,
1150 \ 'WinEnter ' .. s:cmd_winid,
1151 \ 'BufLeave ' .. org_bufnr,
1152 \ 'BufEnter ' .. s:cmd_bufnr,
1153 \ 'CmdWinEnter ' .. s:cmd_winid,
1154 \ 'CmdWinLeave ' .. s:cmd_winid,
1155 \ 'BufLeave ' .. s:cmd_bufnr,
1156 \ 'WinLeave ' .. s:cmd_winid,
1157 \ 'WinEnter ' .. org_winid,
1158 \ 'BufEnter ' .. org_bufnr,
1159 \ ], s:seq)
1160
1161 au!
1162 augroup END
1163endfunc
1164
Bram Moolenaar52604f22017-04-07 16:17:39 +02001165func Test_verbosefile()
1166 set verbosefile=Xlog
1167 echomsg 'foo'
1168 echomsg 'bar'
1169 set verbosefile=
1170 let log = readfile('Xlog')
1171 call assert_match("foo\nbar", join(log, "\n"))
1172 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001173 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001174 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001175 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001176endfunc
1177
Bram Moolenaar4facea32019-10-12 20:17:40 +02001178func Test_verbose_option()
1179 CheckScreendump
1180
1181 let lines =<< trim [SCRIPT]
1182 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1183 call feedkeys("\r", 't') " for the hit-enter prompt
1184 set verbose=20
1185 [SCRIPT]
1186 call writefile(lines, 'XTest_verbose')
1187
1188 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001189 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001190 call term_sendkeys(buf, ":DoSomething\<CR>")
1191 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1192
1193 " clean up
1194 call StopVimInTerminal(buf)
1195 call delete('XTest_verbose')
1196endfunc
1197
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001198func Test_setcmdpos()
1199 func InsertTextAtPos(text, pos)
1200 call assert_equal(0, setcmdpos(a:pos))
1201 return a:text
1202 endfunc
1203
1204 " setcmdpos() with position in the middle of the command line.
1205 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1206 call assert_equal('"1ab2', @:)
1207
1208 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1209 call assert_equal('"1b2a', @:)
1210
1211 " setcmdpos() with position beyond the end of the command line.
1212 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1213 call assert_equal('"12ab', @:)
1214
1215 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001216 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001217endfunc
1218
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001219func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001220 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001221 let encoding_save = &encoding
1222
1223 for e in encodings
1224 exe 'set encoding=' . e
1225
1226 " Test overstrike in the middle of the command line.
1227 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001228 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001229
1230 " Test overstrike going beyond end of command line.
1231 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001232 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001233
1234 " Test toggling insert/overstrike a few times.
1235 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001236 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001237 endfor
1238
Bram Moolenaar30276f22019-01-24 17:59:39 +01001239 " Test overstrike with multi-byte characters.
1240 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001241 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001242
1243 let &encoding = encoding_save
1244endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001245
1246func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001247 CheckFeature cmdwin
1248
Bram Moolenaara046b372019-09-15 17:26:07 +02001249 let winid = win_getid()
1250 sp
1251 try
1252 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1253 catch /^Vim\%((\a\+)\)\=:E11/
1254 endtry
1255 bw!
1256endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001257
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001258func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001259 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001260 CheckScreendump
1261
1262 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001263 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001264 call setline(1, range(30))
1265 2split
1266 [SCRIPT]
1267 call writefile(lines, 'XTest_restore')
1268
1269 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001270 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001271 call term_sendkeys(buf, "q:")
1272 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1273
1274 " normal restore
1275 call term_sendkeys(buf, ":q\<CR>")
1276 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1277
1278 " restore after setting 'lines' with one window
1279 call term_sendkeys(buf, ":close\<CR>")
1280 call term_sendkeys(buf, "q:")
1281 call term_sendkeys(buf, ":set lines=18\<CR>")
1282 call term_sendkeys(buf, ":q\<CR>")
1283 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1284
1285 " clean up
1286 call StopVimInTerminal(buf)
1287 call delete('XTest_restore')
1288endfunc
1289
Bram Moolenaare5b44862021-05-30 13:54:03 +02001290func Test_cmdwin_no_terminal()
1291 CheckFeature cmdwin
1292 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001293 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001294
1295 let buf = RunVimInTerminal('', {'rows': 12})
1296 call TermWait(buf, 50)
1297 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1298 call term_sendkeys(buf, "q:")
1299 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1300 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1301 call term_sendkeys(buf, ":q\<CR>")
1302 call StopVimInTerminal(buf)
1303endfunc
1304
Bram Moolenaar52410572019-10-27 05:12:45 +01001305func Test_buffers_lastused()
1306 " check that buffers are sorted by time when wildmode has lastused
1307 call test_settime(1550020000) " middle
1308 edit bufa
1309 enew
1310 call test_settime(1550030000) " newest
1311 edit bufb
1312 enew
1313 call test_settime(1550010000) " oldest
1314 edit bufc
1315 enew
1316 call test_settime(0)
1317 enew
1318
1319 call assert_equal(['bufa', 'bufb', 'bufc'],
1320 \ getcompletion('', 'buffer'))
1321
1322 let save_wildmode = &wildmode
1323 set wildmode=full:lastused
1324
1325 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1326 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1327 call assert_equal('b bufb', X)
1328 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1329 call assert_equal('b bufa', X)
1330 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1331 call assert_equal('b bufc', X)
1332 enew
1333
1334 edit other
1335 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1336 call assert_equal('b bufb', X)
1337 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1338 call assert_equal('b bufa', X)
1339 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1340 call assert_equal('b bufc', X)
1341 enew
1342
1343 let &wildmode = save_wildmode
1344
1345 bwipeout bufa
1346 bwipeout bufb
1347 bwipeout bufc
1348endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001349
1350func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001351 CheckFeature cmdwin
1352
Bram Moolenaar85db5472019-12-04 15:11:08 +01001353 " This should not generate E488
1354 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001355 " Using feedkeys with q: only should automatically close the cmd window
1356 call feedkeys('q:', 'xt')
1357 call assert_equal(1, winnr('$'))
1358 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001359endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001360
1361" Tests for the issues fixed in 7.4.441.
1362" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1363func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001364 CheckFeature cmdwin
1365
Bram Moolenaar309976e2019-12-05 18:16:33 +01001366 exe "set cedit=\<C-c>"
1367 normal! :
1368 call assert_equal(1, winnr('$'))
1369
1370 let g:cmd_wintype = ''
1371 func CmdWinType()
1372 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001373 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001374 return ''
1375 endfunc
1376
1377 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1378 echo input('')
1379 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001380 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001381
1382 set cedit&vim
1383 delfunc CmdWinType
1384endfunc
1385
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001386" Test for CmdwinEnter autocmd
1387func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001388 CheckFeature cmdwin
1389
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001390 augroup CmdWin
1391 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001392 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001393 autocmd CmdwinEnter * startinsert
1394 augroup END
1395
1396 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1397 call assert_equal('xyz', @:)
1398
1399 augroup CmdWin
1400 au!
1401 augroup END
1402 augroup! CmdWin
1403endfunc
1404
Bram Moolenaar479950f2020-01-19 15:45:17 +01001405func Test_cmdlineclear_tabenter()
1406 CheckScreendump
1407
1408 let lines =<< trim [SCRIPT]
1409 call setline(1, range(30))
1410 [SCRIPT]
1411
1412 call writefile(lines, 'XtestCmdlineClearTabenter')
1413 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001414 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001415 " in one tab make the command line higher with CTRL-W -
1416 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1417 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1418
1419 call StopVimInTerminal(buf)
1420 call delete('XtestCmdlineClearTabenter')
1421endfunc
1422
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001423" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001424func Test_cmdline_expand_special()
1425 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001426 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001427 call assert_fails('e <afile>', 'E495:')
1428 call assert_fails('e <abuf>', 'E496:')
1429 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001430
1431 call writefile([], 'Xfile.cpp')
1432 call writefile([], 'Xfile.java')
1433 new Xfile.cpp
1434 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1435 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1436 close
1437 call delete('Xfile.cpp')
1438 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001439endfunc
1440
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001441func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001442 CheckFeature cmdwin
1443
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001444 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1445 new
1446 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001447 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001448 close!
1449 call feedkeys("q/:close\<CR>", "xt")
1450 call assert_equal(1, winnr('$'))
1451 call feedkeys("q/:exit\<CR>", "xt")
1452 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001453
1454 " opening command window twice should fail
1455 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1456 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001457endfunc
1458
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001459func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001460 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001461 CheckScreendump
1462
1463 " aborting the :smile output caused the cmdline window to use the current
1464 " buffer.
1465 let lines =<< trim [SCRIPT]
1466 au WinNew * smile
1467 [SCRIPT]
1468 call writefile(lines, 'XTest_cmdwin')
1469
1470 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001471 " open cmdwin
1472 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001473 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001474 " quit more prompt for :smile command
1475 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001476 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001477 " execute a simple command
1478 call term_sendkeys(buf, "aecho 'done'\<CR>")
1479 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1480
1481 " clean up
1482 call StopVimInTerminal(buf)
1483 call delete('XTest_cmdwin')
1484endfunc
1485
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001486" Test for backtick expression in the command line
1487func Test_cmd_backtick()
1488 %argd
1489 argadd `=['a', 'b', 'c']`
1490 call assert_equal(['a', 'b', 'c'], argv())
1491 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001492
1493 argadd `echo abc def`
1494 call assert_equal(['abc def'], argv())
1495 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001496endfunc
1497
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001498" Test for the :! command
1499func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001500 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001501
1502 let lines =<< trim [SCRIPT]
1503 " Test for no previous command
1504 call assert_fails('!!', 'E34:')
1505 set nomore
1506 " Test for cmdline expansion with :!
1507 call setline(1, 'foo!')
1508 silent !echo <cWORD> > Xfile.out
1509 call assert_equal(['foo!'], readfile('Xfile.out'))
1510 " Test for using previous command
1511 silent !echo \! !
1512 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1513 call writefile(v:errors, 'Xresult')
1514 call delete('Xfile.out')
1515 qall!
1516 [SCRIPT]
1517 call writefile(lines, 'Xscript')
1518 if RunVim([], [], '--clean -S Xscript')
1519 call assert_equal([], readfile('Xresult'))
1520 endif
1521 call delete('Xscript')
1522 call delete('Xresult')
1523endfunc
1524
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001525" Test error: "E135: *Filter* Autocommands must not change current buffer"
1526func Test_cmd_bang_E135()
1527 new
1528 call setline(1, ['a', 'b', 'c', 'd'])
1529 augroup test_cmd_filter_E135
1530 au!
1531 autocmd FilterReadPost * help
1532 augroup END
1533 call assert_fails('2,3!echo "x"', 'E135:')
1534
1535 augroup test_cmd_filter_E135
1536 au!
1537 augroup END
1538 %bwipe!
1539endfunc
1540
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001541" Test for using ~ for home directory in cmdline completion matches
1542func Test_cmdline_expand_home()
1543 call mkdir('Xdir')
1544 call writefile([], 'Xdir/Xfile1')
1545 call writefile([], 'Xdir/Xfile2')
1546 cd Xdir
1547 let save_HOME = $HOME
1548 let $HOME = getcwd()
1549 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1550 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1551 let $HOME = save_HOME
1552 cd ..
1553 call delete('Xdir', 'rf')
1554endfunc
1555
Bram Moolenaar578fe942020-02-27 21:32:51 +01001556" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1557" or insert mode (when 'insertmode' is set)
1558func Test_cmdline_ctrl_g()
1559 new
1560 call setline(1, 'abc')
1561 call cursor(1, 3)
1562 " If command line is entered from insert mode, using C-\ C-G should back to
1563 " insert mode
1564 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1565 call assert_equal('abxyc', getline(1))
1566 call assert_equal(4, col('.'))
1567
1568 " If command line is entered in 'insertmode', using C-\ C-G should back to
1569 " 'insertmode'
1570 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1571 call assert_equal('ab12xyc', getline(1))
1572 close!
1573endfunc
1574
Bram Moolenaar578fe942020-02-27 21:32:51 +01001575" Test for 'wildmode'
1576func Test_wildmode()
1577 func T(a, c, p)
1578 return "oneA\noneB\noneC"
1579 endfunc
1580 command -nargs=1 -complete=custom,T MyCmd
1581
1582 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001583 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001584 return ''
1585 endfunc
1586 cnoremap <expr> <F2> SaveScreenLine()
1587
1588 set nowildmenu
1589 set wildmode=full,list
1590 let g:Sline = ''
1591 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001592 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001593 call assert_equal('"MyCmd oneA', @:)
1594
1595 set wildmode=longest,full
1596 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1597 call assert_equal('"MyCmd one', @:)
1598 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1599 call assert_equal('"MyCmd oneC', @:)
1600
1601 set wildmode=longest
1602 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1603 call assert_equal('"MyCmd one', @:)
1604
1605 set wildmode=list:longest
1606 let g:Sline = ''
1607 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001608 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001609 call assert_equal('"MyCmd one', @:)
1610
1611 set wildmode=""
1612 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1613 call assert_equal('"MyCmd oneA', @:)
1614
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001615 " Test for wildmode=longest with 'fileignorecase' set
1616 set wildmode=longest
1617 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001618 argadd AAA AAAA AAAAA
1619 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1620 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001621 set fileignorecase&
1622
1623 " Test for listing files with wildmode=list
1624 set wildmode=list
1625 let g:Sline = ''
1626 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001627 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001628 call assert_equal('"b A', @:)
1629
1630 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001631 delcommand MyCmd
1632 delfunc T
1633 delfunc SaveScreenLine
1634 cunmap <F2>
1635 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001636 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001637endfunc
1638
1639" Test for interrupting the command-line completion
1640func Test_interrupt_compl()
1641 func F(lead, cmdl, p)
1642 if a:lead =~ 'tw'
1643 call interrupt()
1644 return
1645 endif
1646 return "one\ntwo\nthree"
1647 endfunc
1648 command -nargs=1 -complete=custom,F Tcmd
1649
1650 set nowildmenu
1651 set wildmode=full
1652 let interrupted = 0
1653 try
1654 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1655 catch /^Vim:Interrupt$/
1656 let interrupted = 1
1657 endtry
1658 call assert_equal(1, interrupted)
1659
1660 delcommand Tcmd
1661 delfunc F
1662 set wildmode&
1663endfunc
1664
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001665" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001666func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001667 let str = ":one two\<C-U>"
1668 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001669 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001670 let str ..= "\<Left>five\<Right>"
1671 let str ..= "\<Home>two "
1672 let str ..= "\<C-Left>one "
1673 let str ..= "\<C-Right> three"
1674 let str ..= "\<End>\<S-Left>four "
1675 let str ..= "\<S-Right> six"
1676 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1677 call feedkeys(str, 'xt')
1678 call assert_equal("\"one two three four five six seven", @:)
1679endfunc
1680
1681" Test for moving the cursor on the / command line in 'rightleft' mode
1682func Test_cmdline_edit_rightleft()
1683 CheckFeature rightleft
1684 set rightleft
1685 set rightleftcmd=search
1686 let str = "/one two\<C-U>"
1687 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001688 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001689 let str ..= "\<Right>five\<Left>"
1690 let str ..= "\<Home>two "
1691 let str ..= "\<C-Right>one "
1692 let str ..= "\<C-Left> three"
1693 let str ..= "\<End>\<S-Right>four "
1694 let str ..= "\<S-Left> six"
1695 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1696 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1697 call assert_equal("\"one two three four five six seven", @/)
1698 set rightleftcmd&
1699 set rightleft&
1700endfunc
1701
1702" Test for using <C-\>e in the command line to evaluate an expression
1703func Test_cmdline_expr()
1704 " Evaluate an expression from the beginning of a command line
1705 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1706 call assert_equal('"hello', @:)
1707
1708 " Use an invalid expression for <C-\>e
1709 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1710
1711 " Insert literal <CTRL-\> in the command line
1712 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1713 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001714endfunc
1715
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001716" Test for 'imcmdline' and 'imsearch'
1717" This test doesn't actually test the input method functionality.
1718func Test_cmdline_inputmethod()
1719 new
1720 call setline(1, ['', 'abc', ''])
1721 set imcmdline
1722
1723 call feedkeys(":\"abc\<CR>", 'xt')
1724 call assert_equal("\"abc", @:)
1725 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1726 call assert_equal("\"abc", @:)
1727 call feedkeys("/abc\<CR>", 'xt')
1728 call assert_equal([2, 1], [line('.'), col('.')])
1729 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1730 call assert_equal([2, 1], [line('.'), col('.')])
1731
1732 set imsearch=2
1733 call cursor(1, 1)
1734 call feedkeys("/abc\<CR>", 'xt')
1735 call assert_equal([2, 1], [line('.'), col('.')])
1736 call cursor(1, 1)
1737 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1738 call assert_equal([2, 1], [line('.'), col('.')])
1739 set imdisable
1740 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1741 call assert_equal([2, 1], [line('.'), col('.')])
1742 set imdisable&
1743 set imsearch&
1744
1745 set imcmdline&
1746 %bwipe!
1747endfunc
1748
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001749" Test for recursively getting multiple command line inputs
1750func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001751 CheckFeature cmdwin
1752
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001753 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1754 call assert_equal('"cyan', @:)
1755endfunc
1756
1757" Test for using CTRL-_ in the command line with 'allowrevins'
1758func Test_cmdline_revins()
1759 CheckNotMSWindows
1760 CheckFeature rightleft
1761 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1762 call assert_equal("\"abc\<c-_>", @:)
1763 set allowrevins
1764 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1765 call assert_equal('"abcñèæ', @:)
1766 set allowrevins&
1767endfunc
1768
1769" Test for typing UTF-8 composing characters in the command line
1770func Test_cmdline_composing_chars()
1771 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1772 call assert_equal('"ゔ', @:)
1773endfunc
1774
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001775" Test for normal mode commands not supported in the cmd window
1776func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001777 CheckFeature cmdwin
1778
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001779 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1780 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1781 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1782 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1783 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1784 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001785 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1786 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1787 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1788 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1789 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1790 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1791 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1792 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1793 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1794 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1795 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1796 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1797 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1798 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1799 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1800 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1801 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1802 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1803 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1804 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1805 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001806endfunc
1807
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001808" Close the Cmd-line window in insert mode using CTRL-C
1809func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001810 CheckFeature cmdwin
1811
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001812 %bw!
1813 let s = ''
1814 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1815 call assert_equal('Hello', s)
1816 call assert_equal(1, winnr('$'))
1817endfunc
1818
Bram Moolenaar0e717042020-04-27 19:29:01 +02001819" test that ";" works to find a match at the start of the first line
1820func Test_zero_line_search()
1821 new
1822 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1823 call cursor(1,1)
1824 0;/pattern/d
1825 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1826 q!
1827endfunc
1828
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001829func Test_read_shellcmd()
1830 CheckUnix
1831 if executable('ls')
1832 " There should be ls in the $PATH
1833 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1834 call assert_match('^"r! .*\<ls\>', @:)
1835 endif
1836
1837 if executable('rm')
1838 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1839 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1840 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001841
1842 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1843 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1844 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001845 endif
1846endfunc
1847
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001848" Test for going up and down the directory tree using 'wildmenu'
1849func Test_wildmenu_dirstack()
1850 CheckUnix
1851 %bw!
1852 call mkdir('Xdir1/dir2/dir3', 'p')
1853 call writefile([], 'Xdir1/file1_1.txt')
1854 call writefile([], 'Xdir1/file1_2.txt')
1855 call writefile([], 'Xdir1/dir2/file2_1.txt')
1856 call writefile([], 'Xdir1/dir2/file2_2.txt')
1857 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
1858 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
1859 cd Xdir1/dir2/dir3
1860 set wildmenu
1861
1862 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
1863 call assert_equal('"e file3_1.txt', @:)
1864 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
1865 call assert_equal('"e ../dir3/', @:)
1866 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1867 call assert_equal('"e ../../dir2/', @:)
1868 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
1869 call assert_equal('"e ../../dir2/dir3/', @:)
1870 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1871 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:)
1872
1873 cd -
1874 call delete('Xdir1', 'rf')
1875 set wildmenu&
1876endfunc
1877
obcat71c6f7a2021-05-13 20:23:10 +02001878" Test for recalling newer or older cmdline from history with <Up>, <Down>,
1879" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
1880func Test_recalling_cmdline()
1881 CheckFeature cmdline_hist
1882
1883 let g:cmdlines = []
1884 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1885
1886 let histories = [
1887 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
1888 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
1889 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
1890 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
1891 "\ TODO: {'name': 'debug', ...}
1892 \]
1893 let keypairs = [
1894 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
1895 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
1896 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
1897 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
1898 \]
1899 let prefix = 'vi'
1900 for h in histories
1901 call histadd(h.name, 'vim')
1902 call histadd(h.name, 'virtue')
1903 call histadd(h.name, 'Virgo')
1904 call histadd(h.name, 'vogue')
1905 call histadd(h.name, 'emacs')
1906 for k in keypairs
1907 let g:cmdlines = []
1908 let keyseqs = h.enter
1909 \ .. prefix
1910 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
1911 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
1912 \ .. h.exit
1913 call feedkeys(keyseqs, 'xt')
1914 call histdel(h.name, -1) " delete the history added by feedkeys above
1915 let expect = k.prefixmatch
1916 \ ? ['virtue', 'vim', 'virtue', prefix]
1917 \ : ['emacs', 'vogue', 'emacs', prefix]
1918 call assert_equal(expect, g:cmdlines)
1919 endfor
1920 endfor
1921
1922 unlet g:cmdlines
1923 cunmap <Plug>(save-cmdline)
1924endfunc
1925
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001926func Test_cmd_map_cmdlineChanged()
1927 let g:log = []
1928 cnoremap <F1> l<Cmd><CR>s
1929 augroup test
1930 autocmd!
1931 autocmd CmdlineChanged : let g:log += [getcmdline()]
1932 augroup END
1933
1934 call feedkeys(":\<F1>\<CR>", 'xt')
1935 call assert_equal(['l', 'ls'], g:log)
1936
Bram Moolenaar796139a2021-05-18 21:38:45 +02001937 let @b = 'b'
1938 cnoremap <F1> a<C-R>b
1939 let g:log = []
1940 call feedkeys(":\<F1>\<CR>", 'xt')
1941 call assert_equal(['a', 'ab'], g:log)
1942
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001943 unlet g:log
1944 cunmap <F1>
1945 augroup test
1946 autocmd!
1947 augroup END
1948endfunc
1949
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001950" Test for the 'suffixes' option
1951func Test_suffixes_opt()
1952 call writefile([], 'Xfile')
1953 call writefile([], 'Xfile.c')
1954 call writefile([], 'Xfile.o')
1955 set suffixes=
1956 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1957 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
1958 set suffixes=.c
1959 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1960 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
1961 set suffixes=,,
1962 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1963 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
1964 set suffixes&
1965 call delete('Xfile')
1966 call delete('Xfile.c')
1967 call delete('Xfile.o')
1968endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001969
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00001970" Test for using a popup menu for the command line completion matches
1971" (wildoptions=pum)
1972func Test_wildmenu_pum()
1973 CheckRunVimInTerminal
1974
1975 let commands =<< trim [CODE]
1976 set wildmenu
1977 set wildoptions=pum
1978 set shm+=I
1979 set noruler
1980 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00001981
1982 func CmdCompl(a, b, c)
1983 return repeat(['aaaa'], 120)
1984 endfunc
1985 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00001986
1987 func MyStatusLine() abort
1988 return 'status'
1989 endfunc
1990 func SetupStatusline()
1991 set statusline=%!MyStatusLine()
1992 set laststatus=2
1993 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00001994 [CODE]
1995 call writefile(commands, 'Xtest')
1996
1997 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
1998
1999 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002000 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2001
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002002 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002003 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002004 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2005
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002006 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002007 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002008 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2009
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002010 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002011 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002012 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2013
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002014 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002015 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002016 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2017
2018 " pressing <C-E> should end completion and go back to the original match
2019 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002020 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2021
2022 " pressing <C-Y> should select the current match and end completion
2023 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002024 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2025
2026 " With 'wildmode' set to 'longest,full', completing a match should display
2027 " the longest match, the wildmenu should not be displayed.
2028 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2029 call TermWait(buf)
2030 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002031 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2032
2033 " pressing <Tab> should display the wildmenu
2034 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002035 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2036
2037 " pressing <Tab> second time should select the next entry in the menu
2038 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002039 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2040
2041 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002042 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002043 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002044 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2045
2046 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002047 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2048
2049 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002050 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2051
2052 " Directory name completion
2053 call mkdir('Xdir/XdirA/XdirB', 'p')
2054 call writefile([], 'Xdir/XfileA')
2055 call writefile([], 'Xdir/XdirA/XfileB')
2056 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2057
2058 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002059 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2060
2061 " Pressing <Right> on a directory name should go into that directory
2062 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002063 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2064
2065 " Pressing <Left> on a directory name should go to the parent directory
2066 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002067 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2068
2069 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002070 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002071 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002072 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2073
2074 " Pressing <C-D> when the popup menu is displayed should remove the popup
2075 " menu
2076 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002077 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2078
2079 " Pressing <S-Tab> should open the popup menu with the last entry selected
2080 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002081 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2082
2083 " Pressing <Esc> should close the popup menu and cancel the cmd line
2084 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002085 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2086
2087 " Typing a character when the popup is open, should close the popup
2088 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002089 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2090
2091 " When the popup is open, entering the cmdline window should close the popup
2092 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002093 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2094 call term_sendkeys(buf, ":q\<CR>")
2095
2096 " After the last popup menu item, <C-N> should show the original string
2097 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002098 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2099
2100 " Use the popup menu for the command name
2101 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002102 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2103
2104 " Pressing the left arrow should remove the popup menu
2105 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002106 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2107
2108 " Pressing <BS> should remove the popup menu and erase the last character
2109 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002110 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2111
2112 " Pressing <C-W> should remove the popup menu and erase the previous word
2113 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002114 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2115
2116 " Pressing <C-U> should remove the popup menu and erase the entire line
2117 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002118 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2119
2120 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2121 " the cmdline from history
2122 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002123 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2124
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002125 " Check "list" still works
2126 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2127 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002128 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2129 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002130 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2131
rbtnn68cc2b82022-02-09 11:55:47 +00002132 " Tests a directory name contained full-width characters.
2133 call mkdir('Xdir/あいう', 'p')
2134 call writefile([], 'Xdir/あいう/abc')
2135 call writefile([], 'Xdir/あいう/xyz')
2136 call writefile([], 'Xdir/あいう/123')
2137
2138 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2139 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002140 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2141
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002142 " Pressing <C-A> when the popup menu is displayed should list all the
2143 " matches and pressing a key after that should remove the popup menu
2144 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2145 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2146 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2147
2148 " Pressing <C-A> when the popup menu is displayed should list all the
2149 " matches and pressing <Left> after that should move the cursor
2150 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2151 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2152 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2153
2154 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2155 " should be displayed correctly on the screen.
2156 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2157 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2158
2159 " After using <C-A> to expand all the filename matches, pressing <Up>
2160 " should not open the popup menu again.
2161 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2162 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2163 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2164 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2165
2166 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2167 " crash Vim
2168 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2169 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2170
Bram Moolenaar414acd32022-02-10 21:09:45 +00002171 " After removing the pum the command line is redrawn
2172 call term_sendkeys(buf, ":edit foo\<CR>")
2173 call term_sendkeys(buf, ":edit bar\<CR>")
2174 call term_sendkeys(buf, ":ls\<CR>")
2175 call term_sendkeys(buf, ":com\<Tab> ")
2176 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002177 call term_sendkeys(buf, "\<C-U>\<CR>")
2178
2179 " Esc still works to abort the command when 'statusline' is set
2180 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2181 call term_sendkeys(buf, ":si\<Tab>")
2182 call term_sendkeys(buf, "\<Esc>")
2183 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002184
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002185 call term_sendkeys(buf, "\<C-U>\<CR>")
2186 call StopVimInTerminal(buf)
2187 call delete('Xtest')
2188 call delete('Xdir', 'rf')
2189endfunc
2190
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002191" Test for wildmenumode() with the cmdline popup menu
2192func Test_wildmenumode_with_pum()
2193 set wildmenu
2194 set wildoptions=pum
2195 cnoremap <expr> <F2> wildmenumode()
2196 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2197 call assert_equal('"sign define10', @:)
2198 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2199 call assert_equal('"sign define jump list place undefine unplace0', @:)
2200 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2201 call assert_equal('"sign 0', @:)
2202 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2203 call assert_equal('"sign define0', @:)
2204 set nowildmenu wildoptions&
2205 cunmap <F2>
2206endfunc
2207
Bram Moolenaar309976e2019-12-05 18:16:33 +01002208" vim: shiftwidth=2 sts=2 expandtab