blob: 8faa25fe8af70316c4f427bb89416fdd8adfcfbc [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
122 call term_sendkeys(buf, "\<Tab>")
123 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
478
479 call assert_equal('syntax', 'syn'->fullcommand())
480endfunc
481
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200482func Test_shellcmd_completion()
483 let save_path = $PATH
484
485 call mkdir('Xpathdir/Xpathsubdir', 'p')
486 call writefile([''], 'Xpathdir/Xfile.exe')
487 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
488
489 " Set PATH to example directory without trailing slash.
490 let $PATH = getcwd() . '/Xpathdir'
491
492 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
493 " dirs in the PATH, even though they won't be executed. We check that only
494 " subdirs of the PWD and executables from the PATH are included in the
495 " suggestions.
496 let actual = getcompletion('X', 'shellcmd')
497 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
498 call insert(expected, 'Xfile.exe')
499 call assert_equal(expected, actual)
500
501 call delete('Xpathdir', 'rf')
502 let $PATH = save_path
503endfunc
504
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200505func Test_expand_star_star()
506 call mkdir('a/b', 'p')
507 call writefile(['asdfasdf'], 'a/b/fileXname')
508 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
509 call assert_equal('find a/b/fileXname', getreg(':'))
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200510 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200511 call delete('a', 'rf')
512endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100513
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100514func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100515 let @a = "def"
516 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
517 call assert_equal('"abc def ghi', @:)
518
519 new
520 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
521
522 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
523 call assert_equal('"aaa asdf bbb', @:)
524
525 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
526 call assert_equal('"aaa /tmp/some bbb', @:)
527
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200528 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
529 call assert_equal('"aaa '.getline(1).' bbb', @:)
530
Bram Moolenaar21efc362016-12-03 14:05:49 +0100531 set incsearch
532 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
533 call assert_equal('"aaa verylongword bbb', @:)
534
535 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
536 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100537
538 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
539 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100540 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200541
542 " Error while typing a command used to cause that it was not executed
543 " in the end.
544 new
545 try
546 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
547 catch /^Vim\%((\a\+)\)\=:E32/
548 " ignore error E32
549 endtry
550 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100551
Bram Moolenaar578fe942020-02-27 21:32:51 +0100552 " Try to paste an invalid register using <C-R>
553 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
554 call assert_equal('"onetwo', @:)
555
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100556 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100557 let @a = "xy\<C-H>z"
558 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
559 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100560 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
561 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100562 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
563 call assert_equal("\"xy\<C-H>z", @:)
564
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100565 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
566 let @a = "xy\<C-V>z"
567 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
568 call assert_equal('"xyz', @:)
569 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
570 call assert_equal("\"xy\<C-V>z", @:)
571
Bram Moolenaar578fe942020-02-27 21:32:51 +0100572 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
573
Bram Moolenaar72532d32018-04-07 19:09:09 +0200574 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100575endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100576
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100577func Test_cmdline_remove_char()
578 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100579
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100580 for e in ['utf8', 'latin1']
581 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100582
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100583 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
584 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100585
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100586 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
587 call assert_equal('"abcdef', @:)
588
589 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
590 call assert_equal('"abc ghi', @:, e)
591
592 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
593 call assert_equal('"def', @:, e)
594 endfor
595
596 let &encoding = encoding_save
597endfunc
598
599func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200600 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100601
602 set keymap=esperanto
603 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
604 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
605 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100606endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100607
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100608func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100609 new
610 2;'(
611 2;')
612 quit
613endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100614
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100615func Test_illegal_address2()
616 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
617 new
618 source Xtest.vim
619 " Trigger calling validate_cursor()
620 diffsp Xtest.vim
621 quit!
622 bwipe!
623 call delete('Xtest.vim')
624endfunc
625
Bram Moolenaarba47b512017-01-24 21:18:19 +0100626func Test_cmdline_complete_wildoptions()
627 help
628 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
629 let a = join(sort(split(@:)),' ')
630 set wildoptions=tagfile
631 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
632 let b = join(sort(split(@:)),' ')
633 call assert_equal(a, b)
634 bw!
635endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100636
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200637func Test_cmdline_complete_user_cmd()
638 command! -complete=color -nargs=1 Foo :
639 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
640 call assert_equal('"Foo blue', @:)
641 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
642 call assert_equal('"Foo blue', @:)
643 delcommand Foo
644endfunc
645
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100646func s:ScriptLocalFunction()
647 echo 'yes'
648endfunc
649
650func Test_cmdline_complete_user_func()
651 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
652 call assert_match('"func Test_cmdline_complete_user', @:)
653 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
654 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100655
656 " g: prefix also works
657 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
658 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100659endfunc
660
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200661func Test_cmdline_complete_user_names()
662 if has('unix') && executable('whoami')
663 let whoami = systemlist('whoami')[0]
664 let first_letter = whoami[0]
665 if len(first_letter) > 0
666 " Trying completion of :e ~x where x is the first letter of
667 " the user name should complete to at least the user name.
668 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
669 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
670 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200671 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200672 " Just in case: check that the system has an Administrator account.
673 let names = system('net user')
674 if names =~ 'Administrator'
675 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100676 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200677 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100678 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200679 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200680 else
681 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200682 endif
683endfunc
684
Bram Moolenaar297610b2019-12-27 17:20:55 +0100685func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200686 CheckExecutable whoami
687 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
688 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100689endfunc
690
Bram Moolenaar8b633132020-03-20 18:20:51 +0100691func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200692 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
693 call assert_equal(lang, v:lc_time)
694
695 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
696 call assert_equal(lang, v:ctype)
697
698 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
699 call assert_equal(lang, v:collate)
700
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200701 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200702 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200703
704 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200705 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200706
Bram Moolenaarec680282020-06-12 19:35:32 +0200707 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200708
Bram Moolenaarec680282020-06-12 19:35:32 +0200709 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
710 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200711
Bram Moolenaarec680282020-06-12 19:35:32 +0200712 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
713 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200714
Bram Moolenaarec680282020-06-12 19:35:32 +0200715 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
716 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200717
718 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
719 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200720endfunc
721
Bram Moolenaar297610b2019-12-27 17:20:55 +0100722func Test_cmdline_complete_env_variable()
723 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100724 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
725 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100726 unlet $X_VIM_TEST_COMPLETE_ENV
727endfunc
728
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100729func Test_cmdline_complete_expression()
730 let g:SomeVar = 'blah'
731 for cmd in ['exe', 'echo', 'echon', 'echomsg']
732 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
733 call assert_match('"' .. cmd .. ' SomeVar', @:)
734 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
735 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
736 endfor
737 unlet g:SomeVar
738endfunc
739
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100740" Test for various command-line completion
741func Test_cmdline_complete_various()
742 " completion for a command starting with a comment
743 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
744 call assert_equal("\" :|\"\<C-A>", @:)
745
746 " completion for a range followed by a comment
747 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
748 call assert_equal("\"1,2\"\<C-A>", @:)
749
750 " completion for :k command
751 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
752 call assert_equal("\"ka\<C-A>", @:)
753
754 " completion for short version of the :s command
755 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
756 call assert_equal("\"sI \<C-A>", @:)
757
758 " completion for :write command
759 call mkdir('Xdir')
760 call writefile(['one'], 'Xdir/Xfile1')
761 let save_cwd = getcwd()
762 cd Xdir
763 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
764 call assert_equal("\"w >> Xfile1", @:)
765 call chdir(save_cwd)
766 call delete('Xdir', 'rf')
767
768 " completion for :w ! and :r ! commands
769 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
770 call assert_equal("\"w !invalid_xyz_cmd", @:)
771 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
772 call assert_equal("\"r !invalid_xyz_cmd", @:)
773
774 " completion for :>> and :<< commands
775 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
776 call assert_equal("\">>>\<C-A>", @:)
777 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
778 call assert_equal("\"<<<\<C-A>", @:)
779
780 " completion for command with +cmd argument
781 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
782 call assert_equal("\"buffer +/pat Xabc", @:)
783 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
784 call assert_equal("\"buffer +/pat\<C-A>", @:)
785
786 " completion for a command with a trailing comment
787 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
788 call assert_equal("\"ls \" comment\<C-A>", @:)
789
790 " completion for a command with a trailing command
791 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
792 call assert_equal("\"ls | ls", @:)
793
794 " completion for a command with an CTRL-V escaped argument
795 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
796 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
797
798 " completion for a command that doesn't take additional arguments
799 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
800 call assert_equal("\"all abc\<C-A>", @:)
801
802 " completion for a command with a command modifier
803 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
804 call assert_equal("\"topleft new", @:)
805
806 " completion for the :match command
807 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
808 call assert_equal("\"match Search /pat/\<C-A>", @:)
809
810 " completion for the :s command
811 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt')
812 call assert_equal("\"s/from/to/g\<C-A>", @:)
813
814 " completion for the :dlist command
815 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
816 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
817
818 " completion for the :doautocmd command
819 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
820 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
821
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200822 " completion of autocmd group after comma
823 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
824 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
825
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100826 " completion for the :augroup command
827 augroup XTest
828 augroup END
829 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
830 call assert_equal("\"augroup XTest", @:)
831 augroup! XTest
832
833 " completion for the :unlet command
834 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
835 call assert_equal("\"unlet one two", @:)
836
837 " completion for the :bdelete command
838 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
839 call assert_equal("\"bdel a b c", @:)
840
841 " completion for the :mapclear command
842 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
843 call assert_equal("\"mapclear <buffer>", @:)
844
845 " completion for user defined commands with menu names
846 menu Test.foo :ls<CR>
847 com -nargs=* -complete=menu MyCmd
848 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
849 call assert_equal('"MyCmd Test.', @:)
850 delcom MyCmd
851 unmenu Test
852
853 " completion for user defined commands with mappings
854 mapclear
855 map <F3> :ls<CR>
856 com -nargs=* -complete=mapping MyCmd
857 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
858 call assert_equal('"MyCmd <F3>', @:)
859 mapclear
860 delcom MyCmd
861
862 " completion for :set path= with multiple backslashes
863 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
864 call assert_equal('"set path=a\\\ b', @:)
865
866 " completion for :set dir= with a backslash
867 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
868 call assert_equal('"set dir=a\ b', @:)
869
870 " completion for the :py3 commands
871 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
872 call assert_equal('"py3 py3do py3file', @:)
873
874 " redir @" is not the start of a comment. So complete after that
875 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
876 call assert_equal('"redir @" | cwindow', @:)
877
878 " completion after a backtick
879 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
880 call assert_equal('"e `a1b2c', @:)
881
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100882 " completion for :language command with an invalid argument
883 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
884 call assert_equal("\"language dummy \t", @:)
885
886 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +0100887 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
888 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100889
890 " completion with ambiguous user defined commands
891 com TCmd1 echo 'TCmd1'
892 com TCmd2 echo 'TCmd2'
893 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
894 call assert_equal('"TCmd ', @:)
895 delcom TCmd1
896 delcom TCmd2
897
898 " completion after a range followed by a pipe (|) character
899 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
900 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +0200901
902 " use <Esc> as the 'wildchar' for completion
903 set wildchar=<Esc>
904 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
905 call assert_equal('"g/a\xb/clearjumps', @:)
906 " pressing <esc> twice should cancel the command
907 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
908 call assert_equal('"g/a\xb/clearjumps', @:)
909 set wildchar&
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100910endfunc
911
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200912func Test_cmdline_write_alternatefile()
913 new
914 call setline('.', ['one', 'two'])
915 f foo.txt
916 new
917 f #-A
918 call assert_equal('foo.txt-A', expand('%'))
919 f #<-B.txt
920 call assert_equal('foo-B.txt', expand('%'))
921 f %<
922 call assert_equal('foo-B', expand('%'))
923 new
Bram Moolenaare2e40752020-09-04 21:18:46 +0200924 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +0200925 bw!
926 f foo-B.txt
927 f %<-A
928 call assert_equal('foo-B-A', expand('%'))
929 bw!
930 bw!
931endfunc
932
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100933" using a leading backslash here
934set cpo+=C
935
936func Test_cmdline_search_range()
937 new
938 call setline(1, ['a', 'b', 'c', 'd'])
939 /d
940 1,\/s/b/B/
941 call assert_equal('B', getline(2))
942
943 /a
944 $
945 \?,4s/c/C/
946 call assert_equal('C', getline(3))
947
948 call setline(1, ['a', 'b', 'c', 'd'])
949 %s/c/c/
950 1,\&s/b/B/
951 call assert_equal('B', getline(2))
952
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100953 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200954 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100955
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100956 bwipe!
957endfunc
958
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100959" Test for the tick mark (') in an excmd range
960func Test_tick_mark_in_range()
961 " If only the tick is passed as a range and no command is specified, there
962 " should not be an error
963 call feedkeys(":'\<CR>", 'xt')
964 call assert_equal("'", getreg(':'))
965 call assert_fails("',print", 'E78:')
966endfunc
967
968" Test for using a line number followed by a search pattern as range
969func Test_lnum_and_pattern_as_range()
970 new
971 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
972 let @" = ''
973 2/foo/yank
974 call assert_equal("foo 3\n", @")
975 call assert_equal(1, line('.'))
976 close!
977endfunc
978
Bram Moolenaar65189a12017-02-06 22:22:17 +0100979" Tests for getcmdline(), getcmdpos() and getcmdtype()
980func Check_cmdline(cmdtype)
981 call assert_equal('MyCmd a', getcmdline())
982 call assert_equal(8, getcmdpos())
983 call assert_equal(a:cmdtype, getcmdtype())
984 return ''
985endfunc
986
Bram Moolenaar96e38a82019-09-09 18:35:33 +0200987set cpo&
988
Bram Moolenaar65189a12017-02-06 22:22:17 +0100989func Test_getcmdtype()
990 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
991
992 let cmdtype = ''
993 debuggreedy
994 call feedkeys(":debug echo 'test'\<CR>", "t")
995 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
996 call feedkeys("cont\<CR>", "xt")
997 0debuggreedy
998 call assert_equal('>', cmdtype)
999
1000 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1001 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1002
1003 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001004 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001005
1006 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1007
1008 cnoremap <expr> <F6> Check_cmdline('=')
1009 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1010 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001011
1012 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001013endfunc
1014
Bram Moolenaar81612b72018-06-23 14:55:03 +02001015func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001016 CheckFeature cmdwin
1017
Bram Moolenaar81612b72018-06-23 14:55:03 +02001018 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1019 call assert_equal('/', a)
1020
1021 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1022 call assert_equal('?', a)
1023
1024 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1025 call assert_equal(':', a)
1026
1027 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1028 call assert_equal(':', a)
1029
1030 call assert_equal('', getcmdwintype())
1031endfunc
1032
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001033func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001034 CheckFeature cmdwin
1035
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001036 let s:seq = []
1037 augroup CmdWin
1038 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1039 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1040 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1041 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1042 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1043 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1044
1045 let org_winid = win_getid()
1046 let org_bufnr = bufnr()
1047 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1048 call assert_equal(':', a)
1049 call assert_equal([
1050 \ 'WinLeave ' .. org_winid,
1051 \ 'WinEnter ' .. s:cmd_winid,
1052 \ 'BufLeave ' .. org_bufnr,
1053 \ 'BufEnter ' .. s:cmd_bufnr,
1054 \ 'CmdWinEnter ' .. s:cmd_winid,
1055 \ 'CmdWinLeave ' .. s:cmd_winid,
1056 \ 'BufLeave ' .. s:cmd_bufnr,
1057 \ 'WinLeave ' .. s:cmd_winid,
1058 \ 'WinEnter ' .. org_winid,
1059 \ 'BufEnter ' .. org_bufnr,
1060 \ ], s:seq)
1061
1062 au!
1063 augroup END
1064endfunc
1065
Bram Moolenaar52604f22017-04-07 16:17:39 +02001066func Test_verbosefile()
1067 set verbosefile=Xlog
1068 echomsg 'foo'
1069 echomsg 'bar'
1070 set verbosefile=
1071 let log = readfile('Xlog')
1072 call assert_match("foo\nbar", join(log, "\n"))
1073 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001074 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001075 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001076 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001077endfunc
1078
Bram Moolenaar4facea32019-10-12 20:17:40 +02001079func Test_verbose_option()
1080 CheckScreendump
1081
1082 let lines =<< trim [SCRIPT]
1083 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1084 call feedkeys("\r", 't') " for the hit-enter prompt
1085 set verbose=20
1086 [SCRIPT]
1087 call writefile(lines, 'XTest_verbose')
1088
1089 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001090 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001091 call term_sendkeys(buf, ":DoSomething\<CR>")
1092 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1093
1094 " clean up
1095 call StopVimInTerminal(buf)
1096 call delete('XTest_verbose')
1097endfunc
1098
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001099func Test_setcmdpos()
1100 func InsertTextAtPos(text, pos)
1101 call assert_equal(0, setcmdpos(a:pos))
1102 return a:text
1103 endfunc
1104
1105 " setcmdpos() with position in the middle of the command line.
1106 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1107 call assert_equal('"1ab2', @:)
1108
1109 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1110 call assert_equal('"1b2a', @:)
1111
1112 " setcmdpos() with position beyond the end of the command line.
1113 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1114 call assert_equal('"12ab', @:)
1115
1116 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001117 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001118endfunc
1119
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001120func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001121 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001122 let encoding_save = &encoding
1123
1124 for e in encodings
1125 exe 'set encoding=' . e
1126
1127 " Test overstrike in the middle of the command line.
1128 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001129 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001130
1131 " Test overstrike going beyond end of command line.
1132 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001133 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001134
1135 " Test toggling insert/overstrike a few times.
1136 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001137 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001138 endfor
1139
Bram Moolenaar30276f22019-01-24 17:59:39 +01001140 " Test overstrike with multi-byte characters.
1141 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001142 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001143
1144 let &encoding = encoding_save
1145endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001146
1147func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001148 CheckFeature cmdwin
1149
Bram Moolenaara046b372019-09-15 17:26:07 +02001150 let winid = win_getid()
1151 sp
1152 try
1153 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1154 catch /^Vim\%((\a\+)\)\=:E11/
1155 endtry
1156 bw!
1157endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001158
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001159func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001160 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001161 CheckScreendump
1162
1163 let lines =<< trim [SCRIPT]
1164 call setline(1, range(30))
1165 2split
1166 [SCRIPT]
1167 call writefile(lines, 'XTest_restore')
1168
1169 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001170 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001171 call term_sendkeys(buf, "q:")
1172 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1173
1174 " normal restore
1175 call term_sendkeys(buf, ":q\<CR>")
1176 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1177
1178 " restore after setting 'lines' with one window
1179 call term_sendkeys(buf, ":close\<CR>")
1180 call term_sendkeys(buf, "q:")
1181 call term_sendkeys(buf, ":set lines=18\<CR>")
1182 call term_sendkeys(buf, ":q\<CR>")
1183 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1184
1185 " clean up
1186 call StopVimInTerminal(buf)
1187 call delete('XTest_restore')
1188endfunc
1189
Bram Moolenaar52410572019-10-27 05:12:45 +01001190func Test_buffers_lastused()
1191 " check that buffers are sorted by time when wildmode has lastused
1192 call test_settime(1550020000) " middle
1193 edit bufa
1194 enew
1195 call test_settime(1550030000) " newest
1196 edit bufb
1197 enew
1198 call test_settime(1550010000) " oldest
1199 edit bufc
1200 enew
1201 call test_settime(0)
1202 enew
1203
1204 call assert_equal(['bufa', 'bufb', 'bufc'],
1205 \ getcompletion('', 'buffer'))
1206
1207 let save_wildmode = &wildmode
1208 set wildmode=full:lastused
1209
1210 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1211 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1212 call assert_equal('b bufb', X)
1213 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1214 call assert_equal('b bufa', X)
1215 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1216 call assert_equal('b bufc', X)
1217 enew
1218
1219 edit other
1220 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1221 call assert_equal('b bufb', X)
1222 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1223 call assert_equal('b bufa', X)
1224 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1225 call assert_equal('b bufc', X)
1226 enew
1227
1228 let &wildmode = save_wildmode
1229
1230 bwipeout bufa
1231 bwipeout bufb
1232 bwipeout bufc
1233endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001234
1235func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001236 CheckFeature cmdwin
1237
Bram Moolenaar85db5472019-12-04 15:11:08 +01001238 " This should not generate E488
1239 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001240 " Using feedkeys with q: only should automatically close the cmd window
1241 call feedkeys('q:', 'xt')
1242 call assert_equal(1, winnr('$'))
1243 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001244endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001245
1246" Tests for the issues fixed in 7.4.441.
1247" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1248func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001249 CheckFeature cmdwin
1250
Bram Moolenaar309976e2019-12-05 18:16:33 +01001251 exe "set cedit=\<C-c>"
1252 normal! :
1253 call assert_equal(1, winnr('$'))
1254
1255 let g:cmd_wintype = ''
1256 func CmdWinType()
1257 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001258 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001259 return ''
1260 endfunc
1261
1262 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1263 echo input('')
1264 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001265 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001266
1267 set cedit&vim
1268 delfunc CmdWinType
1269endfunc
1270
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001271" Test for CmdwinEnter autocmd
1272func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001273 CheckFeature cmdwin
1274
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001275 augroup CmdWin
1276 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001277 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001278 autocmd CmdwinEnter * startinsert
1279 augroup END
1280
1281 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1282 call assert_equal('xyz', @:)
1283
1284 augroup CmdWin
1285 au!
1286 augroup END
1287 augroup! CmdWin
1288endfunc
1289
Bram Moolenaar479950f2020-01-19 15:45:17 +01001290func Test_cmdlineclear_tabenter()
1291 CheckScreendump
1292
1293 let lines =<< trim [SCRIPT]
1294 call setline(1, range(30))
1295 [SCRIPT]
1296
1297 call writefile(lines, 'XtestCmdlineClearTabenter')
1298 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001299 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001300 " in one tab make the command line higher with CTRL-W -
1301 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1302 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1303
1304 call StopVimInTerminal(buf)
1305 call delete('XtestCmdlineClearTabenter')
1306endfunc
1307
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001308" Test for failure in expanding special keywords in cmdline
1309func Test_cmdline_expand_special()
1310 %bwipe!
1311 call assert_fails('e #', 'E499:')
1312 call assert_fails('e <afile>', 'E495:')
1313 call assert_fails('e <abuf>', 'E496:')
1314 call assert_fails('e <amatch>', 'E497:')
1315endfunc
1316
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001317func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001318 CheckFeature cmdwin
1319
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001320 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1321 new
1322 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001323 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001324 close!
1325 call feedkeys("q/:close\<CR>", "xt")
1326 call assert_equal(1, winnr('$'))
1327 call feedkeys("q/:exit\<CR>", "xt")
1328 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001329
1330 " opening command window twice should fail
1331 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1332 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001333endfunc
1334
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001335func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001336 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001337 CheckScreendump
1338
1339 " aborting the :smile output caused the cmdline window to use the current
1340 " buffer.
1341 let lines =<< trim [SCRIPT]
1342 au WinNew * smile
1343 [SCRIPT]
1344 call writefile(lines, 'XTest_cmdwin')
1345
1346 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001347 " open cmdwin
1348 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001349 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001350 " quit more prompt for :smile command
1351 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001352 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001353 " execute a simple command
1354 call term_sendkeys(buf, "aecho 'done'\<CR>")
1355 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1356
1357 " clean up
1358 call StopVimInTerminal(buf)
1359 call delete('XTest_cmdwin')
1360endfunc
1361
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001362" Test for backtick expression in the command line
1363func Test_cmd_backtick()
1364 %argd
1365 argadd `=['a', 'b', 'c']`
1366 call assert_equal(['a', 'b', 'c'], argv())
1367 %argd
1368endfunc
1369
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001370" Test for the :! command
1371func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001372 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001373
1374 let lines =<< trim [SCRIPT]
1375 " Test for no previous command
1376 call assert_fails('!!', 'E34:')
1377 set nomore
1378 " Test for cmdline expansion with :!
1379 call setline(1, 'foo!')
1380 silent !echo <cWORD> > Xfile.out
1381 call assert_equal(['foo!'], readfile('Xfile.out'))
1382 " Test for using previous command
1383 silent !echo \! !
1384 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1385 call writefile(v:errors, 'Xresult')
1386 call delete('Xfile.out')
1387 qall!
1388 [SCRIPT]
1389 call writefile(lines, 'Xscript')
1390 if RunVim([], [], '--clean -S Xscript')
1391 call assert_equal([], readfile('Xresult'))
1392 endif
1393 call delete('Xscript')
1394 call delete('Xresult')
1395endfunc
1396
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001397" Test error: "E135: *Filter* Autocommands must not change current buffer"
1398func Test_cmd_bang_E135()
1399 new
1400 call setline(1, ['a', 'b', 'c', 'd'])
1401 augroup test_cmd_filter_E135
1402 au!
1403 autocmd FilterReadPost * help
1404 augroup END
1405 call assert_fails('2,3!echo "x"', 'E135:')
1406
1407 augroup test_cmd_filter_E135
1408 au!
1409 augroup END
1410 %bwipe!
1411endfunc
1412
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001413" Test for using ~ for home directory in cmdline completion matches
1414func Test_cmdline_expand_home()
1415 call mkdir('Xdir')
1416 call writefile([], 'Xdir/Xfile1')
1417 call writefile([], 'Xdir/Xfile2')
1418 cd Xdir
1419 let save_HOME = $HOME
1420 let $HOME = getcwd()
1421 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1422 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1423 let $HOME = save_HOME
1424 cd ..
1425 call delete('Xdir', 'rf')
1426endfunc
1427
Bram Moolenaar578fe942020-02-27 21:32:51 +01001428" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1429" or insert mode (when 'insertmode' is set)
1430func Test_cmdline_ctrl_g()
1431 new
1432 call setline(1, 'abc')
1433 call cursor(1, 3)
1434 " If command line is entered from insert mode, using C-\ C-G should back to
1435 " insert mode
1436 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1437 call assert_equal('abxyc', getline(1))
1438 call assert_equal(4, col('.'))
1439
1440 " If command line is entered in 'insertmode', using C-\ C-G should back to
1441 " 'insertmode'
1442 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1443 call assert_equal('ab12xyc', getline(1))
1444 close!
1445endfunc
1446
Bram Moolenaar578fe942020-02-27 21:32:51 +01001447" Test for 'wildmode'
1448func Test_wildmode()
1449 func T(a, c, p)
1450 return "oneA\noneB\noneC"
1451 endfunc
1452 command -nargs=1 -complete=custom,T MyCmd
1453
1454 func SaveScreenLine()
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001455 let g:Sline = Screenline(&lines - 1)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001456 return ''
1457 endfunc
1458 cnoremap <expr> <F2> SaveScreenLine()
1459
1460 set nowildmenu
1461 set wildmode=full,list
1462 let g:Sline = ''
1463 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001464 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001465 call assert_equal('"MyCmd oneA', @:)
1466
1467 set wildmode=longest,full
1468 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1469 call assert_equal('"MyCmd one', @:)
1470 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1471 call assert_equal('"MyCmd oneC', @:)
1472
1473 set wildmode=longest
1474 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1475 call assert_equal('"MyCmd one', @:)
1476
1477 set wildmode=list:longest
1478 let g:Sline = ''
1479 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001480 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001481 call assert_equal('"MyCmd one', @:)
1482
1483 set wildmode=""
1484 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1485 call assert_equal('"MyCmd oneA', @:)
1486
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001487 " Test for wildmode=longest with 'fileignorecase' set
1488 set wildmode=longest
1489 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001490 argadd AAA AAAA AAAAA
1491 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1492 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001493 set fileignorecase&
1494
1495 " Test for listing files with wildmode=list
1496 set wildmode=list
1497 let g:Sline = ''
1498 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001499 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001500 call assert_equal('"b A', @:)
1501
1502 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001503 delcommand MyCmd
1504 delfunc T
1505 delfunc SaveScreenLine
1506 cunmap <F2>
1507 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001508 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001509endfunc
1510
1511" Test for interrupting the command-line completion
1512func Test_interrupt_compl()
1513 func F(lead, cmdl, p)
1514 if a:lead =~ 'tw'
1515 call interrupt()
1516 return
1517 endif
1518 return "one\ntwo\nthree"
1519 endfunc
1520 command -nargs=1 -complete=custom,F Tcmd
1521
1522 set nowildmenu
1523 set wildmode=full
1524 let interrupted = 0
1525 try
1526 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1527 catch /^Vim:Interrupt$/
1528 let interrupted = 1
1529 endtry
1530 call assert_equal(1, interrupted)
1531
1532 delcommand Tcmd
1533 delfunc F
1534 set wildmode&
1535endfunc
1536
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001537" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001538func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001539 let str = ":one two\<C-U>"
1540 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001541 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001542 let str ..= "\<Left>five\<Right>"
1543 let str ..= "\<Home>two "
1544 let str ..= "\<C-Left>one "
1545 let str ..= "\<C-Right> three"
1546 let str ..= "\<End>\<S-Left>four "
1547 let str ..= "\<S-Right> six"
1548 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1549 call feedkeys(str, 'xt')
1550 call assert_equal("\"one two three four five six seven", @:)
1551endfunc
1552
1553" Test for moving the cursor on the / command line in 'rightleft' mode
1554func Test_cmdline_edit_rightleft()
1555 CheckFeature rightleft
1556 set rightleft
1557 set rightleftcmd=search
1558 let str = "/one two\<C-U>"
1559 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001560 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001561 let str ..= "\<Right>five\<Left>"
1562 let str ..= "\<Home>two "
1563 let str ..= "\<C-Right>one "
1564 let str ..= "\<C-Left> three"
1565 let str ..= "\<End>\<S-Right>four "
1566 let str ..= "\<S-Left> six"
1567 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1568 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1569 call assert_equal("\"one two three four five six seven", @/)
1570 set rightleftcmd&
1571 set rightleft&
1572endfunc
1573
1574" Test for using <C-\>e in the command line to evaluate an expression
1575func Test_cmdline_expr()
1576 " Evaluate an expression from the beginning of a command line
1577 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1578 call assert_equal('"hello', @:)
1579
1580 " Use an invalid expression for <C-\>e
1581 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1582
1583 " Insert literal <CTRL-\> in the command line
1584 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1585 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001586endfunc
1587
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001588" Test for 'imcmdline' and 'imsearch'
1589" This test doesn't actually test the input method functionality.
1590func Test_cmdline_inputmethod()
1591 new
1592 call setline(1, ['', 'abc', ''])
1593 set imcmdline
1594
1595 call feedkeys(":\"abc\<CR>", 'xt')
1596 call assert_equal("\"abc", @:)
1597 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1598 call assert_equal("\"abc", @:)
1599 call feedkeys("/abc\<CR>", 'xt')
1600 call assert_equal([2, 1], [line('.'), col('.')])
1601 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1602 call assert_equal([2, 1], [line('.'), col('.')])
1603
1604 set imsearch=2
1605 call cursor(1, 1)
1606 call feedkeys("/abc\<CR>", 'xt')
1607 call assert_equal([2, 1], [line('.'), col('.')])
1608 call cursor(1, 1)
1609 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1610 call assert_equal([2, 1], [line('.'), col('.')])
1611 set imdisable
1612 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1613 call assert_equal([2, 1], [line('.'), col('.')])
1614 set imdisable&
1615 set imsearch&
1616
1617 set imcmdline&
1618 %bwipe!
1619endfunc
1620
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001621" Test for recursively getting multiple command line inputs
1622func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001623 CheckFeature cmdwin
1624
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001625 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1626 call assert_equal('"cyan', @:)
1627endfunc
1628
1629" Test for using CTRL-_ in the command line with 'allowrevins'
1630func Test_cmdline_revins()
1631 CheckNotMSWindows
1632 CheckFeature rightleft
1633 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1634 call assert_equal("\"abc\<c-_>", @:)
1635 set allowrevins
1636 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1637 call assert_equal('"abcñèæ', @:)
1638 set allowrevins&
1639endfunc
1640
1641" Test for typing UTF-8 composing characters in the command line
1642func Test_cmdline_composing_chars()
1643 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1644 call assert_equal('"ゔ', @:)
1645endfunc
1646
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001647" Test for normal mode commands not supported in the cmd window
1648func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001649 CheckFeature cmdwin
1650
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001651 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1652 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1653 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1654 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1655 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1656 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001657 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1658 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1659 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1660 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1661 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1662 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1663 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1664 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1665 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1666 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1667 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1668 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1669 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1670 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1671 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1672 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1673 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1674 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1675 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1676 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1677 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001678endfunc
1679
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001680" Close the Cmd-line window in insert mode using CTRL-C
1681func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001682 CheckFeature cmdwin
1683
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001684 %bw!
1685 let s = ''
1686 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1687 call assert_equal('Hello', s)
1688 call assert_equal(1, winnr('$'))
1689endfunc
1690
Bram Moolenaar0e717042020-04-27 19:29:01 +02001691" test that ";" works to find a match at the start of the first line
1692func Test_zero_line_search()
1693 new
1694 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1695 call cursor(1,1)
1696 0;/pattern/d
1697 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1698 q!
1699endfunc
1700
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001701func Test_read_shellcmd()
1702 CheckUnix
1703 if executable('ls')
1704 " There should be ls in the $PATH
1705 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1706 call assert_match('^"r! .*\<ls\>', @:)
1707 endif
1708
1709 if executable('rm')
1710 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1711 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1712 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001713
1714 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1715 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1716 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001717 endif
1718endfunc
1719
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001720" Test for going up and down the directory tree using 'wildmenu'
1721func Test_wildmenu_dirstack()
1722 CheckUnix
1723 %bw!
1724 call mkdir('Xdir1/dir2/dir3', 'p')
1725 call writefile([], 'Xdir1/file1_1.txt')
1726 call writefile([], 'Xdir1/file1_2.txt')
1727 call writefile([], 'Xdir1/dir2/file2_1.txt')
1728 call writefile([], 'Xdir1/dir2/file2_2.txt')
1729 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
1730 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
1731 cd Xdir1/dir2/dir3
1732 set wildmenu
1733
1734 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
1735 call assert_equal('"e file3_1.txt', @:)
1736 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
1737 call assert_equal('"e ../dir3/', @:)
1738 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1739 call assert_equal('"e ../../dir2/', @:)
1740 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
1741 call assert_equal('"e ../../dir2/dir3/', @:)
1742 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1743 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:)
1744
1745 cd -
1746 call delete('Xdir1', 'rf')
1747 set wildmenu&
1748endfunc
1749
Bram Moolenaar309976e2019-12-05 18:16:33 +01001750" vim: shiftwidth=2 sts=2 expandtab