blob: 337cb429885b148493a03e648f959e4d8f9f5c8c [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
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00008func SetUp()
9 func SaveLastScreenLine()
10 let g:Sline = Screenline(&lines - 1)
11 return ''
12 endfunc
13 cnoremap <expr> <F4> SaveLastScreenLine()
14endfunc
15
16func TearDown()
17 delfunc SaveLastScreenLine
18 cunmap <F4>
19endfunc
20
Bram Moolenaarae3150e2016-06-11 23:22:36 +020021func Test_complete_tab()
22 call writefile(['testfile'], 'Xtestfile')
23 call feedkeys(":e Xtest\t\r", "tx")
24 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020025
26 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
27 call feedkeys(":e %\t\r", "tx")
28 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020029 call delete('Xtestfile')
30endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
44 call mkdir('Xtest')
45 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
80 call delete('Xtest', 'rf')
81 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020082endfunc
83
84func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010085 call mkdir('Xdir1/Xdir2', 'p')
86 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
87 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
88 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
89 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020090 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010091
92 " Pressing <Tab> completes, and moves to next files when pressing again.
93 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
94 call assert_equal('testfile1', getline(1))
95 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020096 call assert_equal('testfile2', getline(1))
97
Bram Moolenaar37db6422019-03-28 21:26:23 +010098 " <S-Tab> is like <Tab> but begin with the last match and then go to
99 " previous.
100 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
101 call assert_equal('testfile2', getline(1))
102 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
103 call assert_equal('testfile1', getline(1))
104
105 " <Left>/<Right> to move to previous/next file.
106 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
107 call assert_equal('testfile1', getline(1))
108 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
109 call assert_equal('testfile2', getline(1))
110 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
111 call assert_equal('testfile1', getline(1))
112
113 " <Up>/<Down> to go up/down directories.
114 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
115 call assert_equal('testfile3', getline(1))
116 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
117 call assert_equal('testfile1', getline(1))
118
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100119 " this fails in some Unix GUIs, not sure why
120 if !has('unix') || !has('gui_running')
121 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
122 " different than 'wildchar'.
123 set wildcharm=<C-Z>
124 cnoremap <C-J> <Down><C-Z>
125 cnoremap <C-K> <Up><C-Z>
126 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx')
127 call assert_equal('testfile3', getline(1))
128 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
129 call assert_equal('testfile1', getline(1))
130 set wildcharm=0
131 cunmap <C-J>
132 cunmap <C-K>
133 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100134
Bram Moolenaar578fe942020-02-27 21:32:51 +0100135 " Test for canceling the wild menu by adding a character
136 redrawstatus
137 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
138 call assert_equal('"e Xdir1/Xdir2/x', @:)
139
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100140 " Completion using a relative path
141 cd Xdir1/Xdir2
142 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
143 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
144 cd -
145
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000146 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100147 cnoremap <expr> <F2> wildmenumode()
148 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +0000149 call assert_equal('"cd Xdir1/0', @:)
150 call feedkeys(":e Xdir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
151 call assert_equal('"e Xdir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100152 cunmap <F2>
153
Bram Moolenaar37db6422019-03-28 21:26:23 +0100154 " cleanup
155 %bwipe
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000156 call delete('Xdir1', 'rf')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200157 set nowildmenu
158endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100159
Bram Moolenaara60053b2020-09-03 16:50:13 +0200160func Test_wildmenu_screendump()
161 CheckScreendump
162
163 let lines =<< trim [SCRIPT]
164 set wildmenu hlsearch
165 [SCRIPT]
166 call writefile(lines, 'XTest_wildmenu')
167
168 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
169 call term_sendkeys(buf, ":vim\<Tab>")
170 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
171
172 call term_sendkeys(buf, "\<Tab>")
173 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
174
175 call term_sendkeys(buf, "\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
177
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100178 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200179 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
180 call term_sendkeys(buf, "\<Esc>")
181
182 " clean up
183 call StopVimInTerminal(buf)
184 call delete('XTest_wildmenu')
185endfunc
186
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100187func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100188 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
189 call assert_equal('"map <unique> <silent>', getreg(':'))
190 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
191 call assert_equal('"map <script> <unique>', getreg(':'))
192 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
193 call assert_equal('"map <expr> <script>', getreg(':'))
194 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
195 call assert_equal('"map <buffer> <expr>', getreg(':'))
196 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
197 call assert_equal('"map <nowait> <buffer>', getreg(':'))
198 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
199 call assert_equal('"map <special> <nowait>', getreg(':'))
200 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
201 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200202
Bram Moolenaar1776a282019-05-03 16:05:41 +0200203 map <Middle>x middle
204
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200205 map ,f commaf
206 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200207 map <Left> left
208 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200209 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
210 call assert_equal('"map ,f', getreg(':'))
211 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
212 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200213 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
214 call assert_equal('"map <Left>', getreg(':'))
215 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200216 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200217 unmap ,f
218 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200219 unmap <Left>
220 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200221
222 set cpo-=< cpo-=B cpo-=k
223 map <Left> left
224 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
225 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200226 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200227 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200228 unmap <Left>
229
230 set cpo+=<
231 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200232 exe "set t_k6=\<Esc>[17~"
233 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200234 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
235 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200236 if !has('gui_running')
237 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
238 call assert_equal("\"map <F6>x", getreg(':'))
239 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200240 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200241 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200242 set cpo-=<
243
244 set cpo+=B
245 map <Left> left
246 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
247 call assert_equal('"map <Left>', getreg(':'))
248 unmap <Left>
249 set cpo-=B
250
251 set cpo+=k
252 map <Left> left
253 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
254 call assert_equal('"map <Left>', getreg(':'))
255 unmap <Left>
256 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200257
Bram Moolenaar531be472020-09-23 22:38:05 +0200258 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
259
Bram Moolenaar1776a282019-05-03 16:05:41 +0200260 unmap <Middle>x
261 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100262endfunc
263
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100264func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100265 hi Aardig ctermfg=green
266 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000267 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100268 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000269 call assert_equal('"match none', @:)
270 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
271 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100272endfunc
273
274func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100275 hi Aardig ctermfg=green
276 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
277 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200278 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
279 call assert_equal('"hi default Aardig', getreg(':'))
280 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
281 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100282 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
283 call assert_equal('"hi link', getreg(':'))
284 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
285 call assert_equal('"hi default', getreg(':'))
286 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
287 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200288 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
289 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
290 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
291 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200292
293 " A cleared group does not show up in completions.
294 hi Anders ctermfg=green
295 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
296 hi clear Aardig
297 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
298 hi clear Anders
299 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100300endfunc
301
Bram Moolenaar75e15672020-06-28 13:10:22 +0200302" Test for command-line expansion of "hi Ni " (easter egg)
303func Test_highlight_easter_egg()
304 call test_override('ui_delay', 1)
305 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
306 call assert_equal("\"hi Ni \<Tab>", @:)
307 call test_override('ALL', 0)
308endfunc
309
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200310func Test_getcompletion()
311 let groupcount = len(getcompletion('', 'event'))
312 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200313 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200314 call assert_true(matchcount > 0)
315 call assert_true(groupcount > matchcount)
316
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200317 if has('menu')
318 source $VIMRUNTIME/menu.vim
319 let matchcount = len(getcompletion('', 'menu'))
320 call assert_true(matchcount > 0)
321 call assert_equal(['File.'], getcompletion('File', 'menu'))
322 call assert_true(matchcount > 0)
323 let matchcount = len(getcompletion('File.', 'menu'))
324 call assert_true(matchcount > 0)
325 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200326
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200327 let l = getcompletion('v:n', 'var')
328 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200329 let l = getcompletion('v:notexists', 'var')
330 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200331
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200332 args a.c b.c
333 let l = getcompletion('', 'arglist')
334 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000335 let l = getcompletion('a.', 'buffer')
336 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200337 %argdelete
338
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200339 let l = getcompletion('', 'augroup')
340 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200341 let l = getcompletion('blahblah', 'augroup')
342 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200343
344 let l = getcompletion('', 'behave')
345 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200346 let l = getcompletion('not', 'behave')
347 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200348
349 let l = getcompletion('', 'color')
350 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200351 let l = getcompletion('dirty', 'color')
352 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200353
354 let l = getcompletion('', 'command')
355 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200356 let l = getcompletion('awake', 'command')
357 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200358
359 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200360 call assert_true(index(l, 'samples/') >= 0)
361 let l = getcompletion('NoMatch', 'dir')
362 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200363
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100364 if glob('~/*') !=# ''
365 let l = getcompletion('~/', 'dir')
366 call assert_true(l[0][0] ==# '~')
367 endif
368
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200369 let l = getcompletion('exe', 'expression')
370 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200371 let l = getcompletion('kill', 'expression')
372 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200373
374 let l = getcompletion('tag', 'function')
375 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200376 let l = getcompletion('paint', 'function')
377 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200378
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200379 let Flambda = {-> 'hello'}
380 let l = getcompletion('', 'function')
381 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200382 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200383
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200384 let l = getcompletion('run', 'file')
385 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200386 let l = getcompletion('walk', 'file')
387 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200388 set wildignore=*.vim
389 let l = getcompletion('run', 'file', 1)
390 call assert_true(index(l, 'runtest.vim') < 0)
391 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000392 " Directory name with space character
393 call mkdir('Xdir with space')
394 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
395 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
396 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200397
398 let l = getcompletion('ha', 'filetype')
399 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200400 let l = getcompletion('horse', 'filetype')
401 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200402
403 let l = getcompletion('z', 'syntax')
404 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200405 let l = getcompletion('emacs', 'syntax')
406 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200407
408 let l = getcompletion('jikes', 'compiler')
409 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200410 let l = getcompletion('break', 'compiler')
411 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200412
413 let l = getcompletion('last', 'help')
414 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200415 let l = getcompletion('giveup', 'help')
416 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200417
418 let l = getcompletion('time', 'option')
419 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200420 let l = getcompletion('space', 'option')
421 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200422
423 let l = getcompletion('er', 'highlight')
424 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200425 let l = getcompletion('dark', 'highlight')
426 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200427
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200428 let l = getcompletion('', 'messages')
429 call assert_true(index(l, 'clear') >= 0)
430 let l = getcompletion('not', 'messages')
431 call assert_equal([], l)
432
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200433 let l = getcompletion('', 'mapclear')
434 call assert_true(index(l, '<buffer>') >= 0)
435 let l = getcompletion('not', 'mapclear')
436 call assert_equal([], l)
437
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200438 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200439 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200440 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
441 let root = has('win32') ? 'C:\\' : '/'
442 let l = getcompletion(root, 'shellcmd')
443 let expected = map(filter(glob(root . '*', 0, 1),
444 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
445 call assert_equal(expected, l)
446
Bram Moolenaarb650b982016-08-05 20:35:13 +0200447 if has('cscope')
448 let l = getcompletion('', 'cscope')
449 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
450 call assert_equal(cmds, l)
451 " using cmdline completion must not change the result
452 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
453 let l = getcompletion('', 'cscope')
454 call assert_equal(cmds, l)
455 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
456 let l = getcompletion('find ', 'cscope')
457 call assert_equal(keys, l)
458 endif
459
Bram Moolenaar7522f692016-08-06 14:12:50 +0200460 if has('signs')
461 sign define Testing linehl=Comment
462 let l = getcompletion('', 'sign')
463 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
464 call assert_equal(cmds, l)
465 " using cmdline completion must not change the result
466 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
467 let l = getcompletion('', 'sign')
468 call assert_equal(cmds, l)
469 let l = getcompletion('list ', 'sign')
470 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000471 let l = getcompletion('de*', 'sign')
472 call assert_equal(['define'], l)
473 let l = getcompletion('p?', 'sign')
474 call assert_equal(['place'], l)
475 let l = getcompletion('j.', 'sign')
476 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200477 endif
478
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200479 " Command line completion tests
480 let l = getcompletion('cd ', 'cmdline')
481 call assert_true(index(l, 'samples/') >= 0)
482 let l = getcompletion('cd NoMatch', 'cmdline')
483 call assert_equal([], l)
484 let l = getcompletion('let v:n', 'cmdline')
485 call assert_true(index(l, 'v:null') >= 0)
486 let l = getcompletion('let v:notexists', 'cmdline')
487 call assert_equal([], l)
488 let l = getcompletion('call tag', 'cmdline')
489 call assert_true(index(l, 'taglist(') >= 0)
490 let l = getcompletion('call paint', 'cmdline')
491 call assert_equal([], l)
492
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100493 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000494 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100495 return "oneA\noneB\noneC"
496 endfunc
497 command -nargs=1 -complete=custom,T MyCmd
498 let l = getcompletion('MyCmd ', 'cmdline')
499 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000500 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100501
502 delcommand MyCmd
503 delfunc T
ii144785fe02021-11-21 12:13:56 +0000504 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100505
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200506 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200507 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200508 if has('cmdline_hist')
509 call add(names, 'history')
510 endif
511 if has('gettext')
512 call add(names, 'locale')
513 endif
514 if has('profile')
515 call add(names, 'syntime')
516 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200517
518 set tags=Xtags
519 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
520
521 for name in names
522 let matchcount = len(getcompletion('', name))
523 call assert_true(matchcount >= 0, 'No matches for ' . name)
524 endfor
525
526 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200527 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200528
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000529 edit a~b
530 enew
531 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
532 bw a~b
533
534 if has('unix')
535 edit Xtest\
536 enew
537 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
538 bw Xtest\
539 endif
540
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200541 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200542 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200543 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200544endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200545
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100546func Test_fullcommand()
547 let tests = {
548 \ '': '',
549 \ ':': '',
550 \ ':::': '',
551 \ ':::5': '',
552 \ 'not_a_cmd': '',
553 \ 'Check': '',
554 \ 'syntax': 'syntax',
555 \ ':syntax': 'syntax',
556 \ '::::syntax': 'syntax',
557 \ 'sy': 'syntax',
558 \ 'syn': 'syntax',
559 \ 'synt': 'syntax',
560 \ ':sy': 'syntax',
561 \ '::::sy': 'syntax',
562 \ 'match': 'match',
563 \ '2match': 'match',
564 \ '3match': 'match',
565 \ 'aboveleft': 'aboveleft',
566 \ 'abo': 'aboveleft',
567 \ 's': 'substitute',
568 \ '5s': 'substitute',
569 \ ':5s': 'substitute',
570 \ "'<,'>s": 'substitute',
571 \ ":'<,'>s": 'substitute',
572 \ 'CheckUni': 'CheckUnix',
573 \ 'CheckUnix': 'CheckUnix',
574 \ }
575
576 for [in, want] in items(tests)
577 call assert_equal(want, fullcommand(in))
578 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200579 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100580
581 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200582
583 command -buffer BufferLocalCommand :
584 command GlobalCommand :
585 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
586 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
587 delcommand BufferLocalCommand
588 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100589endfunc
590
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200591func Test_shellcmd_completion()
592 let save_path = $PATH
593
594 call mkdir('Xpathdir/Xpathsubdir', 'p')
595 call writefile([''], 'Xpathdir/Xfile.exe')
596 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
597
598 " Set PATH to example directory without trailing slash.
599 let $PATH = getcwd() . '/Xpathdir'
600
601 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
602 " dirs in the PATH, even though they won't be executed. We check that only
603 " subdirs of the PWD and executables from the PATH are included in the
604 " suggestions.
605 let actual = getcompletion('X', 'shellcmd')
606 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
607 call insert(expected, 'Xfile.exe')
608 call assert_equal(expected, actual)
609
610 call delete('Xpathdir', 'rf')
611 let $PATH = save_path
612endfunc
613
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200614func Test_expand_star_star()
615 call mkdir('a/b', 'p')
616 call writefile(['asdfasdf'], 'a/b/fileXname')
617 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000618 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200619 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200620 call delete('a', 'rf')
621endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100622
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100623func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100624 let @a = "def"
625 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
626 call assert_equal('"abc def ghi', @:)
627
628 new
629 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
630
631 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
632 call assert_equal('"aaa asdf bbb', @:)
633
634 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
635 call assert_equal('"aaa /tmp/some bbb', @:)
636
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200637 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
638 call assert_equal('"aaa '.getline(1).' bbb', @:)
639
Bram Moolenaar21efc362016-12-03 14:05:49 +0100640 set incsearch
641 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
642 call assert_equal('"aaa verylongword bbb', @:)
643
644 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
645 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100646
647 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
648 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100649 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200650
651 " Error while typing a command used to cause that it was not executed
652 " in the end.
653 new
654 try
655 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
656 catch /^Vim\%((\a\+)\)\=:E32/
657 " ignore error E32
658 endtry
659 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100660
Bram Moolenaar578fe942020-02-27 21:32:51 +0100661 " Try to paste an invalid register using <C-R>
662 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
663 call assert_equal('"onetwo', @:)
664
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100665 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100666 let @a = "xy\<C-H>z"
667 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
668 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100669 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
670 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100671 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
672 call assert_equal("\"xy\<C-H>z", @:)
673
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100674 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
675 let @a = "xy\<C-V>z"
676 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
677 call assert_equal('"xyz', @:)
678 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
679 call assert_equal("\"xy\<C-V>z", @:)
680
Bram Moolenaar578fe942020-02-27 21:32:51 +0100681 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
682
Bram Moolenaar72532d32018-04-07 19:09:09 +0200683 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100684endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100685
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100686func Test_cmdline_remove_char()
687 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100688
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100689 for e in ['utf8', 'latin1']
690 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100691
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100692 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
693 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100694
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100695 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
696 call assert_equal('"abcdef', @:)
697
698 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
699 call assert_equal('"abc ghi', @:, e)
700
701 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
702 call assert_equal('"def', @:, e)
703 endfor
704
705 let &encoding = encoding_save
706endfunc
707
708func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200709 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100710
711 set keymap=esperanto
712 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
713 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
714 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100715endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100716
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100717func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100718 new
719 2;'(
720 2;')
721 quit
722endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100723
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100724func Test_illegal_address2()
725 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
726 new
727 source Xtest.vim
728 " Trigger calling validate_cursor()
729 diffsp Xtest.vim
730 quit!
731 bwipe!
732 call delete('Xtest.vim')
733endfunc
734
Bram Moolenaarba47b512017-01-24 21:18:19 +0100735func Test_cmdline_complete_wildoptions()
736 help
737 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
738 let a = join(sort(split(@:)),' ')
739 set wildoptions=tagfile
740 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
741 let b = join(sort(split(@:)),' ')
742 call assert_equal(a, b)
743 bw!
744endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100745
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200746func Test_cmdline_complete_user_cmd()
747 command! -complete=color -nargs=1 Foo :
748 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
749 call assert_equal('"Foo blue', @:)
750 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
751 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000752 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
753 call assert_equal('"Foo a blue', @:)
754 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
755 call assert_equal('"Foo b\', @:)
756 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
757 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200758 delcommand Foo
759endfunc
760
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100761func s:ScriptLocalFunction()
762 echo 'yes'
763endfunc
764
765func Test_cmdline_complete_user_func()
766 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200767 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100768 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
769 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100770
771 " g: prefix also works
772 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
773 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200774
775 " using g: prefix does not result in just "g:" matches from a lambda
776 let Fx = { a -> a }
777 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
778 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200779
780 " existence of script-local dict function does not break user function name
781 " completion
782 function s:a_dict_func() dict
783 endfunction
784 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
785 call assert_match('"call Test_cmdline_complete_user_', @:)
786 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100787endfunc
788
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200789func Test_cmdline_complete_user_names()
790 if has('unix') && executable('whoami')
791 let whoami = systemlist('whoami')[0]
792 let first_letter = whoami[0]
793 if len(first_letter) > 0
794 " Trying completion of :e ~x where x is the first letter of
795 " the user name should complete to at least the user name.
796 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
797 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
798 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200799 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200800 " Just in case: check that the system has an Administrator account.
801 let names = system('net user')
802 if names =~ 'Administrator'
803 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100804 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200805 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100806 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200807 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200808 else
809 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200810 endif
811endfunc
812
Bram Moolenaar297610b2019-12-27 17:20:55 +0100813func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200814 CheckExecutable whoami
815 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
816 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100817endfunc
818
Bram Moolenaar8b633132020-03-20 18:20:51 +0100819func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200820 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
821 call assert_equal(lang, v:lc_time)
822
823 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
824 call assert_equal(lang, v:ctype)
825
826 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
827 call assert_equal(lang, v:collate)
828
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200829 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200830 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200831
832 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200833 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200834
Bram Moolenaarec680282020-06-12 19:35:32 +0200835 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200836
Bram Moolenaarec680282020-06-12 19:35:32 +0200837 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
838 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200839
Bram Moolenaarec680282020-06-12 19:35:32 +0200840 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
841 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200842
Bram Moolenaarec680282020-06-12 19:35:32 +0200843 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
844 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200845
846 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
847 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200848endfunc
849
Bram Moolenaar297610b2019-12-27 17:20:55 +0100850func Test_cmdline_complete_env_variable()
851 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100852 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
853 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100854 unlet $X_VIM_TEST_COMPLETE_ENV
855endfunc
856
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100857func Test_cmdline_complete_expression()
858 let g:SomeVar = 'blah'
859 for cmd in ['exe', 'echo', 'echon', 'echomsg']
860 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
861 call assert_match('"' .. cmd .. ' SomeVar', @:)
862 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
863 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
864 endfor
865 unlet g:SomeVar
866endfunc
867
Bram Moolenaar47016f52021-08-26 16:39:58 +0200868" Unique function name for completion below
869func s:WeirdFunc()
870 echo 'weird'
871endfunc
872
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100873" Test for various command-line completion
874func Test_cmdline_complete_various()
875 " completion for a command starting with a comment
876 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
877 call assert_equal("\" :|\"\<C-A>", @:)
878
879 " completion for a range followed by a comment
880 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
881 call assert_equal("\"1,2\"\<C-A>", @:)
882
883 " completion for :k command
884 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
885 call assert_equal("\"ka\<C-A>", @:)
886
887 " completion for short version of the :s command
888 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
889 call assert_equal("\"sI \<C-A>", @:)
890
891 " completion for :write command
892 call mkdir('Xdir')
893 call writefile(['one'], 'Xdir/Xfile1')
894 let save_cwd = getcwd()
895 cd Xdir
896 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
897 call assert_equal("\"w >> Xfile1", @:)
898 call chdir(save_cwd)
899 call delete('Xdir', 'rf')
900
901 " completion for :w ! and :r ! commands
902 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
903 call assert_equal("\"w !invalid_xyz_cmd", @:)
904 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
905 call assert_equal("\"r !invalid_xyz_cmd", @:)
906
907 " completion for :>> and :<< commands
908 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
909 call assert_equal("\">>>\<C-A>", @:)
910 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
911 call assert_equal("\"<<<\<C-A>", @:)
912
913 " completion for command with +cmd argument
914 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
915 call assert_equal("\"buffer +/pat Xabc", @:)
916 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
917 call assert_equal("\"buffer +/pat\<C-A>", @:)
918
919 " completion for a command with a trailing comment
920 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
921 call assert_equal("\"ls \" comment\<C-A>", @:)
922
923 " completion for a command with a trailing command
924 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
925 call assert_equal("\"ls | ls", @:)
926
927 " completion for a command with an CTRL-V escaped argument
928 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
929 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
930
931 " completion for a command that doesn't take additional arguments
932 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
933 call assert_equal("\"all abc\<C-A>", @:)
934
935 " completion for a command with a command modifier
936 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
937 call assert_equal("\"topleft new", @:)
938
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200939 " completion for vim9 and legacy commands
940 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
941 call assert_equal("\"vim9 call strlen(", @:)
942 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
943 call assert_equal("\"legac call strlen(", @:)
944
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200945 " completion for the :disassemble command
946 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
947 call assert_equal("\"disas debug", @:)
948 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
949 call assert_equal("\"disas profile", @:)
950 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
951 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
952 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
953 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +0200954 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
955 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200956
Bram Moolenaar47016f52021-08-26 16:39:58 +0200957 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +0200958 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +0200959
naohiro onodfe04db2021-09-12 15:45:10 +0200960 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
961 call assert_match('"disas <SNR>\d\+_', @:)
962 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
963 call assert_match('"disas debug <SNR>\d\+_', @:)
964
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100965 " completion for the :match command
966 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
967 call assert_equal("\"match Search /pat/\<C-A>", @:)
968
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100969 " completion for the :doautocmd command
970 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
971 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
972
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200973 " completion of autocmd group after comma
974 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
975 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
976
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200977 " completion of file name in :doautocmd
978 call writefile([], 'Xfile1')
979 call writefile([], 'Xfile2')
980 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
981 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
982 call delete('Xfile1')
983 call delete('Xfile2')
984
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100985 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200986 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100987 augroup END
988 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +0200989 call assert_equal("\"augroup XTest.test", @:)
990 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
991 call assert_equal("\"au XTest.test", @:)
992 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100993
994 " completion for the :unlet command
995 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
996 call assert_equal("\"unlet one two", @:)
997
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +0100998 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +0100999 " FIXME: what should happen on MS-Windows?
1000 if !has('win32')
1001 edit \{someFile}
1002 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1003 call assert_equal("\"buf {someFile}", @:)
1004 bwipe {someFile}
1005 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001006
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001007 " completion for the :bdelete command
1008 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1009 call assert_equal("\"bdel a b c", @:)
1010
1011 " completion for the :mapclear command
1012 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1013 call assert_equal("\"mapclear <buffer>", @:)
1014
1015 " completion for user defined commands with menu names
1016 menu Test.foo :ls<CR>
1017 com -nargs=* -complete=menu MyCmd
1018 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1019 call assert_equal('"MyCmd Test.', @:)
1020 delcom MyCmd
1021 unmenu Test
1022
1023 " completion for user defined commands with mappings
1024 mapclear
1025 map <F3> :ls<CR>
1026 com -nargs=* -complete=mapping MyCmd
1027 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001028 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001029 mapclear
1030 delcom MyCmd
1031
1032 " completion for :set path= with multiple backslashes
1033 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1034 call assert_equal('"set path=a\\\ b', @:)
1035
1036 " completion for :set dir= with a backslash
1037 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1038 call assert_equal('"set dir=a\ b', @:)
1039
1040 " completion for the :py3 commands
1041 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1042 call assert_equal('"py3 py3do py3file', @:)
1043
Bram Moolenaardf749a22021-03-28 15:29:43 +02001044 " completion for the :vim9 commands
1045 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1046 call assert_equal('"vim9cmd vim9script', @:)
1047
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001048 " redir @" is not the start of a comment. So complete after that
1049 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1050 call assert_equal('"redir @" | cwindow', @:)
1051
1052 " completion after a backtick
1053 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1054 call assert_equal('"e `a1b2c', @:)
1055
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001056 " completion for :language command with an invalid argument
1057 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1058 call assert_equal("\"language dummy \t", @:)
1059
1060 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001061 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1062 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001063
1064 " completion with ambiguous user defined commands
1065 com TCmd1 echo 'TCmd1'
1066 com TCmd2 echo 'TCmd2'
1067 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1068 call assert_equal('"TCmd ', @:)
1069 delcom TCmd1
1070 delcom TCmd2
1071
1072 " completion after a range followed by a pipe (|) character
1073 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1074 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001075
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001076 " completion after a :global command
1077 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1078 call assert_equal('"g/a/chistory', @:)
1079 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1080 call assert_equal("\"g/a\\/chist\t", @:)
1081
Bram Moolenaar9c929712020-09-07 22:05:28 +02001082 " use <Esc> as the 'wildchar' for completion
1083 set wildchar=<Esc>
1084 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1085 call assert_equal('"g/a\xb/clearjumps', @:)
1086 " pressing <esc> twice should cancel the command
1087 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1088 call assert_equal('"g/a\xb/clearjumps', @:)
1089 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001090
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001091 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001092 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001093 call writefile([], '~Xtest')
1094 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1095 call assert_equal('"e \~Xtest', @:)
1096 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001097
1098 " should be able to complete a file name that has a '*'
1099 call writefile([], 'Xx*Yy')
1100 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal('"e Xx\*Yy', @:)
1102 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001103
1104 " use a literal star
1105 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1106 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001107 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001108
1109 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1110 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001111endfunc
1112
1113" Test for 'wildignorecase'
1114func Test_cmdline_wildignorecase()
1115 CheckUnix
1116 call writefile([], 'XTEST')
1117 set wildignorecase
1118 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1119 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001120 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001121 let g:Sline = ''
1122 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1123 call assert_equal('"e xt', @:)
1124 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001125 set wildignorecase&
1126 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001127endfunc
1128
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001129func Test_cmdline_write_alternatefile()
1130 new
1131 call setline('.', ['one', 'two'])
1132 f foo.txt
1133 new
1134 f #-A
1135 call assert_equal('foo.txt-A', expand('%'))
1136 f #<-B.txt
1137 call assert_equal('foo-B.txt', expand('%'))
1138 f %<
1139 call assert_equal('foo-B', expand('%'))
1140 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001141 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001142 bw!
1143 f foo-B.txt
1144 f %<-A
1145 call assert_equal('foo-B-A', expand('%'))
1146 bw!
1147 bw!
1148endfunc
1149
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001150" using a leading backslash here
1151set cpo+=C
1152
1153func Test_cmdline_search_range()
1154 new
1155 call setline(1, ['a', 'b', 'c', 'd'])
1156 /d
1157 1,\/s/b/B/
1158 call assert_equal('B', getline(2))
1159
1160 /a
1161 $
1162 \?,4s/c/C/
1163 call assert_equal('C', getline(3))
1164
1165 call setline(1, ['a', 'b', 'c', 'd'])
1166 %s/c/c/
1167 1,\&s/b/B/
1168 call assert_equal('B', getline(2))
1169
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001170 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001171 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001172
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001173 bwipe!
1174endfunc
1175
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001176" Test for the tick mark (') in an excmd range
1177func Test_tick_mark_in_range()
1178 " If only the tick is passed as a range and no command is specified, there
1179 " should not be an error
1180 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001181 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001182 call assert_fails("',print", 'E78:')
1183endfunc
1184
1185" Test for using a line number followed by a search pattern as range
1186func Test_lnum_and_pattern_as_range()
1187 new
1188 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1189 let @" = ''
1190 2/foo/yank
1191 call assert_equal("foo 3\n", @")
1192 call assert_equal(1, line('.'))
1193 close!
1194endfunc
1195
Bram Moolenaar65189a12017-02-06 22:22:17 +01001196" Tests for getcmdline(), getcmdpos() and getcmdtype()
1197func Check_cmdline(cmdtype)
1198 call assert_equal('MyCmd a', getcmdline())
1199 call assert_equal(8, getcmdpos())
1200 call assert_equal(a:cmdtype, getcmdtype())
1201 return ''
1202endfunc
1203
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001204set cpo&
1205
Bram Moolenaar65189a12017-02-06 22:22:17 +01001206func Test_getcmdtype()
1207 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1208
1209 let cmdtype = ''
1210 debuggreedy
1211 call feedkeys(":debug echo 'test'\<CR>", "t")
1212 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1213 call feedkeys("cont\<CR>", "xt")
1214 0debuggreedy
1215 call assert_equal('>', cmdtype)
1216
1217 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1218 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1219
1220 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001221 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001222
1223 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1224
1225 cnoremap <expr> <F6> Check_cmdline('=')
1226 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1227 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001228
1229 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001230endfunc
1231
Bram Moolenaar81612b72018-06-23 14:55:03 +02001232func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001233 CheckFeature cmdwin
1234
Bram Moolenaar81612b72018-06-23 14:55:03 +02001235 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1236 call assert_equal('/', a)
1237
1238 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1239 call assert_equal('?', a)
1240
1241 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1242 call assert_equal(':', a)
1243
1244 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1245 call assert_equal(':', a)
1246
1247 call assert_equal('', getcmdwintype())
1248endfunc
1249
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001250func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001251 CheckFeature cmdwin
1252
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001253 let s:seq = []
1254 augroup CmdWin
1255 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1256 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1257 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1258 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1259 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1260 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1261
1262 let org_winid = win_getid()
1263 let org_bufnr = bufnr()
1264 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1265 call assert_equal(':', a)
1266 call assert_equal([
1267 \ 'WinLeave ' .. org_winid,
1268 \ 'WinEnter ' .. s:cmd_winid,
1269 \ 'BufLeave ' .. org_bufnr,
1270 \ 'BufEnter ' .. s:cmd_bufnr,
1271 \ 'CmdWinEnter ' .. s:cmd_winid,
1272 \ 'CmdWinLeave ' .. s:cmd_winid,
1273 \ 'BufLeave ' .. s:cmd_bufnr,
1274 \ 'WinLeave ' .. s:cmd_winid,
1275 \ 'WinEnter ' .. org_winid,
1276 \ 'BufEnter ' .. org_bufnr,
1277 \ ], s:seq)
1278
1279 au!
1280 augroup END
1281endfunc
1282
Bram Moolenaar52604f22017-04-07 16:17:39 +02001283func Test_verbosefile()
1284 set verbosefile=Xlog
1285 echomsg 'foo'
1286 echomsg 'bar'
1287 set verbosefile=
1288 let log = readfile('Xlog')
1289 call assert_match("foo\nbar", join(log, "\n"))
1290 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001291 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001292 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001293 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001294endfunc
1295
Bram Moolenaar4facea32019-10-12 20:17:40 +02001296func Test_verbose_option()
1297 CheckScreendump
1298
1299 let lines =<< trim [SCRIPT]
1300 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1301 call feedkeys("\r", 't') " for the hit-enter prompt
1302 set verbose=20
1303 [SCRIPT]
1304 call writefile(lines, 'XTest_verbose')
1305
1306 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001307 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001308 call term_sendkeys(buf, ":DoSomething\<CR>")
1309 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1310
1311 " clean up
1312 call StopVimInTerminal(buf)
1313 call delete('XTest_verbose')
1314endfunc
1315
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001316func Test_setcmdpos()
1317 func InsertTextAtPos(text, pos)
1318 call assert_equal(0, setcmdpos(a:pos))
1319 return a:text
1320 endfunc
1321
1322 " setcmdpos() with position in the middle of the command line.
1323 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1324 call assert_equal('"1ab2', @:)
1325
1326 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1327 call assert_equal('"1b2a', @:)
1328
1329 " setcmdpos() with position beyond the end of the command line.
1330 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1331 call assert_equal('"12ab', @:)
1332
1333 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001334 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001335endfunc
1336
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001337func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001338 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001339 let encoding_save = &encoding
1340
1341 for e in encodings
1342 exe 'set encoding=' . e
1343
1344 " Test overstrike in the middle of the command line.
1345 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001346 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001347
1348 " Test overstrike going beyond end of command line.
1349 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001350 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001351
1352 " Test toggling insert/overstrike a few times.
1353 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001354 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001355 endfor
1356
Bram Moolenaar30276f22019-01-24 17:59:39 +01001357 " Test overstrike with multi-byte characters.
1358 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001359 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001360
1361 let &encoding = encoding_save
1362endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001363
1364func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001365 CheckFeature cmdwin
1366
Bram Moolenaara046b372019-09-15 17:26:07 +02001367 let winid = win_getid()
1368 sp
1369 try
1370 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1371 catch /^Vim\%((\a\+)\)\=:E11/
1372 endtry
1373 bw!
1374endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001375
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001376func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001377 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001378 CheckScreendump
1379
1380 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001381 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001382 call setline(1, range(30))
1383 2split
1384 [SCRIPT]
1385 call writefile(lines, 'XTest_restore')
1386
1387 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001388 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001389 call term_sendkeys(buf, "q:")
1390 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1391
1392 " normal restore
1393 call term_sendkeys(buf, ":q\<CR>")
1394 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1395
1396 " restore after setting 'lines' with one window
1397 call term_sendkeys(buf, ":close\<CR>")
1398 call term_sendkeys(buf, "q:")
1399 call term_sendkeys(buf, ":set lines=18\<CR>")
1400 call term_sendkeys(buf, ":q\<CR>")
1401 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1402
1403 " clean up
1404 call StopVimInTerminal(buf)
1405 call delete('XTest_restore')
1406endfunc
1407
Bram Moolenaare5b44862021-05-30 13:54:03 +02001408func Test_cmdwin_no_terminal()
1409 CheckFeature cmdwin
1410 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001411 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001412
1413 let buf = RunVimInTerminal('', {'rows': 12})
1414 call TermWait(buf, 50)
1415 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1416 call term_sendkeys(buf, "q:")
1417 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1418 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1419 call term_sendkeys(buf, ":q\<CR>")
1420 call StopVimInTerminal(buf)
1421endfunc
1422
Bram Moolenaar52410572019-10-27 05:12:45 +01001423func Test_buffers_lastused()
1424 " check that buffers are sorted by time when wildmode has lastused
1425 call test_settime(1550020000) " middle
1426 edit bufa
1427 enew
1428 call test_settime(1550030000) " newest
1429 edit bufb
1430 enew
1431 call test_settime(1550010000) " oldest
1432 edit bufc
1433 enew
1434 call test_settime(0)
1435 enew
1436
1437 call assert_equal(['bufa', 'bufb', 'bufc'],
1438 \ getcompletion('', 'buffer'))
1439
1440 let save_wildmode = &wildmode
1441 set wildmode=full:lastused
1442
1443 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1444 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1445 call assert_equal('b bufb', X)
1446 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1447 call assert_equal('b bufa', X)
1448 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1449 call assert_equal('b bufc', X)
1450 enew
1451
1452 edit other
1453 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1454 call assert_equal('b bufb', X)
1455 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1456 call assert_equal('b bufa', X)
1457 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1458 call assert_equal('b bufc', X)
1459 enew
1460
1461 let &wildmode = save_wildmode
1462
1463 bwipeout bufa
1464 bwipeout bufb
1465 bwipeout bufc
1466endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001467
1468func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001469 CheckFeature cmdwin
1470
Bram Moolenaar85db5472019-12-04 15:11:08 +01001471 " This should not generate E488
1472 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001473 " Using feedkeys with q: only should automatically close the cmd window
1474 call feedkeys('q:', 'xt')
1475 call assert_equal(1, winnr('$'))
1476 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001477endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001478
1479" Tests for the issues fixed in 7.4.441.
1480" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1481func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001482 CheckFeature cmdwin
1483
Bram Moolenaar309976e2019-12-05 18:16:33 +01001484 exe "set cedit=\<C-c>"
1485 normal! :
1486 call assert_equal(1, winnr('$'))
1487
1488 let g:cmd_wintype = ''
1489 func CmdWinType()
1490 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001491 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001492 return ''
1493 endfunc
1494
1495 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1496 echo input('')
1497 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001498 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001499
1500 set cedit&vim
1501 delfunc CmdWinType
1502endfunc
1503
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001504" Test for CmdwinEnter autocmd
1505func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001506 CheckFeature cmdwin
1507
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001508 augroup CmdWin
1509 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001510 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001511 autocmd CmdwinEnter * startinsert
1512 augroup END
1513
1514 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1515 call assert_equal('xyz', @:)
1516
1517 augroup CmdWin
1518 au!
1519 augroup END
1520 augroup! CmdWin
1521endfunc
1522
Bram Moolenaar479950f2020-01-19 15:45:17 +01001523func Test_cmdlineclear_tabenter()
1524 CheckScreendump
1525
1526 let lines =<< trim [SCRIPT]
1527 call setline(1, range(30))
1528 [SCRIPT]
1529
1530 call writefile(lines, 'XtestCmdlineClearTabenter')
1531 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001532 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001533 " in one tab make the command line higher with CTRL-W -
1534 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1535 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1536
1537 call StopVimInTerminal(buf)
1538 call delete('XtestCmdlineClearTabenter')
1539endfunc
1540
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001541" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001542func Test_cmdline_expand_special()
1543 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001544 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001545 call assert_fails('e <afile>', 'E495:')
1546 call assert_fails('e <abuf>', 'E496:')
1547 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001548
1549 call writefile([], 'Xfile.cpp')
1550 call writefile([], 'Xfile.java')
1551 new Xfile.cpp
1552 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1553 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1554 close
1555 call delete('Xfile.cpp')
1556 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001557endfunc
1558
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001559func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001560 CheckFeature cmdwin
1561
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001562 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1563 new
1564 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001565 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001566 close!
1567 call feedkeys("q/:close\<CR>", "xt")
1568 call assert_equal(1, winnr('$'))
1569 call feedkeys("q/:exit\<CR>", "xt")
1570 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001571
1572 " opening command window twice should fail
1573 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1574 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001575endfunc
1576
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001577func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001578 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001579 CheckScreendump
1580
1581 " aborting the :smile output caused the cmdline window to use the current
1582 " buffer.
1583 let lines =<< trim [SCRIPT]
1584 au WinNew * smile
1585 [SCRIPT]
1586 call writefile(lines, 'XTest_cmdwin')
1587
1588 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001589 " open cmdwin
1590 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001591 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001592 " quit more prompt for :smile command
1593 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001594 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001595 " execute a simple command
1596 call term_sendkeys(buf, "aecho 'done'\<CR>")
1597 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1598
1599 " clean up
1600 call StopVimInTerminal(buf)
1601 call delete('XTest_cmdwin')
1602endfunc
1603
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001604" Test for backtick expression in the command line
1605func Test_cmd_backtick()
1606 %argd
1607 argadd `=['a', 'b', 'c']`
1608 call assert_equal(['a', 'b', 'c'], argv())
1609 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001610
1611 argadd `echo abc def`
1612 call assert_equal(['abc def'], argv())
1613 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001614endfunc
1615
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001616" Test for the :! command
1617func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001618 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001619
1620 let lines =<< trim [SCRIPT]
1621 " Test for no previous command
1622 call assert_fails('!!', 'E34:')
1623 set nomore
1624 " Test for cmdline expansion with :!
1625 call setline(1, 'foo!')
1626 silent !echo <cWORD> > Xfile.out
1627 call assert_equal(['foo!'], readfile('Xfile.out'))
1628 " Test for using previous command
1629 silent !echo \! !
1630 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1631 call writefile(v:errors, 'Xresult')
1632 call delete('Xfile.out')
1633 qall!
1634 [SCRIPT]
1635 call writefile(lines, 'Xscript')
1636 if RunVim([], [], '--clean -S Xscript')
1637 call assert_equal([], readfile('Xresult'))
1638 endif
1639 call delete('Xscript')
1640 call delete('Xresult')
1641endfunc
1642
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001643" Test error: "E135: *Filter* Autocommands must not change current buffer"
1644func Test_cmd_bang_E135()
1645 new
1646 call setline(1, ['a', 'b', 'c', 'd'])
1647 augroup test_cmd_filter_E135
1648 au!
1649 autocmd FilterReadPost * help
1650 augroup END
1651 call assert_fails('2,3!echo "x"', 'E135:')
1652
1653 augroup test_cmd_filter_E135
1654 au!
1655 augroup END
1656 %bwipe!
1657endfunc
1658
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001659" Test for using ~ for home directory in cmdline completion matches
1660func Test_cmdline_expand_home()
1661 call mkdir('Xdir')
1662 call writefile([], 'Xdir/Xfile1')
1663 call writefile([], 'Xdir/Xfile2')
1664 cd Xdir
1665 let save_HOME = $HOME
1666 let $HOME = getcwd()
1667 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1668 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1669 let $HOME = save_HOME
1670 cd ..
1671 call delete('Xdir', 'rf')
1672endfunc
1673
Bram Moolenaar578fe942020-02-27 21:32:51 +01001674" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1675" or insert mode (when 'insertmode' is set)
1676func Test_cmdline_ctrl_g()
1677 new
1678 call setline(1, 'abc')
1679 call cursor(1, 3)
1680 " If command line is entered from insert mode, using C-\ C-G should back to
1681 " insert mode
1682 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1683 call assert_equal('abxyc', getline(1))
1684 call assert_equal(4, col('.'))
1685
1686 " If command line is entered in 'insertmode', using C-\ C-G should back to
1687 " 'insertmode'
1688 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1689 call assert_equal('ab12xyc', getline(1))
1690 close!
1691endfunc
1692
Bram Moolenaar578fe942020-02-27 21:32:51 +01001693" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001694func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001695 func T(a, c, p)
1696 return "oneA\noneB\noneC"
1697 endfunc
1698 command -nargs=1 -complete=custom,T MyCmd
1699
Bram Moolenaar578fe942020-02-27 21:32:51 +01001700 set nowildmenu
1701 set wildmode=full,list
1702 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001703 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001704 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001705 call assert_equal('"MyCmd oneA', @:)
1706
1707 set wildmode=longest,full
1708 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1709 call assert_equal('"MyCmd one', @:)
1710 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1711 call assert_equal('"MyCmd oneC', @:)
1712
1713 set wildmode=longest
1714 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1715 call assert_equal('"MyCmd one', @:)
1716
1717 set wildmode=list:longest
1718 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001719 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001720 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001721 call assert_equal('"MyCmd one', @:)
1722
1723 set wildmode=""
1724 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1725 call assert_equal('"MyCmd oneA', @:)
1726
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001727 " Test for wildmode=longest with 'fileignorecase' set
1728 set wildmode=longest
1729 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001730 argadd AAA AAAA AAAAA
1731 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1732 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001733 set fileignorecase&
1734
1735 " Test for listing files with wildmode=list
1736 set wildmode=list
1737 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001738 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001739 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001740 call assert_equal('"b A', @:)
1741
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001742 " when using longest completion match, matches shorter than the argument
1743 " should be ignored (happens with :help)
1744 set wildmode=longest,full
1745 set wildmenu
1746 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1747 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001748 " non existing file
1749 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1750 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001751 set wildmenu&
1752
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001753 " Test for longest file name completion with 'fileignorecase'
1754 " On MS-Windows, file names are case insensitive.
1755 if has('unix')
1756 call writefile([], 'XTESTfoo')
1757 call writefile([], 'Xtestbar')
1758 set nofileignorecase
1759 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1760 call assert_equal('"e XTESTfoo', @:)
1761 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1762 call assert_equal('"e Xtestbar', @:)
1763 set fileignorecase
1764 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1765 call assert_equal('"e Xtest', @:)
1766 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1767 call assert_equal('"e Xtest', @:)
1768 set fileignorecase&
1769 call delete('XTESTfoo')
1770 call delete('Xtestbar')
1771 endif
1772
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001773 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001774 delcommand MyCmd
1775 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001776 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001777 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001778endfunc
1779
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001780func Test_wildmode()
1781 " Test with utf-8 encoding
1782 call Wildmode_tests()
1783
1784 " Test with latin1 encoding
1785 let save_encoding = &encoding
1786 set encoding=latin1
1787 call Wildmode_tests()
1788 let &encoding = save_encoding
1789endfunc
1790
Bram Moolenaar578fe942020-02-27 21:32:51 +01001791" Test for interrupting the command-line completion
1792func Test_interrupt_compl()
1793 func F(lead, cmdl, p)
1794 if a:lead =~ 'tw'
1795 call interrupt()
1796 return
1797 endif
1798 return "one\ntwo\nthree"
1799 endfunc
1800 command -nargs=1 -complete=custom,F Tcmd
1801
1802 set nowildmenu
1803 set wildmode=full
1804 let interrupted = 0
1805 try
1806 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1807 catch /^Vim:Interrupt$/
1808 let interrupted = 1
1809 endtry
1810 call assert_equal(1, interrupted)
1811
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001812 let interrupted = 0
1813 try
1814 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1815 catch /^Vim:Interrupt$/
1816 let interrupted = 1
1817 endtry
1818 call assert_equal(1, interrupted)
1819
Bram Moolenaar578fe942020-02-27 21:32:51 +01001820 delcommand Tcmd
1821 delfunc F
1822 set wildmode&
1823endfunc
1824
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001825" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001826func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001827 let str = ":one two\<C-U>"
1828 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001829 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001830 let str ..= "\<Left>five\<Right>"
1831 let str ..= "\<Home>two "
1832 let str ..= "\<C-Left>one "
1833 let str ..= "\<C-Right> three"
1834 let str ..= "\<End>\<S-Left>four "
1835 let str ..= "\<S-Right> six"
1836 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1837 call feedkeys(str, 'xt')
1838 call assert_equal("\"one two three four five six seven", @:)
1839endfunc
1840
1841" Test for moving the cursor on the / command line in 'rightleft' mode
1842func Test_cmdline_edit_rightleft()
1843 CheckFeature rightleft
1844 set rightleft
1845 set rightleftcmd=search
1846 let str = "/one two\<C-U>"
1847 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001848 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001849 let str ..= "\<Right>five\<Left>"
1850 let str ..= "\<Home>two "
1851 let str ..= "\<C-Right>one "
1852 let str ..= "\<C-Left> three"
1853 let str ..= "\<End>\<S-Right>four "
1854 let str ..= "\<S-Left> six"
1855 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1856 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1857 call assert_equal("\"one two three four five six seven", @/)
1858 set rightleftcmd&
1859 set rightleft&
1860endfunc
1861
1862" Test for using <C-\>e in the command line to evaluate an expression
1863func Test_cmdline_expr()
1864 " Evaluate an expression from the beginning of a command line
1865 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1866 call assert_equal('"hello', @:)
1867
1868 " Use an invalid expression for <C-\>e
1869 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1870
1871 " Insert literal <CTRL-\> in the command line
1872 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1873 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001874endfunc
1875
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001876" Test for 'imcmdline' and 'imsearch'
1877" This test doesn't actually test the input method functionality.
1878func Test_cmdline_inputmethod()
1879 new
1880 call setline(1, ['', 'abc', ''])
1881 set imcmdline
1882
1883 call feedkeys(":\"abc\<CR>", 'xt')
1884 call assert_equal("\"abc", @:)
1885 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1886 call assert_equal("\"abc", @:)
1887 call feedkeys("/abc\<CR>", 'xt')
1888 call assert_equal([2, 1], [line('.'), col('.')])
1889 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1890 call assert_equal([2, 1], [line('.'), col('.')])
1891
1892 set imsearch=2
1893 call cursor(1, 1)
1894 call feedkeys("/abc\<CR>", 'xt')
1895 call assert_equal([2, 1], [line('.'), col('.')])
1896 call cursor(1, 1)
1897 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1898 call assert_equal([2, 1], [line('.'), col('.')])
1899 set imdisable
1900 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1901 call assert_equal([2, 1], [line('.'), col('.')])
1902 set imdisable&
1903 set imsearch&
1904
1905 set imcmdline&
1906 %bwipe!
1907endfunc
1908
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001909" Test for recursively getting multiple command line inputs
1910func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001911 CheckFeature cmdwin
1912
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001913 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1914 call assert_equal('"cyan', @:)
1915endfunc
1916
1917" Test for using CTRL-_ in the command line with 'allowrevins'
1918func Test_cmdline_revins()
1919 CheckNotMSWindows
1920 CheckFeature rightleft
1921 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1922 call assert_equal("\"abc\<c-_>", @:)
1923 set allowrevins
1924 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1925 call assert_equal('"abcñèæ', @:)
1926 set allowrevins&
1927endfunc
1928
1929" Test for typing UTF-8 composing characters in the command line
1930func Test_cmdline_composing_chars()
1931 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1932 call assert_equal('"ゔ', @:)
1933endfunc
1934
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001935" Test for normal mode commands not supported in the cmd window
1936func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001937 CheckFeature cmdwin
1938
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001939 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1940 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1941 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1942 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1943 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1944 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001945 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1946 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1947 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1948 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1949 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1950 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1951 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1952 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1953 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1954 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1955 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1956 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1957 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1958 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1959 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1960 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1961 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1962 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1963 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1964 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1965 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001966endfunc
1967
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001968" Close the Cmd-line window in insert mode using CTRL-C
1969func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001970 CheckFeature cmdwin
1971
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001972 %bw!
1973 let s = ''
1974 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1975 call assert_equal('Hello', s)
1976 call assert_equal(1, winnr('$'))
1977endfunc
1978
Bram Moolenaar0e717042020-04-27 19:29:01 +02001979" test that ";" works to find a match at the start of the first line
1980func Test_zero_line_search()
1981 new
1982 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1983 call cursor(1,1)
1984 0;/pattern/d
1985 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1986 q!
1987endfunc
1988
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001989func Test_read_shellcmd()
1990 CheckUnix
1991 if executable('ls')
1992 " There should be ls in the $PATH
1993 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1994 call assert_match('^"r! .*\<ls\>', @:)
1995 endif
1996
1997 if executable('rm')
1998 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1999 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2000 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002001
2002 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2003 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2004 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002005 endif
2006endfunc
2007
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002008" Test for going up and down the directory tree using 'wildmenu'
2009func Test_wildmenu_dirstack()
2010 CheckUnix
2011 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002012 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002013 call writefile([], 'Xdir1/file1_1.txt')
2014 call writefile([], 'Xdir1/file1_2.txt')
2015 call writefile([], 'Xdir1/dir2/file2_1.txt')
2016 call writefile([], 'Xdir1/dir2/file2_2.txt')
2017 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2018 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002019 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2020 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002021 set wildmenu
2022
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002023 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002024 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002025 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002026 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002027 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002028 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002029 call assert_equal('"e ../../dir3/', @:)
2030 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2031 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002032 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002033 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002034 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002035 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002036 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002037 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2038 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2039
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002040 call delete('Xdir1', 'rf')
2041 set wildmenu&
2042endfunc
2043
obcat71c6f7a2021-05-13 20:23:10 +02002044" Test for recalling newer or older cmdline from history with <Up>, <Down>,
2045" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
2046func Test_recalling_cmdline()
2047 CheckFeature cmdline_hist
2048
2049 let g:cmdlines = []
2050 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2051
2052 let histories = [
2053 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
2054 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
2055 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
2056 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
2057 "\ TODO: {'name': 'debug', ...}
2058 \]
2059 let keypairs = [
2060 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
2061 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
2062 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
2063 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
2064 \]
2065 let prefix = 'vi'
2066 for h in histories
2067 call histadd(h.name, 'vim')
2068 call histadd(h.name, 'virtue')
2069 call histadd(h.name, 'Virgo')
2070 call histadd(h.name, 'vogue')
2071 call histadd(h.name, 'emacs')
2072 for k in keypairs
2073 let g:cmdlines = []
2074 let keyseqs = h.enter
2075 \ .. prefix
2076 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2077 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2078 \ .. h.exit
2079 call feedkeys(keyseqs, 'xt')
2080 call histdel(h.name, -1) " delete the history added by feedkeys above
2081 let expect = k.prefixmatch
2082 \ ? ['virtue', 'vim', 'virtue', prefix]
2083 \ : ['emacs', 'vogue', 'emacs', prefix]
2084 call assert_equal(expect, g:cmdlines)
2085 endfor
2086 endfor
2087
2088 unlet g:cmdlines
2089 cunmap <Plug>(save-cmdline)
2090endfunc
2091
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002092func Test_cmd_map_cmdlineChanged()
2093 let g:log = []
2094 cnoremap <F1> l<Cmd><CR>s
2095 augroup test
2096 autocmd!
2097 autocmd CmdlineChanged : let g:log += [getcmdline()]
2098 augroup END
2099
2100 call feedkeys(":\<F1>\<CR>", 'xt')
2101 call assert_equal(['l', 'ls'], g:log)
2102
Bram Moolenaar796139a2021-05-18 21:38:45 +02002103 let @b = 'b'
2104 cnoremap <F1> a<C-R>b
2105 let g:log = []
2106 call feedkeys(":\<F1>\<CR>", 'xt')
2107 call assert_equal(['a', 'ab'], g:log)
2108
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002109 unlet g:log
2110 cunmap <F1>
2111 augroup test
2112 autocmd!
2113 augroup END
2114endfunc
2115
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002116" Test for the 'suffixes' option
2117func Test_suffixes_opt()
2118 call writefile([], 'Xfile')
2119 call writefile([], 'Xfile.c')
2120 call writefile([], 'Xfile.o')
2121 set suffixes=
2122 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2123 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002124 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2125 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002126 set suffixes=.c
2127 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2128 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002129 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2130 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002131 set suffixes=,,
2132 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2133 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002134 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2135 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002136 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002137 " Test for getcompletion() with different patterns
2138 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2139 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002140 call delete('Xfile')
2141 call delete('Xfile.c')
2142 call delete('Xfile.o')
2143endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002144
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002145" Test for using a popup menu for the command line completion matches
2146" (wildoptions=pum)
2147func Test_wildmenu_pum()
2148 CheckRunVimInTerminal
2149
2150 let commands =<< trim [CODE]
2151 set wildmenu
2152 set wildoptions=pum
2153 set shm+=I
2154 set noruler
2155 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002156
2157 func CmdCompl(a, b, c)
2158 return repeat(['aaaa'], 120)
2159 endfunc
2160 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002161
2162 func MyStatusLine() abort
2163 return 'status'
2164 endfunc
2165 func SetupStatusline()
2166 set statusline=%!MyStatusLine()
2167 set laststatus=2
2168 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002169
2170 func MyTabLine()
2171 return 'my tab line'
2172 endfunc
2173 func SetupTabline()
2174 set statusline=
2175 set tabline=%!MyTabLine()
2176 set showtabline=2
2177 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002178 [CODE]
2179 call writefile(commands, 'Xtest')
2180
2181 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2182
2183 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002184 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2185
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002186 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002187 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002188 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2189
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002190 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002191 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002192 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2193
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002194 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002195 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002196 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2197
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002198 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002199 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002200 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2201
2202 " pressing <C-E> should end completion and go back to the original match
2203 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002204 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2205
2206 " pressing <C-Y> should select the current match and end completion
2207 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002208 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2209
2210 " With 'wildmode' set to 'longest,full', completing a match should display
2211 " the longest match, the wildmenu should not be displayed.
2212 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2213 call TermWait(buf)
2214 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002215 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2216
2217 " pressing <Tab> should display the wildmenu
2218 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002219 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2220
2221 " pressing <Tab> second time should select the next entry in the menu
2222 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002223 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2224
2225 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002226 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2229
2230 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002231 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2232
2233 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2235
2236 " Directory name completion
2237 call mkdir('Xdir/XdirA/XdirB', 'p')
2238 call writefile([], 'Xdir/XfileA')
2239 call writefile([], 'Xdir/XdirA/XfileB')
2240 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2241
2242 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002243 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2244
2245 " Pressing <Right> on a directory name should go into that directory
2246 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002247 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2248
2249 " Pressing <Left> on a directory name should go to the parent directory
2250 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002251 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2252
2253 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002254 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002255 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2257
2258 " Pressing <C-D> when the popup menu is displayed should remove the popup
2259 " menu
2260 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002261 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2262
2263 " Pressing <S-Tab> should open the popup menu with the last entry selected
2264 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002265 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2266
2267 " Pressing <Esc> should close the popup menu and cancel the cmd line
2268 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002269 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2270
2271 " Typing a character when the popup is open, should close the popup
2272 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002273 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2274
2275 " When the popup is open, entering the cmdline window should close the popup
2276 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002277 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2278 call term_sendkeys(buf, ":q\<CR>")
2279
2280 " After the last popup menu item, <C-N> should show the original string
2281 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002282 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2283
2284 " Use the popup menu for the command name
2285 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002286 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2287
2288 " Pressing the left arrow should remove the popup menu
2289 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002290 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2291
2292 " Pressing <BS> should remove the popup menu and erase the last character
2293 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002294 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2295
2296 " Pressing <C-W> should remove the popup menu and erase the previous word
2297 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002298 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2299
2300 " Pressing <C-U> should remove the popup menu and erase the entire line
2301 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2303
2304 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2305 " the cmdline from history
2306 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002307 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2308
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002309 " Check "list" still works
2310 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2311 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002312 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2313 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002314 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2315
rbtnn68cc2b82022-02-09 11:55:47 +00002316 " Tests a directory name contained full-width characters.
2317 call mkdir('Xdir/あいう', 'p')
2318 call writefile([], 'Xdir/あいう/abc')
2319 call writefile([], 'Xdir/あいう/xyz')
2320 call writefile([], 'Xdir/あいう/123')
2321
2322 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2323 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002324 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2325
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002326 " Pressing <C-A> when the popup menu is displayed should list all the
2327 " matches and pressing a key after that should remove the popup menu
2328 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2329 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2331
2332 " Pressing <C-A> when the popup menu is displayed should list all the
2333 " matches and pressing <Left> after that should move the cursor
2334 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2335 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2336 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2337
2338 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2339 " should be displayed correctly on the screen.
2340 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2341 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2342
2343 " After using <C-A> to expand all the filename matches, pressing <Up>
2344 " should not open the popup menu again.
2345 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2346 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2348 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2349
2350 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2351 " crash Vim
2352 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2354
Bram Moolenaar414acd32022-02-10 21:09:45 +00002355 " After removing the pum the command line is redrawn
2356 call term_sendkeys(buf, ":edit foo\<CR>")
2357 call term_sendkeys(buf, ":edit bar\<CR>")
2358 call term_sendkeys(buf, ":ls\<CR>")
2359 call term_sendkeys(buf, ":com\<Tab> ")
2360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002361 call term_sendkeys(buf, "\<C-U>\<CR>")
2362
2363 " Esc still works to abort the command when 'statusline' is set
2364 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2365 call term_sendkeys(buf, ":si\<Tab>")
2366 call term_sendkeys(buf, "\<Esc>")
2367 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002368
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002369 " Esc still works to abort the command when 'tabline' is set
2370 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2371 call term_sendkeys(buf, ":si\<Tab>")
2372 call term_sendkeys(buf, "\<Esc>")
2373 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2374
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002375 call term_sendkeys(buf, "\<C-U>\<CR>")
2376 call StopVimInTerminal(buf)
2377 call delete('Xtest')
2378 call delete('Xdir', 'rf')
2379endfunc
2380
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002381" Test for wildmenumode() with the cmdline popup menu
2382func Test_wildmenumode_with_pum()
2383 set wildmenu
2384 set wildoptions=pum
2385 cnoremap <expr> <F2> wildmenumode()
2386 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2387 call assert_equal('"sign define10', @:)
2388 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2389 call assert_equal('"sign define jump list place undefine unplace0', @:)
2390 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2391 call assert_equal('"sign 0', @:)
2392 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2393 call assert_equal('"sign define0', @:)
2394 set nowildmenu wildoptions&
2395 cunmap <F2>
2396endfunc
2397
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002398" Test for completion after a :substitute command followed by a pipe (|)
2399" character
2400func Test_cmdline_complete_substitute()
2401 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2402 call assert_equal("\"s | \t", @:)
2403 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2404 call assert_equal("\"s/ | \t", @:)
2405 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2406 call assert_equal("\"s/one | \t", @:)
2407 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2408 call assert_equal("\"s/one/ | \t", @:)
2409 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2410 call assert_equal("\"s/one/two | \t", @:)
2411 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2412 call assert_equal('"s/one/two/ | chistory', @:)
2413 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2414 call assert_equal("\"s/one/two/g \t", @:)
2415 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2416 call assert_equal("\"s/one/two/g | chistory", @:)
2417 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2418 call assert_equal("\"s/one/t\\/ | \t", @:)
2419 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2420 call assert_equal('"s/one/t"o/ | chistory', @:)
2421 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2422 call assert_equal('"s/one/t|o/ | chistory', @:)
2423 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2424 call assert_equal("\"&\t", @:)
2425endfunc
2426
2427" Test for the :dlist command completion
2428func Test_cmdline_complete_dlist()
2429 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2430 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2431 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2432 call assert_equal("\"dlist 10 /pat/ \t", @:)
2433 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2434 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2435 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2436 call assert_equal("\"dlist 10 /pat\\\t", @:)
2437 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2438 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2439endfunc
2440
Bram Moolenaar309976e2019-12-05 18:16:33 +01002441" vim: shiftwidth=2 sts=2 expandtab