blob: 36853369855ef6ffb0a103931cb84f11fc6331ae [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 Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
23 call writefile(['testfile'], 'Xtestfile')
24 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030 call delete('Xtestfile')
31endfunc
32
33func Test_complete_list()
34 " We can't see the output, but at least we check the code runs properly.
35 call feedkeys(":e test\<C-D>\r", "tx")
36 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010037
38 " If a command doesn't support completion, then CTRL-D should be literally
39 " used.
40 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
41 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000042
43 " Test for displaying the tail of the completion matches
44 set wildmode=longest,full
45 call mkdir('Xtest')
46 call writefile([], 'Xtest/a.c')
47 call writefile([], 'Xtest/a.h')
48 let g:Sline = ''
49 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
50 call assert_equal('a.c a.h', g:Sline)
51 call assert_equal('"e Xtest/', @:)
52 if has('win32')
53 " Test for 'completeslash'
54 set completeslash=backslash
55 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
56 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000057 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
58 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000059 set completeslash=slash
60 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
61 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000062 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
63 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000064 set completeslash&
65 endif
66
67 " Test for displaying the tail with wildcards
68 let g:Sline = ''
69 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
70 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
71 call assert_equal('"e Xtes?/', @:)
72 let g:Sline = ''
73 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
74 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
75 call assert_equal('"e Xtes*/', @:)
76 let g:Sline = ''
77 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
78 call assert_equal(':e Xtes[/', g:Sline)
79 call assert_equal('"e Xtes[/', @:)
80
81 call delete('Xtest', 'rf')
82 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020083endfunc
84
85func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010086 call mkdir('Xdir1/Xdir2', 'p')
87 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
88 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
89 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
90 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020091 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010092
93 " Pressing <Tab> completes, and moves to next files when pressing again.
94 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
95 call assert_equal('testfile1', getline(1))
96 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020097 call assert_equal('testfile2', getline(1))
98
Bram Moolenaar37db6422019-03-28 21:26:23 +010099 " <S-Tab> is like <Tab> but begin with the last match and then go to
100 " previous.
101 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
102 call assert_equal('testfile2', getline(1))
103 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
104 call assert_equal('testfile1', getline(1))
105
106 " <Left>/<Right> to move to previous/next file.
107 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
108 call assert_equal('testfile1', getline(1))
109 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
110 call assert_equal('testfile2', getline(1))
111 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
112 call assert_equal('testfile1', getline(1))
113
114 " <Up>/<Down> to go up/down directories.
115 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
116 call assert_equal('testfile3', getline(1))
117 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
118 call assert_equal('testfile1', getline(1))
119
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100120 " this fails in some Unix GUIs, not sure why
121 if !has('unix') || !has('gui_running')
122 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
123 " different than 'wildchar'.
124 set wildcharm=<C-Z>
125 cnoremap <C-J> <Down><C-Z>
126 cnoremap <C-K> <Up><C-Z>
127 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx')
128 call assert_equal('testfile3', getline(1))
129 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
130 call assert_equal('testfile1', getline(1))
131 set wildcharm=0
132 cunmap <C-J>
133 cunmap <C-K>
134 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100135
Bram Moolenaar578fe942020-02-27 21:32:51 +0100136 " Test for canceling the wild menu by adding a character
137 redrawstatus
138 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
139 call assert_equal('"e Xdir1/Xdir2/x', @:)
140
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 " Completion using a relative path
142 cd Xdir1/Xdir2
143 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
144 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
145 cd -
146
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000147 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100148 cnoremap <expr> <F2> wildmenumode()
149 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +0000150 call assert_equal('"cd Xdir1/0', @:)
151 call feedkeys(":e Xdir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
152 call assert_equal('"e Xdir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100153 cunmap <F2>
154
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000155 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
156 " After this pressing <Left> or <Right> should not change the selection.
157 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
158 call assert_equal('"sign define', @:)
159 call histadd('cmd', 'TestWildMenu')
160 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
161 call assert_equal('"TestWildMenu', @:)
162
Bram Moolenaar37db6422019-03-28 21:26:23 +0100163 " cleanup
164 %bwipe
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000165 call delete('Xdir1', 'rf')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200166 set nowildmenu
167endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100168
Bram Moolenaara60053b2020-09-03 16:50:13 +0200169func Test_wildmenu_screendump()
170 CheckScreendump
171
172 let lines =<< trim [SCRIPT]
173 set wildmenu hlsearch
174 [SCRIPT]
175 call writefile(lines, 'XTest_wildmenu')
176
177 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
178 call term_sendkeys(buf, ":vim\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
183
184 call term_sendkeys(buf, "\<Tab>")
185 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
186
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100187 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200188 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
189 call term_sendkeys(buf, "\<Esc>")
190
191 " clean up
192 call StopVimInTerminal(buf)
193 call delete('XTest_wildmenu')
194endfunc
195
Bram Moolenaara653e532022-04-19 11:38:24 +0100196func Test_redraw_in_autocmd()
197 CheckScreendump
198
199 let lines =<< trim END
200 set cmdheight=2
201 autocmd CmdlineChanged * redraw
202 END
203 call writefile(lines, 'XTest_redraw')
204
205 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
206 call term_sendkeys(buf, ":for i in range(3)\<CR>")
207 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
208
209 call term_sendkeys(buf, "let i =")
210 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
211
212 " clean up
213 call term_sendkeys(buf, "\<CR>")
214 call StopVimInTerminal(buf)
215 call delete('XTest_redraw')
216endfunc
217
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100218func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100219 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
220 call assert_equal('"map <unique> <silent>', getreg(':'))
221 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
222 call assert_equal('"map <script> <unique>', getreg(':'))
223 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
224 call assert_equal('"map <expr> <script>', getreg(':'))
225 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
226 call assert_equal('"map <buffer> <expr>', getreg(':'))
227 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
228 call assert_equal('"map <nowait> <buffer>', getreg(':'))
229 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
230 call assert_equal('"map <special> <nowait>', getreg(':'))
231 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
232 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200233
Bram Moolenaar1776a282019-05-03 16:05:41 +0200234 map <Middle>x middle
235
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200236 map ,f commaf
237 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200238 map <Left> left
239 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200240 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
241 call assert_equal('"map ,f', getreg(':'))
242 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
243 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200244 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
245 call assert_equal('"map <Left>', getreg(':'))
246 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200247 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200248 unmap ,f
249 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200250 unmap <Left>
251 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200252
253 set cpo-=< cpo-=B cpo-=k
254 map <Left> left
255 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
256 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200257 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200258 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200259 unmap <Left>
260
261 set cpo+=<
262 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200263 exe "set t_k6=\<Esc>[17~"
264 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200265 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
266 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200267 if !has('gui_running')
268 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
269 call assert_equal("\"map <F6>x", getreg(':'))
270 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200271 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200272 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200273 set cpo-=<
274
275 set cpo+=B
276 map <Left> left
277 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
278 call assert_equal('"map <Left>', getreg(':'))
279 unmap <Left>
280 set cpo-=B
281
282 set cpo+=k
283 map <Left> left
284 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
285 call assert_equal('"map <Left>', getreg(':'))
286 unmap <Left>
287 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200288
Bram Moolenaar531be472020-09-23 22:38:05 +0200289 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
290
Bram Moolenaar1776a282019-05-03 16:05:41 +0200291 unmap <Middle>x
292 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100293endfunc
294
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100295func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100296 hi Aardig ctermfg=green
297 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000298 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100299 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000300 call assert_equal('"match none', @:)
301 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
302 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100303endfunc
304
305func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100306 hi Aardig ctermfg=green
307 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200309 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"hi default Aardig', getreg(':'))
311 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100313 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"hi link', getreg(':'))
315 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
316 call assert_equal('"hi default', getreg(':'))
317 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
318 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200319 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
320 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
321 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
322 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200323
324 " A cleared group does not show up in completions.
325 hi Anders ctermfg=green
326 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
327 hi clear Aardig
328 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
329 hi clear Anders
330 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100331endfunc
332
Bram Moolenaar75e15672020-06-28 13:10:22 +0200333" Test for command-line expansion of "hi Ni " (easter egg)
334func Test_highlight_easter_egg()
335 call test_override('ui_delay', 1)
336 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
337 call assert_equal("\"hi Ni \<Tab>", @:)
338 call test_override('ALL', 0)
339endfunc
340
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200341func Test_getcompletion()
342 let groupcount = len(getcompletion('', 'event'))
343 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200344 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200345 call assert_true(matchcount > 0)
346 call assert_true(groupcount > matchcount)
347
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200348 if has('menu')
349 source $VIMRUNTIME/menu.vim
350 let matchcount = len(getcompletion('', 'menu'))
351 call assert_true(matchcount > 0)
352 call assert_equal(['File.'], getcompletion('File', 'menu'))
353 call assert_true(matchcount > 0)
354 let matchcount = len(getcompletion('File.', 'menu'))
355 call assert_true(matchcount > 0)
356 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200357
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200358 let l = getcompletion('v:n', 'var')
359 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200360 let l = getcompletion('v:notexists', 'var')
361 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200362
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200363 args a.c b.c
364 let l = getcompletion('', 'arglist')
365 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000366 let l = getcompletion('a.', 'buffer')
367 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200368 %argdelete
369
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200370 let l = getcompletion('', 'augroup')
371 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200372 let l = getcompletion('blahblah', 'augroup')
373 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200374
375 let l = getcompletion('', 'behave')
376 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200377 let l = getcompletion('not', 'behave')
378 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200379
380 let l = getcompletion('', 'color')
381 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200382 let l = getcompletion('dirty', 'color')
383 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200384
385 let l = getcompletion('', 'command')
386 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200387 let l = getcompletion('awake', 'command')
388 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200389
390 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200391 call assert_true(index(l, 'samples/') >= 0)
392 let l = getcompletion('NoMatch', 'dir')
393 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200394
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100395 if glob('~/*') !=# ''
396 let l = getcompletion('~/', 'dir')
397 call assert_true(l[0][0] ==# '~')
398 endif
399
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200400 let l = getcompletion('exe', 'expression')
401 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200402 let l = getcompletion('kill', 'expression')
403 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200404
405 let l = getcompletion('tag', 'function')
406 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200407 let l = getcompletion('paint', 'function')
408 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200409
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200410 let Flambda = {-> 'hello'}
411 let l = getcompletion('', 'function')
412 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200413 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200414
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200415 let l = getcompletion('run', 'file')
416 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200417 let l = getcompletion('walk', 'file')
418 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200419 set wildignore=*.vim
420 let l = getcompletion('run', 'file', 1)
421 call assert_true(index(l, 'runtest.vim') < 0)
422 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000423 " Directory name with space character
424 call mkdir('Xdir with space')
425 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
426 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
427 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200428
429 let l = getcompletion('ha', 'filetype')
430 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200431 let l = getcompletion('horse', 'filetype')
432 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200433
434 let l = getcompletion('z', 'syntax')
435 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200436 let l = getcompletion('emacs', 'syntax')
437 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200438
439 let l = getcompletion('jikes', 'compiler')
440 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200441 let l = getcompletion('break', 'compiler')
442 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200443
444 let l = getcompletion('last', 'help')
445 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200446 let l = getcompletion('giveup', 'help')
447 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200448
449 let l = getcompletion('time', 'option')
450 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200451 let l = getcompletion('space', 'option')
452 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200453
454 let l = getcompletion('er', 'highlight')
455 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200456 let l = getcompletion('dark', 'highlight')
457 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200458
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200459 let l = getcompletion('', 'messages')
460 call assert_true(index(l, 'clear') >= 0)
461 let l = getcompletion('not', 'messages')
462 call assert_equal([], l)
463
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200464 let l = getcompletion('', 'mapclear')
465 call assert_true(index(l, '<buffer>') >= 0)
466 let l = getcompletion('not', 'mapclear')
467 call assert_equal([], l)
468
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200469 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200470 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200471 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
472 let root = has('win32') ? 'C:\\' : '/'
473 let l = getcompletion(root, 'shellcmd')
474 let expected = map(filter(glob(root . '*', 0, 1),
475 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
476 call assert_equal(expected, l)
477
Bram Moolenaarb650b982016-08-05 20:35:13 +0200478 if has('cscope')
479 let l = getcompletion('', 'cscope')
480 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
481 call assert_equal(cmds, l)
482 " using cmdline completion must not change the result
483 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
484 let l = getcompletion('', 'cscope')
485 call assert_equal(cmds, l)
486 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
487 let l = getcompletion('find ', 'cscope')
488 call assert_equal(keys, l)
489 endif
490
Bram Moolenaar7522f692016-08-06 14:12:50 +0200491 if has('signs')
492 sign define Testing linehl=Comment
493 let l = getcompletion('', 'sign')
494 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
495 call assert_equal(cmds, l)
496 " using cmdline completion must not change the result
497 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
498 let l = getcompletion('', 'sign')
499 call assert_equal(cmds, l)
500 let l = getcompletion('list ', 'sign')
501 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000502 let l = getcompletion('de*', 'sign')
503 call assert_equal(['define'], l)
504 let l = getcompletion('p?', 'sign')
505 call assert_equal(['place'], l)
506 let l = getcompletion('j.', 'sign')
507 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200508 endif
509
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200510 " Command line completion tests
511 let l = getcompletion('cd ', 'cmdline')
512 call assert_true(index(l, 'samples/') >= 0)
513 let l = getcompletion('cd NoMatch', 'cmdline')
514 call assert_equal([], l)
515 let l = getcompletion('let v:n', 'cmdline')
516 call assert_true(index(l, 'v:null') >= 0)
517 let l = getcompletion('let v:notexists', 'cmdline')
518 call assert_equal([], l)
519 let l = getcompletion('call tag', 'cmdline')
520 call assert_true(index(l, 'taglist(') >= 0)
521 let l = getcompletion('call paint', 'cmdline')
522 call assert_equal([], l)
523
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100524 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000525 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100526 return "oneA\noneB\noneC"
527 endfunc
528 command -nargs=1 -complete=custom,T MyCmd
529 let l = getcompletion('MyCmd ', 'cmdline')
530 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000531 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100532
533 delcommand MyCmd
534 delfunc T
ii144785fe02021-11-21 12:13:56 +0000535 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100536
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200537 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200538 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200539 if has('cmdline_hist')
540 call add(names, 'history')
541 endif
542 if has('gettext')
543 call add(names, 'locale')
544 endif
545 if has('profile')
546 call add(names, 'syntime')
547 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200548
549 set tags=Xtags
550 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
551
552 for name in names
553 let matchcount = len(getcompletion('', name))
554 call assert_true(matchcount >= 0, 'No matches for ' . name)
555 endfor
556
557 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200558 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200559
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000560 edit a~b
561 enew
562 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
563 bw a~b
564
565 if has('unix')
566 edit Xtest\
567 enew
568 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
569 bw Xtest\
570 endif
571
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200572 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200573 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200574 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200575endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200576
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000577" Test for getcompletion() with "fuzzy" in 'wildoptions'
578func Test_getcompletion_wildoptions()
579 let save_wildoptions = &wildoptions
580 set wildoptions&
581 let l = getcompletion('space', 'option')
582 call assert_equal([], l)
583 let l = getcompletion('ier', 'command')
584 call assert_equal([], l)
585 set wildoptions=fuzzy
586 let l = getcompletion('space', 'option')
587 call assert_true(index(l, 'backspace') >= 0)
588 let l = getcompletion('ier', 'command')
589 call assert_true(index(l, 'compiler') >= 0)
590 let &wildoptions = save_wildoptions
591endfunc
592
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000593func Test_complete_autoload_error()
594 let save_rtp = &rtp
595 let lines =<< trim END
596 vim9script
597 export def Complete(..._): string
598 return 'match'
599 enddef
600 echo this will cause an error
601 END
602 call mkdir('Xdir/autoload', 'p')
603 call writefile(lines, 'Xdir/autoload/script.vim')
604 exe 'set rtp+=' .. getcwd() .. '/Xdir'
605
606 let lines =<< trim END
607 vim9script
608 import autoload 'script.vim'
609 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
610 &wildcharm = char2nr("\<Tab>")
611 feedkeys(":Cmd \<Tab>", 'xt')
612 END
613 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
614
615 let &rtp = save_rtp
616 call delete('Xdir', 'rf')
617endfunc
618
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100619func Test_fullcommand()
620 let tests = {
621 \ '': '',
622 \ ':': '',
623 \ ':::': '',
624 \ ':::5': '',
625 \ 'not_a_cmd': '',
626 \ 'Check': '',
627 \ 'syntax': 'syntax',
628 \ ':syntax': 'syntax',
629 \ '::::syntax': 'syntax',
630 \ 'sy': 'syntax',
631 \ 'syn': 'syntax',
632 \ 'synt': 'syntax',
633 \ ':sy': 'syntax',
634 \ '::::sy': 'syntax',
635 \ 'match': 'match',
636 \ '2match': 'match',
637 \ '3match': 'match',
638 \ 'aboveleft': 'aboveleft',
639 \ 'abo': 'aboveleft',
640 \ 's': 'substitute',
641 \ '5s': 'substitute',
642 \ ':5s': 'substitute',
643 \ "'<,'>s": 'substitute',
644 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100645 \ 'CheckLin': 'CheckLinux',
646 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100647 \ }
648
649 for [in, want] in items(tests)
650 call assert_equal(want, fullcommand(in))
651 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200652 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100653
654 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200655
656 command -buffer BufferLocalCommand :
657 command GlobalCommand :
658 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
659 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
660 delcommand BufferLocalCommand
661 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100662endfunc
663
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200664func Test_shellcmd_completion()
665 let save_path = $PATH
666
667 call mkdir('Xpathdir/Xpathsubdir', 'p')
668 call writefile([''], 'Xpathdir/Xfile.exe')
669 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
670
671 " Set PATH to example directory without trailing slash.
672 let $PATH = getcwd() . '/Xpathdir'
673
674 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
675 " dirs in the PATH, even though they won't be executed. We check that only
676 " subdirs of the PWD and executables from the PATH are included in the
677 " suggestions.
678 let actual = getcompletion('X', 'shellcmd')
679 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
680 call insert(expected, 'Xfile.exe')
681 call assert_equal(expected, actual)
682
683 call delete('Xpathdir', 'rf')
684 let $PATH = save_path
685endfunc
686
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200687func Test_expand_star_star()
688 call mkdir('a/b', 'p')
689 call writefile(['asdfasdf'], 'a/b/fileXname')
690 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000691 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200692 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200693 call delete('a', 'rf')
694endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100695
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100696func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100697 let @a = "def"
698 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
699 call assert_equal('"abc def ghi', @:)
700
701 new
702 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
703
704 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
705 call assert_equal('"aaa asdf bbb', @:)
706
707 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
708 call assert_equal('"aaa /tmp/some bbb', @:)
709
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200710 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
711 call assert_equal('"aaa '.getline(1).' bbb', @:)
712
Bram Moolenaar21efc362016-12-03 14:05:49 +0100713 set incsearch
714 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
715 call assert_equal('"aaa verylongword bbb', @:)
716
717 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
718 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100719
720 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
721 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100722 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200723
724 " Error while typing a command used to cause that it was not executed
725 " in the end.
726 new
727 try
728 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
729 catch /^Vim\%((\a\+)\)\=:E32/
730 " ignore error E32
731 endtry
732 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100733
Bram Moolenaar578fe942020-02-27 21:32:51 +0100734 " Try to paste an invalid register using <C-R>
735 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
736 call assert_equal('"onetwo', @:)
737
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100738 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100739 let @a = "xy\<C-H>z"
740 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
741 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100742 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
743 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100744 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
745 call assert_equal("\"xy\<C-H>z", @:)
746
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100747 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
748 let @a = "xy\<C-V>z"
749 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
750 call assert_equal('"xyz', @:)
751 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
752 call assert_equal("\"xy\<C-V>z", @:)
753
Bram Moolenaar578fe942020-02-27 21:32:51 +0100754 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
755
Bram Moolenaar72532d32018-04-07 19:09:09 +0200756 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100757endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100758
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100759func Test_cmdline_remove_char()
760 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100761
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100762 for e in ['utf8', 'latin1']
763 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100764
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100765 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
766 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100767
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100768 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
769 call assert_equal('"abcdef', @:)
770
771 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
772 call assert_equal('"abc ghi', @:, e)
773
774 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
775 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100776
777 " This was going before the start in latin1.
778 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100779 endfor
780
781 let &encoding = encoding_save
782endfunc
783
784func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200785 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100786
787 set keymap=esperanto
788 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
789 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
790 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100791endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100792
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100793func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100794 new
795 2;'(
796 2;')
797 quit
798endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100799
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100800func Test_illegal_address2()
801 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
802 new
803 source Xtest.vim
804 " Trigger calling validate_cursor()
805 diffsp Xtest.vim
806 quit!
807 bwipe!
808 call delete('Xtest.vim')
809endfunc
810
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100811func Test_mark_from_line_zero()
812 " this was reading past the end of the first (empty) line
813 new
814 norm oxxxx
815 call assert_fails("0;'(", 'E20:')
816 bwipe!
817endfunc
818
Bram Moolenaarba47b512017-01-24 21:18:19 +0100819func Test_cmdline_complete_wildoptions()
820 help
821 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
822 let a = join(sort(split(@:)),' ')
823 set wildoptions=tagfile
824 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
825 let b = join(sort(split(@:)),' ')
826 call assert_equal(a, b)
827 bw!
828endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100829
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200830func Test_cmdline_complete_user_cmd()
831 command! -complete=color -nargs=1 Foo :
832 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
833 call assert_equal('"Foo blue', @:)
834 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
835 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000836 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
837 call assert_equal('"Foo a blue', @:)
838 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
839 call assert_equal('"Foo b\', @:)
840 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
841 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200842 delcommand Foo
843endfunc
844
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100845func s:ScriptLocalFunction()
846 echo 'yes'
847endfunc
848
849func Test_cmdline_complete_user_func()
850 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200851 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100852 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
853 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100854
855 " g: prefix also works
856 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
857 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200858
859 " using g: prefix does not result in just "g:" matches from a lambda
860 let Fx = { a -> a }
861 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
862 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200863
864 " existence of script-local dict function does not break user function name
865 " completion
866 function s:a_dict_func() dict
867 endfunction
868 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
869 call assert_match('"call Test_cmdline_complete_user_', @:)
870 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100871endfunc
872
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200873func Test_cmdline_complete_user_names()
874 if has('unix') && executable('whoami')
875 let whoami = systemlist('whoami')[0]
876 let first_letter = whoami[0]
877 if len(first_letter) > 0
878 " Trying completion of :e ~x where x is the first letter of
879 " the user name should complete to at least the user name.
880 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
881 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
882 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200883 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200884 " Just in case: check that the system has an Administrator account.
885 let names = system('net user')
886 if names =~ 'Administrator'
887 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100888 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200889 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100890 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200891 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200892 else
893 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200894 endif
895endfunc
896
Bram Moolenaar297610b2019-12-27 17:20:55 +0100897func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200898 CheckExecutable whoami
899 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
900 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100901endfunc
902
Bram Moolenaar8b633132020-03-20 18:20:51 +0100903func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200904 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
905 call assert_equal(lang, v:lc_time)
906
907 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
908 call assert_equal(lang, v:ctype)
909
910 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
911 call assert_equal(lang, v:collate)
912
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200913 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200914 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200915
916 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200917 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200918
Bram Moolenaarec680282020-06-12 19:35:32 +0200919 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200920
Bram Moolenaarec680282020-06-12 19:35:32 +0200921 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
922 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200923
Bram Moolenaarec680282020-06-12 19:35:32 +0200924 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
925 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200926
Bram Moolenaarec680282020-06-12 19:35:32 +0200927 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
928 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200929
930 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
931 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200932endfunc
933
Bram Moolenaar297610b2019-12-27 17:20:55 +0100934func Test_cmdline_complete_env_variable()
935 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100936 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
937 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100938 unlet $X_VIM_TEST_COMPLETE_ENV
939endfunc
940
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100941func Test_cmdline_complete_expression()
942 let g:SomeVar = 'blah'
943 for cmd in ['exe', 'echo', 'echon', 'echomsg']
944 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
945 call assert_match('"' .. cmd .. ' SomeVar', @:)
946 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
947 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
948 endfor
949 unlet g:SomeVar
950endfunc
951
Bram Moolenaar47016f52021-08-26 16:39:58 +0200952" Unique function name for completion below
953func s:WeirdFunc()
954 echo 'weird'
955endfunc
956
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100957" Test for various command-line completion
958func Test_cmdline_complete_various()
959 " completion for a command starting with a comment
960 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
961 call assert_equal("\" :|\"\<C-A>", @:)
962
963 " completion for a range followed by a comment
964 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
965 call assert_equal("\"1,2\"\<C-A>", @:)
966
967 " completion for :k command
968 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
969 call assert_equal("\"ka\<C-A>", @:)
970
971 " completion for short version of the :s command
972 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
973 call assert_equal("\"sI \<C-A>", @:)
974
975 " completion for :write command
976 call mkdir('Xdir')
977 call writefile(['one'], 'Xdir/Xfile1')
978 let save_cwd = getcwd()
979 cd Xdir
980 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
981 call assert_equal("\"w >> Xfile1", @:)
982 call chdir(save_cwd)
983 call delete('Xdir', 'rf')
984
985 " completion for :w ! and :r ! commands
986 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
987 call assert_equal("\"w !invalid_xyz_cmd", @:)
988 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
989 call assert_equal("\"r !invalid_xyz_cmd", @:)
990
991 " completion for :>> and :<< commands
992 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
993 call assert_equal("\">>>\<C-A>", @:)
994 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
995 call assert_equal("\"<<<\<C-A>", @:)
996
997 " completion for command with +cmd argument
998 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
999 call assert_equal("\"buffer +/pat Xabc", @:)
1000 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1001 call assert_equal("\"buffer +/pat\<C-A>", @:)
1002
1003 " completion for a command with a trailing comment
1004 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1005 call assert_equal("\"ls \" comment\<C-A>", @:)
1006
1007 " completion for a command with a trailing command
1008 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1009 call assert_equal("\"ls | ls", @:)
1010
1011 " completion for a command with an CTRL-V escaped argument
1012 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1013 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1014
1015 " completion for a command that doesn't take additional arguments
1016 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1017 call assert_equal("\"all abc\<C-A>", @:)
1018
1019 " completion for a command with a command modifier
1020 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1021 call assert_equal("\"topleft new", @:)
1022
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001023 " completion for vim9 and legacy commands
1024 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1025 call assert_equal("\"vim9 call strlen(", @:)
1026 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1027 call assert_equal("\"legac call strlen(", @:)
1028
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001029 " completion for the :disassemble command
1030 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1031 call assert_equal("\"disas debug", @:)
1032 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1033 call assert_equal("\"disas profile", @:)
1034 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1035 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1036 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1037 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001038 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1039 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001040
Bram Moolenaar47016f52021-08-26 16:39:58 +02001041 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001042 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001043
naohiro onodfe04db2021-09-12 15:45:10 +02001044 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1045 call assert_match('"disas <SNR>\d\+_', @:)
1046 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1047 call assert_match('"disas debug <SNR>\d\+_', @:)
1048
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001049 " completion for the :match command
1050 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1051 call assert_equal("\"match Search /pat/\<C-A>", @:)
1052
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001053 " completion for the :doautocmd command
1054 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1055 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1056
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001057 " completion of autocmd group after comma
1058 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1059 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1060
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001061 " completion of file name in :doautocmd
1062 call writefile([], 'Xfile1')
1063 call writefile([], 'Xfile2')
1064 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
1065 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
1066 call delete('Xfile1')
1067 call delete('Xfile2')
1068
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001069 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001070 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001071 augroup END
1072 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001073 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001074
1075 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001076 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1077 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001078 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1079 call assert_equal("\"au XTest.test", @:)
1080
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001081 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001082
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001083 " autocmd pattern completion
1084 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1085 call assert_equal("\"au BufEnter *.py\t", @:)
1086
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001087 " completion for the :unlet command
1088 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal("\"unlet one two", @:)
1090
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001091 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001092 " FIXME: what should happen on MS-Windows?
1093 if !has('win32')
1094 edit \{someFile}
1095 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1096 call assert_equal("\"buf {someFile}", @:)
1097 bwipe {someFile}
1098 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001099
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001100 " completion for the :bdelete command
1101 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1102 call assert_equal("\"bdel a b c", @:)
1103
1104 " completion for the :mapclear command
1105 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1106 call assert_equal("\"mapclear <buffer>", @:)
1107
1108 " completion for user defined commands with menu names
1109 menu Test.foo :ls<CR>
1110 com -nargs=* -complete=menu MyCmd
1111 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1112 call assert_equal('"MyCmd Test.', @:)
1113 delcom MyCmd
1114 unmenu Test
1115
1116 " completion for user defined commands with mappings
1117 mapclear
1118 map <F3> :ls<CR>
1119 com -nargs=* -complete=mapping MyCmd
1120 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001121 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001122 mapclear
1123 delcom MyCmd
1124
1125 " completion for :set path= with multiple backslashes
1126 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1127 call assert_equal('"set path=a\\\ b', @:)
1128
1129 " completion for :set dir= with a backslash
1130 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal('"set dir=a\ b', @:)
1132
1133 " completion for the :py3 commands
1134 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal('"py3 py3do py3file', @:)
1136
Bram Moolenaardf749a22021-03-28 15:29:43 +02001137 " completion for the :vim9 commands
1138 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal('"vim9cmd vim9script', @:)
1140
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001141 " redir @" is not the start of a comment. So complete after that
1142 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1143 call assert_equal('"redir @" | cwindow', @:)
1144
1145 " completion after a backtick
1146 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1147 call assert_equal('"e `a1b2c', @:)
1148
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001149 " completion for :language command with an invalid argument
1150 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1151 call assert_equal("\"language dummy \t", @:)
1152
1153 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001154 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1155 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001156
1157 " completion with ambiguous user defined commands
1158 com TCmd1 echo 'TCmd1'
1159 com TCmd2 echo 'TCmd2'
1160 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1161 call assert_equal('"TCmd ', @:)
1162 delcom TCmd1
1163 delcom TCmd2
1164
1165 " completion after a range followed by a pipe (|) character
1166 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1167 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001168
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001169 " completion after a :global command
1170 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1171 call assert_equal('"g/a/chistory', @:)
1172 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1173 call assert_equal("\"g/a\\/chist\t", @:)
1174
Bram Moolenaar9c929712020-09-07 22:05:28 +02001175 " use <Esc> as the 'wildchar' for completion
1176 set wildchar=<Esc>
1177 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1178 call assert_equal('"g/a\xb/clearjumps', @:)
1179 " pressing <esc> twice should cancel the command
1180 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1181 call assert_equal('"g/a\xb/clearjumps', @:)
1182 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001183
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001184 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001185 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001186 call writefile([], '~Xtest')
1187 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1188 call assert_equal('"e \~Xtest', @:)
1189 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001190
1191 " should be able to complete a file name that has a '*'
1192 call writefile([], 'Xx*Yy')
1193 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1194 call assert_equal('"e Xx\*Yy', @:)
1195 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001196
1197 " use a literal star
1198 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1199 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001200 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001201
1202 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1203 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001204endfunc
1205
1206" Test for 'wildignorecase'
1207func Test_cmdline_wildignorecase()
1208 CheckUnix
1209 call writefile([], 'XTEST')
1210 set wildignorecase
1211 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001213 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001214 let g:Sline = ''
1215 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1216 call assert_equal('"e xt', @:)
1217 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001218 set wildignorecase&
1219 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001220endfunc
1221
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001222func Test_cmdline_write_alternatefile()
1223 new
1224 call setline('.', ['one', 'two'])
1225 f foo.txt
1226 new
1227 f #-A
1228 call assert_equal('foo.txt-A', expand('%'))
1229 f #<-B.txt
1230 call assert_equal('foo-B.txt', expand('%'))
1231 f %<
1232 call assert_equal('foo-B', expand('%'))
1233 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001234 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001235 bw!
1236 f foo-B.txt
1237 f %<-A
1238 call assert_equal('foo-B-A', expand('%'))
1239 bw!
1240 bw!
1241endfunc
1242
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001243" using a leading backslash here
1244set cpo+=C
1245
1246func Test_cmdline_search_range()
1247 new
1248 call setline(1, ['a', 'b', 'c', 'd'])
1249 /d
1250 1,\/s/b/B/
1251 call assert_equal('B', getline(2))
1252
1253 /a
1254 $
1255 \?,4s/c/C/
1256 call assert_equal('C', getline(3))
1257
1258 call setline(1, ['a', 'b', 'c', 'd'])
1259 %s/c/c/
1260 1,\&s/b/B/
1261 call assert_equal('B', getline(2))
1262
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001263 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001264 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001265
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001266 bwipe!
1267endfunc
1268
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001269" Test for the tick mark (') in an excmd range
1270func Test_tick_mark_in_range()
1271 " If only the tick is passed as a range and no command is specified, there
1272 " should not be an error
1273 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001274 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001275 call assert_fails("',print", 'E78:')
1276endfunc
1277
1278" Test for using a line number followed by a search pattern as range
1279func Test_lnum_and_pattern_as_range()
1280 new
1281 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1282 let @" = ''
1283 2/foo/yank
1284 call assert_equal("foo 3\n", @")
1285 call assert_equal(1, line('.'))
1286 close!
1287endfunc
1288
Bram Moolenaar65189a12017-02-06 22:22:17 +01001289" Tests for getcmdline(), getcmdpos() and getcmdtype()
1290func Check_cmdline(cmdtype)
1291 call assert_equal('MyCmd a', getcmdline())
1292 call assert_equal(8, getcmdpos())
1293 call assert_equal(a:cmdtype, getcmdtype())
1294 return ''
1295endfunc
1296
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001297set cpo&
1298
Bram Moolenaar65189a12017-02-06 22:22:17 +01001299func Test_getcmdtype()
1300 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1301
1302 let cmdtype = ''
1303 debuggreedy
1304 call feedkeys(":debug echo 'test'\<CR>", "t")
1305 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1306 call feedkeys("cont\<CR>", "xt")
1307 0debuggreedy
1308 call assert_equal('>', cmdtype)
1309
1310 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1311 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1312
1313 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001314 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001315
1316 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1317
1318 cnoremap <expr> <F6> Check_cmdline('=')
1319 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1320 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001321
1322 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001323endfunc
1324
Bram Moolenaar81612b72018-06-23 14:55:03 +02001325func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001326 CheckFeature cmdwin
1327
Bram Moolenaar81612b72018-06-23 14:55:03 +02001328 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1329 call assert_equal('/', a)
1330
1331 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1332 call assert_equal('?', a)
1333
1334 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1335 call assert_equal(':', a)
1336
1337 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1338 call assert_equal(':', a)
1339
1340 call assert_equal('', getcmdwintype())
1341endfunc
1342
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001343func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001344 CheckFeature cmdwin
1345
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001346 let s:seq = []
1347 augroup CmdWin
1348 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1349 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1350 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1351 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1352 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1353 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1354
1355 let org_winid = win_getid()
1356 let org_bufnr = bufnr()
1357 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1358 call assert_equal(':', a)
1359 call assert_equal([
1360 \ 'WinLeave ' .. org_winid,
1361 \ 'WinEnter ' .. s:cmd_winid,
1362 \ 'BufLeave ' .. org_bufnr,
1363 \ 'BufEnter ' .. s:cmd_bufnr,
1364 \ 'CmdWinEnter ' .. s:cmd_winid,
1365 \ 'CmdWinLeave ' .. s:cmd_winid,
1366 \ 'BufLeave ' .. s:cmd_bufnr,
1367 \ 'WinLeave ' .. s:cmd_winid,
1368 \ 'WinEnter ' .. org_winid,
1369 \ 'BufEnter ' .. org_bufnr,
1370 \ ], s:seq)
1371
1372 au!
1373 augroup END
1374endfunc
1375
Bram Moolenaar52604f22017-04-07 16:17:39 +02001376func Test_verbosefile()
1377 set verbosefile=Xlog
1378 echomsg 'foo'
1379 echomsg 'bar'
1380 set verbosefile=
1381 let log = readfile('Xlog')
1382 call assert_match("foo\nbar", join(log, "\n"))
1383 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001384 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001385 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001386 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001387endfunc
1388
Bram Moolenaar4facea32019-10-12 20:17:40 +02001389func Test_verbose_option()
1390 CheckScreendump
1391
1392 let lines =<< trim [SCRIPT]
1393 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1394 call feedkeys("\r", 't') " for the hit-enter prompt
1395 set verbose=20
1396 [SCRIPT]
1397 call writefile(lines, 'XTest_verbose')
1398
1399 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001400 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001401 call term_sendkeys(buf, ":DoSomething\<CR>")
1402 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1403
1404 " clean up
1405 call StopVimInTerminal(buf)
1406 call delete('XTest_verbose')
1407endfunc
1408
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001409func Test_setcmdpos()
1410 func InsertTextAtPos(text, pos)
1411 call assert_equal(0, setcmdpos(a:pos))
1412 return a:text
1413 endfunc
1414
1415 " setcmdpos() with position in the middle of the command line.
1416 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1417 call assert_equal('"1ab2', @:)
1418
1419 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1420 call assert_equal('"1b2a', @:)
1421
1422 " setcmdpos() with position beyond the end of the command line.
1423 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1424 call assert_equal('"12ab', @:)
1425
1426 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001427 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001428endfunc
1429
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001430func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001431 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001432 let encoding_save = &encoding
1433
1434 for e in encodings
1435 exe 'set encoding=' . e
1436
1437 " Test overstrike in the middle of the command line.
1438 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001439 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001440
1441 " Test overstrike going beyond end of command line.
1442 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001443 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001444
1445 " Test toggling insert/overstrike a few times.
1446 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001447 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001448 endfor
1449
Bram Moolenaar30276f22019-01-24 17:59:39 +01001450 " Test overstrike with multi-byte characters.
1451 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001452 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001453
1454 let &encoding = encoding_save
1455endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001456
1457func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001458 CheckFeature cmdwin
1459
Bram Moolenaara046b372019-09-15 17:26:07 +02001460 let winid = win_getid()
1461 sp
1462 try
1463 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1464 catch /^Vim\%((\a\+)\)\=:E11/
1465 endtry
1466 bw!
1467endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001468
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001469func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001470 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001471 CheckScreendump
1472
1473 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001474 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001475 call setline(1, range(30))
1476 2split
1477 [SCRIPT]
1478 call writefile(lines, 'XTest_restore')
1479
1480 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001481 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001482 call term_sendkeys(buf, "q:")
1483 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1484
1485 " normal restore
1486 call term_sendkeys(buf, ":q\<CR>")
1487 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1488
1489 " restore after setting 'lines' with one window
1490 call term_sendkeys(buf, ":close\<CR>")
1491 call term_sendkeys(buf, "q:")
1492 call term_sendkeys(buf, ":set lines=18\<CR>")
1493 call term_sendkeys(buf, ":q\<CR>")
1494 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1495
1496 " clean up
1497 call StopVimInTerminal(buf)
1498 call delete('XTest_restore')
1499endfunc
1500
Bram Moolenaare5b44862021-05-30 13:54:03 +02001501func Test_cmdwin_no_terminal()
1502 CheckFeature cmdwin
1503 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001504 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001505
1506 let buf = RunVimInTerminal('', {'rows': 12})
1507 call TermWait(buf, 50)
1508 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1509 call term_sendkeys(buf, "q:")
1510 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1511 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1512 call term_sendkeys(buf, ":q\<CR>")
1513 call StopVimInTerminal(buf)
1514endfunc
1515
Bram Moolenaar52410572019-10-27 05:12:45 +01001516func Test_buffers_lastused()
1517 " check that buffers are sorted by time when wildmode has lastused
1518 call test_settime(1550020000) " middle
1519 edit bufa
1520 enew
1521 call test_settime(1550030000) " newest
1522 edit bufb
1523 enew
1524 call test_settime(1550010000) " oldest
1525 edit bufc
1526 enew
1527 call test_settime(0)
1528 enew
1529
1530 call assert_equal(['bufa', 'bufb', 'bufc'],
1531 \ getcompletion('', 'buffer'))
1532
1533 let save_wildmode = &wildmode
1534 set wildmode=full:lastused
1535
1536 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1537 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1538 call assert_equal('b bufb', X)
1539 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1540 call assert_equal('b bufa', X)
1541 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1542 call assert_equal('b bufc', X)
1543 enew
1544
1545 edit other
1546 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1547 call assert_equal('b bufb', X)
1548 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1549 call assert_equal('b bufa', X)
1550 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1551 call assert_equal('b bufc', X)
1552 enew
1553
1554 let &wildmode = save_wildmode
1555
1556 bwipeout bufa
1557 bwipeout bufb
1558 bwipeout bufc
1559endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001560
1561func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001562 CheckFeature cmdwin
1563
Bram Moolenaar85db5472019-12-04 15:11:08 +01001564 " This should not generate E488
1565 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001566 " Using feedkeys with q: only should automatically close the cmd window
1567 call feedkeys('q:', 'xt')
1568 call assert_equal(1, winnr('$'))
1569 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001570endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001571
1572" Tests for the issues fixed in 7.4.441.
1573" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1574func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001575 CheckFeature cmdwin
1576
Bram Moolenaar309976e2019-12-05 18:16:33 +01001577 exe "set cedit=\<C-c>"
1578 normal! :
1579 call assert_equal(1, winnr('$'))
1580
1581 let g:cmd_wintype = ''
1582 func CmdWinType()
1583 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001584 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001585 return ''
1586 endfunc
1587
1588 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1589 echo input('')
1590 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001591 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001592
1593 set cedit&vim
1594 delfunc CmdWinType
1595endfunc
1596
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001597" Test for CmdwinEnter autocmd
1598func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001599 CheckFeature cmdwin
1600
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001601 augroup CmdWin
1602 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001603 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001604 autocmd CmdwinEnter * startinsert
1605 augroup END
1606
1607 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1608 call assert_equal('xyz', @:)
1609
1610 augroup CmdWin
1611 au!
1612 augroup END
1613 augroup! CmdWin
1614endfunc
1615
Bram Moolenaar479950f2020-01-19 15:45:17 +01001616func Test_cmdlineclear_tabenter()
1617 CheckScreendump
1618
1619 let lines =<< trim [SCRIPT]
1620 call setline(1, range(30))
1621 [SCRIPT]
1622
1623 call writefile(lines, 'XtestCmdlineClearTabenter')
1624 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001625 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001626 " in one tab make the command line higher with CTRL-W -
1627 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1628 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1629
1630 call StopVimInTerminal(buf)
1631 call delete('XtestCmdlineClearTabenter')
1632endfunc
1633
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001634" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001635func Test_cmdline_expand_special()
1636 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001637 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001638 call assert_fails('e <afile>', 'E495:')
1639 call assert_fails('e <abuf>', 'E496:')
1640 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001641
1642 call writefile([], 'Xfile.cpp')
1643 call writefile([], 'Xfile.java')
1644 new Xfile.cpp
1645 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1646 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1647 close
1648 call delete('Xfile.cpp')
1649 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001650endfunc
1651
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001652func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001653 CheckFeature cmdwin
1654
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001655 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1656 new
1657 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001658 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001659 close!
1660 call feedkeys("q/:close\<CR>", "xt")
1661 call assert_equal(1, winnr('$'))
1662 call feedkeys("q/:exit\<CR>", "xt")
1663 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001664
1665 " opening command window twice should fail
1666 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1667 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001668endfunc
1669
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00001670func Test_cmdwin_tabpage()
1671 tabedit
1672 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1673 tabclose!
1674endfunc
1675
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001676func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001677 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001678 CheckScreendump
1679
1680 " aborting the :smile output caused the cmdline window to use the current
1681 " buffer.
1682 let lines =<< trim [SCRIPT]
1683 au WinNew * smile
1684 [SCRIPT]
1685 call writefile(lines, 'XTest_cmdwin')
1686
1687 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001688 " open cmdwin
1689 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001690 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001691 " quit more prompt for :smile command
1692 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001693 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001694 " execute a simple command
1695 call term_sendkeys(buf, "aecho 'done'\<CR>")
1696 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1697
1698 " clean up
1699 call StopVimInTerminal(buf)
1700 call delete('XTest_cmdwin')
1701endfunc
1702
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001703" Test for backtick expression in the command line
1704func Test_cmd_backtick()
1705 %argd
1706 argadd `=['a', 'b', 'c']`
1707 call assert_equal(['a', 'b', 'c'], argv())
1708 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001709
1710 argadd `echo abc def`
1711 call assert_equal(['abc def'], argv())
1712 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001713endfunc
1714
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001715" Test for the :! command
1716func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001717 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001718
1719 let lines =<< trim [SCRIPT]
1720 " Test for no previous command
1721 call assert_fails('!!', 'E34:')
1722 set nomore
1723 " Test for cmdline expansion with :!
1724 call setline(1, 'foo!')
1725 silent !echo <cWORD> > Xfile.out
1726 call assert_equal(['foo!'], readfile('Xfile.out'))
1727 " Test for using previous command
1728 silent !echo \! !
1729 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1730 call writefile(v:errors, 'Xresult')
1731 call delete('Xfile.out')
1732 qall!
1733 [SCRIPT]
1734 call writefile(lines, 'Xscript')
1735 if RunVim([], [], '--clean -S Xscript')
1736 call assert_equal([], readfile('Xresult'))
1737 endif
1738 call delete('Xscript')
1739 call delete('Xresult')
1740endfunc
1741
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001742" Test error: "E135: *Filter* Autocommands must not change current buffer"
1743func Test_cmd_bang_E135()
1744 new
1745 call setline(1, ['a', 'b', 'c', 'd'])
1746 augroup test_cmd_filter_E135
1747 au!
1748 autocmd FilterReadPost * help
1749 augroup END
1750 call assert_fails('2,3!echo "x"', 'E135:')
1751
1752 augroup test_cmd_filter_E135
1753 au!
1754 augroup END
1755 %bwipe!
1756endfunc
1757
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001758" Test for using ~ for home directory in cmdline completion matches
1759func Test_cmdline_expand_home()
1760 call mkdir('Xdir')
1761 call writefile([], 'Xdir/Xfile1')
1762 call writefile([], 'Xdir/Xfile2')
1763 cd Xdir
1764 let save_HOME = $HOME
1765 let $HOME = getcwd()
1766 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1767 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1768 let $HOME = save_HOME
1769 cd ..
1770 call delete('Xdir', 'rf')
1771endfunc
1772
Bram Moolenaar578fe942020-02-27 21:32:51 +01001773" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1774" or insert mode (when 'insertmode' is set)
1775func Test_cmdline_ctrl_g()
1776 new
1777 call setline(1, 'abc')
1778 call cursor(1, 3)
1779 " If command line is entered from insert mode, using C-\ C-G should back to
1780 " insert mode
1781 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1782 call assert_equal('abxyc', getline(1))
1783 call assert_equal(4, col('.'))
1784
1785 " If command line is entered in 'insertmode', using C-\ C-G should back to
1786 " 'insertmode'
1787 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1788 call assert_equal('ab12xyc', getline(1))
1789 close!
1790endfunc
1791
Bram Moolenaar578fe942020-02-27 21:32:51 +01001792" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001793func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001794 func T(a, c, p)
1795 return "oneA\noneB\noneC"
1796 endfunc
1797 command -nargs=1 -complete=custom,T MyCmd
1798
Bram Moolenaar578fe942020-02-27 21:32:51 +01001799 set nowildmenu
1800 set wildmode=full,list
1801 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001802 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001803 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001804 call assert_equal('"MyCmd oneA', @:)
1805
1806 set wildmode=longest,full
1807 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1808 call assert_equal('"MyCmd one', @:)
1809 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1810 call assert_equal('"MyCmd oneC', @:)
1811
1812 set wildmode=longest
1813 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1814 call assert_equal('"MyCmd one', @:)
1815
1816 set wildmode=list:longest
1817 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001818 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001819 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001820 call assert_equal('"MyCmd one', @:)
1821
1822 set wildmode=""
1823 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1824 call assert_equal('"MyCmd oneA', @:)
1825
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001826 " Test for wildmode=longest with 'fileignorecase' set
1827 set wildmode=longest
1828 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001829 argadd AAA AAAA AAAAA
1830 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1831 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001832 set fileignorecase&
1833
1834 " Test for listing files with wildmode=list
1835 set wildmode=list
1836 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001837 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001838 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001839 call assert_equal('"b A', @:)
1840
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001841 " when using longest completion match, matches shorter than the argument
1842 " should be ignored (happens with :help)
1843 set wildmode=longest,full
1844 set wildmenu
1845 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1846 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001847 " non existing file
1848 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1849 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001850 set wildmenu&
1851
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001852 " Test for longest file name completion with 'fileignorecase'
1853 " On MS-Windows, file names are case insensitive.
1854 if has('unix')
1855 call writefile([], 'XTESTfoo')
1856 call writefile([], 'Xtestbar')
1857 set nofileignorecase
1858 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1859 call assert_equal('"e XTESTfoo', @:)
1860 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1861 call assert_equal('"e Xtestbar', @:)
1862 set fileignorecase
1863 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1864 call assert_equal('"e Xtest', @:)
1865 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1866 call assert_equal('"e Xtest', @:)
1867 set fileignorecase&
1868 call delete('XTESTfoo')
1869 call delete('Xtestbar')
1870 endif
1871
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001872 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001873 delcommand MyCmd
1874 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001875 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001876 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001877endfunc
1878
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001879func Test_wildmode()
1880 " Test with utf-8 encoding
1881 call Wildmode_tests()
1882
1883 " Test with latin1 encoding
1884 let save_encoding = &encoding
1885 set encoding=latin1
1886 call Wildmode_tests()
1887 let &encoding = save_encoding
1888endfunc
1889
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001890func Test_custom_complete_autoload()
1891 call mkdir('Xdir/autoload', 'p')
1892 let save_rtp = &rtp
1893 exe 'set rtp=' .. getcwd() .. '/Xdir'
1894 let lines =<< trim END
1895 func vim8#Complete(a, c, p)
1896 return "oneA\noneB\noneC"
1897 endfunc
1898 END
1899 call writefile(lines, 'Xdir/autoload/vim8.vim')
1900
1901 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1902 set nowildmenu
1903 set wildmode=full,list
1904 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1905 call assert_equal('"MyCmd oneA oneB oneC', @:)
1906
1907 let &rtp = save_rtp
1908 set wildmode& wildmenu&
1909 delcommand MyCmd
1910 call delete('Xdir', 'rf')
1911endfunc
1912
Bram Moolenaar578fe942020-02-27 21:32:51 +01001913" Test for interrupting the command-line completion
1914func Test_interrupt_compl()
1915 func F(lead, cmdl, p)
1916 if a:lead =~ 'tw'
1917 call interrupt()
1918 return
1919 endif
1920 return "one\ntwo\nthree"
1921 endfunc
1922 command -nargs=1 -complete=custom,F Tcmd
1923
1924 set nowildmenu
1925 set wildmode=full
1926 let interrupted = 0
1927 try
1928 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1929 catch /^Vim:Interrupt$/
1930 let interrupted = 1
1931 endtry
1932 call assert_equal(1, interrupted)
1933
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001934 let interrupted = 0
1935 try
1936 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1937 catch /^Vim:Interrupt$/
1938 let interrupted = 1
1939 endtry
1940 call assert_equal(1, interrupted)
1941
Bram Moolenaar578fe942020-02-27 21:32:51 +01001942 delcommand Tcmd
1943 delfunc F
1944 set wildmode&
1945endfunc
1946
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001947" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001948func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001949 let str = ":one two\<C-U>"
1950 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001951 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001952 let str ..= "\<Left>five\<Right>"
1953 let str ..= "\<Home>two "
1954 let str ..= "\<C-Left>one "
1955 let str ..= "\<C-Right> three"
1956 let str ..= "\<End>\<S-Left>four "
1957 let str ..= "\<S-Right> six"
1958 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1959 call feedkeys(str, 'xt')
1960 call assert_equal("\"one two three four five six seven", @:)
1961endfunc
1962
1963" Test for moving the cursor on the / command line in 'rightleft' mode
1964func Test_cmdline_edit_rightleft()
1965 CheckFeature rightleft
1966 set rightleft
1967 set rightleftcmd=search
1968 let str = "/one two\<C-U>"
1969 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001970 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001971 let str ..= "\<Right>five\<Left>"
1972 let str ..= "\<Home>two "
1973 let str ..= "\<C-Right>one "
1974 let str ..= "\<C-Left> three"
1975 let str ..= "\<End>\<S-Right>four "
1976 let str ..= "\<S-Left> six"
1977 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1978 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1979 call assert_equal("\"one two three four five six seven", @/)
1980 set rightleftcmd&
1981 set rightleft&
1982endfunc
1983
1984" Test for using <C-\>e in the command line to evaluate an expression
1985func Test_cmdline_expr()
1986 " Evaluate an expression from the beginning of a command line
1987 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1988 call assert_equal('"hello', @:)
1989
1990 " Use an invalid expression for <C-\>e
1991 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1992
1993 " Insert literal <CTRL-\> in the command line
1994 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1995 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001996endfunc
1997
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001998" This was making the insert position negative
1999func Test_cmdline_expr_register()
2000 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2001endfunc
2002
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002003" Test for 'imcmdline' and 'imsearch'
2004" This test doesn't actually test the input method functionality.
2005func Test_cmdline_inputmethod()
2006 new
2007 call setline(1, ['', 'abc', ''])
2008 set imcmdline
2009
2010 call feedkeys(":\"abc\<CR>", 'xt')
2011 call assert_equal("\"abc", @:)
2012 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2013 call assert_equal("\"abc", @:)
2014 call feedkeys("/abc\<CR>", 'xt')
2015 call assert_equal([2, 1], [line('.'), col('.')])
2016 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2017 call assert_equal([2, 1], [line('.'), col('.')])
2018
2019 set imsearch=2
2020 call cursor(1, 1)
2021 call feedkeys("/abc\<CR>", 'xt')
2022 call assert_equal([2, 1], [line('.'), col('.')])
2023 call cursor(1, 1)
2024 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2025 call assert_equal([2, 1], [line('.'), col('.')])
2026 set imdisable
2027 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2028 call assert_equal([2, 1], [line('.'), col('.')])
2029 set imdisable&
2030 set imsearch&
2031
2032 set imcmdline&
2033 %bwipe!
2034endfunc
2035
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002036" Test for recursively getting multiple command line inputs
2037func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002038 CheckFeature cmdwin
2039
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002040 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
2041 call assert_equal('"cyan', @:)
2042endfunc
2043
2044" Test for using CTRL-_ in the command line with 'allowrevins'
2045func Test_cmdline_revins()
2046 CheckNotMSWindows
2047 CheckFeature rightleft
2048 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2049 call assert_equal("\"abc\<c-_>", @:)
2050 set allowrevins
2051 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2052 call assert_equal('"abcñèæ', @:)
2053 set allowrevins&
2054endfunc
2055
2056" Test for typing UTF-8 composing characters in the command line
2057func Test_cmdline_composing_chars()
2058 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2059 call assert_equal('"ゔ', @:)
2060endfunc
2061
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002062" Test for normal mode commands not supported in the cmd window
2063func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002064 CheckFeature cmdwin
2065
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002066 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
2067 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
2068 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
2069 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
2070 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
2071 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02002072 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
2073 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
2074 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
2075 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
2076 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
2077 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
2078 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
2079 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
2080 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
2081 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
2082 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
2083 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
2084 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
2085 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
2086 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
2087 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
2088 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
2089 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
2090 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
2091 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
2092 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002093endfunc
2094
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002095" Close the Cmd-line window in insert mode using CTRL-C
2096func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002097 CheckFeature cmdwin
2098
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002099 %bw!
2100 let s = ''
2101 exe "normal q:a\<C-C>let s='Hello'\<CR>"
2102 call assert_equal('Hello', s)
2103 call assert_equal(1, winnr('$'))
2104endfunc
2105
Bram Moolenaar0e717042020-04-27 19:29:01 +02002106" test that ";" works to find a match at the start of the first line
2107func Test_zero_line_search()
2108 new
2109 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2110 call cursor(1,1)
2111 0;/pattern/d
2112 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2113 q!
2114endfunc
2115
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002116func Test_read_shellcmd()
2117 CheckUnix
2118 if executable('ls')
2119 " There should be ls in the $PATH
2120 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2121 call assert_match('^"r! .*\<ls\>', @:)
2122 endif
2123
2124 if executable('rm')
2125 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2126 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2127 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002128
2129 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2130 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2131 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002132 endif
2133endfunc
2134
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002135" Test for going up and down the directory tree using 'wildmenu'
2136func Test_wildmenu_dirstack()
2137 CheckUnix
2138 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002139 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002140 call writefile([], 'Xdir1/file1_1.txt')
2141 call writefile([], 'Xdir1/file1_2.txt')
2142 call writefile([], 'Xdir1/dir2/file2_1.txt')
2143 call writefile([], 'Xdir1/dir2/file2_2.txt')
2144 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2145 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002146 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2147 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002148 set wildmenu
2149
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002150 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002151 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002152 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002153 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002154 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002155 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002156 call assert_equal('"e ../../dir3/', @:)
2157 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2158 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002159 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002160 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002161 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002162 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002163 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002164 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2165 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2166
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002167 call delete('Xdir1', 'rf')
2168 set wildmenu&
2169endfunc
2170
obcat71c6f7a2021-05-13 20:23:10 +02002171" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002172" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2173" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002174func Test_recalling_cmdline()
2175 CheckFeature cmdline_hist
2176
2177 let g:cmdlines = []
2178 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2179
2180 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002181 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2182 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2183 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2184 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002185 "\ TODO: {'name': 'debug', ...}
2186 \]
2187 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002188 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2189 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2190 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2191 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2192 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002193 \]
2194 let prefix = 'vi'
2195 for h in histories
2196 call histadd(h.name, 'vim')
2197 call histadd(h.name, 'virtue')
2198 call histadd(h.name, 'Virgo')
2199 call histadd(h.name, 'vogue')
2200 call histadd(h.name, 'emacs')
2201 for k in keypairs
2202 let g:cmdlines = []
2203 let keyseqs = h.enter
2204 \ .. prefix
2205 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2206 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2207 \ .. h.exit
2208 call feedkeys(keyseqs, 'xt')
2209 call histdel(h.name, -1) " delete the history added by feedkeys above
2210 let expect = k.prefixmatch
2211 \ ? ['virtue', 'vim', 'virtue', prefix]
2212 \ : ['emacs', 'vogue', 'emacs', prefix]
2213 call assert_equal(expect, g:cmdlines)
2214 endfor
2215 endfor
2216
2217 unlet g:cmdlines
2218 cunmap <Plug>(save-cmdline)
2219endfunc
2220
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002221func Test_cmd_map_cmdlineChanged()
2222 let g:log = []
2223 cnoremap <F1> l<Cmd><CR>s
2224 augroup test
2225 autocmd!
2226 autocmd CmdlineChanged : let g:log += [getcmdline()]
2227 augroup END
2228
2229 call feedkeys(":\<F1>\<CR>", 'xt')
2230 call assert_equal(['l', 'ls'], g:log)
2231
Bram Moolenaar796139a2021-05-18 21:38:45 +02002232 let @b = 'b'
2233 cnoremap <F1> a<C-R>b
2234 let g:log = []
2235 call feedkeys(":\<F1>\<CR>", 'xt')
2236 call assert_equal(['a', 'ab'], g:log)
2237
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002238 unlet g:log
2239 cunmap <F1>
2240 augroup test
2241 autocmd!
2242 augroup END
2243endfunc
2244
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002245" Test for the 'suffixes' option
2246func Test_suffixes_opt()
2247 call writefile([], 'Xfile')
2248 call writefile([], 'Xfile.c')
2249 call writefile([], 'Xfile.o')
2250 set suffixes=
2251 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2252 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002253 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2254 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002255 set suffixes=.c
2256 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2257 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002258 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2259 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002260 set suffixes=,,
2261 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2262 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002263 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2264 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002265 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002266 " Test for getcompletion() with different patterns
2267 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2268 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002269 call delete('Xfile')
2270 call delete('Xfile.c')
2271 call delete('Xfile.o')
2272endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002273
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274" Test for using a popup menu for the command line completion matches
2275" (wildoptions=pum)
2276func Test_wildmenu_pum()
2277 CheckRunVimInTerminal
2278
2279 let commands =<< trim [CODE]
2280 set wildmenu
2281 set wildoptions=pum
2282 set shm+=I
2283 set noruler
2284 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002285
2286 func CmdCompl(a, b, c)
2287 return repeat(['aaaa'], 120)
2288 endfunc
2289 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002290
2291 func MyStatusLine() abort
2292 return 'status'
2293 endfunc
2294 func SetupStatusline()
2295 set statusline=%!MyStatusLine()
2296 set laststatus=2
2297 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002298
2299 func MyTabLine()
2300 return 'my tab line'
2301 endfunc
2302 func SetupTabline()
2303 set statusline=
2304 set tabline=%!MyTabLine()
2305 set showtabline=2
2306 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002307
2308 func DoFeedKeys()
2309 let &wildcharm = char2nr("\t")
2310 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2311 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002312 [CODE]
2313 call writefile(commands, 'Xtest')
2314
2315 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2316
2317 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2319
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002320 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2323
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002324 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002325 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2327
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002328 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002329 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2331
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002332 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002333 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2335
2336 " pressing <C-E> should end completion and go back to the original match
2337 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2339
2340 " pressing <C-Y> should select the current match and end completion
2341 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002342 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2343
2344 " With 'wildmode' set to 'longest,full', completing a match should display
2345 " the longest match, the wildmenu should not be displayed.
2346 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2347 call TermWait(buf)
2348 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002349 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2350
2351 " pressing <Tab> should display the wildmenu
2352 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2354
2355 " pressing <Tab> second time should select the next entry in the menu
2356 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002357 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2358
2359 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002360 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002361 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002362 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2363
2364 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002365 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2366
2367 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002368 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2369
2370 " Directory name completion
2371 call mkdir('Xdir/XdirA/XdirB', 'p')
2372 call writefile([], 'Xdir/XfileA')
2373 call writefile([], 'Xdir/XdirA/XfileB')
2374 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2375
2376 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002377 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2378
2379 " Pressing <Right> on a directory name should go into that directory
2380 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002381 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2382
2383 " Pressing <Left> on a directory name should go to the parent directory
2384 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002385 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2386
2387 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002388 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002389 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002390 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2391
2392 " Pressing <C-D> when the popup menu is displayed should remove the popup
2393 " menu
2394 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002395 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2396
2397 " Pressing <S-Tab> should open the popup menu with the last entry selected
2398 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002399 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2400
2401 " Pressing <Esc> should close the popup menu and cancel the cmd line
2402 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002403 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2404
2405 " Typing a character when the popup is open, should close the popup
2406 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002407 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2408
2409 " When the popup is open, entering the cmdline window should close the popup
2410 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2412 call term_sendkeys(buf, ":q\<CR>")
2413
2414 " After the last popup menu item, <C-N> should show the original string
2415 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002416 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2417
2418 " Use the popup menu for the command name
2419 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002420 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2421
2422 " Pressing the left arrow should remove the popup menu
2423 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002424 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2425
2426 " Pressing <BS> should remove the popup menu and erase the last character
2427 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002428 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2429
2430 " Pressing <C-W> should remove the popup menu and erase the previous word
2431 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002432 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2433
2434 " Pressing <C-U> should remove the popup menu and erase the entire line
2435 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002436 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2437
2438 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2439 " the cmdline from history
2440 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002441 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2442
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002443 " Check "list" still works
2444 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2445 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002446 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2447 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002448 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2449
rbtnn68cc2b82022-02-09 11:55:47 +00002450 " Tests a directory name contained full-width characters.
2451 call mkdir('Xdir/あいう', 'p')
2452 call writefile([], 'Xdir/あいう/abc')
2453 call writefile([], 'Xdir/あいう/xyz')
2454 call writefile([], 'Xdir/あいう/123')
2455
2456 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2457 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002458 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2459
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002460 " Pressing <C-A> when the popup menu is displayed should list all the
2461 " matches and pressing a key after that should remove the popup menu
2462 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2463 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2464 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2465
2466 " Pressing <C-A> when the popup menu is displayed should list all the
2467 " matches and pressing <Left> after that should move the cursor
2468 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2469 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2470 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2471
2472 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2473 " should be displayed correctly on the screen.
2474 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2475 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2476
2477 " After using <C-A> to expand all the filename matches, pressing <Up>
2478 " should not open the popup menu again.
2479 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2480 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2481 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2482 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2483
2484 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2485 " crash Vim
2486 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2487 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2488
Bram Moolenaar414acd32022-02-10 21:09:45 +00002489 " After removing the pum the command line is redrawn
2490 call term_sendkeys(buf, ":edit foo\<CR>")
2491 call term_sendkeys(buf, ":edit bar\<CR>")
2492 call term_sendkeys(buf, ":ls\<CR>")
2493 call term_sendkeys(buf, ":com\<Tab> ")
2494 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002495 call term_sendkeys(buf, "\<C-U>\<CR>")
2496
2497 " Esc still works to abort the command when 'statusline' is set
2498 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2499 call term_sendkeys(buf, ":si\<Tab>")
2500 call term_sendkeys(buf, "\<Esc>")
2501 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002502
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002503 " Esc still works to abort the command when 'tabline' is set
2504 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2505 call term_sendkeys(buf, ":si\<Tab>")
2506 call term_sendkeys(buf, "\<Esc>")
2507 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2508
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002509 " popup is cleared also when 'lazyredraw' is set
2510 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2511 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2512 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2513 call term_sendkeys(buf, "\<Esc>")
2514
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002515 " Pressing <PageDown> should scroll the menu downward
2516 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2517 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2518 call term_sendkeys(buf, "\<PageDown>")
2519 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2520 call term_sendkeys(buf, "\<PageDown>")
2521 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2522 call term_sendkeys(buf, "\<PageDown>")
2523 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2524 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2525 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2526
2527 " Pressing <PageUp> should scroll the menu upward
2528 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2529 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2530 call term_sendkeys(buf, "\<PageUp>")
2531 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2532 call term_sendkeys(buf, "\<PageUp>")
2533 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2534 call term_sendkeys(buf, "\<PageUp>")
2535 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2536
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002537 call term_sendkeys(buf, "\<C-U>\<CR>")
2538 call StopVimInTerminal(buf)
2539 call delete('Xtest')
2540 call delete('Xdir', 'rf')
2541endfunc
2542
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002543" Test for wildmenumode() with the cmdline popup menu
2544func Test_wildmenumode_with_pum()
2545 set wildmenu
2546 set wildoptions=pum
2547 cnoremap <expr> <F2> wildmenumode()
2548 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2549 call assert_equal('"sign define10', @:)
2550 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2551 call assert_equal('"sign define jump list place undefine unplace0', @:)
2552 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2553 call assert_equal('"sign 0', @:)
2554 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2555 call assert_equal('"sign define0', @:)
2556 set nowildmenu wildoptions&
2557 cunmap <F2>
2558endfunc
2559
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002560func Test_wildmenu_with_pum_foldexpr()
2561 CheckRunVimInTerminal
2562
2563 let lines =<< trim END
2564 call setline(1, ['folded one', 'folded two', 'some more text'])
2565 func MyFoldText()
2566 return 'foo'
2567 endfunc
2568 set foldtext=MyFoldText() wildoptions=pum
2569 normal ggzfj
2570 END
2571 call writefile(lines, 'Xpumfold')
2572 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2573 call term_sendkeys(buf, ":set\<Tab>")
2574 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2575
2576 call term_sendkeys(buf, "\<Esc>")
2577 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2578
2579 call StopVimInTerminal(buf)
2580 call delete('Xpumfold')
2581endfunc
2582
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002583" Test for opening the cmdline completion popup menu from the terminal window.
2584" The popup menu should be positioned correctly over the status line of the
2585" bottom-most window.
2586func Test_wildmenu_pum_from_terminal()
2587 CheckRunVimInTerminal
2588 let python = PythonProg()
2589 call CheckPython(python)
2590
2591 %bw!
2592 let cmds = ['set wildmenu wildoptions=pum']
2593 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2594 call add(cmds, "call term_start('" .. pcmd .. "')")
2595 call writefile(cmds, 'Xtest')
2596 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2597 call term_sendkeys(buf, "\r\r\r")
2598 call term_wait(buf)
2599 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2600 call term_wait(buf)
2601 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2602 call term_wait(buf)
2603 call StopVimInTerminal(buf)
2604 call delete('Xtest')
2605endfunc
2606
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002607" Test for completion after a :substitute command followed by a pipe (|)
2608" character
2609func Test_cmdline_complete_substitute()
2610 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2611 call assert_equal("\"s | \t", @:)
2612 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2613 call assert_equal("\"s/ | \t", @:)
2614 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2615 call assert_equal("\"s/one | \t", @:)
2616 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2617 call assert_equal("\"s/one/ | \t", @:)
2618 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2619 call assert_equal("\"s/one/two | \t", @:)
2620 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2621 call assert_equal('"s/one/two/ | chistory', @:)
2622 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2623 call assert_equal("\"s/one/two/g \t", @:)
2624 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2625 call assert_equal("\"s/one/two/g | chistory", @:)
2626 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2627 call assert_equal("\"s/one/t\\/ | \t", @:)
2628 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2629 call assert_equal('"s/one/t"o/ | chistory', @:)
2630 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2631 call assert_equal('"s/one/t|o/ | chistory', @:)
2632 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2633 call assert_equal("\"&\t", @:)
2634endfunc
2635
2636" Test for the :dlist command completion
2637func Test_cmdline_complete_dlist()
2638 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2639 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2640 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2641 call assert_equal("\"dlist 10 /pat/ \t", @:)
2642 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2643 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2644 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2645 call assert_equal("\"dlist 10 /pat\\\t", @:)
2646 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2647 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2648endfunc
2649
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002650" argument list (only for :argdel) fuzzy completion
2651func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002652 argadd change.py count.py charge.py
2653 set wildoptions&
2654 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2655 call assert_equal('"argdel cge', @:)
2656 set wildoptions=fuzzy
2657 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('"argdel change.py charge.py', @:)
2659 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002660 set wildoptions&
2661endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002662
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002663" autocmd group name fuzzy completion
2664func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002665 set wildoptions&
2666 augroup MyFuzzyGroup
2667 augroup END
2668 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2669 call assert_equal('"augroup mfg', @:)
2670 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2671 call assert_equal('"augroup MyFuzzyGroup', @:)
2672 set wildoptions=fuzzy
2673 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2674 call assert_equal('"augroup MyFuzzyGroup', @:)
2675 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal('"augroup My*p', @:)
2677 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002678 set wildoptions&
2679endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002680
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002681" buffer name fuzzy completion
2682func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002683 set wildoptions&
2684 edit SomeFile.txt
2685 enew
2686 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2687 call assert_equal('"b SF', @:)
2688 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2689 call assert_equal('"b SomeFile.txt', @:)
2690 set wildoptions=fuzzy
2691 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2692 call assert_equal('"b SomeFile.txt', @:)
2693 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2694 call assert_equal('"b S*File.txt', @:)
2695 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002696 set wildoptions&
2697endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002698
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002699" buffer name (full path) fuzzy completion
2700func Test_fuzzy_completion_bufname_fullpath()
2701 CheckUnix
2702 set wildoptions&
2703 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2704 edit Xcmd/Xstate/Xfile.js
2705 cd Xcmd/Xstate
2706 enew
2707 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2708 call assert_equal('"b CmdStateFile', @:)
2709 set wildoptions=fuzzy
2710 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2711 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2712 cd -
2713 call delete('Xcmd', 'rf')
2714 set wildoptions&
2715endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002716
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002717" :behave suboptions fuzzy completion
2718func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002719 set wildoptions&
2720 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2721 call assert_equal('"behave xm', @:)
2722 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal('"behave xterm', @:)
2724 set wildoptions=fuzzy
2725 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2726 call assert_equal('"behave xterm', @:)
2727 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2728 call assert_equal('"behave xt*m', @:)
2729 let g:Sline = ''
2730 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2731 call assert_equal('mswin', g:Sline)
2732 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002733 set wildoptions&
2734endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002735
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002736" " colorscheme name fuzzy completion - NOT supported
2737" func Test_fuzzy_completion_colorscheme()
2738" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002739
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002740" built-in command name fuzzy completion
2741func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002742 set wildoptions&
2743 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"sbwin', @:)
2745 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2746 call assert_equal('"sbrewind', @:)
2747 set wildoptions=fuzzy
2748 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2749 call assert_equal('"sbrewind', @:)
2750 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2751 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002752 set wildoptions&
2753endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002754
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002755" " compiler name fuzzy completion - NOT supported
2756" func Test_fuzzy_completion_compiler()
2757" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002758
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002759" :cscope suboptions fuzzy completion
2760func Test_fuzzy_completion_cscope()
2761 CheckFeature cscope
2762 set wildoptions&
2763 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2764 call assert_equal('"cscope ret', @:)
2765 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2766 call assert_equal('"cscope reset', @:)
2767 set wildoptions=fuzzy
2768 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2769 call assert_equal('"cscope reset', @:)
2770 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2771 call assert_equal('"cscope re*t', @:)
2772 set wildoptions&
2773endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002774
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002775" :diffget/:diffput buffer name fuzzy completion
2776func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002777 new SomeBuffer
2778 diffthis
2779 new OtherBuffer
2780 diffthis
2781 set wildoptions&
2782 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2783 call assert_equal('"diffget sbuf', @:)
2784 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2785 call assert_equal('"diffput sbuf', @:)
2786 set wildoptions=fuzzy
2787 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2788 call assert_equal('"diffget SomeBuffer', @:)
2789 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2790 call assert_equal('"diffput SomeBuffer', @:)
2791 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002792 set wildoptions&
2793endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002794
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002795" " directory name fuzzy completion - NOT supported
2796" func Test_fuzzy_completion_dirname()
2797" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002798
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002799" environment variable name fuzzy completion
2800func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002801 set wildoptions&
2802 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2803 call assert_equal('"echo $VUT', @:)
2804 set wildoptions=fuzzy
2805 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2806 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002807 set wildoptions&
2808endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002809
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002810" autocmd event fuzzy completion
2811func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002812 set wildoptions&
2813 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2814 call assert_equal('"autocmd BWout', @:)
2815 set wildoptions=fuzzy
2816 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2817 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818 set wildoptions&
2819endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002821" vim expression fuzzy completion
2822func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002823 let g:PerPlaceCount = 10
2824 set wildoptions&
2825 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"let c = ppc', @:)
2827 set wildoptions=fuzzy
2828 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2829 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002830 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002831endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002833" " file name fuzzy completion - NOT supported
2834" func Test_fuzzy_completion_filename()
2835" endfunc
2836
2837" " files in path fuzzy completion - NOT supported
2838" func Test_fuzzy_completion_filesinpath()
2839" endfunc
2840
2841" " filetype name fuzzy completion - NOT supported
2842" func Test_fuzzy_completion_filetype()
2843" endfunc
2844
2845" user defined function name completion
2846func Test_fuzzy_completion_userdefined_func()
2847 set wildoptions&
2848 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_equal('"call Test_f_u_f', @:)
2850 set wildoptions=fuzzy
2851 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2852 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2853 set wildoptions&
2854endfunc
2855
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002856" <SNR> functions should be sorted to the end
2857func Test_fuzzy_completion_userdefined_snr_func()
2858 func s:Sendmail()
2859 endfunc
2860 func SendSomemail()
2861 endfunc
2862 func S1e2n3dmail()
2863 endfunc
2864 set wildoptions=fuzzy
2865 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002866 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002867 set wildoptions&
2868 delfunc s:Sendmail
2869 delfunc SendSomemail
2870 delfunc S1e2n3dmail
2871endfunc
2872
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002873" user defined command name completion
2874func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002875 set wildoptions&
2876 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2877 call assert_equal('"MsFeat', @:)
2878 set wildoptions=fuzzy
2879 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2880 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002881 set wildoptions&
2882endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002883
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002884" " :help tag fuzzy completion - NOT supported
2885" func Test_fuzzy_completion_helptag()
2886" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002887
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002888" highlight group name fuzzy completion
2889func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002890 set wildoptions&
2891 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2892 call assert_equal('"highlight SKey', @:)
2893 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2894 call assert_equal('"highlight SpecialKey', @:)
2895 set wildoptions=fuzzy
2896 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2897 call assert_equal('"highlight SpecialKey', @:)
2898 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002900 set wildoptions&
2901endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002902
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903" :history suboptions fuzzy completion
2904func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905 set wildoptions&
2906 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2907 call assert_equal('"history dg', @:)
2908 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2909 call assert_equal('"history search', @:)
2910 set wildoptions=fuzzy
2911 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2912 call assert_equal('"history debug', @:)
2913 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002915 set wildoptions&
2916endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002917
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002918" :language locale name fuzzy completion
2919func Test_fuzzy_completion_lang()
2920 CheckUnix
2921 set wildoptions&
2922 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2923 call assert_equal('"lang psx', @:)
2924 set wildoptions=fuzzy
2925 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2926 call assert_equal('"lang POSIX', @:)
2927 set wildoptions&
2928endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" :mapclear buffer argument fuzzy completion
2931func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932 set wildoptions&
2933 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2934 call assert_equal('"mapclear buf', @:)
2935 set wildoptions=fuzzy
2936 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2937 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002938 set wildoptions&
2939endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941" map name fuzzy completion
2942func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002943 " test regex completion works
2944 set wildoptions=fuzzy
2945 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2946 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002947 nmap <plug>MyLongMap :p<CR>
2948 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2949 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2950 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal("\"nmap MLM \t", @:)
2952 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2953 call assert_equal("\"nmap <F2> one two \t", @:)
2954 " duplicate entries should be removed
2955 vmap <plug>MyLongMap :<C-U>#<CR>
2956 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2958 nunmap <plug>MyLongMap
2959 vunmap <plug>MyLongMap
2960 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal("\"nmap ABC\t", @:)
2962 " results should be sorted by best match
2963 nmap <Plug>format :
2964 nmap <Plug>goformat :
2965 nmap <Plug>TestFOrmat :
2966 nmap <Plug>fendoff :
2967 nmap <Plug>state :
2968 nmap <Plug>FendingOff :
2969 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2971 nunmap <Plug>format
2972 nunmap <Plug>goformat
2973 nunmap <Plug>TestFOrmat
2974 nunmap <Plug>fendoff
2975 nunmap <Plug>state
2976 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977 set wildoptions&
2978endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" abbreviation fuzzy completion
2981func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002982 set wildoptions=fuzzy
2983 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal("\"iabbr <nowait>", @:)
2985 iabbr WaitForCompletion WFC
2986 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2987 call assert_equal("\"iabbr WaitForCompletion", @:)
2988 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2989 call assert_equal("\"iabbr a1z\t", @:)
2990 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002991 set wildoptions&
2992endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002993
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002994" menu name fuzzy completion
2995func Test_fuzzy_completion_menu()
2996 CheckGui
2997 set wildoptions&
2998 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2999 call assert_equal('"menu pup', @:)
3000 set wildoptions=fuzzy
3001 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal('"menu PopUp.', @:)
3003 set wildoptions&
3004endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003005
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003006" :messages suboptions fuzzy completion
3007func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003008 set wildoptions&
3009 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"messages clr', @:)
3011 set wildoptions=fuzzy
3012 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003014 set wildoptions&
3015endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003016
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003017" :set option name fuzzy completion
3018func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003019 set wildoptions&
3020 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3021 call assert_equal('"set brkopt', @:)
3022 set wildoptions=fuzzy
3023 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3024 call assert_equal('"set breakindentopt', @:)
3025 set wildoptions&
3026 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal('"set fixendofline', @:)
3028 set wildoptions=fuzzy
3029 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003031 set wildoptions&
3032endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003033
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003034" :set <term_option>
3035func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003036 set wildoptions&
3037 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal('"set t_EC', @:)
3039 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3040 call assert_equal('"set <t_EC>', @:)
3041 set wildoptions=fuzzy
3042 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal('"set t_EC', @:)
3044 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003046 set wildoptions&
3047endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003048
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003049" " :packadd directory name fuzzy completion - NOT supported
3050" func Test_fuzzy_completion_packadd()
3051" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003052
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003053" " shell command name fuzzy completion - NOT supported
3054" func Test_fuzzy_completion_shellcmd()
3055" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003056
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003057" :sign suboptions fuzzy completion
3058func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003059 set wildoptions&
3060 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal('"sign ufe', @:)
3062 set wildoptions=fuzzy
3063 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003065 set wildoptions&
3066endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003067
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003068" :syntax suboptions fuzzy completion
3069func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003070 set wildoptions&
3071 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3072 call assert_equal('"syntax kwd', @:)
3073 set wildoptions=fuzzy
3074 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003076 set wildoptions&
3077endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003078
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003079" syntax group name fuzzy completion
3080func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003081 set wildoptions&
3082 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal('"syntax list mpar', @:)
3084 set wildoptions=fuzzy
3085 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003087 set wildoptions&
3088endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003089
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003090" :syntime suboptions fuzzy completion
3091func Test_fuzzy_completion_syntime()
3092 CheckFeature profile
3093 set wildoptions&
3094 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3095 call assert_equal('"syntime clr', @:)
3096 set wildoptions=fuzzy
3097 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal('"syntime clear', @:)
3099 set wildoptions&
3100endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003101
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003102" " tag name fuzzy completion - NOT supported
3103" func Test_fuzzy_completion_tagname()
3104" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003105
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003106" " tag name and file fuzzy completion - NOT supported
3107" func Test_fuzzy_completion_tagfile()
3108" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003109
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003110" " user names fuzzy completion - how to test this functionality?
3111" func Test_fuzzy_completion_username()
3112" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003113
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003114" user defined variable name fuzzy completion
3115func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003116 let g:SomeVariable=10
3117 set wildoptions&
3118 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal('"let SVar', @:)
3120 set wildoptions=fuzzy
3121 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003123 set wildoptions&
3124endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003125
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003126" Test for sorting the results by the best match
3127func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003128 %bw!
3129 command T123format :
3130 command T123goformat :
3131 command T123TestFOrmat :
3132 command T123fendoff :
3133 command T123state :
3134 command T123FendingOff :
3135 set wildoptions=fuzzy
3136 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3138 delcommand T123format
3139 delcommand T123goformat
3140 delcommand T123TestFOrmat
3141 delcommand T123fendoff
3142 delcommand T123state
3143 delcommand T123FendingOff
3144 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003145 set wildoptions&
3146endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003147
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003148" Test for fuzzy completion of a command with lower case letters and a number
3149func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003150 command Foo2Bar :
3151 set wildoptions=fuzzy
3152 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal('"Foo2Bar', @:)
3154 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal('"Foo2Bar', @:)
3156 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal('"Foo2Bar', @:)
3158 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003159 set wildoptions&
3160endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003161
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003162" Test for command completion for a command starting with 'k'
3163func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003164 command KillKillKill :
3165 set wildoptions&
3166 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal("\"killkill\<Tab>", @:)
3168 set wildoptions=fuzzy
3169 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal('"KillKillKill', @:)
3171 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003172 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003173endfunc
3174
3175" Test for fuzzy completion for user defined custom completion function
3176func Test_fuzzy_completion_custom_func()
3177 func Tcompl(a, c, p)
3178 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3179 endfunc
3180 command -nargs=* -complete=custom,Tcompl Fuzzy :
3181 set wildoptions&
3182 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal("\"Fuzzy format", @:)
3184 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal("\"Fuzzy xy", @:)
3186 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"Fuzzy ttt", @:)
3188 set wildoptions=fuzzy
3189 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3191 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3193 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3194 call assert_equal("\"Fuzzy xy", @:)
3195 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3196 call assert_equal("\"Fuzzy TestFOrmat", @:)
3197 delcom Fuzzy
3198 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003199endfunc
3200
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003201" Test for :breakadd argument completion
3202func Test_cmdline_complete_breakadd()
3203 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal("\"breakadd expr file func here", @:)
3205 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal("\"breakadd expr", @:)
3207 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"breakadd expr", @:)
3209 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"breakadd here", @:)
3211 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal("\"breakadd here", @:)
3213 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"breakadd abc", @:)
3215 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3216 let l = getcompletion('not', 'breakpoint')
3217 call assert_equal([], l)
3218
3219 " Test for :breakadd file [lnum] <file>
3220 call writefile([], 'Xscript')
3221 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakadd file Xscript", @:)
3223 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakadd file Xscript", @:)
3225 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakadd file 20 Xscript", @:)
3227 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakadd file 20 Xscript", @:)
3229 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3231 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal("\"breakadd file 20\t", @:)
3233 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal("\"breakadd file 20x\t", @:)
3235 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakadd file Xscript ", @:)
3237 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3238 call assert_equal("\"breakadd file X1B2C3", @:)
3239 call delete('Xscript')
3240
3241 " Test for :breakadd func [lnum] <function>
3242 func Xbreak_func()
3243 endfunc
3244 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal("\"breakadd func Xbreak_func", @:)
3246 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal("\"breakadd func Xbreak_func", @:)
3248 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3250 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3252 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3253 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3254 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3255 call assert_equal("\"breakadd func 20\t", @:)
3256 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3257 call assert_equal("\"breakadd func 20x\t", @:)
3258 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal("\"breakadd func Xbreak_func ", @:)
3260 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3261 call assert_equal("\"breakadd func X1B2C3", @:)
3262 delfunc Xbreak_func
3263
3264 " Test for :breakadd expr <expression>
3265 let g:Xtest_var = 10
3266 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal("\"breakadd expr Xtest_var", @:)
3268 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal("\"breakadd expr Xtest_var", @:)
3270 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal("\"breakadd expr Xtest_var ", @:)
3272 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal("\"breakadd expr X1B2C3", @:)
3274 unlet g:Xtest_var
3275
3276 " Test for :breakadd here
3277 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_equal("\"breakadd here Xtest", @:)
3279 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"breakadd here Xtest", @:)
3281 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_equal("\"breakadd here ", @:)
3283endfunc
3284
3285" Test for :breakdel argument completion
3286func Test_cmdline_complete_breakdel()
3287 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal("\"breakdel file func here", @:)
3289 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal("\"breakdel file", @:)
3291 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal("\"breakdel file", @:)
3293 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal("\"breakdel here", @:)
3295 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3296 call assert_equal("\"breakdel here", @:)
3297 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3298 call assert_equal("\"breakdel abc", @:)
3299
3300 " Test for :breakdel file [lnum] <file>
3301 call writefile([], 'Xscript')
3302 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3303 call assert_equal("\"breakdel file Xscript", @:)
3304 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3305 call assert_equal("\"breakdel file Xscript", @:)
3306 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3307 call assert_equal("\"breakdel file 20 Xscript", @:)
3308 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal("\"breakdel file 20 Xscript", @:)
3310 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3311 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3312 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3313 call assert_equal("\"breakdel file 20\t", @:)
3314 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3315 call assert_equal("\"breakdel file 20x\t", @:)
3316 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3317 call assert_equal("\"breakdel file Xscript ", @:)
3318 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3319 call assert_equal("\"breakdel file X1B2C3", @:)
3320 call delete('Xscript')
3321
3322 " Test for :breakdel func [lnum] <function>
3323 func Xbreak_func()
3324 endfunc
3325 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3326 call assert_equal("\"breakdel func Xbreak_func", @:)
3327 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3328 call assert_equal("\"breakdel func Xbreak_func", @:)
3329 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3330 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3331 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3333 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3334 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3335 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3336 call assert_equal("\"breakdel func 20\t", @:)
3337 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3338 call assert_equal("\"breakdel func 20x\t", @:)
3339 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3340 call assert_equal("\"breakdel func Xbreak_func ", @:)
3341 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3342 call assert_equal("\"breakdel func X1B2C3", @:)
3343 delfunc Xbreak_func
3344
3345 " Test for :breakdel here
3346 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3347 call assert_equal("\"breakdel here Xtest", @:)
3348 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3349 call assert_equal("\"breakdel here Xtest", @:)
3350 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3351 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003352endfunc
3353
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003354" Test for :scriptnames argument completion
3355func Test_cmdline_complete_scriptnames()
3356 set wildmenu
3357 call writefile(['let a = 1'], 'Xa1b2c3.vim')
3358 source Xa1b2c3.vim
3359 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3360 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3361 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3362 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3363 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3364 call assert_equal("\"script b2c3", @:)
3365 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3366 call assert_match("\"script 2\<Tab>$", @:)
3367 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3369 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3370 call assert_equal("\"script ", @:)
3371 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3372 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3373 new
3374 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3375 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3376 bw!
3377 call delete('Xa1b2c3.vim')
3378 set wildmenu&
3379endfunc
3380
Bram Moolenaard8893442022-05-06 20:38:47 +01003381" this was going over the end of IObuff
3382func Test_report_error_with_composing()
3383 let caught = 'no'
3384 try
3385 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3386 catch /E492:/
3387 let caught = 'yes'
3388 endtry
3389 call assert_equal('yes', caught)
3390endfunc
3391
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003392" Test for expanding 2-letter and 3-letter :substitute command arguments.
3393" These commands don't accept an argument.
3394func Test_cmdline_complete_substitute_short()
3395 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3396 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3397 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3398 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3399 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3400 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3402 endfor
3403endfunc
3404
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003405func Check_completion()
3406 call assert_equal('let a', getcmdline())
3407 call assert_equal(6, getcmdpos())
3408 call assert_equal(7, getcmdscreenpos())
3409 call assert_equal('var', getcmdcompltype())
3410 return ''
3411endfunc
3412
3413func Test_screenpos_and_completion()
3414 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3415endfunc
3416
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003417func Test_recursive_register()
3418 let @= = ''
3419 silent! ?e/
3420 let caught = 'no'
3421 try
3422 normal //
3423 catch /E169:/
3424 let caught = 'yes'
3425 endtry
3426 call assert_equal('yes', caught)
3427endfunc
3428
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003429func Test_long_error_message()
3430 " the error should be truncated, not overrun IObuff
3431 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3432endfunc
3433
Bram Moolenaar309976e2019-12-05 18:16:33 +01003434" vim: shiftwidth=2 sts=2 expandtab