blob: d7a8c4a3fcffcadfcfcc5d83456ae6252c9de16e [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
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00001577func Test_cmdwin_tabpage()
1578 tabedit
1579 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1580 tabclose!
1581endfunc
1582
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001583func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001584 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001585 CheckScreendump
1586
1587 " aborting the :smile output caused the cmdline window to use the current
1588 " buffer.
1589 let lines =<< trim [SCRIPT]
1590 au WinNew * smile
1591 [SCRIPT]
1592 call writefile(lines, 'XTest_cmdwin')
1593
1594 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001595 " open cmdwin
1596 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001597 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001598 " quit more prompt for :smile command
1599 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001600 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001601 " execute a simple command
1602 call term_sendkeys(buf, "aecho 'done'\<CR>")
1603 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1604
1605 " clean up
1606 call StopVimInTerminal(buf)
1607 call delete('XTest_cmdwin')
1608endfunc
1609
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001610" Test for backtick expression in the command line
1611func Test_cmd_backtick()
1612 %argd
1613 argadd `=['a', 'b', 'c']`
1614 call assert_equal(['a', 'b', 'c'], argv())
1615 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001616
1617 argadd `echo abc def`
1618 call assert_equal(['abc def'], argv())
1619 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001620endfunc
1621
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001622" Test for the :! command
1623func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001624 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001625
1626 let lines =<< trim [SCRIPT]
1627 " Test for no previous command
1628 call assert_fails('!!', 'E34:')
1629 set nomore
1630 " Test for cmdline expansion with :!
1631 call setline(1, 'foo!')
1632 silent !echo <cWORD> > Xfile.out
1633 call assert_equal(['foo!'], readfile('Xfile.out'))
1634 " Test for using previous command
1635 silent !echo \! !
1636 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1637 call writefile(v:errors, 'Xresult')
1638 call delete('Xfile.out')
1639 qall!
1640 [SCRIPT]
1641 call writefile(lines, 'Xscript')
1642 if RunVim([], [], '--clean -S Xscript')
1643 call assert_equal([], readfile('Xresult'))
1644 endif
1645 call delete('Xscript')
1646 call delete('Xresult')
1647endfunc
1648
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001649" Test error: "E135: *Filter* Autocommands must not change current buffer"
1650func Test_cmd_bang_E135()
1651 new
1652 call setline(1, ['a', 'b', 'c', 'd'])
1653 augroup test_cmd_filter_E135
1654 au!
1655 autocmd FilterReadPost * help
1656 augroup END
1657 call assert_fails('2,3!echo "x"', 'E135:')
1658
1659 augroup test_cmd_filter_E135
1660 au!
1661 augroup END
1662 %bwipe!
1663endfunc
1664
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001665" Test for using ~ for home directory in cmdline completion matches
1666func Test_cmdline_expand_home()
1667 call mkdir('Xdir')
1668 call writefile([], 'Xdir/Xfile1')
1669 call writefile([], 'Xdir/Xfile2')
1670 cd Xdir
1671 let save_HOME = $HOME
1672 let $HOME = getcwd()
1673 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1674 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1675 let $HOME = save_HOME
1676 cd ..
1677 call delete('Xdir', 'rf')
1678endfunc
1679
Bram Moolenaar578fe942020-02-27 21:32:51 +01001680" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1681" or insert mode (when 'insertmode' is set)
1682func Test_cmdline_ctrl_g()
1683 new
1684 call setline(1, 'abc')
1685 call cursor(1, 3)
1686 " If command line is entered from insert mode, using C-\ C-G should back to
1687 " insert mode
1688 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1689 call assert_equal('abxyc', getline(1))
1690 call assert_equal(4, col('.'))
1691
1692 " If command line is entered in 'insertmode', using C-\ C-G should back to
1693 " 'insertmode'
1694 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1695 call assert_equal('ab12xyc', getline(1))
1696 close!
1697endfunc
1698
Bram Moolenaar578fe942020-02-27 21:32:51 +01001699" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001700func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001701 func T(a, c, p)
1702 return "oneA\noneB\noneC"
1703 endfunc
1704 command -nargs=1 -complete=custom,T MyCmd
1705
Bram Moolenaar578fe942020-02-27 21:32:51 +01001706 set nowildmenu
1707 set wildmode=full,list
1708 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001709 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001710 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001711 call assert_equal('"MyCmd oneA', @:)
1712
1713 set wildmode=longest,full
1714 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1715 call assert_equal('"MyCmd one', @:)
1716 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1717 call assert_equal('"MyCmd oneC', @:)
1718
1719 set wildmode=longest
1720 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1721 call assert_equal('"MyCmd one', @:)
1722
1723 set wildmode=list:longest
1724 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001725 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001726 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001727 call assert_equal('"MyCmd one', @:)
1728
1729 set wildmode=""
1730 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1731 call assert_equal('"MyCmd oneA', @:)
1732
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001733 " Test for wildmode=longest with 'fileignorecase' set
1734 set wildmode=longest
1735 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001736 argadd AAA AAAA AAAAA
1737 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1738 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001739 set fileignorecase&
1740
1741 " Test for listing files with wildmode=list
1742 set wildmode=list
1743 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001744 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001745 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001746 call assert_equal('"b A', @:)
1747
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001748 " when using longest completion match, matches shorter than the argument
1749 " should be ignored (happens with :help)
1750 set wildmode=longest,full
1751 set wildmenu
1752 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1753 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001754 " non existing file
1755 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1756 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001757 set wildmenu&
1758
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001759 " Test for longest file name completion with 'fileignorecase'
1760 " On MS-Windows, file names are case insensitive.
1761 if has('unix')
1762 call writefile([], 'XTESTfoo')
1763 call writefile([], 'Xtestbar')
1764 set nofileignorecase
1765 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"e XTESTfoo', @:)
1767 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1768 call assert_equal('"e Xtestbar', @:)
1769 set fileignorecase
1770 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1771 call assert_equal('"e Xtest', @:)
1772 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1773 call assert_equal('"e Xtest', @:)
1774 set fileignorecase&
1775 call delete('XTESTfoo')
1776 call delete('Xtestbar')
1777 endif
1778
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001779 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001780 delcommand MyCmd
1781 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001782 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001783 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001784endfunc
1785
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001786func Test_wildmode()
1787 " Test with utf-8 encoding
1788 call Wildmode_tests()
1789
1790 " Test with latin1 encoding
1791 let save_encoding = &encoding
1792 set encoding=latin1
1793 call Wildmode_tests()
1794 let &encoding = save_encoding
1795endfunc
1796
Bram Moolenaar578fe942020-02-27 21:32:51 +01001797" Test for interrupting the command-line completion
1798func Test_interrupt_compl()
1799 func F(lead, cmdl, p)
1800 if a:lead =~ 'tw'
1801 call interrupt()
1802 return
1803 endif
1804 return "one\ntwo\nthree"
1805 endfunc
1806 command -nargs=1 -complete=custom,F Tcmd
1807
1808 set nowildmenu
1809 set wildmode=full
1810 let interrupted = 0
1811 try
1812 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1813 catch /^Vim:Interrupt$/
1814 let interrupted = 1
1815 endtry
1816 call assert_equal(1, interrupted)
1817
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001818 let interrupted = 0
1819 try
1820 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1821 catch /^Vim:Interrupt$/
1822 let interrupted = 1
1823 endtry
1824 call assert_equal(1, interrupted)
1825
Bram Moolenaar578fe942020-02-27 21:32:51 +01001826 delcommand Tcmd
1827 delfunc F
1828 set wildmode&
1829endfunc
1830
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001831" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001832func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001833 let str = ":one two\<C-U>"
1834 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001835 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001836 let str ..= "\<Left>five\<Right>"
1837 let str ..= "\<Home>two "
1838 let str ..= "\<C-Left>one "
1839 let str ..= "\<C-Right> three"
1840 let str ..= "\<End>\<S-Left>four "
1841 let str ..= "\<S-Right> six"
1842 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1843 call feedkeys(str, 'xt')
1844 call assert_equal("\"one two three four five six seven", @:)
1845endfunc
1846
1847" Test for moving the cursor on the / command line in 'rightleft' mode
1848func Test_cmdline_edit_rightleft()
1849 CheckFeature rightleft
1850 set rightleft
1851 set rightleftcmd=search
1852 let str = "/one two\<C-U>"
1853 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001854 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001855 let str ..= "\<Right>five\<Left>"
1856 let str ..= "\<Home>two "
1857 let str ..= "\<C-Right>one "
1858 let str ..= "\<C-Left> three"
1859 let str ..= "\<End>\<S-Right>four "
1860 let str ..= "\<S-Left> six"
1861 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1862 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1863 call assert_equal("\"one two three four five six seven", @/)
1864 set rightleftcmd&
1865 set rightleft&
1866endfunc
1867
1868" Test for using <C-\>e in the command line to evaluate an expression
1869func Test_cmdline_expr()
1870 " Evaluate an expression from the beginning of a command line
1871 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1872 call assert_equal('"hello', @:)
1873
1874 " Use an invalid expression for <C-\>e
1875 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1876
1877 " Insert literal <CTRL-\> in the command line
1878 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1879 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001880endfunc
1881
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001882" Test for 'imcmdline' and 'imsearch'
1883" This test doesn't actually test the input method functionality.
1884func Test_cmdline_inputmethod()
1885 new
1886 call setline(1, ['', 'abc', ''])
1887 set imcmdline
1888
1889 call feedkeys(":\"abc\<CR>", 'xt')
1890 call assert_equal("\"abc", @:)
1891 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1892 call assert_equal("\"abc", @:)
1893 call feedkeys("/abc\<CR>", 'xt')
1894 call assert_equal([2, 1], [line('.'), col('.')])
1895 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1896 call assert_equal([2, 1], [line('.'), col('.')])
1897
1898 set imsearch=2
1899 call cursor(1, 1)
1900 call feedkeys("/abc\<CR>", 'xt')
1901 call assert_equal([2, 1], [line('.'), col('.')])
1902 call cursor(1, 1)
1903 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1904 call assert_equal([2, 1], [line('.'), col('.')])
1905 set imdisable
1906 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1907 call assert_equal([2, 1], [line('.'), col('.')])
1908 set imdisable&
1909 set imsearch&
1910
1911 set imcmdline&
1912 %bwipe!
1913endfunc
1914
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001915" Test for recursively getting multiple command line inputs
1916func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001917 CheckFeature cmdwin
1918
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001919 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1920 call assert_equal('"cyan', @:)
1921endfunc
1922
1923" Test for using CTRL-_ in the command line with 'allowrevins'
1924func Test_cmdline_revins()
1925 CheckNotMSWindows
1926 CheckFeature rightleft
1927 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1928 call assert_equal("\"abc\<c-_>", @:)
1929 set allowrevins
1930 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1931 call assert_equal('"abcñèæ', @:)
1932 set allowrevins&
1933endfunc
1934
1935" Test for typing UTF-8 composing characters in the command line
1936func Test_cmdline_composing_chars()
1937 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1938 call assert_equal('"ゔ', @:)
1939endfunc
1940
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001941" Test for normal mode commands not supported in the cmd window
1942func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001943 CheckFeature cmdwin
1944
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001945 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1946 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1947 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1948 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1949 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1950 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001951 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1952 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1953 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1954 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1955 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1956 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1957 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1958 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1959 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1960 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1961 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1962 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1963 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1964 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1965 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1966 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1967 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1968 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1969 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1970 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1971 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001972endfunc
1973
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001974" Close the Cmd-line window in insert mode using CTRL-C
1975func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001976 CheckFeature cmdwin
1977
Bram Moolenaarca68ae12020-03-30 19:32:53 +02001978 %bw!
1979 let s = ''
1980 exe "normal q:a\<C-C>let s='Hello'\<CR>"
1981 call assert_equal('Hello', s)
1982 call assert_equal(1, winnr('$'))
1983endfunc
1984
Bram Moolenaar0e717042020-04-27 19:29:01 +02001985" test that ";" works to find a match at the start of the first line
1986func Test_zero_line_search()
1987 new
1988 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1989 call cursor(1,1)
1990 0;/pattern/d
1991 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1992 q!
1993endfunc
1994
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001995func Test_read_shellcmd()
1996 CheckUnix
1997 if executable('ls')
1998 " There should be ls in the $PATH
1999 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2000 call assert_match('^"r! .*\<ls\>', @:)
2001 endif
2002
2003 if executable('rm')
2004 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2005 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2006 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002007
2008 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2009 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2010 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002011 endif
2012endfunc
2013
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002014" Test for going up and down the directory tree using 'wildmenu'
2015func Test_wildmenu_dirstack()
2016 CheckUnix
2017 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002018 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002019 call writefile([], 'Xdir1/file1_1.txt')
2020 call writefile([], 'Xdir1/file1_2.txt')
2021 call writefile([], 'Xdir1/dir2/file2_1.txt')
2022 call writefile([], 'Xdir1/dir2/file2_2.txt')
2023 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2024 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002025 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2026 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002027 set wildmenu
2028
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002029 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002030 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002031 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002032 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002033 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002034 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002035 call assert_equal('"e ../../dir3/', @:)
2036 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2037 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002038 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002039 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002040 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002041 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002042 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002043 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2044 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2045
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002046 call delete('Xdir1', 'rf')
2047 set wildmenu&
2048endfunc
2049
obcat71c6f7a2021-05-13 20:23:10 +02002050" Test for recalling newer or older cmdline from history with <Up>, <Down>,
2051" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
2052func Test_recalling_cmdline()
2053 CheckFeature cmdline_hist
2054
2055 let g:cmdlines = []
2056 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2057
2058 let histories = [
2059 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
2060 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
2061 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
2062 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
2063 "\ TODO: {'name': 'debug', ...}
2064 \]
2065 let keypairs = [
2066 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
2067 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
2068 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
2069 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
2070 \]
2071 let prefix = 'vi'
2072 for h in histories
2073 call histadd(h.name, 'vim')
2074 call histadd(h.name, 'virtue')
2075 call histadd(h.name, 'Virgo')
2076 call histadd(h.name, 'vogue')
2077 call histadd(h.name, 'emacs')
2078 for k in keypairs
2079 let g:cmdlines = []
2080 let keyseqs = h.enter
2081 \ .. prefix
2082 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2083 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2084 \ .. h.exit
2085 call feedkeys(keyseqs, 'xt')
2086 call histdel(h.name, -1) " delete the history added by feedkeys above
2087 let expect = k.prefixmatch
2088 \ ? ['virtue', 'vim', 'virtue', prefix]
2089 \ : ['emacs', 'vogue', 'emacs', prefix]
2090 call assert_equal(expect, g:cmdlines)
2091 endfor
2092 endfor
2093
2094 unlet g:cmdlines
2095 cunmap <Plug>(save-cmdline)
2096endfunc
2097
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002098func Test_cmd_map_cmdlineChanged()
2099 let g:log = []
2100 cnoremap <F1> l<Cmd><CR>s
2101 augroup test
2102 autocmd!
2103 autocmd CmdlineChanged : let g:log += [getcmdline()]
2104 augroup END
2105
2106 call feedkeys(":\<F1>\<CR>", 'xt')
2107 call assert_equal(['l', 'ls'], g:log)
2108
Bram Moolenaar796139a2021-05-18 21:38:45 +02002109 let @b = 'b'
2110 cnoremap <F1> a<C-R>b
2111 let g:log = []
2112 call feedkeys(":\<F1>\<CR>", 'xt')
2113 call assert_equal(['a', 'ab'], g:log)
2114
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002115 unlet g:log
2116 cunmap <F1>
2117 augroup test
2118 autocmd!
2119 augroup END
2120endfunc
2121
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002122" Test for the 'suffixes' option
2123func Test_suffixes_opt()
2124 call writefile([], 'Xfile')
2125 call writefile([], 'Xfile.c')
2126 call writefile([], 'Xfile.o')
2127 set suffixes=
2128 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2129 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002130 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2131 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002132 set suffixes=.c
2133 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2134 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002135 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2136 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002137 set suffixes=,,
2138 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2139 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002140 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2141 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002142 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002143 " Test for getcompletion() with different patterns
2144 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2145 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002146 call delete('Xfile')
2147 call delete('Xfile.c')
2148 call delete('Xfile.o')
2149endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002150
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002151" Test for using a popup menu for the command line completion matches
2152" (wildoptions=pum)
2153func Test_wildmenu_pum()
2154 CheckRunVimInTerminal
2155
2156 let commands =<< trim [CODE]
2157 set wildmenu
2158 set wildoptions=pum
2159 set shm+=I
2160 set noruler
2161 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002162
2163 func CmdCompl(a, b, c)
2164 return repeat(['aaaa'], 120)
2165 endfunc
2166 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002167
2168 func MyStatusLine() abort
2169 return 'status'
2170 endfunc
2171 func SetupStatusline()
2172 set statusline=%!MyStatusLine()
2173 set laststatus=2
2174 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002175
2176 func MyTabLine()
2177 return 'my tab line'
2178 endfunc
2179 func SetupTabline()
2180 set statusline=
2181 set tabline=%!MyTabLine()
2182 set showtabline=2
2183 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002184
2185 func DoFeedKeys()
2186 let &wildcharm = char2nr("\t")
2187 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2188 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002189 [CODE]
2190 call writefile(commands, 'Xtest')
2191
2192 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2193
2194 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002195 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2196
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002197 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002198 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002199 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2200
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002201 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002202 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002203 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2204
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002205 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002206 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002207 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2208
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002209 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002210 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002211 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2212
2213 " pressing <C-E> should end completion and go back to the original match
2214 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002215 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2216
2217 " pressing <C-Y> should select the current match and end completion
2218 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002219 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2220
2221 " With 'wildmode' set to 'longest,full', completing a match should display
2222 " the longest match, the wildmenu should not be displayed.
2223 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2224 call TermWait(buf)
2225 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002226 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2227
2228 " pressing <Tab> should display the wildmenu
2229 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002230 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2231
2232 " pressing <Tab> second time should select the next entry in the menu
2233 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2235
2236 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002237 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002238 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002239 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2240
2241 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002242 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2243
2244 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002245 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2246
2247 " Directory name completion
2248 call mkdir('Xdir/XdirA/XdirB', 'p')
2249 call writefile([], 'Xdir/XfileA')
2250 call writefile([], 'Xdir/XdirA/XfileB')
2251 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2252
2253 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002254 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2255
2256 " Pressing <Right> on a directory name should go into that directory
2257 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2259
2260 " Pressing <Left> on a directory name should go to the parent directory
2261 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002262 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2263
2264 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002265 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2268
2269 " Pressing <C-D> when the popup menu is displayed should remove the popup
2270 " menu
2271 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002272 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2273
2274 " Pressing <S-Tab> should open the popup menu with the last entry selected
2275 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002276 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2277
2278 " Pressing <Esc> should close the popup menu and cancel the cmd line
2279 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002280 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2281
2282 " Typing a character when the popup is open, should close the popup
2283 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002284 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2285
2286 " When the popup is open, entering the cmdline window should close the popup
2287 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002288 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2289 call term_sendkeys(buf, ":q\<CR>")
2290
2291 " After the last popup menu item, <C-N> should show the original string
2292 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002293 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2294
2295 " Use the popup menu for the command name
2296 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002297 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2298
2299 " Pressing the left arrow should remove the popup menu
2300 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002301 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2302
2303 " Pressing <BS> should remove the popup menu and erase the last character
2304 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002305 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2306
2307 " Pressing <C-W> should remove the popup menu and erase the previous word
2308 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2310
2311 " Pressing <C-U> should remove the popup menu and erase the entire line
2312 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2314
2315 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2316 " the cmdline from history
2317 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2319
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002320 " Check "list" still works
2321 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2322 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002323 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2324 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002325 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2326
rbtnn68cc2b82022-02-09 11:55:47 +00002327 " Tests a directory name contained full-width characters.
2328 call mkdir('Xdir/あいう', 'p')
2329 call writefile([], 'Xdir/あいう/abc')
2330 call writefile([], 'Xdir/あいう/xyz')
2331 call writefile([], 'Xdir/あいう/123')
2332
2333 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2334 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002335 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2336
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002337 " Pressing <C-A> when the popup menu is displayed should list all the
2338 " matches and pressing a key after that should remove the popup menu
2339 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2340 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2341 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2342
2343 " Pressing <C-A> when the popup menu is displayed should list all the
2344 " matches and pressing <Left> after that should move the cursor
2345 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2346 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2348
2349 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2350 " should be displayed correctly on the screen.
2351 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2353
2354 " After using <C-A> to expand all the filename matches, pressing <Up>
2355 " should not open the popup menu again.
2356 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2357 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2358 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2359 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2360
2361 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2362 " crash Vim
2363 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2364 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2365
Bram Moolenaar414acd32022-02-10 21:09:45 +00002366 " After removing the pum the command line is redrawn
2367 call term_sendkeys(buf, ":edit foo\<CR>")
2368 call term_sendkeys(buf, ":edit bar\<CR>")
2369 call term_sendkeys(buf, ":ls\<CR>")
2370 call term_sendkeys(buf, ":com\<Tab> ")
2371 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002372 call term_sendkeys(buf, "\<C-U>\<CR>")
2373
2374 " Esc still works to abort the command when 'statusline' is set
2375 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2376 call term_sendkeys(buf, ":si\<Tab>")
2377 call term_sendkeys(buf, "\<Esc>")
2378 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002379
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002380 " Esc still works to abort the command when 'tabline' is set
2381 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2382 call term_sendkeys(buf, ":si\<Tab>")
2383 call term_sendkeys(buf, "\<Esc>")
2384 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2385
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002386 " popup is cleared also when 'lazyredraw' is set
2387 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2388 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2389 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2390 call term_sendkeys(buf, "\<Esc>")
2391
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002392 call term_sendkeys(buf, "\<C-U>\<CR>")
2393 call StopVimInTerminal(buf)
2394 call delete('Xtest')
2395 call delete('Xdir', 'rf')
2396endfunc
2397
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002398" Test for wildmenumode() with the cmdline popup menu
2399func Test_wildmenumode_with_pum()
2400 set wildmenu
2401 set wildoptions=pum
2402 cnoremap <expr> <F2> wildmenumode()
2403 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2404 call assert_equal('"sign define10', @:)
2405 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2406 call assert_equal('"sign define jump list place undefine unplace0', @:)
2407 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2408 call assert_equal('"sign 0', @:)
2409 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2410 call assert_equal('"sign define0', @:)
2411 set nowildmenu wildoptions&
2412 cunmap <F2>
2413endfunc
2414
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002415" Test for completion after a :substitute command followed by a pipe (|)
2416" character
2417func Test_cmdline_complete_substitute()
2418 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2419 call assert_equal("\"s | \t", @:)
2420 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2421 call assert_equal("\"s/ | \t", @:)
2422 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2423 call assert_equal("\"s/one | \t", @:)
2424 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2425 call assert_equal("\"s/one/ | \t", @:)
2426 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2427 call assert_equal("\"s/one/two | \t", @:)
2428 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2429 call assert_equal('"s/one/two/ | chistory', @:)
2430 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2431 call assert_equal("\"s/one/two/g \t", @:)
2432 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2433 call assert_equal("\"s/one/two/g | chistory", @:)
2434 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2435 call assert_equal("\"s/one/t\\/ | \t", @:)
2436 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2437 call assert_equal('"s/one/t"o/ | chistory', @:)
2438 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2439 call assert_equal('"s/one/t|o/ | chistory', @:)
2440 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2441 call assert_equal("\"&\t", @:)
2442endfunc
2443
2444" Test for the :dlist command completion
2445func Test_cmdline_complete_dlist()
2446 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2447 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2448 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2449 call assert_equal("\"dlist 10 /pat/ \t", @:)
2450 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2451 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2452 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2453 call assert_equal("\"dlist 10 /pat\\\t", @:)
2454 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2455 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2456endfunc
2457
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002458" Test for 'fuzzy' in 'wildoptions' (fuzzy completion)
2459func Test_wildoptions_fuzzy()
2460 " argument list (only for :argdel)
2461 argadd change.py count.py charge.py
2462 set wildoptions&
2463 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2464 call assert_equal('"argdel cge', @:)
2465 set wildoptions=fuzzy
2466 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2467 call assert_equal('"argdel change.py charge.py', @:)
2468 %argdelete
2469
2470 " autocmd group name fuzzy completion
2471 set wildoptions&
2472 augroup MyFuzzyGroup
2473 augroup END
2474 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2475 call assert_equal('"augroup mfg', @:)
2476 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2477 call assert_equal('"augroup MyFuzzyGroup', @:)
2478 set wildoptions=fuzzy
2479 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2480 call assert_equal('"augroup MyFuzzyGroup', @:)
2481 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2482 call assert_equal('"augroup My*p', @:)
2483 augroup! MyFuzzyGroup
2484
2485 " buffer name fuzzy completion
2486 set wildoptions&
2487 edit SomeFile.txt
2488 enew
2489 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2490 call assert_equal('"b SF', @:)
2491 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2492 call assert_equal('"b SomeFile.txt', @:)
2493 set wildoptions=fuzzy
2494 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2495 call assert_equal('"b SomeFile.txt', @:)
2496 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2497 call assert_equal('"b S*File.txt', @:)
2498 %bw!
2499
2500 " buffer name (full path) fuzzy completion
2501 if has('unix')
2502 set wildoptions&
2503 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2504 edit Xcmd/Xstate/Xfile.js
2505 cd Xcmd/Xstate
2506 enew
2507 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2508 call assert_equal('"b CmdStateFile', @:)
2509 set wildoptions=fuzzy
2510 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2511 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2512 cd -
2513 call delete('Xcmd', 'rf')
2514 endif
2515
2516 " :behave suboptions fuzzy completion
2517 set wildoptions&
2518 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2519 call assert_equal('"behave xm', @:)
2520 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2521 call assert_equal('"behave xterm', @:)
2522 set wildoptions=fuzzy
2523 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2524 call assert_equal('"behave xterm', @:)
2525 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2526 call assert_equal('"behave xt*m', @:)
2527 let g:Sline = ''
2528 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2529 call assert_equal('mswin', g:Sline)
2530 call assert_equal('"behave win', @:)
2531
2532 " colorscheme name fuzzy completion - NOT supported
2533
2534 " built-in command name fuzzy completion
2535 set wildoptions&
2536 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2537 call assert_equal('"sbwin', @:)
2538 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2539 call assert_equal('"sbrewind', @:)
2540 set wildoptions=fuzzy
2541 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2542 call assert_equal('"sbrewind', @:)
2543 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2544 call assert_equal('"sbr*d', @:)
2545
2546 " compiler name fuzzy completion - NOT supported
2547
2548 " :cscope suboptions fuzzy completion
2549 if has('cscope')
2550 set wildoptions&
2551 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2552 call assert_equal('"cscope ret', @:)
2553 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2554 call assert_equal('"cscope reset', @:)
2555 set wildoptions=fuzzy
2556 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2557 call assert_equal('"cscope reset', @:)
2558 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2559 call assert_equal('"cscope re*t', @:)
2560 endif
2561
2562 " :diffget/:diffput buffer name fuzzy completion
2563 new SomeBuffer
2564 diffthis
2565 new OtherBuffer
2566 diffthis
2567 set wildoptions&
2568 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2569 call assert_equal('"diffget sbuf', @:)
2570 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2571 call assert_equal('"diffput sbuf', @:)
2572 set wildoptions=fuzzy
2573 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2574 call assert_equal('"diffget SomeBuffer', @:)
2575 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2576 call assert_equal('"diffput SomeBuffer', @:)
2577 %bw!
2578
2579 " directory name fuzzy completion - NOT supported
2580
2581 " environment variable name fuzzy completion
2582 set wildoptions&
2583 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2584 call assert_equal('"echo $VUT', @:)
2585 set wildoptions=fuzzy
2586 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2587 call assert_equal('"echo $VIMRUNTIME', @:)
2588
2589 " autocmd event fuzzy completion
2590 set wildoptions&
2591 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2592 call assert_equal('"autocmd BWout', @:)
2593 set wildoptions=fuzzy
2594 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2595 call assert_equal('"autocmd BufWipeout', @:)
2596
2597 " vim expression fuzzy completion
2598 let g:PerPlaceCount = 10
2599 set wildoptions&
2600 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"let c = ppc', @:)
2602 set wildoptions=fuzzy
2603 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2604 call assert_equal('"let c = PerPlaceCount', @:)
2605
2606 " file name fuzzy completion - NOT supported
2607
2608 " files in path fuzzy completion - NOT supported
2609
2610 " filetype name fuzzy completion - NOT supported
2611
2612 " user defined function name completion
2613 set wildoptions&
2614 call feedkeys(":call Test_w_fuz\<Tab>\<C-B>\"\<CR>", 'tx')
2615 call assert_equal('"call Test_w_fuz', @:)
2616 set wildoptions=fuzzy
2617 call feedkeys(":call Test_w_fuz\<Tab>\<C-B>\"\<CR>", 'tx')
2618 call assert_equal('"call Test_wildoptions_fuzzy()', @:)
2619
2620 " user defined command name completion
2621 set wildoptions&
2622 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2623 call assert_equal('"MsFeat', @:)
2624 set wildoptions=fuzzy
2625 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2626 call assert_equal('"MissingFeature', @:)
2627
2628 " :help tag fuzzy completion - NOT supported
2629
2630 " highlight group name fuzzy completion
2631 set wildoptions&
2632 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2633 call assert_equal('"highlight SKey', @:)
2634 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2635 call assert_equal('"highlight SpecialKey', @:)
2636 set wildoptions=fuzzy
2637 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2638 call assert_equal('"highlight SpecialKey', @:)
2639 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2640 call assert_equal('"highlight Sp*Key', @:)
2641
2642 " :history suboptions fuzzy completion
2643 set wildoptions&
2644 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2645 call assert_equal('"history dg', @:)
2646 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2647 call assert_equal('"history search', @:)
2648 set wildoptions=fuzzy
2649 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2650 call assert_equal('"history debug', @:)
2651 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2652 call assert_equal('"history se*h', @:)
2653
2654 " :language locale name fuzzy completion
2655 if has('unix')
2656 set wildoptions&
2657 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('"lang psx', @:)
2659 set wildoptions=fuzzy
2660 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2661 call assert_equal('"lang POSIX', @:)
2662 endif
2663
2664 " :mapclear buffer argument fuzzy completion
2665 set wildoptions&
2666 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2667 call assert_equal('"mapclear buf', @:)
2668 set wildoptions=fuzzy
2669 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2670 call assert_equal('"mapclear <buffer>', @:)
2671
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002672 " map name fuzzy completion
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002673 " test regex completion works
2674 set wildoptions=fuzzy
2675 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002677 nmap <plug>MyLongMap :p<CR>
2678 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2679 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2680 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal("\"nmap MLM \t", @:)
2682 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2683 call assert_equal("\"nmap <F2> one two \t", @:)
2684 " duplicate entries should be removed
2685 vmap <plug>MyLongMap :<C-U>#<CR>
2686 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2687 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2688 nunmap <plug>MyLongMap
2689 vunmap <plug>MyLongMap
2690 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2691 call assert_equal("\"nmap ABC\t", @:)
2692 " results should be sorted by best match
2693 nmap <Plug>format :
2694 nmap <Plug>goformat :
2695 nmap <Plug>TestFOrmat :
2696 nmap <Plug>fendoff :
2697 nmap <Plug>state :
2698 nmap <Plug>FendingOff :
2699 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2700 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2701 nunmap <Plug>format
2702 nunmap <Plug>goformat
2703 nunmap <Plug>TestFOrmat
2704 nunmap <Plug>fendoff
2705 nunmap <Plug>state
2706 nunmap <Plug>FendingOff
2707
2708 " abbreviation fuzzy completion
2709 set wildoptions=fuzzy
2710 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2711 call assert_equal("\"iabbr <nowait>", @:)
2712 iabbr WaitForCompletion WFC
2713 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2714 call assert_equal("\"iabbr WaitForCompletion", @:)
2715 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2716 call assert_equal("\"iabbr a1z\t", @:)
2717 iunabbrev WaitForCompletion
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002718
2719 " menu name fuzzy completion
2720 if has('gui_running')
2721 set wildoptions&
2722 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal('"menu pup', @:)
2724 set wildoptions=fuzzy
2725 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2726 call assert_equal('"menu PopUp.', @:)
2727 endif
2728
2729 " :messages suboptions fuzzy completion
2730 set wildoptions&
2731 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2732 call assert_equal('"messages clr', @:)
2733 set wildoptions=fuzzy
2734 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2735 call assert_equal('"messages clear', @:)
2736
2737 " :set option name fuzzy completion
2738 set wildoptions&
2739 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2740 call assert_equal('"set brkopt', @:)
2741 set wildoptions=fuzzy
2742 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2743 call assert_equal('"set breakindentopt', @:)
2744 set wildoptions&
2745 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2746 call assert_equal('"set fixendofline', @:)
2747 set wildoptions=fuzzy
2748 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2749 call assert_equal('"set fixendofline', @:)
2750
2751 " :set <term_option>
2752 set wildoptions&
2753 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2754 call assert_equal('"set t_EC', @:)
2755 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2756 call assert_equal('"set <t_EC>', @:)
2757 set wildoptions=fuzzy
2758 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2759 call assert_equal('"set t_EC', @:)
2760 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal('"set <t_EC>', @:)
2762
2763 " :packadd directory name fuzzy completion - NOT supported
2764
2765 " shell command name fuzzy completion - NOT supported
2766
2767 " :sign suboptions fuzzy completion
2768 set wildoptions&
2769 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal('"sign ufe', @:)
2771 set wildoptions=fuzzy
2772 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2773 call assert_equal('"sign undefine', @:)
2774
2775 " :syntax suboptions fuzzy completion
2776 set wildoptions&
2777 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2778 call assert_equal('"syntax kwd', @:)
2779 set wildoptions=fuzzy
2780 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2781 call assert_equal('"syntax keyword', @:)
2782
2783 " syntax group name fuzzy completion
2784 set wildoptions&
2785 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2786 call assert_equal('"syntax list mpar', @:)
2787 set wildoptions=fuzzy
2788 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2789 call assert_equal('"syntax list MatchParen', @:)
2790
2791 " :syntime suboptions fuzzy completion
2792 if has('profile')
2793 set wildoptions&
2794 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal('"syntime clr', @:)
2796 set wildoptions=fuzzy
2797 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2798 call assert_equal('"syntime clear', @:)
2799 endif
2800
2801 " tag name fuzzy completion - NOT supported
2802
2803 " tag name and file fuzzy completion - NOT supported
2804
2805 " user names fuzzy completion - how to test this functionality?
2806
2807 " user defined variable name fuzzy completion
2808 let g:SomeVariable=10
2809 set wildoptions&
2810 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2811 call assert_equal('"let SVar', @:)
2812 set wildoptions=fuzzy
2813 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2814 call assert_equal('"let SomeVariable', @:)
2815
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002816 " Test for sorting the results by the best match
2817 %bw!
2818 command T123format :
2819 command T123goformat :
2820 command T123TestFOrmat :
2821 command T123fendoff :
2822 command T123state :
2823 command T123FendingOff :
2824 set wildoptions=fuzzy
2825 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2827 delcommand T123format
2828 delcommand T123goformat
2829 delcommand T123TestFOrmat
2830 delcommand T123fendoff
2831 delcommand T123state
2832 delcommand T123FendingOff
2833 %bw
2834
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002835 " Test for fuzzy completion of a command with lower case letters and a
2836 " number
2837 command Foo2Bar :
2838 set wildoptions=fuzzy
2839 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2840 call assert_equal('"Foo2Bar', @:)
2841 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2842 call assert_equal('"Foo2Bar', @:)
2843 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"Foo2Bar', @:)
2845 delcommand Foo2Bar
2846
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002847 " Test for command completion for a command starting with 'k'
2848 command KillKillKill :
2849 set wildoptions&
2850 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2851 call assert_equal("\"killkill\<Tab>", @:)
2852 set wildoptions=fuzzy
2853 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2854 call assert_equal('"KillKillKill', @:)
2855 delcom KillKillKill
2856
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002857 set wildoptions&
2858 %bw!
2859endfunc
2860
Bram Moolenaar309976e2019-12-05 18:16:33 +01002861" vim: shiftwidth=2 sts=2 expandtab