blob: f7f55aa60dc9428425ff3cb96c4d582e35977889 [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))
12 call delete('Xtestfile')
13endfunc
14
15func Test_complete_list()
16 " We can't see the output, but at least we check the code runs properly.
17 call feedkeys(":e test\<C-D>\r", "tx")
18 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010019
20 " If a command doesn't support completion, then CTRL-D should be literally
21 " used.
22 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
23 call assert_equal("\"chistory \<C-D>", @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024endfunc
25
26func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010027 call mkdir('Xdir1/Xdir2', 'p')
28 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
29 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
30 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
31 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020032 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010033
34 " Pressing <Tab> completes, and moves to next files when pressing again.
35 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
36 call assert_equal('testfile1', getline(1))
37 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020038 call assert_equal('testfile2', getline(1))
39
Bram Moolenaar37db6422019-03-28 21:26:23 +010040 " <S-Tab> is like <Tab> but begin with the last match and then go to
41 " previous.
42 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
43 call assert_equal('testfile2', getline(1))
44 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
45 call assert_equal('testfile1', getline(1))
46
47 " <Left>/<Right> to move to previous/next file.
48 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
49 call assert_equal('testfile1', getline(1))
50 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
51 call assert_equal('testfile2', getline(1))
52 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
53 call assert_equal('testfile1', getline(1))
54
55 " <Up>/<Down> to go up/down directories.
56 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
57 call assert_equal('testfile3', getline(1))
58 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
59 call assert_equal('testfile1', getline(1))
60
Bram Moolenaar3e112ac2020-12-28 13:41:53 +010061 " this fails in some Unix GUIs, not sure why
62 if !has('unix') || !has('gui_running')
63 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
64 " different than 'wildchar'.
65 set wildcharm=<C-Z>
66 cnoremap <C-J> <Down><C-Z>
67 cnoremap <C-K> <Up><C-Z>
68 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx')
69 call assert_equal('testfile3', getline(1))
70 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
71 call assert_equal('testfile1', getline(1))
72 set wildcharm=0
73 cunmap <C-J>
74 cunmap <C-K>
75 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +010076
Bram Moolenaar578fe942020-02-27 21:32:51 +010077 " Test for canceling the wild menu by adding a character
78 redrawstatus
79 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
80 call assert_equal('"e Xdir1/Xdir2/x', @:)
81
Bram Moolenaar8d588cc2020-02-25 21:47:45 +010082 " Completion using a relative path
83 cd Xdir1/Xdir2
84 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
85 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
86 cd -
87
Bram Moolenaar0e05de42020-03-25 22:23:46 +010088 cnoremap <expr> <F2> wildmenumode()
89 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
90 call assert_equal('"cd Xdir1/1', @:)
91 cunmap <F2>
92
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 " cleanup
94 %bwipe
95 call delete('Xdir1/Xdir2/Xtestfile4')
96 call delete('Xdir1/Xdir2/Xtestfile3')
97 call delete('Xdir1/Xtestfile2')
98 call delete('Xdir1/Xtestfile1')
99 call delete('Xdir1/Xdir2', 'd')
100 call delete('Xdir1', 'd')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200101 set nowildmenu
102endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100103
Bram Moolenaara60053b2020-09-03 16:50:13 +0200104func Test_wildmenu_screendump()
105 CheckScreendump
106
107 let lines =<< trim [SCRIPT]
108 set wildmenu hlsearch
109 [SCRIPT]
110 call writefile(lines, 'XTest_wildmenu')
111
112 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
113 call term_sendkeys(buf, ":vim\<Tab>")
114 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
115
116 call term_sendkeys(buf, "\<Tab>")
117 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
118
119 call term_sendkeys(buf, "\<Tab>")
120 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
121
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100122 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200123 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
124 call term_sendkeys(buf, "\<Esc>")
125
126 " clean up
127 call StopVimInTerminal(buf)
128 call delete('XTest_wildmenu')
129endfunc
130
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100131func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100132 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
133 call assert_equal('"map <unique> <silent>', getreg(':'))
134 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
135 call assert_equal('"map <script> <unique>', getreg(':'))
136 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
137 call assert_equal('"map <expr> <script>', getreg(':'))
138 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
139 call assert_equal('"map <buffer> <expr>', getreg(':'))
140 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
141 call assert_equal('"map <nowait> <buffer>', getreg(':'))
142 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
143 call assert_equal('"map <special> <nowait>', getreg(':'))
144 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
145 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200146
Bram Moolenaar1776a282019-05-03 16:05:41 +0200147 map <Middle>x middle
148
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200149 map ,f commaf
150 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200151 map <Left> left
152 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200153 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
154 call assert_equal('"map ,f', getreg(':'))
155 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
156 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200157 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
158 call assert_equal('"map <Left>', getreg(':'))
159 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200160 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200161 unmap ,f
162 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200163 unmap <Left>
164 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200165
166 set cpo-=< cpo-=B cpo-=k
167 map <Left> left
168 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
169 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200170 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200171 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200172 unmap <Left>
173
174 set cpo+=<
175 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200176 exe "set t_k6=\<Esc>[17~"
177 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200178 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
179 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200180 if !has('gui_running')
181 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
182 call assert_equal("\"map <F6>x", getreg(':'))
183 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200184 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200185 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200186 set cpo-=<
187
188 set cpo+=B
189 map <Left> left
190 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
191 call assert_equal('"map <Left>', getreg(':'))
192 unmap <Left>
193 set cpo-=B
194
195 set cpo+=k
196 map <Left> left
197 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
198 call assert_equal('"map <Left>', getreg(':'))
199 unmap <Left>
200 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200201
Bram Moolenaar531be472020-09-23 22:38:05 +0200202 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
203
Bram Moolenaar1776a282019-05-03 16:05:41 +0200204 unmap <Middle>x
205 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100206endfunc
207
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100208func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100209 hi Aardig ctermfg=green
210 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
211 call assert_equal('"match Aardig', getreg(':'))
212 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
213 call assert_equal('"match none', getreg(':'))
214endfunc
215
216func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100217 hi Aardig ctermfg=green
218 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
219 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200220 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
221 call assert_equal('"hi default Aardig', getreg(':'))
222 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
223 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100224 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
225 call assert_equal('"hi link', getreg(':'))
226 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
227 call assert_equal('"hi default', getreg(':'))
228 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
229 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200230 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
231 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
232 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
233 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200234
235 " A cleared group does not show up in completions.
236 hi Anders ctermfg=green
237 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
238 hi clear Aardig
239 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
240 hi clear Anders
241 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100242endfunc
243
Bram Moolenaar75e15672020-06-28 13:10:22 +0200244" Test for command-line expansion of "hi Ni " (easter egg)
245func Test_highlight_easter_egg()
246 call test_override('ui_delay', 1)
247 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
248 call assert_equal("\"hi Ni \<Tab>", @:)
249 call test_override('ALL', 0)
250endfunc
251
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200252func Test_getcompletion()
253 let groupcount = len(getcompletion('', 'event'))
254 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200255 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200256 call assert_true(matchcount > 0)
257 call assert_true(groupcount > matchcount)
258
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200259 if has('menu')
260 source $VIMRUNTIME/menu.vim
261 let matchcount = len(getcompletion('', 'menu'))
262 call assert_true(matchcount > 0)
263 call assert_equal(['File.'], getcompletion('File', 'menu'))
264 call assert_true(matchcount > 0)
265 let matchcount = len(getcompletion('File.', 'menu'))
266 call assert_true(matchcount > 0)
267 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200268
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200269 let l = getcompletion('v:n', 'var')
270 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200271 let l = getcompletion('v:notexists', 'var')
272 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200273
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200274 args a.c b.c
275 let l = getcompletion('', 'arglist')
276 call assert_equal(['a.c', 'b.c'], l)
277 %argdelete
278
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200279 let l = getcompletion('', 'augroup')
280 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200281 let l = getcompletion('blahblah', 'augroup')
282 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200283
284 let l = getcompletion('', 'behave')
285 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200286 let l = getcompletion('not', 'behave')
287 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200288
289 let l = getcompletion('', 'color')
290 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200291 let l = getcompletion('dirty', 'color')
292 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200293
294 let l = getcompletion('', 'command')
295 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200296 let l = getcompletion('awake', 'command')
297 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200298
299 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200300 call assert_true(index(l, 'samples/') >= 0)
301 let l = getcompletion('NoMatch', 'dir')
302 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200303
304 let l = getcompletion('exe', 'expression')
305 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200306 let l = getcompletion('kill', 'expression')
307 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200308
309 let l = getcompletion('tag', 'function')
310 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200311 let l = getcompletion('paint', 'function')
312 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200313
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200314 let Flambda = {-> 'hello'}
315 let l = getcompletion('', 'function')
316 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200317 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200318
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200319 let l = getcompletion('run', 'file')
320 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200321 let l = getcompletion('walk', 'file')
322 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200323 set wildignore=*.vim
324 let l = getcompletion('run', 'file', 1)
325 call assert_true(index(l, 'runtest.vim') < 0)
326 set wildignore&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200327
328 let l = getcompletion('ha', 'filetype')
329 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200330 let l = getcompletion('horse', 'filetype')
331 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200332
333 let l = getcompletion('z', 'syntax')
334 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200335 let l = getcompletion('emacs', 'syntax')
336 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200337
338 let l = getcompletion('jikes', 'compiler')
339 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200340 let l = getcompletion('break', 'compiler')
341 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200342
343 let l = getcompletion('last', 'help')
344 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200345 let l = getcompletion('giveup', 'help')
346 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200347
348 let l = getcompletion('time', 'option')
349 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200350 let l = getcompletion('space', 'option')
351 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200352
353 let l = getcompletion('er', 'highlight')
354 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200355 let l = getcompletion('dark', 'highlight')
356 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200357
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200358 let l = getcompletion('', 'messages')
359 call assert_true(index(l, 'clear') >= 0)
360 let l = getcompletion('not', 'messages')
361 call assert_equal([], l)
362
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200363 let l = getcompletion('', 'mapclear')
364 call assert_true(index(l, '<buffer>') >= 0)
365 let l = getcompletion('not', 'mapclear')
366 call assert_equal([], l)
367
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200368 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200369 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200370 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
371 let root = has('win32') ? 'C:\\' : '/'
372 let l = getcompletion(root, 'shellcmd')
373 let expected = map(filter(glob(root . '*', 0, 1),
374 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
375 call assert_equal(expected, l)
376
Bram Moolenaarb650b982016-08-05 20:35:13 +0200377 if has('cscope')
378 let l = getcompletion('', 'cscope')
379 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
380 call assert_equal(cmds, l)
381 " using cmdline completion must not change the result
382 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
383 let l = getcompletion('', 'cscope')
384 call assert_equal(cmds, l)
385 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
386 let l = getcompletion('find ', 'cscope')
387 call assert_equal(keys, l)
388 endif
389
Bram Moolenaar7522f692016-08-06 14:12:50 +0200390 if has('signs')
391 sign define Testing linehl=Comment
392 let l = getcompletion('', 'sign')
393 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
394 call assert_equal(cmds, l)
395 " using cmdline completion must not change the result
396 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
397 let l = getcompletion('', 'sign')
398 call assert_equal(cmds, l)
399 let l = getcompletion('list ', 'sign')
400 call assert_equal(['Testing'], l)
401 endif
402
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200403 " Command line completion tests
404 let l = getcompletion('cd ', 'cmdline')
405 call assert_true(index(l, 'samples/') >= 0)
406 let l = getcompletion('cd NoMatch', 'cmdline')
407 call assert_equal([], l)
408 let l = getcompletion('let v:n', 'cmdline')
409 call assert_true(index(l, 'v:null') >= 0)
410 let l = getcompletion('let v:notexists', 'cmdline')
411 call assert_equal([], l)
412 let l = getcompletion('call tag', 'cmdline')
413 call assert_true(index(l, 'taglist(') >= 0)
414 let l = getcompletion('call paint', 'cmdline')
415 call assert_equal([], l)
416
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200417 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200418 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200419 if has('cmdline_hist')
420 call add(names, 'history')
421 endif
422 if has('gettext')
423 call add(names, 'locale')
424 endif
425 if has('profile')
426 call add(names, 'syntime')
427 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200428
429 set tags=Xtags
430 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
431
432 for name in names
433 let matchcount = len(getcompletion('', name))
434 call assert_true(matchcount >= 0, 'No matches for ' . name)
435 endfor
436
437 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200438 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200439
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200440 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200441 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200442 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200443endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200444
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100445func Test_fullcommand()
446 let tests = {
447 \ '': '',
448 \ ':': '',
449 \ ':::': '',
450 \ ':::5': '',
451 \ 'not_a_cmd': '',
452 \ 'Check': '',
453 \ 'syntax': 'syntax',
454 \ ':syntax': 'syntax',
455 \ '::::syntax': 'syntax',
456 \ 'sy': 'syntax',
457 \ 'syn': 'syntax',
458 \ 'synt': 'syntax',
459 \ ':sy': 'syntax',
460 \ '::::sy': 'syntax',
461 \ 'match': 'match',
462 \ '2match': 'match',
463 \ '3match': 'match',
464 \ 'aboveleft': 'aboveleft',
465 \ 'abo': 'aboveleft',
466 \ 's': 'substitute',
467 \ '5s': 'substitute',
468 \ ':5s': 'substitute',
469 \ "'<,'>s": 'substitute',
470 \ ":'<,'>s": 'substitute',
471 \ 'CheckUni': 'CheckUnix',
472 \ 'CheckUnix': 'CheckUnix',
473 \ }
474
475 for [in, want] in items(tests)
476 call assert_equal(want, fullcommand(in))
477 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200478 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100479
480 call assert_equal('syntax', 'syn'->fullcommand())
481endfunc
482
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200483func Test_shellcmd_completion()
484 let save_path = $PATH
485
486 call mkdir('Xpathdir/Xpathsubdir', 'p')
487 call writefile([''], 'Xpathdir/Xfile.exe')
488 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
489
490 " Set PATH to example directory without trailing slash.
491 let $PATH = getcwd() . '/Xpathdir'
492
493 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
494 " dirs in the PATH, even though they won't be executed. We check that only
495 " subdirs of the PWD and executables from the PATH are included in the
496 " suggestions.
497 let actual = getcompletion('X', 'shellcmd')
498 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
499 call insert(expected, 'Xfile.exe')
500 call assert_equal(expected, actual)
501
502 call delete('Xpathdir', 'rf')
503 let $PATH = save_path
504endfunc
505
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200506func Test_expand_star_star()
507 call mkdir('a/b', 'p')
508 call writefile(['asdfasdf'], 'a/b/fileXname')
509 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
510 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200511 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200512 call delete('a', 'rf')
513endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100514
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100515func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100516 let @a = "def"
517 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
518 call assert_equal('"abc def ghi', @:)
519
520 new
521 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
522
523 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
524 call assert_equal('"aaa asdf bbb', @:)
525
526 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
527 call assert_equal('"aaa /tmp/some bbb', @:)
528
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200529 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
530 call assert_equal('"aaa '.getline(1).' bbb', @:)
531
Bram Moolenaar21efc362016-12-03 14:05:49 +0100532 set incsearch
533 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
534 call assert_equal('"aaa verylongword bbb', @:)
535
536 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
537 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100538
539 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
540 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100541 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200542
543 " Error while typing a command used to cause that it was not executed
544 " in the end.
545 new
546 try
547 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
548 catch /^Vim\%((\a\+)\)\=:E32/
549 " ignore error E32
550 endtry
551 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100552
Bram Moolenaar578fe942020-02-27 21:32:51 +0100553 " Try to paste an invalid register using <C-R>
554 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
555 call assert_equal('"onetwo', @:)
556
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100557 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100558 let @a = "xy\<C-H>z"
559 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
560 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100561 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
562 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100563 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
564 call assert_equal("\"xy\<C-H>z", @:)
565
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100566 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
567 let @a = "xy\<C-V>z"
568 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
569 call assert_equal('"xyz', @:)
570 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
571 call assert_equal("\"xy\<C-V>z", @:)
572
Bram Moolenaar578fe942020-02-27 21:32:51 +0100573 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
574
Bram Moolenaar72532d32018-04-07 19:09:09 +0200575 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100576endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100577
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100578func Test_cmdline_remove_char()
579 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100580
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100581 for e in ['utf8', 'latin1']
582 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100583
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100584 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
585 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100586
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100587 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
588 call assert_equal('"abcdef', @:)
589
590 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
591 call assert_equal('"abc ghi', @:, e)
592
593 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
594 call assert_equal('"def', @:, e)
595 endfor
596
597 let &encoding = encoding_save
598endfunc
599
600func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200601 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100602
603 set keymap=esperanto
604 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
605 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
606 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100607endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100608
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100609func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100610 new
611 2;'(
612 2;')
613 quit
614endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100615
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100616func Test_illegal_address2()
617 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
618 new
619 source Xtest.vim
620 " Trigger calling validate_cursor()
621 diffsp Xtest.vim
622 quit!
623 bwipe!
624 call delete('Xtest.vim')
625endfunc
626
Bram Moolenaarba47b512017-01-24 21:18:19 +0100627func Test_cmdline_complete_wildoptions()
628 help
629 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
630 let a = join(sort(split(@:)),' ')
631 set wildoptions=tagfile
632 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
633 let b = join(sort(split(@:)),' ')
634 call assert_equal(a, b)
635 bw!
636endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100637
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200638func Test_cmdline_complete_user_cmd()
639 command! -complete=color -nargs=1 Foo :
640 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
641 call assert_equal('"Foo blue', @:)
642 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
643 call assert_equal('"Foo blue', @:)
644 delcommand Foo
645endfunc
646
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100647func s:ScriptLocalFunction()
648 echo 'yes'
649endfunc
650
651func Test_cmdline_complete_user_func()
652 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200653 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100654 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
655 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100656
657 " g: prefix also works
658 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
659 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200660
661 " using g: prefix does not result in just "g:" matches from a lambda
662 let Fx = { a -> a }
663 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
664 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200665
666 " existence of script-local dict function does not break user function name
667 " completion
668 function s:a_dict_func() dict
669 endfunction
670 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
671 call assert_match('"call Test_cmdline_complete_user_', @:)
672 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100673endfunc
674
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200675func Test_cmdline_complete_user_names()
676 if has('unix') && executable('whoami')
677 let whoami = systemlist('whoami')[0]
678 let first_letter = whoami[0]
679 if len(first_letter) > 0
680 " Trying completion of :e ~x where x is the first letter of
681 " the user name should complete to at least the user name.
682 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
683 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
684 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200685 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200686 " Just in case: check that the system has an Administrator account.
687 let names = system('net user')
688 if names =~ 'Administrator'
689 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100690 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200691 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100692 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200693 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200694 else
695 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200696 endif
697endfunc
698
Bram Moolenaar297610b2019-12-27 17:20:55 +0100699func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200700 CheckExecutable whoami
701 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
702 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100703endfunc
704
Bram Moolenaar8b633132020-03-20 18:20:51 +0100705func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200706 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
707 call assert_equal(lang, v:lc_time)
708
709 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
710 call assert_equal(lang, v:ctype)
711
712 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
713 call assert_equal(lang, v:collate)
714
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200715 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200716 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200717
718 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200719 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200720
Bram Moolenaarec680282020-06-12 19:35:32 +0200721 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200722
Bram Moolenaarec680282020-06-12 19:35:32 +0200723 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
724 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200725
Bram Moolenaarec680282020-06-12 19:35:32 +0200726 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
727 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200728
Bram Moolenaarec680282020-06-12 19:35:32 +0200729 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
730 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200731
732 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
733 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200734endfunc
735
Bram Moolenaar297610b2019-12-27 17:20:55 +0100736func Test_cmdline_complete_env_variable()
737 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100738 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
739 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100740 unlet $X_VIM_TEST_COMPLETE_ENV
741endfunc
742
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100743func Test_cmdline_complete_expression()
744 let g:SomeVar = 'blah'
745 for cmd in ['exe', 'echo', 'echon', 'echomsg']
746 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
747 call assert_match('"' .. cmd .. ' SomeVar', @:)
748 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
749 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
750 endfor
751 unlet g:SomeVar
752endfunc
753
Bram Moolenaar47016f52021-08-26 16:39:58 +0200754" Unique function name for completion below
755func s:WeirdFunc()
756 echo 'weird'
757endfunc
758
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100759" Test for various command-line completion
760func Test_cmdline_complete_various()
761 " completion for a command starting with a comment
762 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
763 call assert_equal("\" :|\"\<C-A>", @:)
764
765 " completion for a range followed by a comment
766 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
767 call assert_equal("\"1,2\"\<C-A>", @:)
768
769 " completion for :k command
770 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
771 call assert_equal("\"ka\<C-A>", @:)
772
773 " completion for short version of the :s command
774 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
775 call assert_equal("\"sI \<C-A>", @:)
776
777 " completion for :write command
778 call mkdir('Xdir')
779 call writefile(['one'], 'Xdir/Xfile1')
780 let save_cwd = getcwd()
781 cd Xdir
782 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
783 call assert_equal("\"w >> Xfile1", @:)
784 call chdir(save_cwd)
785 call delete('Xdir', 'rf')
786
787 " completion for :w ! and :r ! commands
788 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
789 call assert_equal("\"w !invalid_xyz_cmd", @:)
790 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
791 call assert_equal("\"r !invalid_xyz_cmd", @:)
792
793 " completion for :>> and :<< commands
794 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
795 call assert_equal("\">>>\<C-A>", @:)
796 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
797 call assert_equal("\"<<<\<C-A>", @:)
798
799 " completion for command with +cmd argument
800 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
801 call assert_equal("\"buffer +/pat Xabc", @:)
802 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
803 call assert_equal("\"buffer +/pat\<C-A>", @:)
804
805 " completion for a command with a trailing comment
806 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
807 call assert_equal("\"ls \" comment\<C-A>", @:)
808
809 " completion for a command with a trailing command
810 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
811 call assert_equal("\"ls | ls", @:)
812
813 " completion for a command with an CTRL-V escaped argument
814 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
815 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
816
817 " completion for a command that doesn't take additional arguments
818 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
819 call assert_equal("\"all abc\<C-A>", @:)
820
821 " completion for a command with a command modifier
822 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
823 call assert_equal("\"topleft new", @:)
824
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200825 " completion for vim9 and legacy commands
826 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
827 call assert_equal("\"vim9 call strlen(", @:)
828 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
829 call assert_equal("\"legac call strlen(", @:)
830
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200831 " completion for the :disassemble command
832 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
833 call assert_equal("\"disas debug", @:)
834 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
835 call assert_equal("\"disas profile", @:)
836 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
837 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
838 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
839 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
840
Bram Moolenaar47016f52021-08-26 16:39:58 +0200841 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
842 call assert_match('"disas <SNR>\d\+_WeirdFunc()', @:)
843
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100844 " completion for the :match command
845 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
846 call assert_equal("\"match Search /pat/\<C-A>", @:)
847
848 " completion for the :s command
849 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
850 call assert_equal("\"s/from/to/g\<C-A>", @:)
851
852 " completion for the :dlist command
853 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
854 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
855
856 " completion for the :doautocmd command
857 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
858 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
859
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200860 " completion of autocmd group after comma
861 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
862 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
863
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200864 " completion of file name in :doautocmd
865 call writefile([], 'Xfile1')
866 call writefile([], 'Xfile2')
867 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
868 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
869 call delete('Xfile1')
870 call delete('Xfile2')
871
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100872 " completion for the :augroup command
873 augroup XTest
874 augroup END
875 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
876 call assert_equal("\"augroup XTest", @:)
877 augroup! XTest
878
879 " completion for the :unlet command
880 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
881 call assert_equal("\"unlet one two", @:)
882
883 " completion for the :bdelete command
884 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
885 call assert_equal("\"bdel a b c", @:)
886
887 " completion for the :mapclear command
888 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
889 call assert_equal("\"mapclear <buffer>", @:)
890
891 " completion for user defined commands with menu names
892 menu Test.foo :ls<CR>
893 com -nargs=* -complete=menu MyCmd
894 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
895 call assert_equal('"MyCmd Test.', @:)
896 delcom MyCmd
897 unmenu Test
898
899 " completion for user defined commands with mappings
900 mapclear
901 map <F3> :ls<CR>
902 com -nargs=* -complete=mapping MyCmd
903 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
904 call assert_equal('"MyCmd <F3>', @:)
905 mapclear
906 delcom MyCmd
907
908 " completion for :set path= with multiple backslashes
909 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
910 call assert_equal('"set path=a\\\ b', @:)
911
912 " completion for :set dir= with a backslash
913 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
914 call assert_equal('"set dir=a\ b', @:)
915
916 " completion for the :py3 commands
917 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
918 call assert_equal('"py3 py3do py3file', @:)
919
Bram Moolenaardf749a22021-03-28 15:29:43 +0200920 " completion for the :vim9 commands
921 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
922 call assert_equal('"vim9cmd vim9script', @:)
923
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100924 " redir @" is not the start of a comment. So complete after that
925 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
926 call assert_equal('"redir @" | cwindow', @:)
927
928 " completion after a backtick
929 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
930 call assert_equal('"e `a1b2c', @:)
931
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100932 " completion for :language command with an invalid argument
933 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
934 call assert_equal("\"language dummy \t", @:)
935
936 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +0100937 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
938 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100939
940 " completion with ambiguous user defined commands
941 com TCmd1 echo 'TCmd1'
942 com TCmd2 echo 'TCmd2'
943 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
944 call assert_equal('"TCmd ', @:)
945 delcom TCmd1
946 delcom TCmd2
947
948 " completion after a range followed by a pipe (|) character
949 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
950 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +0200951
952 " use <Esc> as the 'wildchar' for completion
953 set wildchar=<Esc>
954 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
955 call assert_equal('"g/a\xb/clearjumps', @:)
956 " pressing <esc> twice should cancel the command
957 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
958 call assert_equal('"g/a\xb/clearjumps', @:)
959 set wildchar&
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100960endfunc
961
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200962func Test_cmdline_write_alternatefile()
963 new
964 call setline('.', ['one', 'two'])
965 f foo.txt
966 new
967 f #-A
968 call assert_equal('foo.txt-A', expand('%'))
969 f #<-B.txt
970 call assert_equal('foo-B.txt', expand('%'))
971 f %<
972 call assert_equal('foo-B', expand('%'))
973 new
Bram Moolenaare2e40752020-09-04 21:18:46 +0200974 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200975 bw!
976 f foo-B.txt
977 f %<-A
978 call assert_equal('foo-B-A', expand('%'))
979 bw!
980 bw!
981endfunc
982
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100983" using a leading backslash here
984set cpo+=C
985
986func Test_cmdline_search_range()
987 new
988 call setline(1, ['a', 'b', 'c', 'd'])
989 /d
990 1,\/s/b/B/
991 call assert_equal('B', getline(2))
992
993 /a
994 $
995 \?,4s/c/C/
996 call assert_equal('C', getline(3))
997
998 call setline(1, ['a', 'b', 'c', 'd'])
999 %s/c/c/
1000 1,\&s/b/B/
1001 call assert_equal('B', getline(2))
1002
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001003 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001004 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001005
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001006 bwipe!
1007endfunc
1008
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001009" Test for the tick mark (') in an excmd range
1010func Test_tick_mark_in_range()
1011 " If only the tick is passed as a range and no command is specified, there
1012 " should not be an error
1013 call feedkeys(":'\<CR>", 'xt')
1014 call assert_equal("'", getreg(':'))
1015 call assert_fails("',print", 'E78:')
1016endfunc
1017
1018" Test for using a line number followed by a search pattern as range
1019func Test_lnum_and_pattern_as_range()
1020 new
1021 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1022 let @" = ''
1023 2/foo/yank
1024 call assert_equal("foo 3\n", @")
1025 call assert_equal(1, line('.'))
1026 close!
1027endfunc
1028
Bram Moolenaar65189a12017-02-06 22:22:17 +01001029" Tests for getcmdline(), getcmdpos() and getcmdtype()
1030func Check_cmdline(cmdtype)
1031 call assert_equal('MyCmd a', getcmdline())
1032 call assert_equal(8, getcmdpos())
1033 call assert_equal(a:cmdtype, getcmdtype())
1034 return ''
1035endfunc
1036
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001037set cpo&
1038
Bram Moolenaar65189a12017-02-06 22:22:17 +01001039func Test_getcmdtype()
1040 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1041
1042 let cmdtype = ''
1043 debuggreedy
1044 call feedkeys(":debug echo 'test'\<CR>", "t")
1045 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1046 call feedkeys("cont\<CR>", "xt")
1047 0debuggreedy
1048 call assert_equal('>', cmdtype)
1049
1050 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1051 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1052
1053 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001054 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001055
1056 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1057
1058 cnoremap <expr> <F6> Check_cmdline('=')
1059 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1060 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001061
1062 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001063endfunc
1064
Bram Moolenaar81612b72018-06-23 14:55:03 +02001065func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001066 CheckFeature cmdwin
1067
Bram Moolenaar81612b72018-06-23 14:55:03 +02001068 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1069 call assert_equal('/', a)
1070
1071 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1072 call assert_equal('?', a)
1073
1074 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1075 call assert_equal(':', a)
1076
1077 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1078 call assert_equal(':', a)
1079
1080 call assert_equal('', getcmdwintype())
1081endfunc
1082
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001083func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001084 CheckFeature cmdwin
1085
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001086 let s:seq = []
1087 augroup CmdWin
1088 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1089 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1090 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1091 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1092 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1093 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1094
1095 let org_winid = win_getid()
1096 let org_bufnr = bufnr()
1097 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1098 call assert_equal(':', a)
1099 call assert_equal([
1100 \ 'WinLeave ' .. org_winid,
1101 \ 'WinEnter ' .. s:cmd_winid,
1102 \ 'BufLeave ' .. org_bufnr,
1103 \ 'BufEnter ' .. s:cmd_bufnr,
1104 \ 'CmdWinEnter ' .. s:cmd_winid,
1105 \ 'CmdWinLeave ' .. s:cmd_winid,
1106 \ 'BufLeave ' .. s:cmd_bufnr,
1107 \ 'WinLeave ' .. s:cmd_winid,
1108 \ 'WinEnter ' .. org_winid,
1109 \ 'BufEnter ' .. org_bufnr,
1110 \ ], s:seq)
1111
1112 au!
1113 augroup END
1114endfunc
1115
Bram Moolenaar52604f22017-04-07 16:17:39 +02001116func Test_verbosefile()
1117 set verbosefile=Xlog
1118 echomsg 'foo'
1119 echomsg 'bar'
1120 set verbosefile=
1121 let log = readfile('Xlog')
1122 call assert_match("foo\nbar", join(log, "\n"))
1123 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001124 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001125 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001126 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001127endfunc
1128
Bram Moolenaar4facea32019-10-12 20:17:40 +02001129func Test_verbose_option()
1130 CheckScreendump
1131
1132 let lines =<< trim [SCRIPT]
1133 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1134 call feedkeys("\r", 't') " for the hit-enter prompt
1135 set verbose=20
1136 [SCRIPT]
1137 call writefile(lines, 'XTest_verbose')
1138
1139 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001140 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001141 call term_sendkeys(buf, ":DoSomething\<CR>")
1142 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1143
1144 " clean up
1145 call StopVimInTerminal(buf)
1146 call delete('XTest_verbose')
1147endfunc
1148
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001149func Test_setcmdpos()
1150 func InsertTextAtPos(text, pos)
1151 call assert_equal(0, setcmdpos(a:pos))
1152 return a:text
1153 endfunc
1154
1155 " setcmdpos() with position in the middle of the command line.
1156 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1157 call assert_equal('"1ab2', @:)
1158
1159 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1160 call assert_equal('"1b2a', @:)
1161
1162 " setcmdpos() with position beyond the end of the command line.
1163 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1164 call assert_equal('"12ab', @:)
1165
1166 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001167 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001168endfunc
1169
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001170func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001171 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001172 let encoding_save = &encoding
1173
1174 for e in encodings
1175 exe 'set encoding=' . e
1176
1177 " Test overstrike in the middle of the command line.
1178 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001179 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001180
1181 " Test overstrike going beyond end of command line.
1182 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001183 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001184
1185 " Test toggling insert/overstrike a few times.
1186 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001187 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001188 endfor
1189
Bram Moolenaar30276f22019-01-24 17:59:39 +01001190 " Test overstrike with multi-byte characters.
1191 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001192 call assert_equal('"abcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001193
1194 let &encoding = encoding_save
1195endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001196
1197func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001198 CheckFeature cmdwin
1199
Bram Moolenaara046b372019-09-15 17:26:07 +02001200 let winid = win_getid()
1201 sp
1202 try
1203 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1204 catch /^Vim\%((\a\+)\)\=:E11/
1205 endtry
1206 bw!
1207endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001208
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001209func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001210 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001211 CheckScreendump
1212
1213 let lines =<< trim [SCRIPT]
1214 call setline(1, range(30))
1215 2split
1216 [SCRIPT]
1217 call writefile(lines, 'XTest_restore')
1218
1219 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001220 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001221 call term_sendkeys(buf, "q:")
1222 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1223
1224 " normal restore
1225 call term_sendkeys(buf, ":q\<CR>")
1226 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1227
1228 " restore after setting 'lines' with one window
1229 call term_sendkeys(buf, ":close\<CR>")
1230 call term_sendkeys(buf, "q:")
1231 call term_sendkeys(buf, ":set lines=18\<CR>")
1232 call term_sendkeys(buf, ":q\<CR>")
1233 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1234
1235 " clean up
1236 call StopVimInTerminal(buf)
1237 call delete('XTest_restore')
1238endfunc
1239
Bram Moolenaare5b44862021-05-30 13:54:03 +02001240func Test_cmdwin_no_terminal()
1241 CheckFeature cmdwin
1242 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001243 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001244
1245 let buf = RunVimInTerminal('', {'rows': 12})
1246 call TermWait(buf, 50)
1247 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1248 call term_sendkeys(buf, "q:")
1249 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1250 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1251 call term_sendkeys(buf, ":q\<CR>")
1252 call StopVimInTerminal(buf)
1253endfunc
1254
Bram Moolenaar52410572019-10-27 05:12:45 +01001255func Test_buffers_lastused()
1256 " check that buffers are sorted by time when wildmode has lastused
1257 call test_settime(1550020000) " middle
1258 edit bufa
1259 enew
1260 call test_settime(1550030000) " newest
1261 edit bufb
1262 enew
1263 call test_settime(1550010000) " oldest
1264 edit bufc
1265 enew
1266 call test_settime(0)
1267 enew
1268
1269 call assert_equal(['bufa', 'bufb', 'bufc'],
1270 \ getcompletion('', 'buffer'))
1271
1272 let save_wildmode = &wildmode
1273 set wildmode=full:lastused
1274
1275 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1276 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1277 call assert_equal('b bufb', X)
1278 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1279 call assert_equal('b bufa', X)
1280 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1281 call assert_equal('b bufc', X)
1282 enew
1283
1284 edit other
1285 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1286 call assert_equal('b bufb', X)
1287 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1288 call assert_equal('b bufa', X)
1289 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1290 call assert_equal('b bufc', X)
1291 enew
1292
1293 let &wildmode = save_wildmode
1294
1295 bwipeout bufa
1296 bwipeout bufb
1297 bwipeout bufc
1298endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001299
1300func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001301 CheckFeature cmdwin
1302
Bram Moolenaar85db5472019-12-04 15:11:08 +01001303 " This should not generate E488
1304 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001305 " Using feedkeys with q: only should automatically close the cmd window
1306 call feedkeys('q:', 'xt')
1307 call assert_equal(1, winnr('$'))
1308 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001309endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001310
1311" Tests for the issues fixed in 7.4.441.
1312" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1313func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001314 CheckFeature cmdwin
1315
Bram Moolenaar309976e2019-12-05 18:16:33 +01001316 exe "set cedit=\<C-c>"
1317 normal! :
1318 call assert_equal(1, winnr('$'))
1319
1320 let g:cmd_wintype = ''
1321 func CmdWinType()
1322 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001323 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001324 return ''
1325 endfunc
1326
1327 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1328 echo input('')
1329 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001330 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001331
1332 set cedit&vim
1333 delfunc CmdWinType
1334endfunc
1335
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001336" Test for CmdwinEnter autocmd
1337func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001338 CheckFeature cmdwin
1339
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001340 augroup CmdWin
1341 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001342 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001343 autocmd CmdwinEnter * startinsert
1344 augroup END
1345
1346 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1347 call assert_equal('xyz', @:)
1348
1349 augroup CmdWin
1350 au!
1351 augroup END
1352 augroup! CmdWin
1353endfunc
1354
Bram Moolenaar479950f2020-01-19 15:45:17 +01001355func Test_cmdlineclear_tabenter()
1356 CheckScreendump
1357
1358 let lines =<< trim [SCRIPT]
1359 call setline(1, range(30))
1360 [SCRIPT]
1361
1362 call writefile(lines, 'XtestCmdlineClearTabenter')
1363 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001364 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001365 " in one tab make the command line higher with CTRL-W -
1366 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1367 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1368
1369 call StopVimInTerminal(buf)
1370 call delete('XtestCmdlineClearTabenter')
1371endfunc
1372
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001373" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001374func Test_cmdline_expand_special()
1375 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001376 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001377 call assert_fails('e <afile>', 'E495:')
1378 call assert_fails('e <abuf>', 'E496:')
1379 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001380
1381 call writefile([], 'Xfile.cpp')
1382 call writefile([], 'Xfile.java')
1383 new Xfile.cpp
1384 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1385 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1386 close
1387 call delete('Xfile.cpp')
1388 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001389endfunc
1390
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001391func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001392 CheckFeature cmdwin
1393
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001394 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1395 new
1396 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001397 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001398 close!
1399 call feedkeys("q/:close\<CR>", "xt")
1400 call assert_equal(1, winnr('$'))
1401 call feedkeys("q/:exit\<CR>", "xt")
1402 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001403
1404 " opening command window twice should fail
1405 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1406 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001407endfunc
1408
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001409func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001410 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001411 CheckScreendump
1412
1413 " aborting the :smile output caused the cmdline window to use the current
1414 " buffer.
1415 let lines =<< trim [SCRIPT]
1416 au WinNew * smile
1417 [SCRIPT]
1418 call writefile(lines, 'XTest_cmdwin')
1419
1420 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001421 " open cmdwin
1422 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001423 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001424 " quit more prompt for :smile command
1425 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001426 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001427 " execute a simple command
1428 call term_sendkeys(buf, "aecho 'done'\<CR>")
1429 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1430
1431 " clean up
1432 call StopVimInTerminal(buf)
1433 call delete('XTest_cmdwin')
1434endfunc
1435
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001436" Test for backtick expression in the command line
1437func Test_cmd_backtick()
1438 %argd
1439 argadd `=['a', 'b', 'c']`
1440 call assert_equal(['a', 'b', 'c'], argv())
1441 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001442
1443 argadd `echo abc def`
1444 call assert_equal(['abc def'], argv())
1445 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001446endfunc
1447
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001448" Test for the :! command
1449func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001450 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001451
1452 let lines =<< trim [SCRIPT]
1453 " Test for no previous command
1454 call assert_fails('!!', 'E34:')
1455 set nomore
1456 " Test for cmdline expansion with :!
1457 call setline(1, 'foo!')
1458 silent !echo <cWORD> > Xfile.out
1459 call assert_equal(['foo!'], readfile('Xfile.out'))
1460 " Test for using previous command
1461 silent !echo \! !
1462 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1463 call writefile(v:errors, 'Xresult')
1464 call delete('Xfile.out')
1465 qall!
1466 [SCRIPT]
1467 call writefile(lines, 'Xscript')
1468 if RunVim([], [], '--clean -S Xscript')
1469 call assert_equal([], readfile('Xresult'))
1470 endif
1471 call delete('Xscript')
1472 call delete('Xresult')
1473endfunc
1474
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001475" Test error: "E135: *Filter* Autocommands must not change current buffer"
1476func Test_cmd_bang_E135()
1477 new
1478 call setline(1, ['a', 'b', 'c', 'd'])
1479 augroup test_cmd_filter_E135
1480 au!
1481 autocmd FilterReadPost * help
1482 augroup END
1483 call assert_fails('2,3!echo "x"', 'E135:')
1484
1485 augroup test_cmd_filter_E135
1486 au!
1487 augroup END
1488 %bwipe!
1489endfunc
1490
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001491" Test for using ~ for home directory in cmdline completion matches
1492func Test_cmdline_expand_home()
1493 call mkdir('Xdir')
1494 call writefile([], 'Xdir/Xfile1')
1495 call writefile([], 'Xdir/Xfile2')
1496 cd Xdir
1497 let save_HOME = $HOME
1498 let $HOME = getcwd()
1499 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1500 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1501 let $HOME = save_HOME
1502 cd ..
1503 call delete('Xdir', 'rf')
1504endfunc
1505
Bram Moolenaar578fe942020-02-27 21:32:51 +01001506" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1507" or insert mode (when 'insertmode' is set)
1508func Test_cmdline_ctrl_g()
1509 new
1510 call setline(1, 'abc')
1511 call cursor(1, 3)
1512 " If command line is entered from insert mode, using C-\ C-G should back to
1513 " insert mode
1514 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1515 call assert_equal('abxyc', getline(1))
1516 call assert_equal(4, col('.'))
1517
1518 " If command line is entered in 'insertmode', using C-\ C-G should back to
1519 " 'insertmode'
1520 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1521 call assert_equal('ab12xyc', getline(1))
1522 close!
1523endfunc
1524
Bram Moolenaar578fe942020-02-27 21:32:51 +01001525" Test for 'wildmode'
1526func Test_wildmode()
1527 func T(a, c, p)
1528 return "oneA\noneB\noneC"
1529 endfunc
1530 command -nargs=1 -complete=custom,T MyCmd
1531
1532 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001533 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001534 return ''
1535 endfunc
1536 cnoremap <expr> <F2> SaveScreenLine()
1537
1538 set nowildmenu
1539 set wildmode=full,list
1540 let g:Sline = ''
1541 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001542 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001543 call assert_equal('"MyCmd oneA', @:)
1544
1545 set wildmode=longest,full
1546 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1547 call assert_equal('"MyCmd one', @:)
1548 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1549 call assert_equal('"MyCmd oneC', @:)
1550
1551 set wildmode=longest
1552 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1553 call assert_equal('"MyCmd one', @:)
1554
1555 set wildmode=list:longest
1556 let g:Sline = ''
1557 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001558 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001559 call assert_equal('"MyCmd one', @:)
1560
1561 set wildmode=""
1562 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1563 call assert_equal('"MyCmd oneA', @:)
1564
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001565 " Test for wildmode=longest with 'fileignorecase' set
1566 set wildmode=longest
1567 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001568 argadd AAA AAAA AAAAA
1569 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1570 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001571 set fileignorecase&
1572
1573 " Test for listing files with wildmode=list
1574 set wildmode=list
1575 let g:Sline = ''
1576 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001577 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001578 call assert_equal('"b A', @:)
1579
1580 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001581 delcommand MyCmd
1582 delfunc T
1583 delfunc SaveScreenLine
1584 cunmap <F2>
1585 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001586 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001587endfunc
1588
1589" Test for interrupting the command-line completion
1590func Test_interrupt_compl()
1591 func F(lead, cmdl, p)
1592 if a:lead =~ 'tw'
1593 call interrupt()
1594 return
1595 endif
1596 return "one\ntwo\nthree"
1597 endfunc
1598 command -nargs=1 -complete=custom,F Tcmd
1599
1600 set nowildmenu
1601 set wildmode=full
1602 let interrupted = 0
1603 try
1604 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1605 catch /^Vim:Interrupt$/
1606 let interrupted = 1
1607 endtry
1608 call assert_equal(1, interrupted)
1609
1610 delcommand Tcmd
1611 delfunc F
1612 set wildmode&
1613endfunc
1614
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001615" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001616func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001617 let str = ":one two\<C-U>"
1618 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001619 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001620 let str ..= "\<Left>five\<Right>"
1621 let str ..= "\<Home>two "
1622 let str ..= "\<C-Left>one "
1623 let str ..= "\<C-Right> three"
1624 let str ..= "\<End>\<S-Left>four "
1625 let str ..= "\<S-Right> six"
1626 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1627 call feedkeys(str, 'xt')
1628 call assert_equal("\"one two three four five six seven", @:)
1629endfunc
1630
1631" Test for moving the cursor on the / command line in 'rightleft' mode
1632func Test_cmdline_edit_rightleft()
1633 CheckFeature rightleft
1634 set rightleft
1635 set rightleftcmd=search
1636 let str = "/one two\<C-U>"
1637 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001638 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001639 let str ..= "\<Right>five\<Left>"
1640 let str ..= "\<Home>two "
1641 let str ..= "\<C-Right>one "
1642 let str ..= "\<C-Left> three"
1643 let str ..= "\<End>\<S-Right>four "
1644 let str ..= "\<S-Left> six"
1645 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1646 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1647 call assert_equal("\"one two three four five six seven", @/)
1648 set rightleftcmd&
1649 set rightleft&
1650endfunc
1651
1652" Test for using <C-\>e in the command line to evaluate an expression
1653func Test_cmdline_expr()
1654 " Evaluate an expression from the beginning of a command line
1655 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1656 call assert_equal('"hello', @:)
1657
1658 " Use an invalid expression for <C-\>e
1659 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1660
1661 " Insert literal <CTRL-\> in the command line
1662 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1663 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001664endfunc
1665
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001666" Test for 'imcmdline' and 'imsearch'
1667" This test doesn't actually test the input method functionality.
1668func Test_cmdline_inputmethod()
1669 new
1670 call setline(1, ['', 'abc', ''])
1671 set imcmdline
1672
1673 call feedkeys(":\"abc\<CR>", 'xt')
1674 call assert_equal("\"abc", @:)
1675 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1676 call assert_equal("\"abc", @:)
1677 call feedkeys("/abc\<CR>", 'xt')
1678 call assert_equal([2, 1], [line('.'), col('.')])
1679 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1680 call assert_equal([2, 1], [line('.'), col('.')])
1681
1682 set imsearch=2
1683 call cursor(1, 1)
1684 call feedkeys("/abc\<CR>", 'xt')
1685 call assert_equal([2, 1], [line('.'), col('.')])
1686 call cursor(1, 1)
1687 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1688 call assert_equal([2, 1], [line('.'), col('.')])
1689 set imdisable
1690 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1691 call assert_equal([2, 1], [line('.'), col('.')])
1692 set imdisable&
1693 set imsearch&
1694
1695 set imcmdline&
1696 %bwipe!
1697endfunc
1698
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001699" Test for recursively getting multiple command line inputs
1700func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001701 CheckFeature cmdwin
1702
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001703 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1704 call assert_equal('"cyan', @:)
1705endfunc
1706
1707" Test for using CTRL-_ in the command line with 'allowrevins'
1708func Test_cmdline_revins()
1709 CheckNotMSWindows
1710 CheckFeature rightleft
1711 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1712 call assert_equal("\"abc\<c-_>", @:)
1713 set allowrevins
1714 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1715 call assert_equal('"abcñèæ', @:)
1716 set allowrevins&
1717endfunc
1718
1719" Test for typing UTF-8 composing characters in the command line
1720func Test_cmdline_composing_chars()
1721 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1722 call assert_equal('"ゔ', @:)
1723endfunc
1724
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001725" Test for normal mode commands not supported in the cmd window
1726func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001727 CheckFeature cmdwin
1728
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001729 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1730 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1731 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1732 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1733 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1734 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001735 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1736 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1737 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1738 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1739 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1740 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1741 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1742 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1743 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1744 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1745 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1746 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1747 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1748 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1749 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1750 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1751 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1752 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1753 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1754 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1755 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001756endfunc
1757
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001758" Close the Cmd-line window in insert mode using CTRL-C
1759func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001760 CheckFeature cmdwin
1761
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001762 %bw!
1763 let s = ''
1764 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1765 call assert_equal('Hello', s)
1766 call assert_equal(1, winnr('$'))
1767endfunc
1768
Bram Moolenaar0e717042020-04-27 19:29:01 +02001769" test that ";" works to find a match at the start of the first line
1770func Test_zero_line_search()
1771 new
1772 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1773 call cursor(1,1)
1774 0;/pattern/d
1775 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1776 q!
1777endfunc
1778
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001779func Test_read_shellcmd()
1780 CheckUnix
1781 if executable('ls')
1782 " There should be ls in the $PATH
1783 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1784 call assert_match('^"r! .*\<ls\>', @:)
1785 endif
1786
1787 if executable('rm')
1788 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1789 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1790 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001791
1792 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1793 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1794 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001795 endif
1796endfunc
1797
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001798" Test for going up and down the directory tree using 'wildmenu'
1799func Test_wildmenu_dirstack()
1800 CheckUnix
1801 %bw!
1802 call mkdir('Xdir1/dir2/dir3', 'p')
1803 call writefile([], 'Xdir1/file1_1.txt')
1804 call writefile([], 'Xdir1/file1_2.txt')
1805 call writefile([], 'Xdir1/dir2/file2_1.txt')
1806 call writefile([], 'Xdir1/dir2/file2_2.txt')
1807 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
1808 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
1809 cd Xdir1/dir2/dir3
1810 set wildmenu
1811
1812 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
1813 call assert_equal('"e file3_1.txt', @:)
1814 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
1815 call assert_equal('"e ../dir3/', @:)
1816 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1817 call assert_equal('"e ../../dir2/', @:)
1818 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
1819 call assert_equal('"e ../../dir2/dir3/', @:)
1820 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1821 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:)
1822
1823 cd -
1824 call delete('Xdir1', 'rf')
1825 set wildmenu&
1826endfunc
1827
obcat71c6f7a2021-05-13 20:23:10 +02001828" Test for recalling newer or older cmdline from history with <Up>, <Down>,
1829" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
1830func Test_recalling_cmdline()
1831 CheckFeature cmdline_hist
1832
1833 let g:cmdlines = []
1834 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1835
1836 let histories = [
1837 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
1838 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
1839 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
1840 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
1841 "\ TODO: {'name': 'debug', ...}
1842 \]
1843 let keypairs = [
1844 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
1845 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
1846 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
1847 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
1848 \]
1849 let prefix = 'vi'
1850 for h in histories
1851 call histadd(h.name, 'vim')
1852 call histadd(h.name, 'virtue')
1853 call histadd(h.name, 'Virgo')
1854 call histadd(h.name, 'vogue')
1855 call histadd(h.name, 'emacs')
1856 for k in keypairs
1857 let g:cmdlines = []
1858 let keyseqs = h.enter
1859 \ .. prefix
1860 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
1861 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
1862 \ .. h.exit
1863 call feedkeys(keyseqs, 'xt')
1864 call histdel(h.name, -1) " delete the history added by feedkeys above
1865 let expect = k.prefixmatch
1866 \ ? ['virtue', 'vim', 'virtue', prefix]
1867 \ : ['emacs', 'vogue', 'emacs', prefix]
1868 call assert_equal(expect, g:cmdlines)
1869 endfor
1870 endfor
1871
1872 unlet g:cmdlines
1873 cunmap <Plug>(save-cmdline)
1874endfunc
1875
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001876func Test_cmd_map_cmdlineChanged()
1877 let g:log = []
1878 cnoremap <F1> l<Cmd><CR>s
1879 augroup test
1880 autocmd!
1881 autocmd CmdlineChanged : let g:log += [getcmdline()]
1882 augroup END
1883
1884 call feedkeys(":\<F1>\<CR>", 'xt')
1885 call assert_equal(['l', 'ls'], g:log)
1886
Bram Moolenaar796139a2021-05-18 21:38:45 +02001887 let @b = 'b'
1888 cnoremap <F1> a<C-R>b
1889 let g:log = []
1890 call feedkeys(":\<F1>\<CR>", 'xt')
1891 call assert_equal(['a', 'ab'], g:log)
1892
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001893 unlet g:log
1894 cunmap <F1>
1895 augroup test
1896 autocmd!
1897 augroup END
1898endfunc
1899
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001900" Test for the 'suffixes' option
1901func Test_suffixes_opt()
1902 call writefile([], 'Xfile')
1903 call writefile([], 'Xfile.c')
1904 call writefile([], 'Xfile.o')
1905 set suffixes=
1906 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1907 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
1908 set suffixes=.c
1909 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1910 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
1911 set suffixes=,,
1912 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
1913 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
1914 set suffixes&
1915 call delete('Xfile')
1916 call delete('Xfile.c')
1917 call delete('Xfile.o')
1918endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001919
Bram Moolenaar309976e2019-12-05 18:16:33 +01001920" vim: shiftwidth=2 sts=2 expandtab