robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 8c77b5be50c50ab119

master
201.6 KiB5798 linesraw
1" Tests for editing the command line.
2
3source check.vim
4source screendump.vim
5source view_util.vim
6source shared.vim
7
8func SetUp()
9  func SaveLastScreenLine()
10    let g:Sline = Screenline(&lines - 1)
11    return ''
12  endfunc
13  cnoremap <expr> <F4> SaveLastScreenLine()
14endfunc
15
16func TearDown()
17  delfunc SaveLastScreenLine
18  cunmap <F4>
19endfunc
20
21func Test_complete_tab()
22  call writefile(['testfile'], 'Xtestfile')
23  call feedkeys(":e Xtest\t\r", "tx")
24  call assert_equal('testfile', getline(1))
25
26  " Pressing <Tab> after '%' completes the current file, also on MS-Windows
27  call feedkeys(":e %\t\r", "tx")
28  call assert_equal('e Xtestfile', @:)
29  call delete('Xtestfile')
30endfunc
31
32func Test_complete_list()
33  " We can't see the output, but at least we check the code runs properly.
34  call feedkeys(":e test\<C-D>\r", "tx")
35  call assert_equal('test', expand('%:t'))
36
37  " If a command doesn't support completion, then CTRL-D should be literally
38  " used.
39  call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40  call assert_equal("\"chistory \<C-D>", @:)
41
42  " Test for displaying the tail of the completion matches
43  set wildmode=longest,full
44  call mkdir('Xtest')
45  call writefile([], 'Xtest/a.c')
46  call writefile([], 'Xtest/a.h')
47  let g:Sline = ''
48  call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49  call assert_equal('a.c  a.h', g:Sline)
50  call assert_equal('"e Xtest/', @:)
51  if has('win32')
52    " Test for 'completeslash'
53    set completeslash=backslash
54    call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55    call assert_equal('"e Xtest\', @:)
56    call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57    call assert_equal('"e Xtest\a.', @:)
58    set completeslash=slash
59    call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60    call assert_equal('"e Xtest/', @:)
61    call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62    call assert_equal('"e Xtest/a.', @:)
63    set completeslash&
64  endif
65
66  " Test for displaying the tail with wildcards
67  let g:Sline = ''
68  call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69  call assert_equal('Xtest/a.c  Xtest/a.h', g:Sline)
70  call assert_equal('"e Xtes?/', @:)
71  let g:Sline = ''
72  call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73  call assert_equal('Xtest/a.c  Xtest/a.h', g:Sline)
74  call assert_equal('"e Xtes*/', @:)
75  let g:Sline = ''
76  call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77  call assert_equal(':e Xtes[/', g:Sline)
78  call assert_equal('"e Xtes[/', @:)
79
80  call delete('Xtest', 'rf')
81  set wildmode&
82endfunc
83
84func Test_complete_wildmenu()
85  call mkdir('Xwilddir1/Xdir2', 'pR')
86  call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
87  call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
88  call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
89  call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
90  set wildmenu
91
92  " Pressing <Tab> completes, and moves to next files when pressing again.
93  call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
94  call assert_equal('testfile1', getline(1))
95  call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
96  call assert_equal('testfile2', getline(1))
97
98  " <S-Tab> is like <Tab> but begin with the last match and then go to
99  " previous.
100  call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
101  call assert_equal('testfile2', getline(1))
102  call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
103  call assert_equal('testfile1', getline(1))
104
105  " <Left>/<Right> to move to previous/next file.
106  call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
107  call assert_equal('testfile1', getline(1))
108  call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
109  call assert_equal('testfile2', getline(1))
110  call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
111  call assert_equal('testfile1', getline(1))
112
113  " <Up>/<Down> to go up/down directories.
114  call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
115  call assert_equal('testfile3', getline(1))
116  call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
117  call assert_equal('testfile1', getline(1))
118
119  " this fails in some Unix GUIs, not sure why
120  if !has('unix') || !has('gui_running')
121    " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
122    " different than 'wildchar'.
123    set wildcharm=<C-Z>
124    cnoremap <C-J> <Down><C-Z>
125    cnoremap <C-K> <Up><C-Z>
126    call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
127    call assert_equal('testfile3', getline(1))
128    call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
129    call assert_equal('testfile1', getline(1))
130    set wildcharm=0
131    cunmap <C-J>
132    cunmap <C-K>
133  endif
134
135  " Test for canceling the wild menu by adding a character
136  redrawstatus
137  call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
138  call assert_equal('"e Xwilddir1/Xdir2/x', @:)
139
140  " Completion using a relative path
141  cd Xwilddir1/Xdir2
142  call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
143  call assert_equal('"e Xtestfile3 Xtestfile4', @:)
144  cd -
145
146  " test for wildmenumode()
147  cnoremap <expr> <F2> wildmenumode()
148  call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
149  call assert_equal('"cd Xwilddir1/0', @:)
150  call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
151  call assert_equal('"e Xwilddir1/Xdir2/1', @:)
152  cunmap <F2>
153
154  " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
155  " After this pressing <Left> or <Right> should not change the selection.
156  call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
157  call assert_equal('"sign define', @:)
158  call histadd('cmd', 'TestWildMenu')
159  call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
160  call assert_equal('"TestWildMenu', @:)
161
162  " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
163  call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
164  call assert_equal('"sign un yy zz', @:)
165
166  call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
167  call assert_equal('"sign unplace yy zz', @:)
168
169  " This used to crash
170  call feedkeys(":sign un\<Tab>\<S-Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx')
171  " Ctrl-Y is inserted literally like before 9.1.1714
172  call assert_equal("\"sign undefine unplace\<C-Y>", @:)
173  " Also test Ctrl-Y after Ctrl-A with selected item (the result is the same)
174  call feedkeys(":sign un\<Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx')
175  call assert_equal("\"sign undefine unplace\<C-Y>", @:)
176  call feedkeys(":sign un\<Tab>\<Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx')
177  call assert_equal("\"sign undefine unplace\<C-Y>", @:)
178
179  " cleanup
180  %bwipe
181  set nowildmenu
182endfunc
183
184func Test_wildmenu_screendump()
185  CheckScreendump
186
187  let lines =<< trim [SCRIPT]
188    set wildmenu hlsearch
189  [SCRIPT]
190  call writefile(lines, 'XTest_wildmenu', 'D')
191
192  " Test simple wildmenu
193  let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
194  call term_sendkeys(buf, ":vim\<Tab>")
195  call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
196
197  call term_sendkeys(buf, "\<Tab>")
198  call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
199
200  call term_sendkeys(buf, "\<Tab>")
201  call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
202
203  " Looped back to the original value
204  call term_sendkeys(buf, "\<Tab>\<Tab>")
205  call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
206
207  " Test that the wild menu is cleared properly
208  call term_sendkeys(buf, " ")
209  call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
210
211  " Test that a different wildchar still works
212  call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
213  call term_sendkeys(buf, ":vim\<Esc>")
214  call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
215
216  " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
217  " sure clean up is properly done in edge case like this.
218  call term_sendkeys(buf, "\<Esc>")
219  call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
220
221  " clean up
222  call StopVimInTerminal(buf)
223endfunc
224
225func Test_wildmenu_with_input_func()
226  CheckScreendump
227
228  let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8})
229
230  call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
231  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {})
232  call term_sendkeys(buf, "ech\<Tab>")
233  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {})
234  call term_sendkeys(buf, "\<Space>")
235  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {})
236  call term_sendkeys(buf, "bufn\<Tab>")
237  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {})
238  call term_sendkeys(buf, "\<CR>")
239
240  call term_sendkeys(buf, ":set wildoptions+=pum\<CR>")
241
242  call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
243  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {})
244  call term_sendkeys(buf, "ech\<Tab>")
245  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {})
246  call term_sendkeys(buf, "\<Space>")
247  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {})
248  call term_sendkeys(buf, "bufn\<Tab>")
249  call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {})
250  call term_sendkeys(buf, "\<CR>")
251
252  " clean up
253  call StopVimInTerminal(buf)
254endfunc
255
256func Test_redraw_in_autocmd()
257  CheckScreendump
258
259  let lines =<< trim END
260      set cmdheight=2
261      autocmd CmdlineChanged * redraw
262  END
263  call writefile(lines, 'XTest_redraw', 'D')
264
265  let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
266  call term_sendkeys(buf, ":for i in range(3)\<CR>")
267  call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
268
269  call term_sendkeys(buf, "let i =")
270  call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
271
272  " clean up
273  call term_sendkeys(buf, "\<CR>")
274  call StopVimInTerminal(buf)
275endfunc
276
277func Test_redrawstatus_in_autocmd()
278  CheckScreendump
279
280  let lines =<< trim END
281      set laststatus=2
282      set statusline=%=:%{getcmdline()}
283      autocmd CmdlineChanged * redrawstatus
284  END
285  call writefile(lines, 'XTest_redrawstatus', 'D')
286
287  let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
288  " :redrawstatus is postponed if messages have scrolled
289  call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
290  call term_sendkeys(buf, ":foobar")
291  call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
292  " it is not postponed if messages have not scrolled
293  call term_sendkeys(buf, "\<Esc>:for in in range(3)")
294  call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
295  " with cmdheight=1 messages have scrolled when typing :endfor
296  call term_sendkeys(buf, "\<CR>:endfor")
297  call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
298  call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
299  " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
300  call term_sendkeys(buf, ":for in in range(3)")
301  call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
302  call term_sendkeys(buf, "\<CR>:endfor")
303  call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
304
305  " clean up
306  call term_sendkeys(buf, "\<CR>")
307  call StopVimInTerminal(buf)
308endfunc
309
310func Test_changing_cmdheight()
311  CheckScreendump
312
313  let lines =<< trim END
314      set cmdheight=1 laststatus=2
315      func EchoOne()
316        set laststatus=2 cmdheight=1
317        echo 'foo'
318        echo 'bar'
319        set cmdheight=2
320      endfunc
321      func EchoTwo()
322        set laststatus=2
323        set cmdheight=5
324        echo 'foo'
325        echo 'bar'
326        set cmdheight=1
327      endfunc
328  END
329  call writefile(lines, 'XTest_cmdheight', 'D')
330
331  let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
332  call term_sendkeys(buf, ":resize -3\<CR>")
333  call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
334
335  " :resize now also changes 'cmdheight' accordingly
336  call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
337  call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
338
339  " using more space moves the status line up
340  call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
341  call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
342
343  " reducing cmdheight moves status line down
344  call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
345  call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
346
347  " reducing window size and then setting cmdheight
348  call term_sendkeys(buf, ":resize -1\<CR>")
349  call term_sendkeys(buf, ":set cmdheight=1\<CR>")
350  call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
351
352  " setting 'cmdheight' works after outputting two messages
353  call term_sendkeys(buf, ":call EchoTwo()\<CR>")
354  call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
355
356  " increasing 'cmdheight' doesn't clear the messages that need hit-enter
357  call term_sendkeys(buf, ":call EchoOne()\<CR>")
358  call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
359
360  " window commands do not reduce 'cmdheight' to value lower than :set by user
361  call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
362  call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
363
364  " clean up
365  call StopVimInTerminal(buf)
366endfunc
367
368func Test_cmdheight_tabline()
369  CheckScreendump
370
371  let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
372  call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
373
374  " clean up
375  call StopVimInTerminal(buf)
376endfunc
377
378func Test_map_completion()
379  call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
380  call assert_equal('"map <unique> <silent>', getreg(':'))
381  call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
382  call assert_equal('"map <script> <unique>', getreg(':'))
383  call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
384  call assert_equal('"map <expr> <script>', getreg(':'))
385  call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
386  call assert_equal('"map <buffer> <expr>', getreg(':'))
387  call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
388  call assert_equal('"map <nowait> <buffer>', getreg(':'))
389  call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
390  call assert_equal('"map <special> <nowait>', getreg(':'))
391  call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
392  call assert_equal('"map <silent> <special>', getreg(':'))
393
394  map <Middle>x middle
395
396  map ,f commaf
397  map ,g commaf
398  map <Left> left
399  map <A-Left>x shiftleft
400  call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
401  call assert_equal('"map ,f', getreg(':'))
402  call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
403  call assert_equal('"map ,g', getreg(':'))
404  call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
405  call assert_equal('"map <Left>', getreg(':'))
406  call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
407  call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
408  call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
409  call assert_equal("\"map <M-Left>x", getreg(':'))
410  unmap ,f
411  unmap ,g
412  unmap <Left>
413  unmap <A-Left>x
414
415  set cpo-=< cpo-=k
416  map <Left> left
417  call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
418  call assert_equal('"map <Left>', getreg(':'))
419  call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
420  call assert_equal("\"map <M\<Tab>", getreg(':'))
421  call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
422  call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
423  unmap <Left>
424
425  " set cpo+=<
426  map <Left> left
427  exe "set t_k6=\<Esc>[17~"
428  call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
429  call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
430  call assert_equal('"map <Left>', getreg(':'))
431  if !has('gui_running')
432    call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
433    " call assert_equal("\"map <F6>x", getreg(':'))
434  endif
435  unmap <Left>
436  call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
437  set cpo-=<
438
439  set cpo+=B
440  map <Left> left
441  call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
442  call assert_equal('"map <Left>', getreg(':'))
443  unmap <Left>
444  set cpo-=B
445
446  " set cpo+=k
447  map <Left> left
448  call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
449  call assert_equal('"map <Left>', getreg(':'))
450  unmap <Left>
451  set cpo-=k
452
453  call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
454
455  unmap <Middle>x
456  set cpo&vim
457endfunc
458
459func Test_match_completion()
460  hi Aardig ctermfg=green
461  " call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
462  call feedkeys(":match A\<Tab>\<Home>\"\<CR>", 'xt')
463  call assert_equal('"match Aardig', @:)
464  call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
465  call assert_equal('"match none', @:)
466  call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
467  call assert_equal('"match | chistory', @:)
468endfunc
469
470func Test_highlight_completion()
471  hi Aardig ctermfg=green
472  " call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
473  call feedkeys(":hi A\<Tab>\<Home>\"\<CR>", 'xt')
474  call assert_equal('"hi Aardig', getreg(':'))
475  " call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
476  call feedkeys(":hi default A\<Tab>\<Home>\"\<CR>", 'xt')
477  call assert_equal('"hi default Aardig', getreg(':'))
478  call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
479  call assert_equal('"hi clear Aardig', getreg(':'))
480  call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
481  call assert_equal('"hi link', getreg(':'))
482  call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
483  call assert_equal('"hi default', getreg(':'))
484  call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
485  call assert_equal('"hi clear', getreg(':'))
486
487  " A cleared group does not show up in completions.
488  hi clear Added
489  hi Anders ctermfg=green
490  call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
491  hi clear Aardig
492  call assert_equal(['Anders'], getcompletion('A', 'highlight'))
493  hi clear Anders
494  call assert_equal([], getcompletion('A', 'highlight'))
495endfunc
496
497func Test_getcompletion()
498  let groupcount = len(getcompletion('', 'event'))
499  call assert_true(groupcount > 0)
500  let matchcount = len('File'->getcompletion('event'))
501  call assert_true(matchcount > 0)
502  call assert_true(groupcount > matchcount)
503
504  if has('menu')
505    source $VIMRUNTIME/menu.vim
506    let matchcount = len(getcompletion('', 'menu'))
507    call assert_true(matchcount > 0)
508    call assert_equal(['File.'], getcompletion('File', 'menu'))
509    call assert_true(matchcount > 0)
510    let matchcount = len(getcompletion('File.', 'menu'))
511    call assert_true(matchcount > 0)
512    source $VIMRUNTIME/delmenu.vim
513  endif
514
515  let l = getcompletion('v:n', 'var')
516  call assert_true(index(l, 'v:null') >= 0)
517  let l = getcompletion('v:notexists', 'var')
518  call assert_equal([], l)
519
520  args a.c b.c
521  let l = getcompletion('', 'arglist')
522  call assert_equal(['a.c', 'b.c'], l)
523  let l = getcompletion('a.', 'buffer')
524  call assert_equal(['a.c'], l)
525  %argdelete
526
527  let l = getcompletion('', 'augroup')
528  call assert_true(index(l, 'END') >= 0)
529  let l = getcompletion('blahblah', 'augroup')
530  call assert_equal([], l)
531
532  " let l = getcompletion('', 'behave')
533  " call assert_true(index(l, 'mswin') >= 0)
534  " let l = getcompletion('not', 'behave')
535  " call assert_equal([], l)
536
537  let l = getcompletion('', 'color')
538  call assert_true(index(l, 'default') >= 0)
539  let l = getcompletion('dirty', 'color')
540  call assert_equal([], l)
541
542  let l = getcompletion('', 'command')
543  call assert_true(index(l, 'sleep') >= 0)
544  let l = getcompletion('awake', 'command')
545  call assert_equal([], l)
546
547  let l = getcompletion('', 'dir')
548  call assert_true(index(l, 'sautest/') >= 0)
549  let l = getcompletion('NoMatch', 'dir')
550  call assert_equal([], l)
551
552  if glob('~/*') !=# ''
553    let l = getcompletion('~/', 'dir')
554    call assert_true(l[0][0] ==# '~')
555  endif
556
557  let l = getcompletion('exe', 'expression')
558  call assert_true(index(l, 'executable(') >= 0)
559  let l = getcompletion('kill', 'expression')
560  call assert_equal([], l)
561
562  let l = getcompletion('', 'filetypecmd')
563  call assert_equal(["detect", "indent", "off", "on", "plugin"], l)
564  let l = getcompletion('not', 'filetypecmd')
565  call assert_equal([], l)
566  let l = getcompletion('o', 'filetypecmd')
567  call assert_equal(['off', 'on'], l)
568  let l = getcompletion('det', 'filetypecmd')
569  call assert_equal(['detect'], l)
570
571  let l = getcompletion('tag', 'function')
572  call assert_true(index(l, 'taglist(') >= 0)
573  let l = getcompletion('paint', 'function')
574  call assert_equal([], l)
575
576  let Flambda = {-> 'hello'}
577  let l = getcompletion('', 'function')
578  let l = filter(l, {i, v -> v =~ 'lambda'})
579  call assert_equal(0, len(l))
580
581  let l = getcompletion('run', 'file')
582  call assert_true(index(l, 'runtest.vim') >= 0)
583  let l = getcompletion('walk', 'file')
584  call assert_equal([], l)
585  set wildignore=*.vim
586  let l = getcompletion('run', 'file', 1)
587  call assert_true(index(l, 'runtest.vim') < 0)
588  set wildignore&
589  " Directory name with space character
590  call mkdir('Xdir with space')
591  call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
592  call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
593  call delete('Xdir with space', 'd')
594
595  let l = getcompletion('ha', 'filetype')
596  call assert_true(index(l, 'hamster') >= 0)
597  let l = getcompletion('horse', 'filetype')
598  call assert_equal([], l)
599
600  if has('keymap')
601    let l = getcompletion('acc', 'keymap')
602    call assert_true(index(l, 'accents') >= 0)
603    let l = getcompletion('nullkeymap', 'keymap')
604    call assert_equal([], l)
605  endif
606
607  let l = getcompletion('z', 'syntax')
608  call assert_true(index(l, 'zimbu') >= 0)
609  let l = getcompletion('emacs', 'syntax')
610  call assert_equal([], l)
611
612  let l = getcompletion('jikes', 'compiler')
613  call assert_true(index(l, 'jikes') >= 0)
614  let l = getcompletion('break', 'compiler')
615  call assert_equal([], l)
616
617  let l = getcompletion('last', 'help')
618  call assert_true(index(l, ':tablast') >= 0)
619  let l = getcompletion('giveup', 'help')
620  call assert_equal([], l)
621
622  let l = getcompletion('time', 'option')
623  call assert_true(index(l, 'timeoutlen') >= 0)
624  let l = getcompletion('space', 'option')
625  call assert_equal([], l)
626
627  let l = getcompletion('er', 'highlight')
628  call assert_true(index(l, 'ErrorMsg') >= 0)
629  let l = getcompletion('dark', 'highlight')
630  call assert_equal([], l)
631
632  let l = getcompletion('', 'messages')
633  call assert_true(index(l, 'clear') >= 0)
634  let l = getcompletion('not', 'messages')
635  call assert_equal([], l)
636
637  let l = getcompletion('', 'mapclear')
638  call assert_true(index(l, '<buffer>') >= 0)
639  let l = getcompletion('not', 'mapclear')
640  call assert_equal([], l)
641
642  let l = getcompletion('', 'retab')
643  call assert_true(index(l, '-indentonly') >= 0)
644  let l = getcompletion('not', 'retab')
645  call assert_equal([], l)
646
647  let l = getcompletion('.', 'shellcmd')
648  call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
649  call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
650  let root = has('win32') ? 'C:\\' : '/'
651  let l = getcompletion(root, 'shellcmd')
652  let expected = map(filter(glob(root . '*', 0, 1),
653        \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
654  call assert_equal(expected, l)
655
656  if has('cscope')
657    let l = getcompletion('', 'cscope')
658    let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
659    call assert_equal(cmds, l)
660    " using cmdline completion must not change the result
661    call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
662    let l = getcompletion('', 'cscope')
663    call assert_equal(cmds, l)
664    let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
665    let l = getcompletion('find ', 'cscope')
666    call assert_equal(keys, l)
667  endif
668
669  if has('signs')
670    sign define Testing linehl=Comment
671    let l = getcompletion('', 'sign')
672    let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
673    call assert_equal(cmds, l)
674    " using cmdline completion must not change the result
675    call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
676    let l = getcompletion('', 'sign')
677    call assert_equal(cmds, l)
678    let l = getcompletion('list ', 'sign')
679    call assert_equal(['Testing'], l)
680    let l = getcompletion('de*', 'sign')
681    call assert_equal(['define'], l)
682    let l = getcompletion('p?', 'sign')
683    call assert_equal(['place'], l)
684    let l = getcompletion('j.', 'sign')
685    call assert_equal(['jump'], l)
686  endif
687
688  " Command line completion tests
689  let l = getcompletion('cd ', 'cmdline')
690  call assert_true(index(l, 'samples/') >= 0)
691  let l = getcompletion('cd NoMatch', 'cmdline')
692  call assert_equal([], l)
693  let l = getcompletion('let v:n', 'cmdline')
694  call assert_true(index(l, 'v:null') >= 0)
695  let l = getcompletion('let v:notexists', 'cmdline')
696  call assert_equal([], l)
697  let l = getcompletion('call tag', 'cmdline')
698  call assert_true(index(l, 'taglist(') >= 0)
699  let l = getcompletion('call paint', 'cmdline')
700  call assert_equal([], l)
701  let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
702  call assert_equal(['<buffer>'], l)
703  let l = getcompletion('retab! ', 'cmdline')
704  call assert_true(index(l, '-indentonly') >= 0)
705
706  func T(a, c, p)
707    let g:cmdline_compl_params = [a:a, a:c, a:p]
708    return "oneA\noneB\noneC"
709  endfunc
710  command -nargs=1 -complete=custom,T MyCmd
711  let l = getcompletion('MyCmd ', 'cmdline')
712  call assert_equal(['oneA', 'oneB', 'oneC'], l)
713  call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
714
715  delcommand MyCmd
716  delfunc T
717  unlet g:cmdline_compl_params
718
719  " For others test if the name is recognized.
720  let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
721      \ 'tag_listfiles', 'user']
722  if has('cmdline_hist')
723    call add(names, 'history')
724  endif
725  if has('gettext')
726    call add(names, 'locale')
727  endif
728  if has('profile')
729    call add(names, 'syntime')
730  endif
731
732  set tags=Xtags
733  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
734
735  for name in names
736    let matchcount = len(getcompletion('', name))
737    call assert_true(matchcount >= 0, 'No matches for ' . name)
738  endfor
739
740  call delete('Xtags')
741  set tags&
742
743  edit a~b
744  enew
745  call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
746  bw a~b
747
748  if has('unix')
749    edit Xtest\
750    enew
751    call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
752    bw Xtest\
753  endif
754
755  call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
756  call assert_fails('call getcompletion("", "burp")', 'E475:')
757  call assert_fails('call getcompletion("abc", [])', 'E1174:')
758endfunc
759
760func Test_getcompletiontype()
761  call assert_fails('call getcompletiontype()', 'E119:')
762  call assert_fails('call getcompletiontype({})', 'E1174:')
763  call assert_equal('command', getcompletiontype(''))
764  call assert_equal('', getcompletiontype('dummy '))
765  call assert_equal('', getcompletiontype('ls '))
766  call assert_equal('dir_in_path', getcompletiontype('cd '))
767  call assert_equal('var', getcompletiontype('let v:n'))
768  call assert_equal('function', getcompletiontype('call tag'))
769  call assert_equal('help', getcompletiontype('help '))
770  " must not write into a read-only empty string
771  call assert_equal('command', getcompletiontype(v:_null_string))
772  call assert_equal(getcompletion('', 'cmdline'),
773    \ getcompletion(v:_null_string, 'cmdline'))
774  call assert_fails('call getcompletion([], "cmdline")', 'E730:')
775endfunc
776
777func Test_multibyte_expression()
778  " Get a dialog in the GUI
779  CheckNotGui
780
781  " This was using uninitialized memory.
782  let lines =<< trim END
783      set verbose=6
784      norm @=ٷ
785      qall!
786  END
787  call writefile(lines, 'XmultiScript', 'D')
788  call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
789endfunc
790
791" Test for getcompletion() with "fuzzy" in 'wildoptions'
792func Test_getcompletion_wildoptions()
793  let save_wildoptions = &wildoptions
794  set wildoptions&
795  let l = getcompletion('space', 'option')
796  call assert_equal([], l)
797  let l = getcompletion('ier', 'command')
798  call assert_equal([], l)
799  set wildoptions=fuzzy
800  let l = getcompletion('space', 'option')
801  call assert_true(index(l, 'backspace') >= 0)
802  let l = getcompletion('ier', 'command')
803  call assert_true(index(l, 'compiler') >= 0)
804  let &wildoptions = save_wildoptions
805endfunc
806
807func Test_fullcommand()
808  let tests = {
809        \ '':           '',
810        \ ':':          '',
811        \ ':::':        '',
812        \ ':::5':       '',
813        \ 'not_a_cmd':  '',
814        \ 'Check':      '',
815        \ 'syntax':     'syntax',
816        \ ':syntax':    'syntax',
817        \ '::::syntax': 'syntax',
818        \ 'sy':         'syntax',
819        \ 'syn':        'syntax',
820        \ 'synt':       'syntax',
821        \ ':sy':        'syntax',
822        \ '::::sy':     'syntax',
823        \ 'match':      'match',
824        \ '2match':     'match',
825        \ '3match':     'match',
826        \ 'aboveleft':  'aboveleft',
827        \ 'abo':        'aboveleft',
828        \ 's':          'substitute',
829        \ '5s':         'substitute',
830        \ ':5s':        'substitute',
831        \ "'<,'>s":     'substitute',
832        \ ":'<,'>s":    'substitute',
833        \ 'CheckLin':   'CheckLinux',
834        \ 'CheckLinux': 'CheckLinux',
835  \ }
836
837  for [in, want] in items(tests)
838    call assert_equal(want, fullcommand(in))
839  endfor
840  call assert_equal('', fullcommand(v:_null_string))
841
842  call assert_equal('syntax', 'syn'->fullcommand())
843
844  command -buffer BufferLocalCommand :
845  command GlobalCommand :
846  call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
847  call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
848  delcommand BufferLocalCommand
849  delcommand GlobalCommand
850endfunc
851
852func Test_shellcmd_completion()
853  let save_path = $PATH
854
855  call mkdir('Xpathdir/Xpathsubdir', 'pR')
856  call writefile([''], 'Xpathdir/Xfile.exe')
857  call setfperm('Xpathdir/Xfile.exe', 'rwx------')
858
859  " Set PATH to example directory without trailing slash.
860  let $PATH = getcwd() . '/Xpathdir'
861
862  " Test for the ":!<TAB>" case.  Previously, this would include subdirs of
863  " dirs in the PATH, even though they won't be executed.  We check that only
864  " subdirs of the PWD and executables from the PATH are included in the
865  " suggestions.
866  let actual = getcompletion('X', 'shellcmd')
867  let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
868  call insert(expected, 'Xfile.exe')
869  call assert_equal(expected, actual)
870
871  let $PATH = save_path
872endfunc
873
874func Test_expand_star_star()
875  call mkdir('a/b/c', 'pR')
876  call writefile(['asdfasdf'], 'a/b/c/fileXname')
877  call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
878  call assert_equal('find a/b/c/fileXname', @:)
879  bwipe!
880endfunc
881
882func Test_cmdline_paste()
883  let @a = "def"
884  call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
885  call assert_equal('"abc def ghi', @:)
886
887  new
888  call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
889
890  call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
891  call assert_equal('"aaa asdf bbb', @:)
892
893  call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
894  call assert_equal('"aaa /tmp/some bbb', @:)
895
896  call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
897  call assert_equal('"aaa '.getline(1).' bbb', @:)
898
899  set incsearch
900  call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
901  call assert_equal('"aaa verylongword bbb', @:)
902
903  call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
904  call assert_equal('"aaa a;b-c*d bbb', @:)
905
906  call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
907  call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
908  bwipe!
909
910  " Error while typing a command used to cause that it was not executed
911  " in the end.
912  new
913  try
914    call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
915  catch /^Vim\%((\a\+)\)\=:E32/
916    " ignore error E32
917  endtry
918  call assert_equal("Xtestfile", bufname("%"))
919
920  " Try to paste an invalid register using <C-R>
921  call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
922  call assert_equal('"onetwo', @:)
923
924  " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
925  let @a = "xy\<C-H>z"
926  call feedkeys(":\"\<C-R>=@a\<CR>\<CR>", 'xt')
927  call assert_equal('"xz', @:)
928  call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
929  call assert_equal("\"xy\<C-H>z", @:)
930  call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
931  call assert_equal("\"xy\<C-H>z", @:)
932
933  " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
934  let @a = "xy\<C-V>z"
935  call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
936  call assert_equal('"xyz', @:)
937  call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
938  call assert_equal("\"xy\<C-V>z", @:)
939
940  call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
941
942  bwipe!
943endfunc
944
945func Test_cmdline_remove_char()
946  let encoding_save = &encoding
947
948  " for e in ['utf8', 'latin1']
949  for e in ['utf8']
950    exe 'set encoding=' . e
951
952    call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
953    call assert_equal('"abc ef', @:, e)
954
955    call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
956    call assert_equal('"abcdef', @:)
957
958    call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
959    call assert_equal('"abc ghi', @:, e)
960
961    call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
962    call assert_equal('"def', @:, e)
963
964    " This was going before the start in latin1.
965    call feedkeys(": \<C-W>\<CR>", 'tx')
966  endfor
967
968  let &encoding = encoding_save
969endfunc
970
971func Test_cmdline_del_utf8()
972  let @s = '⒌'
973  call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
974  call assert_equal('",,', @:)
975
976  let @s = 'a̳'
977  call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
978  call assert_equal('",,', @:)
979
980  let @s = 'β̳'
981  call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
982  call assert_equal('",,', @:)
983
984  if has('arabic')
985    let @s = 'لا'
986    call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
987    call assert_equal('",,', @:)
988  endif
989endfunc
990
991func Test_cmdline_keymap_ctrl_hat()
992  CheckFeature keymap
993
994  set keymap=esperanto
995  call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
996  call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
997  set keymap=
998endfunc
999
1000func Test_illegal_address1()
1001  new
1002  2;'(
1003  2;')
1004  quit
1005endfunc
1006
1007func Test_illegal_address2()
1008  call writefile(['c', 'x', '  x', '.', '1;y'], 'Xtest.vim')
1009  new
1010  source Xtest.vim
1011  " Trigger calling validate_cursor()
1012  diffsp Xtest.vim
1013  quit!
1014  bwipe!
1015  call delete('Xtest.vim')
1016endfunc
1017
1018func Test_mark_from_line_zero()
1019  " this was reading past the end of the first (empty) line
1020  new
1021  norm oxxxx
1022  call assert_fails("0;'(", 'E20:')
1023  bwipe!
1024endfunc
1025
1026func Test_cmdline_complete_wildoptions()
1027  help
1028  call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1029  let a = join(sort(split(@:)),' ')
1030  set wildoptions=tagfile
1031  call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1032  let b = join(sort(split(@:)),' ')
1033  call assert_equal(a, b)
1034  bw!
1035endfunc
1036
1037func Test_cmdline_complete_user_cmd()
1038  command! -complete=color -nargs=1 Foo :
1039  call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1040  call assert_equal('"Foo blue', @:)
1041  call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1042  call assert_equal('"Foo blue', @:)
1043  call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1044  call assert_equal('"Foo a blue', @:)
1045  call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1046  call assert_equal('"Foo b\', @:)
1047  call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1048  call assert_equal('"Foo b\x', @:)
1049  delcommand Foo
1050
1051  redraw
1052  call assert_equal('~', Screenline(&lines - 1))
1053  command! FooOne :
1054  command! FooTwo :
1055
1056  set nowildmenu
1057  call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1058  call assert_equal('"FooOne', @:)
1059  call assert_equal('~', Screenline(&lines - 1))
1060
1061  call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1062  call assert_equal('"FooTwo', @:)
1063  call assert_equal('~', Screenline(&lines - 1))
1064
1065  delcommand FooOne
1066  delcommand FooTwo
1067  set wildmenu&
1068endfunc
1069
1070func Test_complete_user_cmd()
1071  command FooBar echo 'global'
1072  command -buffer FooBar echo 'local'
1073  call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1074  call assert_equal('"FooBar', @:)
1075
1076  delcommand -buffer FooBar
1077  delcommand FooBar
1078endfunc
1079
1080func s:ScriptLocalFunction()
1081  echo 'yes'
1082endfunc
1083
1084func Test_cmdline_complete_user_func()
1085  call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1086  call assert_match('"func Test_cmdline_complete_user_', @:)
1087  call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1088  call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
1089
1090  " g: prefix also works
1091  call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1092  call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
1093
1094  " using g: prefix does not result in just "g:" matches from a lambda
1095  let Fx = { a ->  a }
1096  call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1097  call assert_match('"echo g:[A-Z]', @:)
1098
1099  " existence of script-local dict function does not break user function name
1100  " completion
1101  function s:a_dict_func() dict
1102  endfunction
1103  call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1104  call assert_match('"call Test_cmdline_complete_user_', @:)
1105  delfunction s:a_dict_func
1106endfunc
1107
1108func Test_cmdline_complete_user_names()
1109  if has('unix') && executable('whoami')
1110    let whoami = systemlist('whoami')[0]
1111    let first_letter = whoami[0]
1112    if len(first_letter) > 0
1113      " Trying completion of  :e ~x  where x is the first letter of
1114      " the user name should complete to at least the user name.
1115      call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1116      call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1117    endif
1118  elseif has('win32')
1119    " Just in case: check that the system has an Administrator account.
1120    let names = system('net user')
1121    if names =~ 'Administrator'
1122      " Trying completion of  :e ~A  should complete to Administrator.
1123      " There could be other names starting with "A" before Administrator.
1124      call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
1125      call assert_match('^"e \~.*Administrator', @:)
1126    endif
1127  else
1128    throw 'Skipped: does not work on this platform'
1129  endif
1130endfunc
1131
1132func Test_cmdline_complete_shellcmdline()
1133  CheckExecutable whoami
1134  command -nargs=1 -complete=shellcmdline MyCmd
1135
1136  call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1137  call assert_match('^".*\<whoami\>', @:)
1138  let l = getcompletion('whoam', 'shellcmdline')
1139  call assert_match('\<whoami\>', join(l, ' '))
1140
1141  delcommand MyCmd
1142endfunc
1143
1144func Test_cmdline_complete_bang()
1145  CheckExecutable whoami
1146  call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1147  call assert_match('^".*\<whoami\>', @:)
1148endfunc
1149
1150func Test_cmdline_complete_languages()
1151  let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1152  call assert_equal(lang, v:lc_time)
1153
1154  let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1155  call assert_equal(lang, v:ctype)
1156
1157  let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1158  call assert_equal(lang, v:collate)
1159
1160  let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
1161  call assert_equal(lang, v:lang)
1162
1163  call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
1164  call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
1165
1166  if has('unix')
1167    " TODO: these tests don't work on Windows. lang appears to be 'C'
1168    " but C does not appear in the completion. Why?
1169    call assert_match('^"language .*\<' . lang . '\>', @:)
1170
1171    call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1172    call assert_match('^"language .*\<' . lang . '\>', @:)
1173
1174    call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1175    call assert_match('^"language .*\<' . lang . '\>', @:)
1176
1177    call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1178    call assert_match('^"language .*\<' . lang . '\>', @:)
1179
1180    call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1181    call assert_match('^"language .*\<' . lang . '\>', @:)
1182  endif
1183endfunc
1184
1185func Test_cmdline_complete_env_variable()
1186  let $X_VIM_TEST_COMPLETE_ENV = 'foo'
1187  call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1188  call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
1189  unlet $X_VIM_TEST_COMPLETE_ENV
1190endfunc
1191
1192func Test_cmdline_complete_expression()
1193  let g:SomeVar = 'blah'
1194  for cmd in ['exe', 'echo', 'echon', 'echomsg', 'echoerr',
1195        "\ 'echoconsole', 'echowindow']
1196        \ ]
1197    call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1198    call assert_match('"' .. cmd .. ' SomeVar', @:, cmd)
1199    call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1200    call assert_match('"' .. cmd .. ' foo SomeVar', @:, cmd)
1201  endfor
1202  unlet g:SomeVar
1203endfunc
1204
1205func Test_cmdline_complete_argopt()
1206  " completion for ++opt=arg for file commands
1207  call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1208  call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1209  call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1210
1211  call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
1212  " Test ++ff in the middle of the cmdline
1213  call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1214  call assert_equal("\"edit ++fileformat= zz", @:)
1215
1216  call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1217  call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1218  call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1219  call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1220  call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1221
1222  call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1223
1224  " completion should skip the ++opt and continue
1225  call writefile([], 'Xaaaaa.txt', 'D')
1226  call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1227  call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1228
1229  if has('terminal')
1230    " completion for terminal's [options]
1231    call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1232    call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1233    call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1234
1235    call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1236
1237    " :terminal completion should skip the ++opt when considering what is the
1238    " first option, which is a list of shell commands, unlike second option
1239    " onwards.
1240    let first_param = getcompletion('terminal ', 'cmdline')
1241    let second_param = getcompletion('terminal foo ', 'cmdline')
1242    let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1243    call assert_equal(first_param, skipped_opt_param)
1244    call assert_notequal(first_param, second_param)
1245  endif
1246endfunc
1247
1248" Unique function name for completion below
1249func s:WeirdFunc()
1250  echo 'weird'
1251endfunc
1252
1253" Test for various command-line completion
1254func Test_cmdline_complete_various()
1255  " completion for a command starting with a comment
1256  call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1257  call assert_equal("\" :|\"\<C-A>", @:)
1258
1259  " completion for a range followed by a comment
1260  call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1261  call assert_equal("\"1,2\"\<C-A>", @:)
1262
1263  " completion for :k command
1264  call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1265  call assert_equal("\"ka\<C-A>", @:)
1266
1267  " completion for :keepmarks command
1268  call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1269  call assert_equal("\"kee edit", @:)
1270
1271  " completion for short version of the :s command
1272  call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1273  call assert_equal("\"sI \<C-A>", @:)
1274
1275  " completion for :write command
1276  call mkdir('Xcwdir')
1277  call writefile(['one'], 'Xcwdir/Xfile1')
1278  let save_cwd = getcwd()
1279  cd Xcwdir
1280  call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1281  call assert_equal("\"w >> Xfile1", @:)
1282  call chdir(save_cwd)
1283  call delete('Xcwdir', 'rf')
1284
1285  " completion for :w ! and :r ! commands
1286  call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1287  call assert_equal("\"w !invalid_xyz_cmd", @:)
1288  call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1289  call assert_equal("\"r !invalid_xyz_cmd", @:)
1290
1291  " completion for :>> and :<< commands
1292  call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1293  call assert_equal("\">>>\<C-A>", @:)
1294  call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1295  call assert_equal("\"<<<\<C-A>", @:)
1296
1297  " completion for command with +cmd argument
1298  call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1299  call assert_equal("\"buffer +/pat Xabc", @:)
1300  call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1301  call assert_equal("\"buffer +/pat\<C-A>", @:)
1302
1303  " completion for a command with a trailing comment
1304  call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1305  call assert_equal("\"ls \" comment\<C-A>", @:)
1306
1307  " completion for a command with a trailing command
1308  call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1309  call assert_equal("\"ls | ls lsp", @:)
1310
1311  " completion for a command with an CTRL-V escaped argument
1312  call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1313  call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1314
1315  " completion for a command that doesn't take additional arguments
1316  call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1317  call assert_equal("\"all abc\<C-A>", @:)
1318
1319  " completion for :wincmd with :horizontal modifier
1320  call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1321  call assert_equal("\"horizontal wincmd", @:)
1322
1323  " completion for a command with a command modifier
1324  call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1325  call assert_equal("\"topleft new", @:)
1326
1327  " completion for the :disassemble command
1328  " call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1329  " call assert_equal("\"disas debug", @:)
1330  " call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1331  " call assert_equal("\"disas profile", @:)
1332  " call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1333  " call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1334  " call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1335  " call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
1336  " call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1337  " call assert_equal("\"disas Test_cmdline_complete_various", @:)
1338
1339  " call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
1340  " call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
1341
1342  " call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1343  " call assert_match('"disas <SNR>\d\+_', @:)
1344  " call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1345  " call assert_match('"disas debug <SNR>\d\+_', @:)
1346
1347  " completion for the :match command
1348  call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1349  call assert_equal("\"match Search /pat/\<C-A>", @:)
1350
1351  " completion for the :doautocmd command
1352  call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1353  call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1354
1355  " completion of autocmd group after comma
1356  call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1357  call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1358
1359  " completion of file name in :doautocmd
1360  call writefile([], 'Xvarfile1')
1361  call writefile([], 'Xvarfile2')
1362  call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1363  call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
1364  call delete('Xvarfile1')
1365  call delete('Xvarfile2')
1366
1367  " completion for the :augroup command
1368  augroup XTest.test
1369  augroup END
1370  call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
1371  call assert_equal("\"augroup XTest.test", @:)
1372  call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1373  call assert_equal("\"au XTest.test", @:)
1374  augroup! XTest.test
1375
1376  " completion for the :unlet command
1377  call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1378  call assert_equal("\"unlet one two", @:)
1379
1380  " completion for the :buffer command with curlies
1381  " FIXME: what should happen on MS-Windows?
1382  if !has('win32')
1383    edit \{someFile}
1384    call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1385    call assert_equal("\"buf {someFile}", @:)
1386    bwipe {someFile}
1387  endif
1388
1389  " completion for the :bdelete command
1390  call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1391  call assert_equal("\"bdel a b c", @:)
1392
1393  " completion for the :mapclear command
1394  call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1395  call assert_equal("\"mapclear <buffer>", @:)
1396
1397  " completion for user defined commands with menu names
1398  menu Test.foo :ls<CR>
1399  com -nargs=* -complete=menu MyCmd
1400  call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1401  call assert_equal('"MyCmd Test.', @:)
1402  delcom MyCmd
1403  unmenu Test
1404
1405  " completion for user defined commands with mappings
1406  mapclear
1407  map <F3> :ls<CR>
1408  com -nargs=* -complete=mapping MyCmd
1409  call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
1410  call assert_equal('"MyCmd <F3> <F4>', @:)
1411  mapclear
1412  delcom MyCmd
1413
1414  " Prepare for path completion
1415  call mkdir('Xa b c', 'D')
1416  defer delete('Xcomma,foobar.txt')
1417  call writefile([], 'Xcomma,foobar.txt')
1418
1419  " completion for :set path= with multiple backslashes
1420  call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1421  call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1422  set path&
1423
1424  " completion for :set dir= with a backslash
1425  call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1426  call assert_equal('"set dir=Xa\ b\ c/', @:)
1427  set dir&
1428
1429  " completion for :set tags= / set dictionary= with escaped commas
1430  if has('win32')
1431    " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1432    " '\,'
1433    call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1434    call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1435
1436    call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1437    call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1438
1439    call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1440    call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1441
1442    " completion for :set dictionary= with escaped commas (same behavior, but
1443    " different internal code path from 'set tags=' for escaping the output)
1444    call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1445    call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1446  else
1447    " In other platforms, backslashes are rounded down (since '\,' itself will
1448    " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1449    call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1450    call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1451
1452    call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1453    call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1454
1455    call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1456    call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1457
1458    " completion for :set dictionary= with escaped commas (same behavior, but
1459    " different internal code path from 'set tags=' for escaping the output)
1460    call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1461    call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1462  endif
1463  set tags&
1464  set dictionary&
1465
1466  " completion for :set makeprg= with no escaped commas
1467  call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1468  call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1469
1470  if !has('win32')
1471    " Cannot create file with backslash in file name in Windows, so only test
1472    " this elsewhere.
1473    defer delete('Xcomma\,fooslash.txt')
1474    call writefile([], 'Xcomma\,fooslash.txt')
1475    call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1476    call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1477  endif
1478  set makeprg&
1479
1480  " completion for the :py3 commands
1481  call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1482  call assert_equal('"py3 py3do py3file', @:)
1483
1484  " redir @" is not the start of a comment. So complete after that
1485  call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1486  call assert_equal('"redir @" | cwindow', @:)
1487
1488  " completion after a backtick
1489  call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1490  call assert_equal('"e `a1b2c', @:)
1491
1492  " completion for :language command with an invalid argument
1493  call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1494  call assert_equal("\"language dummy \t", @:)
1495
1496  " completion for commands after a :global command
1497  call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1498  call assert_equal('"g/a\xb/clearjumps', @:)
1499
1500  " completion with ambiguous user defined commands
1501  com TCmd1 echo 'TCmd1'
1502  com TCmd2 echo 'TCmd2'
1503  call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1504  call assert_equal('"TCmd ', @:)
1505  delcom TCmd1
1506  delcom TCmd2
1507
1508  " completion after a range followed by a pipe (|) character
1509  call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1510  call assert_equal('"1,10 | chistory', @:)
1511
1512  " completion after a :global command
1513  call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1514  call assert_equal('"g/a/chistory', @:)
1515  set wildchar=0
1516  call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1517  call assert_equal("\"g/a\\/chist\t", @:)
1518  set wildchar&
1519
1520  " use <Esc> as the 'wildchar' for completion
1521  set wildchar=<Esc>
1522  call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1523  call assert_equal('"g/a\xb/clearjumps', @:)
1524  " pressing <esc> twice should cancel the command
1525  call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1526  call assert_equal('"g/a\xb/clearjumps', @:)
1527  set wildchar&
1528
1529  if has('unix')
1530    " should be able to complete a file name that starts with a '~'.
1531    call writefile([], '~Xtest')
1532    call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1533    call assert_equal('"e \~Xtest', @:)
1534    call delete('~Xtest')
1535
1536    " should be able to complete a file name that has a '*'
1537    call writefile([], 'Xx*Yy')
1538    call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1539    call assert_equal('"e Xx\*Yy', @:)
1540    call delete('Xx*Yy')
1541
1542    " use a literal star
1543    call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1544    call assert_equal('"e \*', @:)
1545  endif
1546
1547  call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1548  call assert_equal('"py3file', @:)
1549endfunc
1550
1551" Test that expanding a pattern doesn't interfere with cmdline completion.
1552func Test_expand_during_cmdline_completion()
1553  func ExpandStuff()
1554    badd <script>:p:h/README.*
1555    call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1556    $bwipe
1557    call assert_equal('README.txt', expand('README.*'))
1558    call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1559  endfunc
1560  augroup test_CmdlineChanged
1561    autocmd!
1562    autocmd CmdlineChanged * call ExpandStuff()
1563  augroup END
1564
1565  call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1566  call assert_equal('"sign place', @:)
1567
1568  augroup test_CmdlineChanged
1569    au!
1570  augroup END
1571  augroup! test_CmdlineChanged
1572  delfunc ExpandStuff
1573endfunc
1574
1575" Test for 'wildignorecase'
1576func Test_cmdline_wildignorecase()
1577  CheckUnix
1578  call writefile([], 'XTEST')
1579  set wildignorecase
1580  call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1581  call assert_equal('"e XTEST', @:)
1582  call assert_equal(['XTEST'], getcompletion('xt', 'file'))
1583  let g:Sline = ''
1584  call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1585  call assert_equal('"e xt', @:)
1586  call assert_equal('XTEST', g:Sline)
1587  set wildignorecase&
1588  call delete('XTEST')
1589endfunc
1590
1591func Test_cmdline_write_alternatefile()
1592  new
1593  call setline('.', ['one', 'two'])
1594  f foo.txt
1595  new
1596  f #-A
1597  call assert_equal('foo.txt-A', expand('%'))
1598  f #<-B.txt
1599  call assert_equal('foo-B.txt', expand('%'))
1600  f %<
1601  call assert_equal('foo-B', expand('%'))
1602  new
1603  call assert_fails('f #<', 'E95')
1604  bw!
1605  f foo-B.txt
1606  f %<-A
1607  call assert_equal('foo-B-A', expand('%'))
1608  bw!
1609  bw!
1610endfunc
1611
1612func Test_cmdline_expand_cur_alt_file()
1613  enew
1614  file http://some.com/file.txt
1615  call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1616  call assert_equal('"e http://some.com/file.txt', @:)
1617  edit another
1618  call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1619  call assert_equal('"e http://some.com/file.txt', @:)
1620  bwipe
1621  bwipe http://some.com/file.txt
1622endfunc
1623
1624" using a leading backslash here
1625set cpo+=C
1626
1627func Test_cmdline_search_range()
1628  new
1629  call setline(1, ['a', 'b', 'c', 'd'])
1630  /d
1631  1,\/s/b/B/
1632  call assert_equal('B', getline(2))
1633
1634  /a
1635  $
1636  \?,4s/c/C/
1637  call assert_equal('C', getline(3))
1638
1639  call setline(1, ['a', 'b', 'c', 'd'])
1640  %s/c/c/
1641  1,\&s/b/B/
1642  call assert_equal('B', getline(2))
1643
1644  let @/ = 'apple'
1645  call assert_fails('\/print', ['E486:.*apple'])
1646
1647  bwipe!
1648endfunc
1649
1650" Test for the tick mark (') in an excmd range
1651func Test_tick_mark_in_range()
1652  " If only the tick is passed as a range and no command is specified, there
1653  " should not be an error
1654  call feedkeys(":'\<CR>", 'xt')
1655  call assert_equal("'", @:)
1656  call assert_fails("',print", 'E78:')
1657endfunc
1658
1659" Test for using a line number followed by a search pattern as range
1660func Test_lnum_and_pattern_as_range()
1661  new
1662  call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1663  let @" = ''
1664  2/foo/yank
1665  call assert_equal("foo 3\n", @")
1666  call assert_equal(1, line('.'))
1667  bw!
1668endfunc
1669
1670" Tests for getcmdline(), getcmdpos() and getcmdtype()
1671func Check_cmdline(cmdtype)
1672  call assert_equal('MyCmd a', getcmdline())
1673  call assert_equal(8, getcmdpos())
1674  call assert_equal(a:cmdtype, getcmdtype())
1675  return ''
1676endfunc
1677
1678set cpo&
1679
1680func Test_getcmdtype_getcmdprompt()
1681  call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1682
1683  let cmdtype = ''
1684  debuggreedy
1685  call feedkeys(":debug echo 'test'\<CR>", "t")
1686  call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1687  call feedkeys("cont\<CR>", "xt")
1688  0debuggreedy
1689  call assert_equal('>', cmdtype)
1690
1691  call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1692  call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1693
1694  call feedkeys(":call input('Answer?')\<CR>", "t")
1695  call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
1696
1697  call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1698
1699  cnoremap <expr> <F6> Check_cmdline('=')
1700  call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1701  cunmap <F6>
1702
1703  call assert_equal('', getcmdline())
1704
1705  call assert_equal('', getcmdprompt())
1706  augroup test_CmdlineEnter
1707    autocmd!
1708    autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1709  augroup END
1710  call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1711  call assert_equal('Answer?', g:cmdprompt)
1712  call assert_equal('', getcmdprompt())
1713  call feedkeys(":\<CR>\<ESC>", "xt")
1714  call assert_equal('', g:cmdprompt)
1715  call assert_equal('', getcmdprompt())
1716
1717  let str = "C" .. repeat("c", 1023) .. "xyz"
1718  call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1719  call assert_equal(str, g:cmdprompt)
1720
1721  call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1722  call assert_equal('Ans?', g:cmdprompt)
1723  call assert_equal('', getcmdprompt())
1724
1725  augroup test_CmdlineEnter
1726    au!
1727  augroup END
1728  augroup! test_CmdlineEnter
1729endfunc
1730
1731func Test_getcmdwintype()
1732  throw "Skipped: Nvim supports cmdwin freedom #40312"
1733  call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1734  call assert_equal('/', a)
1735
1736  call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1737  call assert_equal('?', a)
1738
1739  call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1740  call assert_equal(':', a)
1741
1742  call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1743  call assert_equal(':', a)
1744
1745  call assert_equal('', getcmdwintype())
1746endfunc
1747
1748func Test_getcmdwin_autocmd()
1749  throw "Skipped: Nvim supports cmdwin freedom #40312"
1750  let s:seq = []
1751  augroup CmdWin
1752  au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1753  au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1754  au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1755  au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1756  au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1757  au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1758
1759  let org_winid = win_getid()
1760  let org_bufnr = bufnr()
1761  call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1762  call assert_equal(':', a)
1763  call assert_equal([
1764	\ 'WinLeave ' .. org_winid,
1765	\ 'WinEnter ' .. s:cmd_winid,
1766	\ 'BufLeave ' .. org_bufnr,
1767	\ 'BufEnter ' .. s:cmd_bufnr,
1768	\ 'CmdWinEnter ' .. s:cmd_winid,
1769	\ 'CmdWinLeave ' .. s:cmd_winid,
1770	\ 'BufLeave ' .. s:cmd_bufnr,
1771	\ 'WinLeave ' .. s:cmd_winid,
1772	\ 'WinEnter ' .. org_winid,
1773	\ 'BufEnter ' .. org_bufnr,
1774	\ ], s:seq)
1775
1776  au!
1777  augroup END
1778endfunc
1779
1780func Test_verbosefile()
1781  set verbosefile=Xlog
1782  echomsg 'foo'
1783  echomsg 'bar'
1784  set verbosefile=
1785  let log = readfile('Xlog')
1786  call assert_match("foo\nbar", join(log, "\n"))
1787  call delete('Xlog')
1788  call mkdir('Xdir')
1789  if !has('win32')  " FIXME: no error on Windows, libuv bug?
1790  call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
1791  endif
1792  call delete('Xdir', 'd')
1793endfunc
1794
1795func Test_verbose_option()
1796  " See test/functional/legacy/cmdline_spec.lua
1797  CheckScreendump
1798
1799  let lines =<< trim [SCRIPT]
1800    command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1801    call feedkeys("\r", 't') " for the hit-enter prompt
1802    set verbose=20
1803  [SCRIPT]
1804  call writefile(lines, 'XTest_verbose')
1805
1806  let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
1807  call TermWait(buf, 50)
1808  call term_sendkeys(buf, ":DoSomething\<CR>")
1809  call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1810
1811  " clean up
1812  call StopVimInTerminal(buf)
1813  call delete('XTest_verbose')
1814endfunc
1815
1816func Test_setcmdpos()
1817  func InsertTextAtPos(text, pos)
1818    call assert_equal(0, setcmdpos(a:pos))
1819    return a:text
1820  endfunc
1821
1822  " setcmdpos() with position in the middle of the command line.
1823  call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1824  call assert_equal('"1ab2', @:)
1825
1826  call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1827  call assert_equal('"1b2a', @:)
1828
1829  " setcmdpos() with position beyond the end of the command line.
1830  call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1831  call assert_equal('"12ab', @:)
1832
1833  " setcmdpos() returns 1 when not editing the command line.
1834  call assert_equal(1, 3->setcmdpos())
1835endfunc
1836
1837func Test_cmdline_overstrike()
1838  " Nvim: only utf8 is supported.
1839  let encodings = ['utf8']
1840  let encoding_save = &encoding
1841
1842  for e in encodings
1843    exe 'set encoding=' . e
1844
1845    " Test overstrike in the middle of the command line.
1846    call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
1847    call assert_equal('"0ab1cd4', @:, e)
1848
1849    " Test overstrike going beyond end of command line.
1850    call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
1851    call assert_equal('"0ab1cdefgh', @:, e)
1852
1853    " Test toggling insert/overstrike a few times.
1854    call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
1855    call assert_equal('"ab0cd3ef4', @:, e)
1856  endfor
1857
1858  " Test overstrike with multi-byte characters.
1859  call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
1860  call assert_equal('"テabキcdエディタ', @:, e)
1861
1862  let &encoding = encoding_save
1863endfunc
1864
1865func Test_cmdwin_bug()
1866  throw 'Skipped: Nvim supports cmdwin freedom #40312'
1867  let winid = win_getid()
1868  sp
1869  try
1870    call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1871  catch /^Vim\%((\a\+)\)\=:E11/
1872  endtry
1873  bw!
1874endfunc
1875
1876func Test_cmdwin_restore()
1877  CheckScreendump
1878
1879  let lines =<< trim [SCRIPT]
1880    call setline(1, range(30))
1881    2split
1882  [SCRIPT]
1883  call writefile(lines, 'XTest_restore')
1884
1885  let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
1886  call TermWait(buf, 50)
1887  call term_sendkeys(buf, "q:")
1888  call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1889
1890  " normal restore
1891  call term_sendkeys(buf, ":q\<CR>")
1892  call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1893
1894  " restore after setting 'lines' with one window
1895  call term_sendkeys(buf, ":close\<CR>")
1896  call term_sendkeys(buf, "q:")
1897  call term_sendkeys(buf, ":set lines=18\<CR>")
1898  call term_sendkeys(buf, ":q\<CR>")
1899  call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1900
1901  " clean up
1902  call StopVimInTerminal(buf)
1903  call delete('XTest_restore')
1904endfunc
1905
1906func Test_cmdwin_no_terminal()
1907  CheckFeature cmdwin
1908  CheckFeature terminal
1909  CheckNotMSWindows
1910
1911  let buf = RunVimInTerminal('', {'rows': 12})
1912  call TermWait(buf, 50)
1913  call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1914  call term_sendkeys(buf, "q:")
1915  call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1916  call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1917  call term_sendkeys(buf, ":q\<CR>")
1918  call StopVimInTerminal(buf)
1919endfunc
1920
1921func Test_buffers_lastused()
1922  " check that buffers are sorted by time when wildmode has lastused
1923  edit bufc " oldest
1924
1925  sleep 1200m
1926  enew
1927  edit bufa " middle
1928
1929  sleep 1200m
1930  enew
1931  edit bufb " newest
1932
1933  enew
1934
1935  call assert_equal(['bufc', 'bufa', 'bufb'],
1936	\ getcompletion('', 'buffer'))
1937
1938  let save_wildmode = &wildmode
1939  set wildmode=full:lastused
1940
1941  let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1942  call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1943  call assert_equal('b bufb', X)
1944  call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1945  call assert_equal('b bufa', X)
1946  call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1947  call assert_equal('b bufc', X)
1948  enew
1949
1950  sleep 1200m
1951  edit other
1952  call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1953  call assert_equal('b bufb', X)
1954  call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1955  call assert_equal('b bufa', X)
1956  call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1957  call assert_equal('b bufc', X)
1958  enew
1959
1960  let &wildmode = save_wildmode
1961
1962  bwipeout bufa
1963  bwipeout bufb
1964  bwipeout bufc
1965endfunc
1966
1967func Test_cmdwin_feedkeys()
1968  throw "Skipped: Nvim supports cmdwin freedom #40312"
1969  " This should not generate E488
1970  call feedkeys("q:\<CR>", 'x')
1971  " Using feedkeys with q: only should automatically close the cmd window
1972  call feedkeys('q:', 'xt')
1973  call assert_equal(1, winnr('$'))
1974  call assert_equal('', getcmdwintype())
1975endfunc
1976
1977" Tests for the issues fixed in 7.4.441.
1978" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1979func Test_cmdwin_cedit()
1980  throw 'Skipped: Nvim supports cmdwin freedom #40312'
1981  exe "set cedit=\<C-c>"
1982  normal! :
1983  call assert_equal(1, winnr('$'))
1984
1985  let g:cmd_wintype = ''
1986  func CmdWinType()
1987      let g:cmd_wintype = getcmdwintype()
1988      let g:wintype = win_gettype()
1989      return ''
1990  endfunc
1991
1992  call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1993  echo input('')
1994  call assert_equal('@', g:cmd_wintype)
1995  call assert_equal('command', g:wintype)
1996
1997  set cedit&vim
1998  delfunc CmdWinType
1999endfunc
2000
2001" Test for CmdwinEnter autocmd
2002func Test_cmdwin_autocmd()
2003  CheckFeature cmdwin
2004
2005  augroup CmdWin
2006    au!
2007    autocmd BufLeave * if &buftype == '' | update | endif
2008    autocmd CmdwinEnter * startinsert
2009  augroup END
2010
2011  call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
2012  call assert_equal('xyz', @:)
2013
2014  augroup CmdWin
2015    au!
2016  augroup END
2017  augroup! CmdWin
2018endfunc
2019
2020func Test_cmdlineclear_tabenter()
2021  " See test/functional/legacy/cmdline_spec.lua
2022  CheckScreendump
2023
2024  let lines =<< trim [SCRIPT]
2025    call setline(1, range(30))
2026  [SCRIPT]
2027
2028  call writefile(lines, 'XtestCmdlineClearTabenter')
2029  let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
2030  call TermWait(buf, 25)
2031  " in one tab make the command line higher with CTRL-W -
2032  call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
2033  call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2034
2035  call StopVimInTerminal(buf)
2036  call delete('XtestCmdlineClearTabenter')
2037endfunc
2038
2039" Test for expanding special keywords in cmdline
2040func Test_cmdline_expand_special()
2041  new
2042  %bwipe!
2043  call assert_fails('e #', 'E194:')
2044  call assert_fails('e <afile>', 'E495:')
2045  call assert_fails('e <abuf>', 'E496:')
2046  call assert_fails('e <amatch>', 'E497:')
2047
2048  call writefile([], 'Xfile.cpp')
2049  call writefile([], 'Xfile.java')
2050  new Xfile.cpp
2051  call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2052  call assert_equal('"e Xfile.cpp Xfile.java', @:)
2053  close
2054  call delete('Xfile.cpp')
2055  call delete('Xfile.java')
2056endfunc
2057
2058func Test_cmdwin_jump_to_win()
2059  throw "Skipped: Nvim supports cmdwin freedom #40312"
2060  call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
2061  new
2062  set modified
2063  call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
2064  close!
2065  call feedkeys("q/:close\<CR>", "xt")
2066  call assert_equal(1, winnr('$'))
2067  call feedkeys("q/:exit\<CR>", "xt")
2068  call assert_equal(1, winnr('$'))
2069
2070  " opening command window twice should fail
2071  call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
2072  call assert_equal(1, winnr('$'))
2073endfunc
2074
2075func Test_cmdwin_tabpage()
2076  throw "Skipped: Nvim supports cmdwin freedom #40312"
2077  tabedit
2078  call assert_fails("silent norm q/g	:I\<Esc>", 'E11:')
2079  tabclose!
2080endfunc
2081
2082func Test_cmdwin_interrupted_more_prompt()
2083  CheckScreendump
2084
2085  " aborting the :smile output caused the cmdline window to use the current
2086  " buffer.
2087  let lines =<< trim [SCRIPT]
2088    au WinNew * smile
2089  [SCRIPT]
2090  call writefile(lines, 'XTest_cmdwin')
2091
2092  let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
2093  " open cmdwin
2094  call term_sendkeys(buf, "q:")
2095  call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
2096  " quit more prompt for :smile command
2097  call term_sendkeys(buf, "q")
2098  call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
2099  " execute a simple command
2100  call term_sendkeys(buf, "aecho 'done'\<CR>")
2101  call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
2102
2103  " clean up
2104  call StopVimInTerminal(buf)
2105  call delete('XTest_cmdwin')
2106endfunc
2107
2108" Test for backtick expression in the command line
2109func Test_cmd_backtick()
2110  CheckNotMSWindows  " FIXME: see #19297
2111  %argd
2112  argadd `=['a', 'b', 'c']`
2113  call assert_equal(['a', 'b', 'c'], argv())
2114  %argd
2115
2116  argadd `echo abc def`
2117  call assert_equal(['abc def'], argv())
2118  %argd
2119endfunc
2120
2121" Test for the :! command
2122func Test_cmd_bang()
2123  CheckUnix
2124
2125  let lines =<< trim [SCRIPT]
2126    " Test for no previous command
2127    call assert_fails('!!', 'E34:')
2128    set nomore
2129    " Test for cmdline expansion with :!
2130    call setline(1, 'foo!')
2131    silent !echo <cWORD> > Xfile.out
2132    call assert_equal(['foo!'], readfile('Xfile.out'))
2133    " Test for using previous command
2134    silent !echo \! !
2135    call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2136    call writefile(v:errors, 'Xresult')
2137    call delete('Xfile.out')
2138    qall!
2139  [SCRIPT]
2140  call writefile(lines, 'Xscript')
2141  if RunVim([], [], '--clean -S Xscript')
2142    call assert_equal([], readfile('Xresult'))
2143  endif
2144  call delete('Xscript')
2145  call delete('Xresult')
2146endfunc
2147
2148" Test error: "E135: *Filter* Autocommands must not change current buffer"
2149func Test_cmd_bang_E135()
2150  new
2151  call setline(1, ['a', 'b', 'c', 'd'])
2152  augroup test_cmd_filter_E135
2153    au!
2154    autocmd FilterReadPost * help
2155  augroup END
2156  call assert_fails('2,3!echo "x"', 'E135:')
2157
2158  augroup test_cmd_filter_E135
2159    au!
2160  augroup END
2161  augroup! test_cmd_filter_E135
2162  %bwipe!
2163endfunc
2164
2165func Test_cmd_bang_args()
2166  new
2167  :.!
2168  call assert_equal(0, v:shell_error)
2169
2170  " Note that below there is one space char after the '!'.  This caused a
2171  " shell error in the past, see https://github.com/vim/vim/issues/11495.
2172  :.! 
2173  call assert_equal(0, v:shell_error)
2174  bwipe!
2175
2176  CheckUnix
2177  :.!pwd
2178  call assert_equal(0, v:shell_error)
2179  :.! pwd
2180  call assert_equal(0, v:shell_error)
2181
2182  " Note there is one space after 'pwd'.
2183  :.! pwd 
2184  call assert_equal(0, v:shell_error)
2185
2186  " Note there are two spaces after 'pwd'.
2187  :.!  pwd  
2188  call assert_equal(0, v:shell_error)
2189  :.!ls ~
2190  call assert_equal(0, v:shell_error)
2191
2192  " Note there is one space char after '~'.
2193  :.!ls  ~ 
2194  call assert_equal(0, v:shell_error)
2195
2196  " Note there are two spaces after '~'.
2197  :.!ls  ~  
2198  call assert_equal(0, v:shell_error)
2199
2200  :.!echo "foo"
2201  call assert_equal(getline('.'), "foo")
2202  :.!echo "foo  "
2203  call assert_equal(getline('.'), "foo  ")
2204  :.!echo " foo  "
2205  call assert_equal(getline('.'), " foo  ")
2206  :.!echo  " foo  "
2207  call assert_equal(getline('.'), " foo  ")
2208
2209  %bwipe!
2210endfunc
2211
2212" Test for using ~ for home directory in cmdline completion matches
2213func Test_cmdline_expand_home()
2214  call mkdir('Xexpdir')
2215  call writefile([], 'Xexpdir/Xfile1')
2216  call writefile([], 'Xexpdir/Xfile2')
2217  cd Xexpdir
2218  let save_HOME = $HOME
2219  let $HOME = getcwd()
2220  call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2221  call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2222  let $HOME = save_HOME
2223  cd ..
2224  call delete('Xexpdir', 'rf')
2225endfunc
2226
2227" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2228" or insert mode (when 'insertmode' is set)
2229func Test_cmdline_ctrl_g()
2230  new
2231  call setline(1, 'abc')
2232  call cursor(1, 3)
2233  " If command line is entered from insert mode, using C-\ C-G should back to
2234  " insert mode
2235  call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2236  call assert_equal('abxyc', getline(1))
2237  call assert_equal(4, col('.'))
2238
2239  " If command line is entered in 'insertmode', using C-\ C-G should back to
2240  " 'insertmode'
2241  " call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2242  " call assert_equal('ab12xyc', getline(1))
2243  bw!
2244endfunc
2245
2246" Test for 'wildmode'
2247func Wildmode_tests()
2248  func T(a, c, p)
2249    return "oneA\noneB\noneC"
2250  endfunc
2251  command -nargs=1 -complete=custom,T MyCmd
2252
2253  set nowildmenu
2254  set wildmode=full,list
2255  let g:Sline = ''
2256  call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
2257  call assert_equal('oneA  oneB  oneC', g:Sline)
2258  call assert_equal('"MyCmd oneA', @:)
2259
2260  set wildmode=longest,full
2261  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2262  call assert_equal('"MyCmd one', @:)
2263  call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2264  call assert_equal('"MyCmd oneC', @:)
2265
2266  set wildmode=longest
2267  call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2268  call assert_equal('"MyCmd one', @:)
2269
2270  set wildmode=list:longest
2271  let g:Sline = ''
2272  call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
2273  call assert_equal('oneA  oneB  oneC', g:Sline)
2274  call assert_equal('"MyCmd one', @:)
2275
2276  " Colon-separated modes apply during the same completion phase.
2277  call writefile([], 'XwildmodeA', 'D')
2278  call writefile([], 'XwildmodeB', 'D')
2279  call writefile([], 'XwildmodeC', 'D')
2280  set wildmode=list:full
2281  let g:Sline = ''
2282  call feedkeys(":e Xwildmode\t\<F4>\<C-B>\"\<CR>", 'xt')
2283  call assert_equal('XwildmodeA  XwildmodeB  XwildmodeC', g:Sline)
2284  call assert_equal('"e XwildmodeA', @:)
2285  call feedkeys(":e Xwildmode\t\t\<C-B>\"\<CR>", 'xt')
2286  call assert_equal('"e XwildmodeB', @:)
2287
2288  " Comma-separated modes apply on consecutive Tab presses.
2289  set wildmode=list,full
2290  let g:Sline = ''
2291  call feedkeys(":MyCmd o\t\<F4>\<C-B>\"\<CR>", 'xt')
2292  call assert_equal('oneA  oneB  oneC', g:Sline)
2293  call assert_equal('"MyCmd o', @:)
2294  call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2295  call assert_equal('"MyCmd oneA', @:)
2296
2297  set wildmode=""
2298  call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2299  call assert_equal('"MyCmd oneA', @:)
2300
2301  " Test for wildmode=longest with 'fileignorecase' set
2302  set wildmode=longest
2303  set fileignorecase
2304  argadd AAA AAAA AAAAA
2305  call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2306  call assert_equal('"buffer AAA', @:)
2307  set fileignorecase&
2308
2309  " Test for listing files with wildmode=list
2310  set wildmode=list
2311  let g:Sline = ''
2312  call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
2313  call assert_equal('AAA    AAAA   AAAAA', g:Sline)
2314  call assert_equal('"b A', @:)
2315
2316  " When 'wildmenu' is not set, 'noselect' completes first item
2317  set wildmode=noselect
2318  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2319  call assert_equal('"MyCmd oneA', @:)
2320
2321  " When 'noselect' is present, do not complete first <tab>.
2322  set wildmenu
2323  set wildmode=noselect
2324  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2325  call assert_equal('"MyCmd o', @:)
2326  call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2327  call assert_equal('"MyCmd o', @:)
2328  call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2329  call assert_equal('"MyCmd o', @:)
2330
2331  " 'noselect' takes precedence over 'full' on the first Tab.
2332  set wildmode=noselect:full
2333  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2334  call assert_equal('"MyCmd o', @:)
2335  call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2336  call assert_equal('"MyCmd oneA', @:)
2337
2338  " When 'full' is present, complete after first <tab>.
2339  set wildmode=noselect,full
2340  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2341  call assert_equal('"MyCmd o', @:)
2342  call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2343  call assert_equal('"MyCmd oneA', @:)
2344  call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2345  call assert_equal('"MyCmd oneB', @:)
2346  call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2347  call assert_equal('"MyCmd oneB', @:)
2348
2349  " 'noselect' has no effect when 'longest' is present.
2350  set wildmode=noselect:longest
2351  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2352  call assert_equal('"MyCmd one', @:)
2353
2354  " Complete 'noselect' value in 'wildmode' option
2355  set wildmode&
2356  call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2357  call assert_equal('"set wildmode=noselect', @:)
2358  call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2359  call assert_equal('"set wildmode=noselect', @:)
2360
2361  " when using longest completion match, matches shorter than the argument
2362  " should be ignored (happens with :help)
2363  set wildmode=longest,full
2364  " XXX: This test is incorrect.  ':help a*' will never yield 'help a'
2365  "   because '`a' exists as a menu item.  The intent was to test a case
2366  "   handled by nextwild().
2367  " call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2368  " call assert_equal('"help a', @:)
2369  " non existing file
2370  call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2371  call assert_equal('"e a1b2y3z4', @:)
2372
2373  " Test for longest file name completion with 'fileignorecase'
2374  " On MS-Windows, file names are case insensitive.
2375  if has('unix')
2376    call writefile([], 'XTESTfoo', 'D')
2377    call writefile([], 'Xtestbar', 'D')
2378    set nofileignorecase
2379    call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2380    call assert_equal('"e XTESTfoo', @:)
2381    call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2382    call assert_equal('"e Xtestbar', @:)
2383    set fileignorecase
2384    call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2385    call assert_equal('"e Xtest', @:)
2386    call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2387    call assert_equal('"e Xtest', @:)
2388    set fileignorecase&
2389  endif
2390
2391  " If 'noselect' is present, single item menu should not insert item
2392  func! T(a, c, p)
2393    return "oneA"
2394  endfunc
2395  command! -nargs=1 -complete=custom,T MyCmd
2396  set wildmode=noselect,full
2397  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2398  call assert_equal('"MyCmd o', @:)
2399  call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2400  call assert_equal('"MyCmd oneA', @:)
2401  " 'nowildmenu' should make 'noselect' ineffective
2402  set nowildmenu
2403  call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2404  call assert_equal('"MyCmd oneA', @:)
2405
2406  %argdelete
2407  delcommand MyCmd
2408  delfunc T
2409  set wildmode&
2410  %bwipe!
2411endfunc
2412
2413func Test_wildmode()
2414  " Test with utf-8 encoding
2415  call Wildmode_tests()
2416
2417  " Test with latin1 encoding
2418  let save_encoding = &encoding
2419  " set encoding=latin1
2420  " call Wildmode_tests()
2421  let &encoding = save_encoding
2422endfunc
2423
2424func Test_custom_complete_autoload()
2425  call mkdir('Xcustdir/autoload', 'p')
2426  let save_rtp = &rtp
2427  exe 'set rtp=' .. getcwd() .. '/Xcustdir'
2428  let lines =<< trim END
2429      func vim8#Complete(a, c, p)
2430        return "oneA\noneB\noneC"
2431      endfunc
2432  END
2433  call writefile(lines, 'Xcustdir/autoload/vim8.vim')
2434
2435  command -nargs=1 -complete=custom,vim8#Complete MyCmd
2436  set nowildmenu
2437  set wildmode=full,list
2438  call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2439  call assert_equal('"MyCmd oneA oneB oneC', @:)
2440
2441  let &rtp = save_rtp
2442  set wildmode& wildmenu&
2443  delcommand MyCmd
2444  call delete('Xcustdir', 'rf')
2445endfunc
2446
2447" Test for interrupting the command-line completion
2448func Test_interrupt_compl()
2449  func F(lead, cmdl, p)
2450    if a:lead =~ 'tw'
2451      call interrupt()
2452      return
2453    endif
2454    return "one\ntwo\nthree"
2455  endfunc
2456  command -nargs=1 -complete=custom,F Tcmd
2457
2458  set nowildmenu
2459  set wildmode=full
2460  let interrupted = 0
2461  try
2462    call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2463  catch /^Vim:Interrupt$/
2464    let interrupted = 1
2465  endtry
2466  call assert_equal(1, interrupted)
2467
2468  let interrupted = 0
2469  try
2470    call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2471  catch /^Vim:Interrupt$/
2472    let interrupted = 1
2473  endtry
2474  call assert_equal(1, interrupted)
2475
2476  delcommand Tcmd
2477  delfunc F
2478  set wildmode&
2479endfunc
2480
2481" Test for moving the cursor on the : command line
2482func Test_cmdline_edit()
2483  let str = ":one two\<C-U>"
2484  let str ..= "one two\<C-W>\<C-W>"
2485  let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
2486  let str ..= "\<Left>five\<Right>"
2487  let str ..= "\<Home>two "
2488  let str ..= "\<C-Left>one "
2489  let str ..= "\<C-Right> three"
2490  let str ..= "\<End>\<S-Left>four "
2491  let str ..= "\<S-Right> six"
2492  let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2493  call feedkeys(str, 'xt')
2494  call assert_equal("\"one two three four five six seven", @:)
2495endfunc
2496
2497" Test for moving the cursor on the / command line in 'rightleft' mode
2498func Test_cmdline_edit_rightleft()
2499  CheckFeature rightleft
2500  set rightleft
2501  set rightleftcmd=search
2502  let str = "/one two\<C-U>"
2503  let str ..= "one two\<C-W>\<C-W>"
2504  let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
2505  let str ..= "\<Right>five\<Left>"
2506  let str ..= "\<Home>two "
2507  let str ..= "\<C-Right>one "
2508  let str ..= "\<C-Left> three"
2509  let str ..= "\<End>\<S-Right>four "
2510  let str ..= "\<S-Left> six"
2511  let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2512  call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2513  call assert_equal("\"one two three four five six seven", @/)
2514  set rightleftcmd&
2515  set rightleft&
2516endfunc
2517
2518" Test for using <C-\>e in the command line to evaluate an expression
2519func Test_cmdline_expr()
2520  " Evaluate an expression from the beginning of a command line
2521  call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2522  call assert_equal('"hello', @:)
2523
2524  " Use an invalid expression for <C-\>e
2525  call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2526
2527  " Insert literal <CTRL-\> in the command line
2528  call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2529  call assert_equal("\"e \<C-\>\<C-Y>", @:)
2530endfunc
2531
2532" This was making the insert position negative
2533func Test_cmdline_expr_register()
2534  exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2535endfunc
2536
2537" Test for 'imcmdline' and 'imsearch'
2538" This test doesn't actually test the input method functionality.
2539func Test_cmdline_inputmethod()
2540  throw 'Skipped: Nvim does not allow setting the value of a hidden option'
2541  new
2542  call setline(1, ['', 'abc', ''])
2543  set imcmdline
2544
2545  call feedkeys(":\"abc\<CR>", 'xt')
2546  call assert_equal("\"abc", @:)
2547  call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2548  call assert_equal("\"abc", @:)
2549  call feedkeys("/abc\<CR>", 'xt')
2550  call assert_equal([2, 1], [line('.'), col('.')])
2551  call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2552  call assert_equal([2, 1], [line('.'), col('.')])
2553
2554  " set imsearch=2
2555  call cursor(1, 1)
2556  call feedkeys("/abc\<CR>", 'xt')
2557  call assert_equal([2, 1], [line('.'), col('.')])
2558  call cursor(1, 1)
2559  call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2560  call assert_equal([2, 1], [line('.'), col('.')])
2561  set imdisable
2562  call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2563  call assert_equal([2, 1], [line('.'), col('.')])
2564  set imdisable&
2565  set imsearch&
2566
2567  set imcmdline&
2568  %bwipe!
2569endfunc
2570
2571" Test for recursively getting multiple command line inputs
2572func Test_cmdwin_multi_input()
2573  call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
2574  call assert_equal('"cyan', @:)
2575endfunc
2576
2577" Test for using CTRL-_ in the command line with 'allowrevins'
2578func Test_cmdline_revins()
2579  CheckNotMSWindows
2580  CheckFeature rightleft
2581  call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2582  call assert_equal("\"abc\<c-_>", @:)
2583  set allowrevins
2584  call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2585  " call assert_equal('"abcñèæ', @:)
2586  call assert_equal('"abcxyz', @:)
2587  set allowrevins&
2588endfunc
2589
2590" Test for typing UTF-8 composing characters in the command line
2591func Test_cmdline_composing_chars()
2592  call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2593  call assert_equal('"ゔ', @:)
2594endfunc
2595
2596" Test for normal mode commands not supported in the cmd window
2597func Test_cmdwin_blocked_commands()
2598  throw 'Skipped: Nvim supports cmdwin freedom #40312'
2599  call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
2600  call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
2601  call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
2602  call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
2603  call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
2604  call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
2605  call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
2606  call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
2607  call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
2608  call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
2609  call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
2610  call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
2611  call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
2612  call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
2613  call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
2614  call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
2615  call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
2616  call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
2617  call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
2618  call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
2619  call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
2620  call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
2621  call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
2622  call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
2623  call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
2624  call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
2625  call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
2626endfunc
2627
2628" Close the Cmd-line window in insert mode using CTRL-C
2629func Test_cmdwin_insert_mode_close()
2630  throw "Skipped: Nvim supports cmdwin freedom #40312"
2631  %bw!
2632  let s = ''
2633  exe "normal q:a\<C-C>let s='Hello'\<CR>"
2634  call assert_equal('Hello', s)
2635  call assert_equal(1, winnr('$'))
2636endfunc
2637
2638func Test_cmdwin_ex_mode_with_modifier()
2639  " this was accessing memory after allocated text in Ex mode
2640  new
2641  call setline(1, ['some', 'text', 'lines'])
2642  silent! call feedkeys("gQnormal vq:atopleft\<C-V>\<CR>\<CR>", 'xt')
2643  bwipe!
2644endfunc
2645
2646" test that ";" works to find a match at the start of the first line
2647func Test_zero_line_search()
2648  new
2649  call setline(1, ["1, pattern", "2, ", "3, pattern"])
2650  call cursor(1,1)
2651  0;/pattern/d
2652  call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2653  q!
2654endfunc
2655
2656func Test_read_shellcmd()
2657  CheckUnix
2658  if executable('ls')
2659    " There should be ls in the $PATH
2660    call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2661    call assert_match('^"r! .*\<ls\>', @:)
2662  endif
2663
2664  if executable('rm')
2665    call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2666    call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2667    call assert_match('^"r!.*\<rm\>', @:)
2668
2669    call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2670    call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2671    call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
2672  endif
2673endfunc
2674
2675" Test for going up and down the directory tree using 'wildmenu'
2676func Test_wildmenu_dirstack()
2677  CheckUnix
2678  %bw!
2679  call mkdir('Xdir1/dir2/dir3/dir4', 'p')
2680  call writefile([], 'Xdir1/file1_1.txt')
2681  call writefile([], 'Xdir1/file1_2.txt')
2682  call writefile([], 'Xdir1/dir2/file2_1.txt')
2683  call writefile([], 'Xdir1/dir2/file2_2.txt')
2684  call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2685  call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
2686  call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2687  call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
2688  set wildmenu
2689
2690  cd Xdir1/dir2/dir3/dir4
2691  call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
2692  call assert_equal('"e file4_1.txt', @:)
2693  call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
2694  call assert_equal('"e ../dir4/', @:)
2695  call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2696  call assert_equal('"e ../../dir3/', @:)
2697  call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2698  call assert_equal('"e ../../../dir2/', @:)
2699  call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
2700  call assert_equal('"e ../../dir3/dir4/', @:)
2701  call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2702  call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
2703  cd -
2704  call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2705  call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2706
2707  call delete('Xdir1', 'rf')
2708  set wildmenu&
2709endfunc
2710
2711" Test for recalling newer or older cmdline from history with <Up>, <Down>,
2712" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2713" <C-n>.
2714func Test_recalling_cmdline()
2715  CheckFeature cmdline_hist
2716
2717  let g:cmdlines = []
2718  cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2719
2720  let histories = [
2721  \  #{name: 'cmd',    enter: ':',                    exit: "\<Esc>"},
2722  \  #{name: 'search', enter: '/',                    exit: "\<Esc>"},
2723  \  #{name: 'expr',   enter: ":\<C-r>=",             exit: "\<Esc>\<Esc>"},
2724  \  #{name: 'input',  enter: ":call input('')\<CR>", exit: "\<CR>"},
2725  "\ TODO: {'name': 'debug', ...}
2726  \]
2727  let keypairs = [
2728  \  #{older: "\<Up>",     newer: "\<Down>",     prefixmatch: v:true},
2729  \  #{older: "\<S-Up>",   newer: "\<S-Down>",   prefixmatch: v:false},
2730  \  #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2731  \  #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2732  \  #{older: "\<C-p>",    newer: "\<C-n>",      prefixmatch: v:false},
2733  \]
2734  let prefix = 'vi'
2735  for h in histories
2736    call histadd(h.name, 'vim')
2737    call histadd(h.name, 'virtue')
2738    call histadd(h.name, 'Virgo')
2739    call histadd(h.name, 'vogue')
2740    call histadd(h.name, 'emacs')
2741    for k in keypairs
2742      let g:cmdlines = []
2743      let keyseqs = h.enter
2744      \          .. prefix
2745      \          .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2746      \          .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2747      \          .. h.exit
2748      call feedkeys(keyseqs, 'xt')
2749      call histdel(h.name, -1) " delete the history added by feedkeys above
2750      let expect = k.prefixmatch
2751      \          ? ['virtue', 'vim',   'virtue', prefix]
2752      \          : ['emacs',  'vogue', 'emacs',  prefix]
2753      call assert_equal(expect, g:cmdlines)
2754    endfor
2755  endfor
2756
2757  unlet g:cmdlines
2758  cunmap <Plug>(save-cmdline)
2759endfunc
2760
2761func Test_recalling_cmdline_with_mappings()
2762  CheckFeature cmdline_hist
2763
2764  cnoremap <F2> <Cmd>let g:cmdline = getcmdline()<CR>
2765  cnoremap <CR> <CR>
2766  cnoremap <Up> <Up>
2767  let save_a = ['a', getreg('a'), getregtype('a')]
2768
2769  call feedkeys(":echo 'foo'\<CR>", 'tx')
2770  call assert_equal("echo 'foo'", @:)
2771  call feedkeys(":echo 'bar'\<CR>", 'tx')
2772  call assert_equal("echo 'bar'", @:)
2773
2774  call assert_equal("echo 'bar'", histget(':', -1))
2775  call assert_equal("echo 'foo'", histget(':', -2))
2776
2777  let g:cmdline = ''
2778  " This command comes completely from a mapping.
2779  nmap <F3> :echo 'baz'<F2><CR>
2780  call feedkeys("\<F3>", 'tx')
2781  call assert_equal('baz', Screenline(&lines)->trim())
2782  call assert_equal("echo 'baz'", g:cmdline)
2783  call assert_equal("echo 'bar'", @:)
2784  call assert_equal("echo 'bar'", histget(':', -1))
2785  call assert_equal("echo 'foo'", histget(':', -2))
2786
2787  let g:cmdline = ''
2788  " A command coming from :normal is ignored in the history even if the keys
2789  " don't explicitly leave Cmdline mode.
2790  exe "normal :echo 'baz'\<F2>"
2791  call assert_equal("echo 'baz'", g:cmdline)
2792  call assert_equal("echo 'bar'", @:)
2793  call assert_equal("echo 'bar'", histget(':', -1))
2794  call assert_equal("echo 'foo'", histget(':', -2))
2795
2796  if has('unix')
2797    new
2798    call setline(1, ['aaa'])
2799    setlocal formatprg=cat
2800    " Formatting with non-typed "gq" should not change cmdline history.
2801    normal! gqgq
2802    call assert_equal(":.!cat", Screenline(&lines)->trim())
2803    call assert_equal("echo 'bar'", @:)
2804    call assert_equal("echo 'bar'", histget(':', -1))
2805    call assert_equal("echo 'foo'", histget(':', -2))
2806    bwipe!
2807  endif
2808
2809  " This case can still be considered a typed command.
2810  call timer_start(1, {-> feedkeys("\<CR>", 't')})
2811  call feedkeys(":\<Up>\<Up>", 'tx!')
2812  call assert_equal('foo', Screenline(&lines)->trim())
2813  call assert_equal("echo 'foo'", @:)
2814  call assert_equal("echo 'foo'", histget(':', -1))
2815  call assert_equal("echo 'bar'", histget(':', -2))
2816
2817  call feedkeys(":\<Up>\<F2>\<Esc>", 'tx')
2818  call assert_equal("echo 'foo'", g:cmdline)
2819  call assert_equal("echo 'foo'", @:)
2820
2821  " A command from an executed register is also ignored in the history.
2822  call feedkeys(':let @a=":echo ''zzz''\<cr>"' .. "\<CR>", 'tx')
2823  call feedkeys(":norm @a\<cr>", 'tx')
2824  call assert_equal('zzz', Screenline(&lines)->trim())
2825  call assert_equal('norm @a', @:)
2826  call assert_equal('norm @a', histget(':', -1))
2827  call assert_equal('let @a=":echo ''zzz''\<cr>"', histget(':', -2))
2828  call assert_equal("echo 'foo'", histget(':', -3))
2829  call assert_equal("echo 'bar'", histget(':', -4))
2830
2831  unlet g:cmdline
2832  call call('setreg', save_a)
2833  cunmap <F2>
2834  cunmap <CR>
2835  cunmap <Up>
2836  nunmap <F3>
2837endfunc
2838
2839func Test_cmd_map_cmdlineChanged()
2840  let g:log = []
2841  cnoremap <F1> l<Cmd><CR>s
2842  augroup test_CmdlineChanged
2843    autocmd!
2844    autocmd CmdlineChanged : let g:log += [getcmdline()]
2845  augroup END
2846
2847  call feedkeys(":\<F1>\<CR>", 'xt')
2848  call assert_equal(['l', 'ls'], g:log)
2849
2850  let @b = 'b'
2851  cnoremap <F1> a<C-R>b
2852  let g:log = []
2853  call feedkeys(":\<F1>\<CR>", 'xt')
2854  call assert_equal(['a', 'ab'], g:log)
2855
2856  unlet g:log
2857  cunmap <F1>
2858  augroup test_CmdlineChanged
2859    autocmd!
2860  augroup END
2861  augroup! test_CmdlineChanged
2862endfunc
2863
2864" Test for the 'suffixes' option
2865func Test_suffixes_opt()
2866  call writefile([], 'Xsuffile')
2867  call writefile([], 'Xsuffile.c')
2868  call writefile([], 'Xsuffile.o')
2869  set suffixes=
2870  call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2871  call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2872  call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2873  call assert_equal('"e Xsuffile.c', @:)
2874  set suffixes=.c
2875  call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2876  call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2877  call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2878  call assert_equal('"e Xsuffile.o', @:)
2879  set suffixes=,,
2880  call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2881  call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2882  call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2883  call assert_equal('"e Xsuffile.o', @:)
2884  set suffixes&
2885  " Test for getcompletion() with different patterns
2886  call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2887  call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
2888  call delete('Xsuffile')
2889  call delete('Xsuffile.c')
2890  call delete('Xsuffile.o')
2891endfunc
2892
2893" Test for using a popup menu for the command line completion matches
2894" (wildoptions=pum)
2895func Test_wildmenu_pum()
2896  CheckScreendump
2897  CheckRunVimInTerminal
2898
2899  let commands =<< trim [CODE]
2900    set wildmenu
2901    set wildoptions=pum
2902    set shm+=I
2903    set noruler
2904    set noshowcmd
2905
2906    func CmdCompl(a, b, c)
2907      return repeat(['aaaa'], 120)
2908    endfunc
2909    command -nargs=* -complete=customlist,CmdCompl Tcmd
2910
2911    func MyStatusLine() abort
2912      return 'status'
2913    endfunc
2914    func SetupStatusline()
2915      set statusline=%!MyStatusLine()
2916      set laststatus=2
2917    endfunc
2918
2919    func MyTabLine()
2920      return 'my tab line'
2921    endfunc
2922    func SetupTabline()
2923      set statusline=
2924      set tabline=%!MyTabLine()
2925      set showtabline=2
2926    endfunc
2927
2928    func DoFeedKeys()
2929      let &wildcharm = char2nr("\t")
2930      call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2931    endfunc
2932  [CODE]
2933  call writefile(commands, 'Xtest', 'D')
2934
2935  let rows = 10
2936  let buf = RunVimInTerminal('-S Xtest', #{rows: rows})
2937
2938  call term_sendkeys(buf, ":sign \<Tab>")
2939  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
2940  call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2941
2942  " going down the popup menu using <Down>
2943  call term_sendkeys(buf, "\<Down>\<Down>")
2944  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign list') + 1)])
2945  call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2946
2947  " going down the popup menu using <C-N>
2948  call term_sendkeys(buf, "\<C-N>")
2949  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign place') + 1)])
2950  call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2951
2952  " going up the popup menu using <C-P>
2953  call term_sendkeys(buf, "\<C-P>")
2954  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign list') + 1)])
2955  call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2956
2957  " going up the popup menu using <Up>
2958  call term_sendkeys(buf, "\<Up>")
2959  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign jump') + 1)])
2960  call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2961
2962  " pressing <C-E> should end completion and go back to the original match
2963  call term_sendkeys(buf, "\<C-E>")
2964  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign ') + 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
2965  call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2966
2967  " pressing <C-Y> should select the current match and end completion
2968  call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
2969  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
2970  call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2971
2972  " With 'wildmode' set to 'longest,full', completing a match should display
2973  " the longest match, the wildmenu should not be displayed.
2974  call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2975  call term_sendkeys(buf, ":sign u\<Tab>")
2976  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign un') + 1)])
2977  call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2978
2979  " pressing <Tab> should display the wildmenu
2980  call term_sendkeys(buf, "\<Tab>")
2981  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
2982  call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2983
2984  " pressing <Tab> second time should select the next entry in the menu
2985  call term_sendkeys(buf, "\<Tab>")
2986  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
2987  call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2988
2989  call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
2990  " showing popup menu in different columns in the cmdline
2991  call term_sendkeys(buf, ":sign define \<Tab>")
2992  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define culhl=') + 1)], g:test_timeout, ((rows - 1), '\<texthl=\s\+$'))
2993  call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2994
2995  call term_sendkeys(buf, " \<Tab>")
2996  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define culhl= culhl=') + 1)], g:test_timeout, ((rows - 1), '\<texthl=\s\+$'))
2997  call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2998
2999  call term_sendkeys(buf, " \<Tab>")
3000  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define culhl= culhl= culhl=') + 1)], g:test_timeout, ((rows - 1), '\<texthl=\s\+$'))
3001  call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
3002
3003  " Directory name completion
3004  call mkdir('Xnamedir/XdirA/XdirB', 'pR')
3005  call writefile([], 'Xnamedir/XfileA')
3006  call writefile([], 'Xnamedir/XdirA/XfileB')
3007  call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
3008
3009  call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
3010  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':e Xnamedir/XdirA/') + 1)], g:test_timeout, ((rows - 1), '\<XfileA\s\+$'))
3011  call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
3012
3013  " Pressing <Right> on a directory name should go into that directory
3014  call term_sendkeys(buf, "\<Right>")
3015  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':e Xnamedir/XdirA/XdirB/') + 1)], g:test_timeout, ((rows - 1), '\<XfileB\s\+$'))
3016  call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
3017
3018  " Pressing <Left> on a directory name should go to the parent directory
3019  call term_sendkeys(buf, "\<Left>")
3020  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':e Xnamedir/XdirA/') + 1)], g:test_timeout, ((rows - 1), '\<XfileA\s\+$'))
3021  call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
3022
3023  " Pressing <C-A> when the popup menu is displayed should list all the
3024  " matches but the popup menu should still remain (FIXME: the menu goes away)
3025  call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
3026  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define jump list place undefine unplace') + 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3027  call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
3028
3029  " Pressing <C-D> when the popup menu is displayed should remove the popup
3030  " menu
3031  call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
3032  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define') + 1)], g:test_timeout, ((rows - 1), '^define$'))
3033  call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
3034
3035  " Pressing <S-Tab> should open the popup menu with the last entry selected
3036  call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
3037  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3038  call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
3039
3040  " Pressing <Esc> should close the popup menu and cancel the cmd line
3041  call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
3042  call WaitForTermCurPosAndLinesToMatch(buf, [1, 1], g:test_timeout, (rows, '^$'), ((rows - 1), '^\~\s\+$'))
3043  call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
3044
3045  " Typing a character when the popup is open, should close the popup
3046  call term_sendkeys(buf, ":sign \<Tab>x")
3047  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign definex') + 1)])
3048  call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
3049
3050  " When the popup is open, entering the cmdline window should close the popup
3051  call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
3052  call WaitForTermCurPosAndLinesToMatch(buf, [6, strlen(':sign define')], g:test_timeout, (rows, '^You discovered the command-line window! You can close it with ":q"\.'))
3053  call WaitFor({buf_ -> {-> term_scrape(buf, 6)->slice(1, 5)->filter({_, v -> v.fg == '#af5f00'})->len() == 4}}(buf), g:test_timeout)
3054  call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
3055  call term_sendkeys(buf, ":q\<CR>")
3056
3057  " After the last popup menu item, <C-N> should show the original string
3058  call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
3059  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign u') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3060  call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
3061
3062  " Use the popup menu for the command name
3063  call term_sendkeys(buf, "\<C-U>bu\<Tab>")
3064  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':bufdo') + 1)], g:test_timeout, ((rows - 1), '\<bunload\s\+$'))
3065  call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
3066
3067  " Pressing the left arrow should remove the popup menu
3068  call term_sendkeys(buf, "\<Left>\<Left>")
3069  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':bufdo') + 0)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3070  call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
3071
3072  " Pressing <BS> should remove the popup menu and erase the last character
3073  call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
3074  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign defin') + 1)])
3075  call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
3076
3077  " Pressing <C-W> should remove the popup menu and erase the previous word
3078  call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
3079  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign ') + 1)])
3080  call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
3081
3082  " Pressing <C-U> should remove the popup menu and erase the entire line
3083  call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
3084  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':') + 1)])
3085  call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
3086
3087  " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
3088  " the cmdline from history
3089  call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
3090  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign xyz') + 1)])
3091  call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
3092
3093  " Check that when "longest" produces no result, "list" works
3094  call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
3095  call term_sendkeys(buf, ":cn\<Tab>")
3096  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cn') + 1)], g:test_timeout, ((rows - 1), '\<cnoremenu$'))
3097  call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
3098  " No-op?
3099  call term_sendkeys(buf, "\<Tab>")
3100  call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
3101  call term_sendkeys(buf, "s")
3102  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cns') + 1)])
3103  call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
3104
3105  " Tests a directory name contained full-width characters.
3106  call mkdir('Xnamedir/あいう', 'p')
3107  call writefile([], 'Xnamedir/あいう/abc')
3108  call writefile([], 'Xnamedir/あいう/xyz')
3109  call writefile([], 'Xnamedir/あいう/123')
3110
3111  call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
3112  call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
3113  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strwidth(':e Xnamedir/あいう/123') + 1)], g:test_timeout, ((rows - 1), '\<xyz\s\+$'))
3114  call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
3115
3116  " Pressing <C-A> when the popup menu is displayed should list all the
3117  " matches and pressing a key after that should remove the popup menu
3118  call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
3119  call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
3120  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define jump list place undefine unplacex') + 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3121  call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
3122
3123  " Pressing <C-A> when the popup menu is displayed should list all the
3124  " matches and pressing <Left> after that should move the cursor
3125  call term_sendkeys(buf, "\<C-U>abc\<Esc>")
3126  call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
3127  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define jump list place undefine unplace') + 0)])
3128  call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
3129
3130  " When <C-A> displays a lot of matches (screen scrolls), all the matches
3131  " should be displayed correctly on the screen.
3132  call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
3133  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(' aaa') + 0)], g:test_timeout, (rows, '^\saaaa$'))
3134  call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
3135
3136  " After using <C-A> to expand all the filename matches, pressing <Up>
3137  " should not open the popup menu again.
3138  call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
3139  call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
3140  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':e XdirB/ XfileB') + 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3141  call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
3142  call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
3143
3144  " After using <C-A> to expand all the matches, pressing <S-Tab> used to
3145  " crash Vim
3146  call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
3147  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define jump list place undefine unplace') + 1)])
3148  call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
3149
3150  " After removing the pum the command line is redrawn
3151  call term_sendkeys(buf, ":edit foo\<CR>")
3152  call term_sendkeys(buf, ":edit bar\<CR>")
3153  call term_sendkeys(buf, ":ls\<CR>")
3154  call term_sendkeys(buf, ":com\<Tab> ")
3155  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':comclear ') + 1)])
3156  call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
3157  call term_sendkeys(buf, "\<C-U>\<CR>")
3158
3159  " Esc still works to abort the command when 'statusline' is set
3160  call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
3161  call term_sendkeys(buf, ":si\<Tab>")
3162  call term_sendkeys(buf, "\<Esc>")
3163  call WaitForTermCurPosAndLinesToMatch(buf, [1, 1], g:test_timeout, ((rows - 1), '^status\s\+$'))
3164  call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
3165
3166  " Esc still works to abort the command when 'tabline' is set
3167  call term_sendkeys(buf, ":call SetupTabline()\<CR>")
3168  call term_sendkeys(buf, ":si\<Tab>")
3169  call term_sendkeys(buf, "\<Esc>")
3170  call WaitForTermCurPosAndLinesToMatch(buf, [2, 1], g:test_timeout, ((rows - 1), '^bar\s\+$'))
3171  call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
3172
3173  " popup is cleared also when 'lazyredraw' is set
3174  call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
3175  call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
3176  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':abbreviate') + 1)], g:test_timeout, ((rows - 1), '\<abstract\s\+$'))
3177  call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
3178  call term_sendkeys(buf, "\<Esc>")
3179
3180  " Pressing <PageDown> should scroll the menu downward
3181  call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
3182  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3183  call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
3184  call term_sendkeys(buf, "\<PageDown>")
3185  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
3186  call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
3187  call term_sendkeys(buf, "\<PageDown>")
3188  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign ') + 1)])
3189  call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
3190  call term_sendkeys(buf, "\<PageDown>")
3191  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define') + 1)])
3192  call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
3193  call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
3194  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
3195  call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
3196
3197  " Pressing <PageUp> should scroll the menu upward
3198  call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
3199  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign ') + 1)])
3200  call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
3201  call term_sendkeys(buf, "\<PageUp>")
3202  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
3203  call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
3204  call term_sendkeys(buf, "\<PageUp>")
3205  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign jump') + 1)])
3206  call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
3207  call term_sendkeys(buf, "\<PageUp>")
3208  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign define') + 1)])
3209  call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
3210
3211  " pressing <C-E> to end completion should work in middle of the line too
3212  call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
3213  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':set wildcharzz') - 1)], g:test_timeout, ((rows - 1), '\<wildcharm\s\+$'))
3214  call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
3215  call term_sendkeys(buf, "\<C-E>")
3216  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':set wildchazz') - 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3217  call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
3218
3219  " pressing <C-Y> should select the current match and end completion
3220  call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
3221  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':set wildcharzz') - 1)])
3222  call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
3223
3224  call term_sendkeys(buf, "\<Esc>:set showtabline& laststatus& lazyredraw&\<CR>")
3225
3226  " "longest:list" shows list whether it finds a candidate or not
3227  call term_sendkeys(buf, ":set wildmode=longest:list,full wildoptions&\<CR>")
3228  call term_sendkeys(buf, ":cn\<Tab>")
3229  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cn') + 1)], g:test_timeout, ((rows - 1), '\<cnoremenu$'))
3230  call VerifyScreenDump(buf, 'Test_wildmenu_pum_55', {})
3231  call term_sendkeys(buf, "\<Tab>")
3232  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cnewer') + 1)], g:test_timeout, ((rows - 1), '\<cnoremenu\s\+$'))
3233  call VerifyScreenDump(buf, 'Test_wildmenu_pum_56', {})
3234  call term_sendkeys(buf, "\<Esc>:sign u\<Tab>")
3235  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign un') + 1)], g:test_timeout, ((rows - 1), '\<unplace$'))
3236  call VerifyScreenDump(buf, 'Test_wildmenu_pum_57', {})
3237
3238  " "longest:full" shows wildmenu whether it finds a candidate or not; item not selected
3239  call term_sendkeys(buf, "\<Esc>:set wildmode=longest:full,full\<CR>")
3240  call term_sendkeys(buf, ":sign u\<Tab>")
3241  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign un') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3242  call VerifyScreenDump(buf, 'Test_wildmenu_pum_58', {})
3243  call term_sendkeys(buf, "\<Tab>")
3244  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)])
3245  call VerifyScreenDump(buf, 'Test_wildmenu_pum_59', {})
3246  call term_sendkeys(buf, "\<Esc>:cn\<Tab>")
3247  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cn') + 1)], g:test_timeout, ((rows - 1), '\<cnoremenu\s\+$'))
3248  call VerifyScreenDump(buf, 'Test_wildmenu_pum_60', {})
3249  call term_sendkeys(buf, "\<Tab>")
3250  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cnewer') + 1)])
3251  call VerifyScreenDump(buf, 'Test_wildmenu_pum_61', {})
3252
3253  " If "longest,full" finds a candidate, wildmenu is not shown
3254  call term_sendkeys(buf, "\<Esc>:set wildmode=longest,full\<CR>")
3255  call term_sendkeys(buf, ":sign u\<Tab>")
3256  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign un') + 1)], g:test_timeout, ((rows - 1), '\~\s\+$'))
3257  call VerifyScreenDump(buf, 'Test_wildmenu_pum_62', {})
3258  " Subsequent wildchar shows wildmenu
3259  call term_sendkeys(buf, "\<Tab>")
3260  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3261  call VerifyScreenDump(buf, 'Test_wildmenu_pum_63', {})
3262
3263  " 'longest' does not find candidate, and displays menu without selecting item
3264  call term_sendkeys(buf, "\<Esc>:set wildmode=longest,noselect\<CR>")
3265  call term_sendkeys(buf, ":cn\<Tab>")
3266  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':cn') + 1)], g:test_timeout, ((rows - 1), '\<cnoremenu\s\+$'))
3267  call VerifyScreenDump(buf, 'Test_wildmenu_pum_64', {})
3268
3269  " If "longest" finds no candidate in "longest,full", "full" is used
3270  call term_sendkeys(buf, "\<Esc>:set wildmode=longest,full\<CR>")
3271  call term_sendkeys(buf, ":set wildoptions=pum\<CR>")
3272  call term_sendkeys(buf, ":sign un\<Tab>")
3273  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)], g:test_timeout, ((rows - 1), '\<unplace\s\+$'))
3274  call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
3275  call term_sendkeys(buf, "\<Tab>")
3276  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
3277  call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
3278
3279  " Similarly for "longest,noselect:full"
3280  call term_sendkeys(buf, "\<Esc>:set wildmode=longest,noselect:full\<CR>")
3281  call term_sendkeys(buf, ":sign un\<Tab>")
3282  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign un') + 1)])
3283  call VerifyScreenDump(buf, 'Test_wildmenu_pum_65', {})
3284  call term_sendkeys(buf, "\<Tab>")
3285  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign undefine') + 1)])
3286  call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
3287  call term_sendkeys(buf, "\<Tab>")
3288  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':sign unplace') + 1)])
3289  call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
3290
3291  call term_sendkeys(buf, "\<C-U>\<Esc>")
3292  call StopVimInTerminal(buf)
3293endfunc
3294
3295" Test that popup_settext() from a CmdlineChanged autocmd updates the
3296" cmdline-mode info popup without needing an explicit :redraw (#20175).
3297func Test_wildmenu_pum_info_async_update()
3298  CheckScreendump
3299  CheckRunVimInTerminal
3300
3301  let lines =<< trim END
3302      vim9script
3303      set completeopt=menuone,popup
3304      set wildmenu wildoptions=pum wildcharm=<Tab>
3305      augroup Test
3306          au!
3307          au CmdlineChanged : UpdateInfo()
3308      augroup END
3309
3310      def UpdateInfo()
3311          if getcmdcompltype() != 'customlist,Complete'
3312              return
3313          endif
3314          var id = popup_findinfo()
3315          if id != 0
3316              id->popup_settext('done')
3317              popup_show(id)
3318          endif
3319      enddef
3320
3321      def Complete(_, _, _): list<dict<any>>
3322          return [{word: '1', info: 'lazy'}, {word: '2', info: 'lazy'}]
3323      enddef
3324
3325      command! -nargs=1 -complete=customlist,Complete Test echo <args>
3326  END
3327  call writefile(lines, 'XtestWildmenuInfoAsync', 'D')
3328  let buf = RunVimInTerminal('-S XtestWildmenuInfoAsync', #{rows: 14, cols: 50})
3329  call term_sendkeys(buf, ":Test \<Tab>")
3330  call TermWait(buf, 200)
3331  call VerifyScreenDump(buf, 'Test_wildmenu_pum_info_async_update', {})
3332
3333  call term_sendkeys(buf, "\<Esc>")
3334  call StopVimInTerminal(buf)
3335endfunc
3336
3337" Test that "list" and "full" in the same 'wildmode' phase list the matches
3338" and show the wildmenu as well
3339func Test_wildmenu_with_list_full()
3340  call writefile([], 'XwildA', 'D')
3341  call writefile([], 'XwildB', 'D')
3342  func! SaveScreenLineAbove()
3343    let g:Sabove = Screenline(&lines - 2)
3344    return ''
3345  endfunc
3346  cnoremap <expr> <F2> wildmenumode()
3347  cnoremap <expr> <F3> SaveScreenLineAbove()
3348  set wildmenu wildmode=list:full
3349
3350  " The matches are listed above the menu.
3351  let [g:Sabove, g:Sline] = ['', '']
3352  call feedkeys(":e Xwild\<Tab>\<F3>\<F4>\<F2>\<C-B>\"\<CR>", 'xt')
3353  call assert_equal('"e XwildA1', @:)
3354  call assert_equal('XwildA  XwildB', g:Sabove)
3355  call assert_equal('XwildA  XwildB', g:Sline)
3356
3357  " The popup menu is shown over the listed matches.
3358  set wildoptions=pum
3359  call feedkeys(":e Xwild\<Tab>\<F2>\<C-B>\"\<CR>", 'xt')
3360  call assert_equal('"e XwildA1', @:)
3361
3362  " Without 'wildmenu' the matches are listed as before.
3363  set nowildmenu wildoptions=
3364  let g:Sline = ''
3365  call feedkeys(":e Xwild\<Tab>\<F4>\<F2>\<C-B>\"\<CR>", 'xt')
3366  call assert_equal('XwildA  XwildB', g:Sline)
3367  call assert_equal('"e XwildA0', @:)
3368
3369  cunmap <F2>
3370  cunmap <F3>
3371  delfunc SaveScreenLineAbove
3372  unlet g:Sabove
3373  set nowildmenu wildoptions& wildmode&
3374endfunc
3375
3376" Test for wildmenumode() with the cmdline popup menu
3377func Test_wildmenumode_with_pum()
3378  set wildmenu
3379  set wildoptions=pum
3380  cnoremap <expr> <F2> wildmenumode()
3381  call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
3382  call assert_equal('"sign define10', @:)
3383  call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
3384  call assert_equal('"sign define jump list place undefine unplace0', @:)
3385  call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
3386  call assert_equal('"sign 0', @:)
3387  call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
3388  call assert_equal('"sign define0', @:)
3389  set nowildmenu wildoptions&
3390  cunmap <F2>
3391endfunc
3392
3393func Test_wildmenu_with_pum_foldexpr()
3394  CheckScreendump
3395  CheckRunVimInTerminal
3396
3397  let lines =<< trim END
3398      call setline(1, ['folded one', 'folded two', 'some more text'])
3399      func MyFoldText()
3400        return 'foo'
3401      endfunc
3402      set foldtext=MyFoldText() wildoptions=pum
3403      normal ggzfj
3404  END
3405  call writefile(lines, 'Xpumfold')
3406  let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
3407  call term_sendkeys(buf, ":set\<Tab>")
3408  call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
3409
3410  call term_sendkeys(buf, "\<Esc>")
3411  call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
3412
3413  call StopVimInTerminal(buf)
3414  call delete('Xpumfold')
3415endfunc
3416
3417" Test for opening the cmdline completion popup menu from the terminal window.
3418" The popup menu should be positioned correctly over the status line of the
3419" bottom-most window.
3420func Test_wildmenu_pum_from_terminal()
3421  CheckScreendump
3422  CheckRunVimInTerminal
3423  let python = PythonProg()
3424  call CheckPython(python)
3425
3426  %bw!
3427  let cmds = ['set wildmenu wildoptions=pum']
3428  let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
3429  call add(cmds, "call term_start('" .. pcmd .. "')")
3430  call writefile(cmds, 'Xtest', 'D')
3431  let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
3432  call term_sendkeys(buf, "\r\r\r")
3433  call term_wait(buf)
3434  call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
3435  call term_wait(buf)
3436  call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
3437  call term_wait(buf)
3438  call StopVimInTerminal(buf)
3439endfunc
3440
3441func Test_wildmenu_pum_odd_wildchar()
3442  CheckScreendump
3443  CheckRunVimInTerminal
3444
3445  " Test odd wildchar interactions with pum. Make sure they behave properly
3446  " and don't lead to memory corruption due to improperly cleaned up memory.
3447  let lines =<< trim END
3448    set wildoptions=pum
3449    set wildchar=<C-E>
3450  END
3451  call writefile(lines, 'XwildmenuTest', 'D')
3452  let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
3453
3454  call term_sendkeys(buf, ":\<C-E>")
3455  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3456
3457  " <C-E> being a wildchar takes priority over its original functionality
3458  call term_sendkeys(buf, "\<C-E>")
3459  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
3460
3461  call term_sendkeys(buf, "\<Esc>")
3462  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3463
3464  " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
3465  " command-line, and we need to make sure to clean up properly.
3466  call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3467  call term_sendkeys(buf, ":\<Esc>")
3468  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3469
3470  call term_sendkeys(buf, "\<Esc>")
3471  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3472
3473  " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3474  " and we again need to make sure we clean up properly.
3475  call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3476  call term_sendkeys(buf, ":\<C-\>\<C-\>")
3477  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3478
3479  call term_sendkeys(buf, "\<C-N>")
3480  call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3481
3482  call StopVimInTerminal(buf)
3483endfunc
3484
3485" Test that 'rightleft' should not affect cmdline completion popup menu.
3486func Test_wildmenu_pum_rightleft()
3487  CheckFeature rightleft
3488  CheckScreendump
3489
3490  let lines =<< trim END
3491    set wildoptions=pum
3492    set rightleft
3493  END
3494  call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3495  let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3496
3497  call term_sendkeys(buf, ":sign \<Tab>")
3498  call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3499
3500  " Behavior is the same when using 'keymap'.
3501  call term_sendkeys(buf, "\<Esc>:set keymap=dvorak\<CR>")
3502  call TermWait(buf)
3503  " ";gul" -> "sign" when using Dvorak keymap.
3504  call term_sendkeys(buf, ":\<C-^>;gul \<Tab>")
3505  call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3506  call term_sendkeys(buf, "\<Esc>:set keymap&\<CR>")
3507
3508  call StopVimInTerminal(buf)
3509endfunc
3510
3511" Test highlighting when pattern matches non-first character of item
3512func Test_wildmenu_pum_hl_nonfirst()
3513  CheckScreendump
3514  let lines =<< trim END
3515    set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3516    hi PmenuMatchSel  ctermfg=6 ctermbg=7
3517    hi PmenuMatch     ctermfg=4 ctermbg=225
3518    func T(a, c, p)
3519      return ["oneA", "o neBneB", "aoneC"]
3520    endfunc
3521    command -nargs=1 -complete=customlist,T MyCmd
3522  END
3523
3524  call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3525  let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3526
3527  call term_sendkeys(buf, ":MyCmd ne\<tab>")
3528  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3529  call term_sendkeys(buf, "\<Esc>")
3530  call StopVimInTerminal(buf)
3531endfunc
3532
3533" Test highlighting matched text in cmdline completion popup menu.
3534func Test_wildmenu_pum_hl_match()
3535  CheckScreendump
3536
3537  let lines =<< trim END
3538    set wildoptions=pum,fuzzy
3539    hi PmenuMatchSel  ctermfg=6 ctermbg=7
3540    hi PmenuMatch     ctermfg=4 ctermbg=225
3541  END
3542  call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3543  let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3544
3545  call term_sendkeys(buf, ":sign plc\<Tab>")
3546  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3547  call term_sendkeys(buf, "\<Tab>")
3548  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3549  call term_sendkeys(buf, "\<Tab>")
3550  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3551  call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3552  call TermWait(buf)
3553  call term_sendkeys(buf, ":sign un\<Tab>")
3554  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3555  call term_sendkeys(buf, "\<Tab>")
3556  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3557  call term_sendkeys(buf, "\<Tab>")
3558  call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3559  call term_sendkeys(buf, "\<Esc>")
3560
3561  call StopVimInTerminal(buf)
3562endfunc
3563
3564" Test for completion after a :substitute command followed by a pipe (|)
3565" character
3566func Test_cmdline_complete_substitute()
3567  set wildchar=0
3568  call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3569  call assert_equal("\"s | \t", @:)
3570  call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3571  call assert_equal("\"s/ | \t", @:)
3572  call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3573  call assert_equal("\"s/one | \t", @:)
3574  set wildchar&
3575  call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3576  call assert_equal("\"s/one/ | \t", @:)
3577  call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3578  call assert_equal("\"s/one/two | \t", @:)
3579  call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3580  call assert_equal('"s/one/two/ | chistory', @:)
3581  call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3582  call assert_equal("\"s/one/two/g \t", @:)
3583  call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3584  call assert_equal("\"s/one/two/g | chistory", @:)
3585  call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3586  call assert_equal("\"s/one/t\\/ | \t", @:)
3587  call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3588  call assert_equal('"s/one/t"o/ | chistory', @:)
3589  call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3590  call assert_equal('"s/one/t|o/ | chistory', @:)
3591  call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3592  call assert_equal("\"&\t", @:)
3593endfunc
3594
3595" Test for the :dlist command completion
3596func Test_cmdline_complete_dlist()
3597  call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3598  call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3599  call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3600  call assert_equal("\"dlist 10 /pat/ \t", @:)
3601  call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3602  call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3603  call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3604  call assert_equal("\"dlist 10 /pat\\\t", @:)
3605  call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3606  call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3607endfunc
3608
3609" argument list (only for :argdel) fuzzy completion
3610func Test_fuzzy_completion_arglist()
3611  argadd change.py count.py charge.py
3612  set wildoptions&
3613  call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3614  call assert_equal('"argdel cge', @:)
3615  set wildoptions=fuzzy
3616  call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3617  call assert_equal('"argdel change.py charge.py', @:)
3618  %argdelete
3619  set wildoptions&
3620endfunc
3621
3622" autocmd group name fuzzy completion
3623func Test_fuzzy_completion_autocmd()
3624  set wildoptions&
3625  augroup MyFuzzyGroup
3626  augroup END
3627  call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3628  call assert_equal('"augroup mfg', @:)
3629  call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3630  call assert_equal('"augroup MyFuzzyGroup', @:)
3631  set wildoptions=fuzzy
3632  call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3633  call assert_equal('"augroup MyFuzzyGroup', @:)
3634  call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3635  call assert_equal('"augroup My*p', @:)
3636  augroup! MyFuzzyGroup
3637  set wildoptions&
3638endfunc
3639
3640" buffer name fuzzy completion
3641func Test_fuzzy_completion_bufname()
3642  set wildoptions&
3643  " Use a long name to reduce the risk of matching a random directory name
3644  edit SomeRandomFileWithLetters.txt
3645  enew
3646  call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3647  call assert_equal('"b SRFWL', @:)
3648  call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3649  call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3650  set wildoptions=fuzzy
3651  call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3652  call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3653  call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3654  call assert_equal('"b S*FileWithLetters.txt', @:)
3655  %bw!
3656  set wildoptions&
3657endfunc
3658
3659" buffer name (full path) fuzzy completion
3660func Test_fuzzy_completion_bufname_fullpath()
3661  CheckUnix
3662  set wildoptions&
3663  call mkdir('Xcmd/Xstate', 'pR')
3664  edit Xcmd/Xstate/Xfile.js
3665  cd Xcmd/Xstate
3666  enew
3667  call feedkeys(":b cmdstatefile\<Tab>\<C-B>\"\<CR>", 'tx')
3668  call assert_equal('"b cmdstatefile', @:)
3669  set wildoptions=fuzzy
3670  call feedkeys(":b cmdstatefile\<Tab>\<C-B>\"\<CR>", 'tx')
3671  call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3672  cd -
3673  set wildoptions&
3674endfunc
3675
3676" :behave suboptions fuzzy completion
3677func Test_fuzzy_completion_behave()
3678  throw 'Skipped: Nvim removed :behave'
3679  set wildoptions&
3680  call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3681  call assert_equal('"behave xm', @:)
3682  call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3683  call assert_equal('"behave xterm', @:)
3684  set wildoptions=fuzzy
3685  call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3686  call assert_equal('"behave xterm', @:)
3687  call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3688  call assert_equal('"behave xt*m', @:)
3689  let g:Sline = ''
3690  call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3691  call assert_equal('mswin', g:Sline)
3692  call assert_equal('"behave win', @:)
3693  set wildoptions&
3694endfunc
3695
3696" :filetype suboptions completion
3697func Test_completion_filetypecmd()
3698  set wildoptions&
3699  call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3700  call assert_equal('"filetype detect indent off on plugin', @:)
3701  call feedkeys(":filetype det\<C-A>\<C-B>\"\<CR>", 'tx')
3702  call assert_equal('"filetype detect', @:)
3703  call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3704  call assert_equal('"filetype plugin indent off on', @:)
3705  call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3706  call assert_equal('"filetype indent off on plugin', @:)
3707  call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3708  call assert_equal('"filetype indent', @:)
3709  call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3710  call assert_equal('"filetype plugin', @:)
3711  call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3712  call assert_equal('"filetype off on', @:)
3713  call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3714  call assert_equal('"filetype indent off', @:)
3715  call feedkeys(":filetype plugin\<C-A>\<C-B>\"\<CR>", 'tx')
3716  call assert_equal('"filetype plugin', @:)
3717  call feedkeys(":filetype plugin indent\<C-A>\<C-B>\"\<CR>", 'tx')
3718  call assert_equal('"filetype plugin indent', @:)
3719  set wildoptions&
3720endfunc
3721
3722" " colorscheme name fuzzy completion - NOT supported
3723" func Test_fuzzy_completion_colorscheme()
3724" endfunc
3725
3726" built-in command name fuzzy completion
3727func Test_fuzzy_completion_cmdname()
3728  set wildoptions&
3729  call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3730  call assert_equal('"sbwin', @:)
3731  call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3732  call assert_equal('"sbrewind', @:)
3733  set wildoptions=fuzzy
3734  call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3735  call assert_equal('"sbrewind', @:)
3736  call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3737  call assert_equal('"sbr*d', @:)
3738  set wildoptions&
3739endfunc
3740
3741" " compiler name fuzzy completion - NOT supported
3742" func Test_fuzzy_completion_compiler()
3743" endfunc
3744
3745" :cscope suboptions fuzzy completion
3746func Test_fuzzy_completion_cscope()
3747  CheckFeature cscope
3748  set wildoptions&
3749  call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3750  call assert_equal('"cscope ret', @:)
3751  call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3752  call assert_equal('"cscope reset', @:)
3753  set wildoptions=fuzzy
3754  call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3755  call assert_equal('"cscope reset', @:)
3756  call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3757  call assert_equal('"cscope re*t', @:)
3758  set wildoptions&
3759endfunc
3760
3761" :diffget/:diffput buffer name fuzzy completion
3762func Test_fuzzy_completion_diff()
3763  new SomeBuffer
3764  diffthis
3765  new OtherBuffer
3766  diffthis
3767  set wildoptions&
3768  call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3769  call assert_equal('"diffget sbuf', @:)
3770  call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3771  call assert_equal('"diffput sbuf', @:)
3772  set wildoptions=fuzzy
3773  call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3774  call assert_equal('"diffget SomeBuffer', @:)
3775  call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3776  call assert_equal('"diffput SomeBuffer', @:)
3777  %bw!
3778  set wildoptions&
3779endfunc
3780
3781" " directory name fuzzy completion - NOT supported
3782" func Test_fuzzy_completion_dirname()
3783" endfunc
3784
3785" environment variable name fuzzy completion
3786func Test_fuzzy_completion_env()
3787  set wildoptions&
3788  call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3789  call assert_equal('"echo $VUT', @:)
3790  set wildoptions=fuzzy
3791  call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3792  call assert_equal('"echo $VIMRUNTIME', @:)
3793  set wildoptions&
3794endfunc
3795
3796" autocmd event fuzzy completion
3797func Test_fuzzy_completion_autocmd_event()
3798  set wildoptions&
3799  call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3800  call assert_equal('"autocmd BWout', @:)
3801  set wildoptions=fuzzy
3802  call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3803  call assert_equal('"autocmd BufWipeout', @:)
3804  set wildoptions&
3805endfunc
3806
3807" vim expression fuzzy completion
3808func Test_fuzzy_completion_expr()
3809  let g:PerPlaceCount = 10
3810  set wildoptions&
3811  call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3812  call assert_equal('"let c = ppc', @:)
3813  set wildoptions=fuzzy
3814  call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3815  call assert_equal('"let c = PerPlaceCount', @:)
3816  set wildoptions&
3817endfunc
3818
3819" " file name fuzzy completion - NOT supported
3820" func Test_fuzzy_completion_filename()
3821" endfunc
3822
3823" " files in path fuzzy completion - NOT supported
3824" func Test_fuzzy_completion_filesinpath()
3825" endfunc
3826
3827" " filetype name fuzzy completion - NOT supported
3828" func Test_fuzzy_completion_filetype()
3829" endfunc
3830
3831" user defined function name completion
3832func Test_fuzzy_completion_userdefined_func()
3833  set wildoptions&
3834  call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3835  call assert_equal('"call Test_f_u_f', @:)
3836  set wildoptions=fuzzy
3837  call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3838  call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3839  set wildoptions&
3840endfunc
3841
3842" <SNR> functions should be sorted to the end
3843func Test_fuzzy_completion_userdefined_snr_func()
3844  func s:Sendmail()
3845  endfunc
3846  func SendSomemail()
3847  endfunc
3848  func S1e2n3dmail()
3849  endfunc
3850  set wildoptions=fuzzy
3851  call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
3852  call assert_equal('"call SendSomemail() S1e2n3dmail() '
3853        \ .. expand("<SID>") .. 'Sendmail()', @:)
3854  set wildoptions&
3855  delfunc s:Sendmail
3856  delfunc SendSomemail
3857  delfunc S1e2n3dmail
3858endfunc
3859
3860" user defined command name completion
3861func Test_fuzzy_completion_userdefined_cmd()
3862  set wildoptions&
3863  call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3864  call assert_equal('"MsFeat', @:)
3865  set wildoptions=fuzzy
3866  call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3867  call assert_equal('"MissingFeature', @:)
3868  set wildoptions&
3869endfunc
3870
3871" " :help tag fuzzy completion - NOT supported
3872" func Test_fuzzy_completion_helptag()
3873" endfunc
3874
3875" highlight group name fuzzy completion
3876func Test_fuzzy_completion_hlgroup()
3877  set wildoptions&
3878  call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3879  call assert_equal('"highlight SKey', @:)
3880  call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3881  call assert_equal('"highlight SpecialKey', @:)
3882  set wildoptions=fuzzy
3883  call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3884  call assert_equal('"highlight SpecialKey', @:)
3885  call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3886  call assert_equal('"highlight Sp*Key', @:)
3887  set wildoptions&
3888endfunc
3889
3890" :history suboptions fuzzy completion
3891func Test_fuzzy_completion_history()
3892  set wildoptions&
3893  call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3894  call assert_equal('"history dg', @:)
3895  call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3896  call assert_equal('"history search', @:)
3897  set wildoptions=fuzzy
3898  call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3899  call assert_equal('"history debug', @:)
3900  call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3901  call assert_equal('"history se*h', @:)
3902  set wildoptions&
3903endfunc
3904
3905" :language locale name fuzzy completion
3906func Test_fuzzy_completion_lang()
3907  CheckUnix
3908  set wildoptions&
3909  call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3910  call assert_equal('"lang psx', @:)
3911  set wildoptions=fuzzy
3912  call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3913  call assert_equal('"lang POSIX', @:)
3914  set wildoptions&
3915endfunc
3916
3917" :mapclear buffer argument fuzzy completion
3918func Test_fuzzy_completion_mapclear()
3919  set wildoptions&
3920  call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3921  call assert_equal('"mapclear buf', @:)
3922  set wildoptions=fuzzy
3923  call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3924  call assert_equal('"mapclear <buffer>', @:)
3925  set wildoptions&
3926endfunc
3927
3928" map name fuzzy completion
3929func Test_fuzzy_completion_mapname()
3930  " test regex completion works
3931  set wildoptions=fuzzy
3932  call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3933  call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
3934  nmap <plug>MyLongMap :p<CR>
3935  call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3936  call assert_equal("\"nmap <Plug>MyLongMap", @:)
3937  call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3938  call assert_equal("\"nmap MLM \t", @:)
3939  call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3940  call assert_equal("\"nmap <F2> one two \t", @:)
3941  " duplicate entries should be removed
3942  vmap <plug>MyLongMap :<C-U>#<CR>
3943  call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3944  call assert_equal("\"nmap <Plug>MyLongMap", @:)
3945  nunmap <plug>MyLongMap
3946  vunmap <plug>MyLongMap
3947  call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3948  call assert_equal("\"nmap ABC\t", @:)
3949  " results should be sorted by best match
3950  nmap <Plug>format :
3951  nmap <Plug>goformat :
3952  nmap <Plug>TestFOrmat :
3953  nmap <Plug>fendoff :
3954  nmap <Plug>state :
3955  nmap <Plug>FendingOff :
3956  call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3957  call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>fendoff <Plug>goformat", @:)
3958  nunmap <Plug>format
3959  nunmap <Plug>goformat
3960  nunmap <Plug>TestFOrmat
3961  nunmap <Plug>fendoff
3962  nunmap <Plug>state
3963  nunmap <Plug>FendingOff
3964  set wildoptions&
3965endfunc
3966
3967" abbreviation fuzzy completion
3968func Test_fuzzy_completion_abbr()
3969  set wildoptions=fuzzy
3970  call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3971  call assert_equal("\"iabbr <nowait>", @:)
3972  iabbr WaitForCompletion WFC
3973  call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3974  call assert_equal("\"iabbr WaitForCompletion", @:)
3975  call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3976  call assert_equal("\"iabbr a1z\t", @:)
3977
3978  iunabbrev WaitForCompletion
3979  set wildoptions&
3980endfunc
3981
3982" menu name fuzzy completion
3983func Test_fuzzy_completion_menu()
3984  CheckFeature menu
3985
3986  source $VIMRUNTIME/menu.vim
3987  set wildoptions&
3988  call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3989  call assert_equal('"menu pup', @:)
3990  set wildoptions=fuzzy
3991  call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3992  call assert_equal('"menu PopUp.', @:)
3993
3994  set wildoptions&
3995  source $VIMRUNTIME/delmenu.vim
3996endfunc
3997
3998" :messages suboptions fuzzy completion
3999func Test_fuzzy_completion_messages()
4000  set wildoptions&
4001  call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
4002  call assert_equal('"messages clr', @:)
4003  set wildoptions=fuzzy
4004  call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
4005  call assert_equal('"messages clear', @:)
4006  set wildoptions&
4007endfunc
4008
4009" :set option name fuzzy completion
4010func Test_fuzzy_completion_option()
4011  set wildoptions&
4012  call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
4013  call assert_equal('"set brkopt', @:)
4014  set wildoptions=fuzzy
4015  call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
4016  call assert_equal('"set breakindentopt', @:)
4017  set wildoptions&
4018  call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
4019  call assert_equal('"set fixendofline', @:)
4020  set wildoptions=fuzzy
4021  call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
4022  call assert_equal('"set fixendofline', @:)
4023  set wildoptions&
4024endfunc
4025
4026" :set <term_option>
4027func Test_fuzzy_completion_term_option()
4028  throw 'Skipped: Nvim does not support term options'
4029  set wildoptions&
4030  call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
4031  call assert_equal('"set t_EC', @:)
4032  call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
4033  call assert_equal('"set <t_EC>', @:)
4034  set wildoptions=fuzzy
4035  call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
4036  call assert_equal('"set t_EC', @:)
4037  call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
4038  call assert_equal('"set <t_EC>', @:)
4039  set wildoptions&
4040endfunc
4041
4042" " :packadd directory name fuzzy completion - NOT supported
4043" func Test_fuzzy_completion_packadd()
4044" endfunc
4045
4046" " shell command name fuzzy completion - NOT supported
4047" func Test_fuzzy_completion_shellcmd()
4048" endfunc
4049
4050" :sign suboptions fuzzy completion
4051func Test_fuzzy_completion_sign()
4052  set wildoptions&
4053  call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
4054  call assert_equal('"sign ufe', @:)
4055  set wildoptions=fuzzy
4056  call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
4057  call assert_equal('"sign undefine', @:)
4058  set wildoptions&
4059endfunc
4060
4061" :syntax suboptions fuzzy completion
4062func Test_fuzzy_completion_syntax_cmd()
4063  set wildoptions&
4064  call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
4065  call assert_equal('"syntax kwd', @:)
4066  set wildoptions=fuzzy
4067  call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
4068  call assert_equal('"syntax keyword', @:)
4069  set wildoptions&
4070endfunc
4071
4072" syntax group name fuzzy completion
4073func Test_fuzzy_completion_syntax_group()
4074  set wildoptions&
4075  call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
4076  call assert_equal('"syntax list mpar', @:)
4077  set wildoptions=fuzzy
4078  call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
4079  call assert_equal('"syntax list MatchParen', @:)
4080  set wildoptions&
4081endfunc
4082
4083" :syntime suboptions fuzzy completion
4084func Test_fuzzy_completion_syntime()
4085  CheckFeature profile
4086  set wildoptions&
4087  call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
4088  call assert_equal('"syntime clr', @:)
4089  set wildoptions=fuzzy
4090  call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
4091  call assert_equal('"syntime clear', @:)
4092  set wildoptions&
4093endfunc
4094
4095" " tag name fuzzy completion - NOT supported
4096" func Test_fuzzy_completion_tagname()
4097" endfunc
4098
4099" " tag name and file fuzzy completion - NOT supported
4100" func Test_fuzzy_completion_tagfile()
4101" endfunc
4102
4103" " user names fuzzy completion - how to test this functionality?
4104" func Test_fuzzy_completion_username()
4105" endfunc
4106
4107" user defined variable name fuzzy completion
4108func Test_fuzzy_completion_userdefined_var()
4109  let g:SomeVariable=10
4110  set wildoptions&
4111  call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
4112  call assert_equal('"let SVar', @:)
4113  set wildoptions=fuzzy
4114  call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
4115  call assert_equal('"let SomeVariable', @:)
4116  set wildoptions&
4117endfunc
4118
4119" Test for sorting the results by the best match
4120func Test_fuzzy_completion_cmd_sort_results()
4121  %bw!
4122  command T123format :
4123  command T123goformat :
4124  command T123TestFOrmat :
4125  command T123fendoff :
4126  command T123state :
4127  command T123FendingOff :
4128  set wildoptions=fuzzy
4129  call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
4130  call assert_equal('"T123format T123TestFOrmat T123FendingOff T123fendoff T123goformat', @:)
4131  delcommand T123format
4132  delcommand T123goformat
4133  delcommand T123TestFOrmat
4134  delcommand T123fendoff
4135  delcommand T123state
4136  delcommand T123FendingOff
4137  %bw
4138  set wildoptions&
4139endfunc
4140
4141" Test for fuzzy completion of a command with lower case letters and a number
4142func Test_fuzzy_completion_cmd_alnum()
4143  command Foo2Bar :
4144  set wildoptions=fuzzy
4145  call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
4146  call assert_equal('"Foo2Bar', @:)
4147  call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
4148  call assert_equal('"Foo2Bar', @:)
4149  call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
4150  call assert_equal('"Foo2Bar', @:)
4151  delcommand Foo2Bar
4152  set wildoptions&
4153endfunc
4154
4155" Test for command completion for a command starting with 'k'
4156func Test_fuzzy_completion_cmd_k()
4157  command KillKillKill :
4158  set wildoptions&
4159  call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
4160  call assert_equal("\"killkill\<Tab>", @:)
4161  set wildoptions=fuzzy
4162  call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
4163  call assert_equal('"KillKillKill', @:)
4164  delcom KillKillKill
4165  set wildoptions&
4166endfunc
4167
4168" Issue #20241: with 'ignorecase', a lowercase "k"-prefixed input should
4169" still complete a user command starting with "K".
4170func Test_cmdline_complete_user_cmd_k_with_ignorecase()
4171  command! Kz echo "hello"
4172  command! Gz echo "here"
4173
4174  set noignorecase
4175  call assert_equal([], getcompletion('kz', 'cmdline'))
4176  call assert_equal([], getcompletion('gz', 'cmdline'))
4177  call assert_equal(['Kz'], getcompletion('Kz', 'cmdline'))
4178  call assert_equal(['Gz'], getcompletion('Gz', 'cmdline'))
4179
4180  set ignorecase
4181  call assert_equal(['Kz'], getcompletion('kz', 'cmdline'))
4182  call assert_equal(['Gz'], getcompletion('gz', 'cmdline'))
4183
4184  set ignorecase&
4185  delcommand Kz
4186  delcommand Gz
4187endfunc
4188
4189" Test for fuzzy completion for user defined custom completion function
4190func Test_fuzzy_completion_custom_func()
4191  func Tcompl(a, c, p)
4192    return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
4193  endfunc
4194  command -nargs=* -complete=custom,Tcompl Fuzzy :
4195  set wildoptions&
4196  call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
4197  call assert_equal("\"Fuzzy format", @:)
4198  call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
4199  call assert_equal("\"Fuzzy xy", @:)
4200  call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
4201  call assert_equal("\"Fuzzy ttt", @:)
4202  set wildoptions=fuzzy
4203  call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
4204  call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
4205  call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
4206  call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
4207  call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
4208  call assert_equal("\"Fuzzy xy", @:)
4209  call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
4210  call assert_equal("\"Fuzzy TestFOrmat", @:)
4211  delcom Fuzzy
4212  set wildoptions&
4213endfunc
4214
4215" Test for fuzzy completion in the middle of a cmdline instead of at the end
4216func Test_fuzzy_completion_in_middle()
4217  set wildoptions=fuzzy
4218  call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
4219  call assert_equal("\"set wildchar wildcharm wrap", @:)
4220
4221  call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
4222  call assert_equal("\"args ++encoding= zz", @:)
4223  set wildoptions&
4224endfunc
4225
4226" Test for :breakadd argument completion
4227func Test_cmdline_complete_breakadd()
4228  call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
4229  call assert_equal("\"breakadd expr file func here", @:)
4230  call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
4231  call assert_equal("\"breakadd expr", @:)
4232  call feedkeys(":breakadd    \<Tab>\<C-B>\"\<CR>", 'tx')
4233  call assert_equal("\"breakadd    expr", @:)
4234  call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
4235  call assert_equal("\"breakadd here", @:)
4236  call feedkeys(":breakadd    he\<Tab>\<C-B>\"\<CR>", 'tx')
4237  call assert_equal("\"breakadd    here", @:)
4238  call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
4239  call assert_equal("\"breakadd abc", @:)
4240  call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
4241  let l = getcompletion('not', 'breakpoint')
4242  call assert_equal([], l)
4243
4244  " Test for :breakadd file [lnum] <file>
4245  call writefile([], 'Xscript')
4246  call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4247  call assert_equal("\"breakadd file Xscript", @:)
4248  call feedkeys(":breakadd   file   Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4249  call assert_equal("\"breakadd   file   Xscript", @:)
4250  call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4251  call assert_equal("\"breakadd file 20 Xscript", @:)
4252  call feedkeys(":breakadd   file   20   Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4253  call assert_equal("\"breakadd   file   20   Xscript", @:)
4254  call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4255  call assert_equal("\"breakadd file 20x Xsc\t", @:)
4256  call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
4257  call assert_equal("\"breakadd file 20\t", @:)
4258  call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
4259  call assert_equal("\"breakadd file 20x\t", @:)
4260  call feedkeys(":breakadd file Xscript  \<Tab>\<C-B>\"\<CR>", 'tx')
4261  call assert_equal("\"breakadd file Xscript  ", @:)
4262  call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
4263  call assert_equal("\"breakadd file X1B2C3", @:)
4264  call delete('Xscript')
4265
4266  " Test for :breakadd func [lnum] <function>
4267  func Xbreak_func()
4268  endfunc
4269  call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4270  call assert_equal("\"breakadd func Xbreak_func", @:)
4271  call feedkeys(":breakadd    func    Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4272  call assert_equal("\"breakadd    func    Xbreak_func", @:)
4273  call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4274  call assert_equal("\"breakadd func 20 Xbreak_func", @:)
4275  call feedkeys(":breakadd   func   20   Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4276  call assert_equal("\"breakadd   func   20   Xbreak_func", @:)
4277  call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4278  call assert_equal("\"breakadd func 20x Xbr\t", @:)
4279  call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
4280  call assert_equal("\"breakadd func 20\t", @:)
4281  call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
4282  call assert_equal("\"breakadd func 20x\t", @:)
4283  call feedkeys(":breakadd func Xbreak_func  \<Tab>\<C-B>\"\<CR>", 'tx')
4284  call assert_equal("\"breakadd func Xbreak_func  ", @:)
4285  call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
4286  call assert_equal("\"breakadd func X1B2C3", @:)
4287  delfunc Xbreak_func
4288
4289  " Test for :breakadd expr <expression>
4290  let g:Xtest_var = 10
4291  call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4292  call assert_equal("\"breakadd expr Xtest_var", @:)
4293  call feedkeys(":breakadd    expr    Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4294  call assert_equal("\"breakadd    expr    Xtest_var", @:)
4295  call feedkeys(":breakadd expr Xtest_var  \<Tab>\<C-B>\"\<CR>", 'tx')
4296  call assert_equal("\"breakadd expr Xtest_var  ", @:)
4297  call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
4298  call assert_equal("\"breakadd expr X1B2C3", @:)
4299  unlet g:Xtest_var
4300
4301  " Test for :breakadd here
4302  call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4303  call assert_equal("\"breakadd here Xtest", @:)
4304  call feedkeys(":breakadd   here   Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4305  call assert_equal("\"breakadd   here   Xtest", @:)
4306  call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
4307  call assert_equal("\"breakadd here ", @:)
4308endfunc
4309
4310" Test for :breakdel argument completion
4311func Test_cmdline_complete_breakdel()
4312  call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
4313  call assert_equal("\"breakdel file func here", @:)
4314  call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
4315  call assert_equal("\"breakdel file", @:)
4316  call feedkeys(":breakdel    \<Tab>\<C-B>\"\<CR>", 'tx')
4317  call assert_equal("\"breakdel    file", @:)
4318  call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
4319  call assert_equal("\"breakdel here", @:)
4320  call feedkeys(":breakdel    he\<Tab>\<C-B>\"\<CR>", 'tx')
4321  call assert_equal("\"breakdel    here", @:)
4322  call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
4323  call assert_equal("\"breakdel abc", @:)
4324
4325  " Test for :breakdel file [lnum] <file>
4326  call writefile([], 'Xscript')
4327  call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4328  call assert_equal("\"breakdel file Xscript", @:)
4329  call feedkeys(":breakdel   file   Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4330  call assert_equal("\"breakdel   file   Xscript", @:)
4331  call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4332  call assert_equal("\"breakdel file 20 Xscript", @:)
4333  call feedkeys(":breakdel   file   20   Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4334  call assert_equal("\"breakdel   file   20   Xscript", @:)
4335  call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
4336  call assert_equal("\"breakdel file 20x Xsc\t", @:)
4337  call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
4338  call assert_equal("\"breakdel file 20\t", @:)
4339  call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
4340  call assert_equal("\"breakdel file 20x\t", @:)
4341  call feedkeys(":breakdel file Xscript  \<Tab>\<C-B>\"\<CR>", 'tx')
4342  call assert_equal("\"breakdel file Xscript  ", @:)
4343  call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
4344  call assert_equal("\"breakdel file X1B2C3", @:)
4345  call delete('Xscript')
4346
4347  " Test for :breakdel func [lnum] <function>
4348  func Xbreak_func()
4349  endfunc
4350  call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4351  call assert_equal("\"breakdel func Xbreak_func", @:)
4352  call feedkeys(":breakdel   func   Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4353  call assert_equal("\"breakdel   func   Xbreak_func", @:)
4354  call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4355  call assert_equal("\"breakdel func 20 Xbreak_func", @:)
4356  call feedkeys(":breakdel   func   20   Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4357  call assert_equal("\"breakdel   func   20   Xbreak_func", @:)
4358  call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
4359  call assert_equal("\"breakdel func 20x Xbr\t", @:)
4360  call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
4361  call assert_equal("\"breakdel func 20\t", @:)
4362  call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
4363  call assert_equal("\"breakdel func 20x\t", @:)
4364  call feedkeys(":breakdel func Xbreak_func  \<Tab>\<C-B>\"\<CR>", 'tx')
4365  call assert_equal("\"breakdel func Xbreak_func  ", @:)
4366  call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
4367  call assert_equal("\"breakdel func X1B2C3", @:)
4368  delfunc Xbreak_func
4369
4370  " Test for :breakdel here
4371  call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4372  call assert_equal("\"breakdel here Xtest", @:)
4373  call feedkeys(":breakdel   here   Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
4374  call assert_equal("\"breakdel   here   Xtest", @:)
4375  call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
4376  call assert_equal("\"breakdel here ", @:)
4377endfunc
4378
4379" Test for :scriptnames argument completion
4380func Test_cmdline_complete_scriptnames()
4381  set wildmenu
4382  call writefile(['let a = 1'], 'Xa1b2c3.vim')
4383  source Xa1b2c3.vim
4384  call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
4385  call assert_match("\"script .*Xa1b2c3.vim$", @:)
4386  call feedkeys(":script    \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
4387  call assert_match("\"script .*Xa1b2c3.vim$", @:)
4388  call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
4389  call assert_equal("\"script b2c3", @:)
4390  call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
4391  call assert_match("\"script 2\<Tab>$", @:)
4392  call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
4393  call assert_match("\"script .*Xa1b2c3.vim $", @:)
4394  call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
4395  call assert_equal("\"script ", @:)
4396  call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
4397  call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
4398  new
4399  call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
4400  call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
4401  bw!
4402  call delete('Xa1b2c3.vim')
4403  set wildmenu&
4404endfunc
4405
4406" this was going over the end of IObuff
4407func Test_report_error_with_composing()
4408  let caught = 'no'
4409  try
4410    exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
4411  catch /E492:/
4412    let caught = 'yes'
4413  endtry
4414  call assert_equal('yes', caught)
4415endfunc
4416
4417" Test for expanding 2-letter and 3-letter :substitute command arguments.
4418" These commands don't accept an argument.
4419func Test_cmdline_complete_substitute_short()
4420  for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
4421        \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
4422        \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
4423        \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
4424        \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
4425    call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
4426    call assert_equal('"' .. cmd .. " \<Tab>", @:)
4427  endfor
4428endfunc
4429
4430" Test for shellcmdline command argument completion
4431func Test_cmdline_complete_shellcmdline_argument()
4432  command -nargs=+ -complete=shellcmdline MyCmd
4433
4434  set wildoptions=fuzzy
4435
4436  call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4437  call assert_equal('"MyCmd vim test_cmdline.vim', @:)
4438  call assert_equal(['test_cmdline.vim'],
4439        \ getcompletion('vim test_cmdline.', 'shellcmdline'))
4440
4441  call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
4442  call assert_equal('"MyCmd vim nonexistentfile', @:)
4443  call assert_equal([],
4444        \ getcompletion('vim nonexistentfile', 'shellcmdline'))
4445
4446  let compl1 = getcompletion('', 'file')[0]
4447  let compl2 = getcompletion('', 'file')[1]
4448  call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
4449  call assert_equal('"MyCmd vim ' .. compl1, @:)
4450
4451  call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
4452  call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
4453
4454  let compl = getcompletion('', 'file')[1]
4455  call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
4456  call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
4457
4458  set wildoptions&
4459  call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4460  call assert_equal('"MyCmd vim test_cmdline.vim', @:)
4461  call assert_equal(['test_cmdline.vim'],
4462        \ getcompletion('vim test_cmdline.', 'shellcmdline'))
4463
4464  call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
4465  call assert_equal('"MyCmd vim nonexistentfile', @:)
4466  call assert_equal([],
4467        \ getcompletion('vim nonexistentfile', 'shellcmdline'))
4468
4469  let compl1 = getcompletion('', 'file')[0]
4470  let compl2 = getcompletion('', 'file')[1]
4471  call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
4472  call assert_equal('"MyCmd vim ' .. compl1, @:)
4473
4474  call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
4475  call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
4476
4477  let compl = getcompletion('', 'file')[1]
4478  call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
4479  call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
4480
4481  delcommand MyCmd
4482endfunc
4483
4484" Test for :! shell command argument completion
4485func Test_cmdline_complete_bang_cmd_argument()
4486  set wildoptions=fuzzy
4487  call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4488  call assert_equal('"!vim test_cmdline.vim', @:)
4489  set wildoptions&
4490  call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4491  call assert_equal('"!vim test_cmdline.vim', @:)
4492endfunc
4493
4494func Call_cmd_funcs()
4495  return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
4496endfunc
4497
4498func Test_screenpos_and_completion()
4499  call assert_equal(0, getcmdpos())
4500  call assert_equal(0, getcmdscreenpos())
4501  call assert_equal('', getcmdcompltype())
4502  call assert_equal('', getcmdcomplpat())
4503
4504  cnoremap <expr> <F2> string(Call_cmd_funcs())
4505  call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
4506  call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
4507  call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
4508  call assert_equal("\"quit [6, 7, '', '']", @:)
4509  call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
4510  call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
4511
4512  " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4513  " cmdline completion.
4514  let g:results = []
4515  cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4516  call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4517  call assert_equal([
4518        \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4519        \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4520        \ ['sign un', 8, 9, 'sign', 'un']], g:results)
4521
4522  unlet g:results
4523  cunmap <F2>
4524endfunc
4525
4526func Test_recursive_register()
4527  let @= = ''
4528  silent! ?e/
4529  let caught = 'no'
4530  try
4531    normal // 
4532  catch /E169:/
4533    let caught = 'yes'
4534  endtry
4535  call assert_equal('yes', caught)
4536endfunc
4537
4538func Test_long_error_message()
4539  " the error should be truncated, not overrun IObuff
4540  silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4541endfunc
4542
4543func Test_cmdline_redraw_tabline()
4544  CheckRunVimInTerminal
4545
4546  let lines =<< trim END
4547      set showtabline=2
4548      autocmd CmdlineEnter * set tabline=foo
4549  END
4550  call writefile(lines, 'Xcmdline_redraw_tabline')
4551  let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4552  call term_sendkeys(buf, ':')
4553  call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4554
4555  call StopVimInTerminal(buf)
4556  call delete('Xcmdline_redraw_tabline')
4557endfunc
4558
4559func Test_wildmenu_pum_disable_while_shown()
4560  set wildoptions=pum
4561  set wildmenu
4562  cnoremap <F2> <Cmd>set nowildmenu<CR>
4563  call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4564  call assert_equal(0, pumvisible())
4565  cunmap <F2>
4566  set wildoptions& wildmenu&
4567endfunc
4568
4569func Test_setcmdline()
4570  func SetText(text, pos)
4571    call assert_equal(0, setcmdline(v:_null_string))
4572    call assert_equal('', getcmdline())
4573    call assert_equal(1, getcmdpos())
4574
4575    call assert_equal(0, setcmdline(''[: -1]))
4576    call assert_equal('', getcmdline())
4577    call assert_equal(1, getcmdpos())
4578
4579    autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
4580    call assert_equal(0, setcmdline(a:text))
4581    call assert_equal(a:text, getcmdline())
4582    call assert_equal(len(a:text) + 1, getcmdpos())
4583    call assert_equal(getcmdtype(), g:cmdtype)
4584    unlet g:cmdtype
4585    autocmd! CmdlineChanged
4586
4587    call assert_equal(0, setcmdline(a:text, a:pos))
4588    call assert_equal(a:text, getcmdline())
4589    call assert_equal(a:pos, getcmdpos())
4590
4591    call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
4592    call assert_fails('call setcmdline({}, 0)', 'E1174:')
4593    call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
4594
4595    return ''
4596  endfunc
4597
4598  call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4599  call assert_equal('set rtp?', @:)
4600
4601  call feedkeys(":let g:str = input('? ')\<CR>", 't')
4602  call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4603  call assert_equal('foo', g:str)
4604  unlet g:str
4605
4606  delfunc SetText
4607
4608  " setcmdline() returns 1 when not editing the command line.
4609  call assert_equal(1, 'foo'->setcmdline())
4610
4611  " Called in custom function
4612  func CustomComplete(A, L, P)
4613    call assert_equal(0, setcmdline("DoCmd "))
4614    return "January\nFebruary\nMars\n"
4615  endfunc
4616
4617  com! -nargs=* -complete=custom,CustomComplete DoCmd :
4618  call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4619  call assert_equal('"DoCmd January February Mars', @:)
4620  delcom DoCmd
4621  delfunc CustomComplete
4622
4623  " Called in <expr>
4624  cnoremap <expr>a setcmdline('let foo=')
4625  call feedkeys(":a\<CR>", 'tx')
4626  call assert_equal('let foo=0', @:)
4627  cunmap a
4628
4629  " setcmdline() during wildmenu completion should not freeze.
4630  " Stripping completion state when cmdline was replaced externally.
4631  set wildmenu
4632  call mkdir('Xsetcmdlinedir', 'pR')
4633  call writefile([], 'Xsetcmdlinedir/Xfile1')
4634  call writefile([], 'Xsetcmdlinedir/Xfile2')
4635  func g:SetCmdLineEmpty()
4636    call setcmdline('', 1)
4637    return "\<Left>"
4638  endfunc
4639  cnoremap <expr> a g:SetCmdLineEmpty()
4640  call feedkeys(":e Xsetcmdlinedir/\<Tab>a\<C-B>\"\<CR>", 'tx')
4641  call assert_equal('"', @:)
4642  cunmap a
4643  delfunc g:SetCmdLineEmpty
4644  set nowildmenu
4645endfunc
4646
4647func Test_rulerformat_position()
4648  CheckScreendump
4649
4650  let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4651  call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4652  call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4653  call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4654  call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4655
4656  " clean up
4657  call StopVimInTerminal(buf)
4658endfunc
4659
4660" Test for using "%!" in 'rulerformat' to use a function
4661func Test_rulerformat_function()
4662  CheckScreendump
4663
4664  let lines =<< trim END
4665    func TestRulerFn()
4666      return '10,20%=30%%'
4667    endfunc
4668  END
4669  call writefile(lines, 'Xrulerformat_function', 'D')
4670
4671  let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4672  call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4673  call term_sendkeys(buf, ":redraw!\<CR>")
4674  call term_wait(buf)
4675  call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4676
4677  " clean up
4678  call StopVimInTerminal(buf)
4679endfunc
4680
4681func Test_getcompletion_usercmd()
4682  command! -nargs=* -complete=command TestCompletion echo <q-args>
4683
4684  call assert_equal(getcompletion('', 'cmdline'),
4685        \ getcompletion('TestCompletion ', 'cmdline'))
4686  call assert_equal(['<buffer>'],
4687        \ getcompletion('TestCompletion map <bu', 'cmdline'))
4688
4689  delcom TestCompletion
4690endfunc
4691
4692func Test_custom_completion()
4693  func CustomComplete1(lead, line, pos)
4694    return "a\nb\nc"
4695  endfunc
4696  func CustomComplete2(lead, line, pos)
4697    return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4698  endfunc
4699  func Check_custom_completion()
4700    call assert_equal('custom,CustomComplete1', getcmdcompltype())
4701    return ''
4702  endfunc
4703  func Check_customlist_completion()
4704    call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4705    return ''
4706  endfunc
4707
4708  command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4709  command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4710
4711  call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4712  call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4713  call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 '))
4714  call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 '))
4715
4716  call assert_fails("call getcompletion('', 'custom')", 'E475:')
4717  call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4718
4719  call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4720  call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4721  call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
4722
4723  delcom Test1
4724  delcom Test2
4725
4726  delfunc CustomComplete1
4727  delfunc CustomComplete2
4728  delfunc Check_custom_completion
4729  delfunc Check_customlist_completion
4730endfunc
4731
4732" Test that 'customlist' completion accepts dict items with extra info
4733" (kind/menu/info) for display in the popup menu, and that string items still
4734" work in the same list.
4735func Test_customlist_dict_completion()
4736  func DictComp(A, L, P)
4737    return [
4738          \ {'word': 'apple',  'kind': 'f', 'menu': 'fruit',     'info': 'A red fruit'},
4739          \ {'word': 'banana', 'kind': 'f', 'menu': 'fruit',     'info': 'A yellow fruit'},
4740          \ {'word': 'carrot', 'kind': 'v', 'menu': 'vegetable', 'info': 'An orange vegetable'},
4741          \ 'plain',
4742          \ ]
4743  endfunc
4744  command -nargs=1 -complete=customlist,DictComp DictCmd echo <q-args>
4745
4746  " getcompletion() returns only the "word" of each item; string items pass
4747  " through unchanged.
4748  call assert_equal(['apple', 'banana', 'carrot', 'plain'],
4749        \ getcompletion('', 'customlist,DictComp'))
4750
4751  " Items missing a "word" key are silently skipped.
4752  func DictCompMissingWord(A, L, P)
4753    return [{'kind': 'x'}, {'word': 'ok'}]
4754  endfunc
4755  call assert_equal(['ok'],
4756        \ getcompletion('', 'customlist,DictCompMissingWord'))
4757
4758  " Tab completion still selects the word.
4759  call feedkeys(":DictCmd a\<Tab>\<C-B>\"\<CR>", 'xt')
4760  call assert_equal('"DictCmd apple', @:)
4761
4762  " "abbr" overrides display only; "word" is what gets inserted.
4763  func DictCompAbbr(A, L, P)
4764    return [{'word': 'apple', 'abbr': 'APPLE🍎'}]
4765  endfunc
4766  call assert_equal(['apple'],
4767        \ getcompletion('', 'customlist,DictCompAbbr'))
4768  command -nargs=1 -complete=customlist,DictCompAbbr DictAbbrCmd echo <q-args>
4769  call feedkeys(":DictAbbrCmd \<Tab>\<C-B>\"\<CR>", 'xt')
4770  call assert_equal('"DictAbbrCmd apple', @:)
4771
4772  delcommand DictAbbrCmd
4773  delcommand DictCmd
4774  delfunc DictComp
4775  delfunc DictCompMissingWord
4776  delfunc DictCompAbbr
4777endfunc
4778
4779func Test_customlist_dict_completion_info_popup()
4780  CheckScreendump
4781
4782  let lines =<< trim END
4783    func DictComp(A, L, P)
4784      return [
4785            \ {'word': 'apple',  'kind': 'f', 'menu': 'fruit',     'info': 'A red fruit',    'abbr': '🍎'},
4786            \ {'word': 'banana', 'kind': 'f', 'menu': 'fruit',     'info': 'A yellow fruit', 'abbr': '🍌'},
4787            \ {'word': 'carrot', 'kind': 'v', 'menu': 'vegetable', 'info': 'An orange vegetable'},
4788            \ 'plain',
4789            \ ]
4790    endfunc
4791    command -nargs=1 -complete=customlist,DictComp DictCmd echo <q-args>
4792    set wildmenu wildoptions=pum completeopt=menu,popup
4793  END
4794  call writefile(lines, 'XTest_customlist_info_popup', 'D')
4795  let rows = 12
4796  let buf = RunVimInTerminal('-S XTest_customlist_info_popup', {'rows': rows})
4797
4798  call term_sendkeys(buf, ":DictCmd \<Tab>")
4799  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':DictCmd apple') + 1)], g:test_timeout, ((rows - 4), 'A red fruit'))
4800  call VerifyScreenDump(buf, 'Test_customlist_info_popup_01', {})
4801
4802  call term_sendkeys(buf, "\<Tab>")
4803  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':DictCmd banana') + 1)], g:test_timeout, ((rows - 3), 'A yellow fruit'))
4804  call VerifyScreenDump(buf, 'Test_customlist_info_popup_02', {})
4805
4806  call term_sendkeys(buf, "\<Tab>")
4807  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':DictCmd carrot') + 1)], g:test_timeout, ((rows - 2), 'An orange vegetable'))
4808  call VerifyScreenDump(buf, 'Test_customlist_info_popup_03', {})
4809
4810  call term_sendkeys(buf, "\<Tab>")
4811  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':DictCmd plain') + 1)], g:test_timeout, ((rows - 1), '^\~\s\+plain\s\+$'))
4812  call VerifyScreenDump(buf, 'Test_customlist_info_popup_04', {})
4813
4814  call term_sendkeys(buf, "\<Tab>")
4815  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':DictCmd ') + 1)], g:test_timeout)
4816  call VerifyScreenDump(buf, 'Test_customlist_info_popup_05', {})
4817
4818  call term_sendkeys(buf, "\<Esc>")
4819
4820  " Tests for Insert mode i_CTRL-X_CTRL-V
4821  call term_sendkeys(buf, "iDictCmd \<C-X>\<C-V>")
4822  call VerifyScreenDump(buf, 'Test_customlist_info_popup_06', {})
4823
4824  call term_sendkeys(buf, "\<C-N>")
4825  call VerifyScreenDump(buf, 'Test_customlist_info_popup_07', {})
4826
4827  call term_sendkeys(buf, "\<C-N>")
4828  call VerifyScreenDump(buf, 'Test_customlist_info_popup_08', {})
4829
4830  call term_sendkeys(buf, "\<C-N>")
4831  call VerifyScreenDump(buf, 'Test_customlist_info_popup_09', {})
4832
4833  call term_sendkeys(buf, "\<C-N>")
4834  call VerifyScreenDump(buf, 'Test_customlist_info_popup_10', {})
4835
4836  " Starting another i_CTRL-X_CTRL-V completion should not leak memory
4837  call term_sendkeys(buf, "\<C-U>sign un\<C-X>\<C-V>")
4838  call VerifyScreenDump(buf, 'Test_customlist_info_popup_11', {})
4839
4840  call StopVimInTerminal(buf)
4841endfunc
4842
4843" Test that the mouse scroll wheel scrolls the info popup of the command line
4844" completion popup menu when the mouse pointer is on top of it.
4845func Test_wildmenu_pum_info_mouse_scroll()
4846  CheckScreendump
4847  CheckFeature quickfix
4848
4849  let lines =<< trim END
4850    func DictComp(A, L, P)
4851      let info = join(map(range(1, 30), '"info line " .. v:val'), "\n")
4852      return [
4853            \ {'word': 'apple',  'kind': 'f', 'menu': 'fruit', 'info': info},
4854            \ {'word': 'banana', 'kind': 'f', 'menu': 'fruit', 'info': info},
4855            \ ]
4856    endfunc
4857    command -nargs=1 -complete=customlist,DictComp DictCmd echo <q-args>
4858    set wildmenu wildoptions=pum completeopt=menu,popup mouse=a
4859
4860    " Put the mouse on top of the info popup and turn the scroll wheel.
4861    func ScrollInfo(keys)
4862      let pos = popup_getpos(popup_findinfo())
4863      call test_setmouse(pos.line + 1, pos.col + 1)
4864      call feedkeys(a:keys, 'nt')
4865    endfunc
4866    cnoremap <F6> <Cmd>call ScrollInfo(repeat("\<ScrollWheelDown>", 3))<CR>
4867    cnoremap <F7> <Cmd>call ScrollInfo(repeat("\<ScrollWheelUp>", 2))<CR>
4868  END
4869  call writefile(lines, 'XtestWildmenuMouseScroll', 'D')
4870  let buf = RunVimInTerminal('-S XtestWildmenuMouseScroll', #{rows: 12})
4871
4872  " The info popup is shown next to the completion popup menu.
4873  call term_sendkeys(buf, ":DictCmd \<Tab>")
4874  call VerifyScreenDump(buf, 'Test_wildmenu_pum_info_mouse_scroll_1', {})
4875
4876  " Scrolling down with the wheel scrolls the info popup without closing the
4877  " completion popup menu.
4878  call term_sendkeys(buf, "\<F6>")
4879  call VerifyScreenDump(buf, 'Test_wildmenu_pum_info_mouse_scroll_2', {})
4880
4881  " Scrolling back up scrolls the info popup up again.
4882  call term_sendkeys(buf, "\<F7>")
4883  call VerifyScreenDump(buf, 'Test_wildmenu_pum_info_mouse_scroll_3', {})
4884
4885  call term_sendkeys(buf, "\<Esc>")
4886  call StopVimInTerminal(buf)
4887endfunc
4888
4889func Test_cmdline_complete_findfunc_dict()
4890  CheckScreendump
4891
4892  let lines =<< trim END
4893    set wildmenu wildoptions=pum completeopt=menu,popup
4894    func FindComplete(cmdarg, cmdcomplete)
4895      return [
4896            \ 'Xplain',
4897            \ {'word': 'Xfile1', 'kind': 'F', 'menu': 'file', 'info': '1st file'},
4898            \ {'word': 'Xfile2', 'kind': 'F', 'menu': 'file', 'info': '2nd file'},
4899            \ {'word': 'Xdir1',  'kind': 'D', 'menu': 'dir',  'info': '1st dir'},
4900            \ {'word': 'Xdir2',  'kind': 'D', 'menu': 'dir',  'info': '2nd dir'},
4901            \ ]
4902    endfunc
4903    set findfunc=FindComplete
4904  END
4905  call writefile(lines, 'XTest_compl_findfunc_dict', 'D')
4906  let rows = 12
4907  let buf = RunVimInTerminal('-S XTest_compl_findfunc_dict', {'rows': rows})
4908
4909  call term_sendkeys(buf, ":find \<Tab>")
4910  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':find Xplain') + 1)], g:test_timeout, ((rows - 5), '^\~\s\+Xplain\s\+$'))
4911  call VerifyScreenDump(buf, 'Test_compl_findfunc_dict_01', {})
4912
4913  call term_sendkeys(buf, "\<PageDown>")
4914  call WaitForTermCurPosAndLinesToMatch(buf, [rows, (strlen(':find Xdir1') + 1)], g:test_timeout, ((rows - 2), '1st dir'))
4915  call VerifyScreenDump(buf, 'Test_compl_findfunc_dict_02', {})
4916
4917  call term_sendkeys(buf, "\<Esc>")
4918  call StopVimInTerminal(buf)
4919endfunc
4920
4921func Test_custom_completion_with_glob()
4922  func TestGlobComplete(A, L, P)
4923    return split(glob('Xglob*'), "\n")
4924  endfunc
4925
4926  command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4927  call writefile([], 'Xglob1', 'D')
4928  call writefile([], 'Xglob2', 'D')
4929
4930  call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4931  call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4932
4933  delcommand TestGlobComplete
4934  delfunc TestGlobComplete
4935endfunc
4936
4937func Test_window_size_stays_same_after_changing_cmdheight()
4938  set laststatus=2
4939  let expected = winheight(0)
4940  function! Function_name() abort
4941    call feedkeys(":"..repeat('x', &columns), 'x')
4942    let &cmdheight=2
4943    let &cmdheight=1
4944    redraw
4945  endfunction
4946  call Function_name()
4947  call assert_equal(expected, winheight(0))
4948endfunc
4949
4950" verify that buffer-completion finds all buffer names matching a pattern
4951func Test_buffer_completion()
4952  " should return empty list
4953  call assert_equal([], getcompletion('', 'buffer'))
4954
4955  call mkdir('Xbuf_complete', 'R')
4956  e Xbuf_complete/Foobar.c
4957  e Xbuf_complete/MyFoobar.c
4958  e AFoobar.h
4959  let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4960
4961  call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4962  call assert_equal(expected, getcompletion('Foo', 'buffer'))
4963  call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4964  call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4965endfunc
4966
4967" :set t_??
4968func Test_term_option()
4969  throw 'Skipped: Nvim does not support termcap options'
4970  set wildoptions&
4971  let _cpo = &cpo
4972  set cpo-=C
4973  " There may be more, test only until t_xo
4974  let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm'
4975        \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe'
4976        \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC'
4977        \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr'
4978        \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi'
4979        \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*'
4980  call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
4981  call assert_match(expected, @:)
4982  let &cpo = _cpo
4983endfunc
4984
4985func Test_ex_command_completion()
4986  " required for :*
4987  " set cpo+=*
4988  let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4989  " :++ and :-- are only valid in Vim9 script context, so they can be ignored
4990  " call assert_equal(['++', '--'], sort(list))
4991  call assert_equal([], sort(list))
4992  call assert_equal(2, exists(':k'))
4993  call assert_equal(0, exists(':ke'))
4994  call assert_equal(1, exists(':kee'))
4995  call assert_equal(1, exists(':keep'))
4996  call assert_equal(1, exists(':keepm'))
4997  call assert_equal(1, exists(':keepma'))
4998  call assert_equal(1, exists(':keepmar'))
4999  call assert_equal(1, exists(':keepmark'))
5000  call assert_equal(2, exists(':keepmarks'))
5001  call assert_equal(2, exists(':keepalt'))
5002  call assert_equal(2, exists(':keepjumps'))
5003  call assert_equal(2, exists(':keeppatterns'))
5004  set cpo-=*
5005endfunc
5006
5007func Test_cd_bslash_completion_windows()
5008  CheckMSWindows
5009  let save_shellslash = &shellslash
5010  set noshellslash
5011  call system('mkdir XXXa\_b')
5012  defer delete('XXXa', 'rf')
5013  call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
5014  call assert_equal('"cd XXXa\_b\', @:)
5015  let &shellslash = save_shellslash
5016endfunc
5017
5018" Test cmdcomplete_info() with CmdlineLeavePre autocmd
5019func Test_cmdcomplete_info()
5020  augroup test_CmdlineLeavePre
5021    autocmd!
5022    " Calling expand() should not interfere with cmdcomplete_info().
5023    autocmd CmdlineLeavePre * call expand('test_cmdline.*')
5024    autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
5025  augroup END
5026
5027  " Disable char_avail so that wildtrigger() does not bail out
5028  call Ntest_override("char_avail", 1)
5029
5030  cnoremap <F8> <C-R>=wildtrigger()[-1]<CR>
5031
5032  call assert_equal({}, cmdcomplete_info())
5033
5034  for trig in ["\<Tab>", "\<F8>"]
5035    new
5036    call assert_equal({}, cmdcomplete_info())
5037    call feedkeys(":h echom\<cr>", "tx") " No expansion
5038    call assert_equal('{}', g:cmdcomplete_info)
5039    call feedkeys($":h echoms{trig}\<cr>", "tx")
5040    call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
5041    call feedkeys($":h echom{trig}\<cr>", "tx")
5042    call assert_equal(
5043          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
5044          \ g:cmdcomplete_info)
5045    call feedkeys($":h echom{trig}\<tab>\<cr>", "tx")
5046    call assert_equal(
5047          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
5048          \ g:cmdcomplete_info)
5049    call feedkeys($":h echom{trig}\<tab>\<tab>\<cr>", "tx")
5050    call assert_equal(
5051          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
5052          \ g:cmdcomplete_info)
5053
5054    set wildoptions=pum
5055    call feedkeys($":h echoms{trig}\<cr>", "tx")
5056    call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
5057    call feedkeys($":h echom{trig}\<cr>", "tx")
5058    call assert_equal(
5059          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
5060          \ g:cmdcomplete_info)
5061    call feedkeys($":h echom{trig}\<tab>\<cr>", "tx")
5062    call assert_equal(
5063          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
5064          \ g:cmdcomplete_info)
5065    call feedkeys($":h echom{trig}\<tab>\<tab>\<cr>", "tx")
5066    call assert_equal(
5067          \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
5068          \ g:cmdcomplete_info)
5069    bw!
5070    " set wildoptions&
5071    set wildoptions=  " Accommodate Nvim default
5072  endfor
5073
5074  " wildtrigger() should not show matches when prefix is invalid
5075  for pat in ["", " ", "22"]
5076    call feedkeys($":{pat}\<F8>\<cr>", "tx") " No expansion
5077    call assert_equal('{}', g:cmdcomplete_info)
5078  endfor
5079
5080  augroup test_CmdlineLeavePre | autocmd! | augroup END
5081  call Ntest_override("char_avail", 0)
5082  unlet g:cmdcomplete_info
5083  cunmap <F8>
5084endfunc
5085
5086" Test wildcharm completion for '/' and '?' search
5087func Test_search_complete()
5088  CheckOption incsearch
5089  set wildcharm=<c-z>
5090
5091  " Disable char_avail so that expansion of commandline works
5092  call Ntest_override("char_avail", 1)
5093
5094  func GetComplInfo()
5095    let g:compl_info = cmdcomplete_info()
5096    return ''
5097  endfunc
5098
5099  new
5100  cnoremap <buffer><expr> <F9> GetComplInfo()
5101  cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR>
5102
5103  " Pressing <Tab> inserts tab character
5104  set wildchar=0
5105  call setline(1, "x\t")
5106  call feedkeys("/x\t\r", "tx")
5107  call assert_equal("x\t", @/)
5108  set wildchar&
5109
5110  call setline(1, ['the', 'these', 'thethe', 'thethere', 'foobar'])
5111
5112  for trig in ["\<tab>", "\<c-z>", "\<F8>"]
5113    " Test menu first item and order
5114    call feedkeys($"gg2j/t{trig}\<f9>", 'tx')
5115    call assert_equal(['the', 'thethere', 'there', 'these', 'thethe'], g:compl_info.matches)
5116    call feedkeys($"gg2j?t{trig}\<f9>", 'tx')
5117    call assert_equal(['these', 'the', 'there', 'thethere', 'thethe'], g:compl_info.matches)
5118
5119    " <c-n> and <c-p> cycle through menu items
5120    call feedkeys($"gg/the{trig}\<cr>", 'tx')
5121    call assert_equal('these', getline('.'))
5122    call feedkeys($"gg/the{trig}\<c-n>\<cr>", 'tx')
5123    call assert_equal('thethe', getline('.'))
5124    call feedkeys($"gg/the{trig}".repeat("\<c-n>", 5)."\<cr>", 'tx')
5125    call assert_equal('these', getline('.'))
5126    call feedkeys($"G?the{trig}\<cr>", 'tx')
5127    call assert_equal('thethere', getline('.'))
5128    call feedkeys($"G?the{trig}".repeat("\<c-p>", 5)."\<cr>", 'tx')
5129    call assert_equal('thethere', getline('.'))
5130
5131    " Beginning of word pattern (<) retains '<'
5132    call feedkeys($"gg2j/\\<t{trig}\<f9>", 'tx')
5133    call assert_equal(['\<thethere', '\<the', '\<these', '\<thethe'], g:compl_info.matches)
5134    call feedkeys($"gg2j?\\<t{trig}\<f9>", 'tx')
5135    call assert_equal(['\<these', '\<the', '\<thethere', '\<thethe'], g:compl_info.matches)
5136    call feedkeys($"gg2j/\\v<t{trig}\<f9>", 'tx')
5137    call assert_equal(['\v<thethere', '\v<the', '\v<these', '\v<thethe'], g:compl_info.matches)
5138    call feedkeys($"gg2j?\\v<th{trig}\<f9>", 'tx')
5139    call assert_equal(['\v<these', '\v<the', '\v<thethere', '\v<thethe'], g:compl_info.matches)
5140  endfor
5141
5142  " Ctrl-G goes from one match to the next, after menu is opened
5143  set incsearch
5144  " first match
5145  call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<cr>", 'tx')
5146  call assert_equal('thethe', getline('.'))
5147  " second match
5148  call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<c-g>\<cr>", 'tx')
5149  call assert_equal('thethere', getline('.'))
5150  call assert_equal([0, 0, 0, 0], getpos('"'))
5151
5152  " CTRL-T goes to the previous match
5153  " first match
5154  call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2)."\<c-t>\<cr>", 'tx')
5155  call assert_equal('thethere', getline('.'))
5156  " second match
5157  call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2).repeat("\<c-t>", 2)."\<cr>", 'tx')
5158  call assert_equal('thethe', getline('.'))
5159
5160  " wild menu is cleared properly
5161  call feedkeys("/the\<c-z>\<esc>/\<f9>", 'tx')
5162  call assert_equal({}, g:compl_info)
5163  call feedkeys("/the\<c-z>\<c-e>\<f9>", 'tx')
5164  call assert_equal([], g:compl_info.matches)
5165
5166  " Do not expand if offset is present (/pattern/offset and ?pattern?offset)
5167  for pat in ["/", "/2", "/-3", "\\/"]
5168    call feedkeys("/the" . pat . "\<c-z>\<f9>", 'tx')
5169    call assert_equal({}, g:compl_info)
5170  endfor
5171  for pat in ["?", "?2", "?-3", "\\\\?"]
5172    call feedkeys("?the" . pat . "\<c-z>\<f9>", 'tx')
5173    call assert_equal({}, g:compl_info)
5174  endfor
5175
5176  " Last letter of match is multibyte
5177  call setline('$', ['theΩ'])
5178  call feedkeys("gg/th\<c-z>\<f9>", 'tx')
5179  call assert_equal(['these', 'thethe', 'the', 'thethere', 'there', 'theΩ'],
5180        \ g:compl_info.matches)
5181
5182  " Identical words
5183  call setline(1, ["foo", "foo", "foo", "foobar"])
5184  call feedkeys("gg/f\<c-z>\<f9>", 'tx')
5185  call assert_equal(['foo', 'foobar'], g:compl_info.matches)
5186
5187  " Exact match
5188  call feedkeys("/foo\<c-z>\<f9>", 'tx')
5189  call assert_equal(['foo', 'foobar'], g:compl_info.matches)
5190
5191  " Match case correctly
5192  %d
5193  call setline(1, ["foobar", "Foobar", "fooBAr", "FooBARR"])
5194
5195  call feedkeys("gg/f\<tab>\<f9>", 'tx')
5196  call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches)
5197  call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
5198  call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
5199  call feedkeys("gg/FO\<tab>\<f9>", 'tx')
5200  call assert_equal({}, g:compl_info)
5201  call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
5202  call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
5203
5204  set ignorecase
5205  call feedkeys("gg/f\<tab>\<f9>", 'tx')
5206  call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches)
5207  call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
5208  call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches)
5209  call feedkeys("gg/FO\<tab>\<f9>", 'tx')
5210  call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches)
5211  call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
5212  call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
5213
5214  set smartcase
5215  call feedkeys("gg/f\<tab>\<f9>", 'tx')
5216  call assert_equal(['foobar', 'fooBAr', 'foobarr'], g:compl_info.matches)
5217  call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
5218  call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
5219  call feedkeys("gg/FO\<tab>\<f9>", 'tx')
5220  call assert_equal({}, g:compl_info)
5221
5222  " Issue #17680 (getcompletion() does not support search completion)
5223  let result = getcompletion('%s/', 'cmdline')
5224  call assert_equal([], result)
5225
5226  call feedkeys("gg/foob\<tab>\<f9>", 'tx')
5227  call assert_equal(['foobar', 'foobarr'], g:compl_info.matches)
5228  call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
5229  call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
5230  call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
5231  call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
5232
5233  set wildoptions+=exacttext ignorecase& smartcase&
5234  call feedkeys("gg/F\<tab>\<f9>", 'tx')
5235  call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
5236  call feedkeys("gg/foob\<tab>\<f9>", 'tx')
5237  call assert_equal([], g:compl_info.matches)
5238  call feedkeys("gg/r\\n.\<tab>\<f9>", 'tx')
5239  call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches)
5240
5241  set ignorecase
5242  call feedkeys("gg/F\<tab>\<f9>", 'tx')
5243  call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
5244  call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx')
5245  call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches)
5246
5247  set smartcase
5248  call feedkeys("gg/f\<tab>\<f9>", 'tx')
5249  call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
5250  call feedkeys("gg/foob\<tab>\<f9>", 'tx')
5251  call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
5252  call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx')
5253  call assert_equal({}, g:compl_info)
5254  call feedkeys("gg/r\\n.*\\n\<tab>\<f9>", 'tx')
5255  call assert_equal(['r\nFoobar\nfooBAr', 'r\nfooBAr\nFooBARR'], g:compl_info.matches)
5256
5257  " Issue #17858
5258  %d
5259  set wildcharm=0 incsearch& ignorecase& smartcase& wildoptions&
5260  setlocal iskeyword=!-~,192-255
5261  let l:lines = ['th=~/foo', 'these', 'tho']
5262  call setline(1, l:lines)
5263  call feedkeys("G/th\<tab>\<f9>", 'tx')
5264  call assert_equal(l:lines, g:compl_info.matches)
5265
5266  bw!
5267  call Ntest_override("char_avail", 0)
5268  delfunc GetComplInfo
5269  unlet! g:compl_info
5270endfunc
5271
5272func Test_search_wildmenu_screendump()
5273  CheckScreendump
5274
5275  let lines =<< trim [SCRIPT]
5276    call test_override('alloc_lines', 1)
5277    set wildmenu wildcharm=<f5>
5278    call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
5279  [SCRIPT]
5280  call writefile(lines, 'XTest_search_wildmenu', 'D')
5281  let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10})
5282
5283  " Pattern has newline at EOF
5284  call term_sendkeys(buf, "gg2j/e\\n\<f5>")
5285  call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {})
5286
5287  " longest:full
5288  call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>")
5289  call term_sendkeys(buf, "gg/t\<f5>")
5290  call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {})
5291
5292  " list:full
5293  call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>")
5294  call term_sendkeys(buf, "gg/t\<f5>")
5295  call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {})
5296
5297  " noselect:full
5298  call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>")
5299  call term_sendkeys(buf, "gg/t\<f5>")
5300  call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {})
5301
5302  " Multiline
5303  call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>")
5304  call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {})
5305
5306  " 'incsearch' is redrawn after accepting completion
5307  call term_sendkeys(buf, "\<esc>:set wim=full\<cr>")
5308  call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
5309  call term_sendkeys(buf, "/th")
5310  call VerifyScreenDump(buf, 'Test_search_wildmenu_6', {})
5311  call term_sendkeys(buf, "\<f5>")
5312  call VerifyScreenDump(buf, 'Test_search_wildmenu_7', {})
5313  call term_sendkeys(buf, "\<c-n>\<c-y>")
5314  call VerifyScreenDump(buf, 'Test_search_wildmenu_8', {})
5315
5316  " 'incsearch' highlight is restored after dismissing popup (Ctrl_E)
5317  call term_sendkeys(buf, "\<esc>:set wop=pum is hls&\<cr>")
5318  call term_sendkeys(buf, "gg/th\<tab>\<c-e>")
5319  call TermWait(buf, 50)
5320  call VerifyScreenDump(buf, 'Test_search_wildmenu_9', {})
5321
5322  call term_sendkeys(buf, "\<esc>")
5323  call StopVimInTerminal(buf)
5324endfunc
5325
5326" Issue #17858
5327func Test_search_wildmenu_iminsert()
5328  CheckScreendump
5329
5330  let lines =<< trim [SCRIPT]
5331    set wop=pum imi=1
5332    setlocal iskeyword=!-~,192-255
5333    call setline(1, [
5334          \ "global toggle global-local global/local glyphs toggles English",
5335          \ "accordingly. toggled accordingly single-byte",
5336          \ ])
5337    call cursor(2, 42)
5338  [SCRIPT]
5339  call writefile(lines, 'XTest_search_wildmenu', 'D')
5340  let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 12})
5341
5342  call term_sendkeys(buf, "/gl\<Tab>")
5343  call TermWait(buf, 50)
5344  call VerifyScreenDump(buf, 'Test_search_wildmenu_iminsert', {})
5345
5346  call term_sendkeys(buf, "\<esc>")
5347  call StopVimInTerminal(buf)
5348endfunc
5349
5350" Test wildcharm completion for :s and :g with range
5351func Test_range_complete()
5352  set wildcharm=<c-z>
5353
5354  " Disable char_avail so that expansion of commandline works
5355  call Ntest_override("char_avail", 1)
5356
5357  func GetComplInfo()
5358    let g:compl_info = cmdcomplete_info()
5359    return ''
5360  endfunc
5361  new
5362  cnoremap <buffer><expr> <F9> GetComplInfo()
5363  cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR>
5364
5365  call setline(1, ['ab', 'ba', 'ca', 'af'])
5366
5367  for trig in ["\<tab>", "\<c-z>", "\<F8>"]
5368    call feedkeys($":%s/a{trig}\<f9>", 'xt')
5369    call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
5370    " call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt')
5371    call feedkeys($":verbose :%s/a{trig}\<f9>", 'xt')
5372    call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
5373  endfor
5374
5375  call feedkeys(":%s/\<c-z>\<f9>", 'xt')
5376  call assert_equal({}, g:compl_info)
5377
5378  for cmd in ['s', 'g']
5379    call feedkeys($":1,2{cmd}/a\<c-z>\<f9>", 'xt')
5380    call assert_equal(['ab', 'a'], g:compl_info.matches)
5381  endfor
5382
5383  1
5384  call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt')
5385  call assert_equal(['ab', 'a'], g:compl_info.matches)
5386
5387  /f
5388  call feedkeys(":1,s/b\<c-z>\<f9>", 'xt')
5389  call assert_equal(['b', 'ba'], g:compl_info.matches)
5390
5391  /c
5392  call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt')
5393  call assert_equal(['a', 'af'], g:compl_info.matches)
5394
5395  %s/c/c/
5396  call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt')
5397  call assert_equal(['ab', 'a'], g:compl_info.matches)
5398
5399  3
5400  normal! ma
5401  call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt')
5402  call assert_equal(['a', 'af'], g:compl_info.matches)
5403
5404  " Line number followed by a search pattern ([start]/pattern/[command])
5405  call feedkeys("3/a\<c-z>\<f9>", 'xt')
5406  call assert_equal(['a', 'af', 'ab'], g:compl_info.matches)
5407
5408  bw!
5409  call Ntest_override("char_avail", 0)
5410  delfunc GetComplInfo
5411  unlet! g:compl_info
5412  set wildcharm=0
5413endfunc
5414
5415" With 'noselect' in 'wildmode', ensure that the popup menu (pum) does not retain
5416" its scroll position after reopening. The menu should open showing the top items,
5417" regardless of previous scrolling.
5418func Test_pum_scroll_noselect()
5419  CheckScreendump
5420
5421  let lines =<< trim [SCRIPT]
5422    command! -nargs=* -complete=customlist,TestFn TestCmd echo
5423    func TestFn(a, b, c)
5424      return map(range(1, 50), 'printf("a%d", v:val)')
5425    endfunc
5426    set wildmode=noselect,full
5427    set wildoptions=pum
5428    set wildmenu
5429    set noruler
5430  [SCRIPT]
5431  call writefile(lines, 'XTest_pum_scroll', 'D')
5432  let buf = RunVimInTerminal('-S XTest_pum_scroll', {'rows': 10})
5433
5434  call term_sendkeys(buf, ":TestCmd \<tab>" . repeat("\<c-n>", 20))
5435  call TermWait(buf, 50)
5436  call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_1', {})
5437
5438  call term_sendkeys(buf, "\<esc>:TestCmd \<tab>")
5439  call TermWait(buf, 50)
5440  call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_2', {})
5441
5442  call term_sendkeys(buf, "\<esc>")
5443  call StopVimInTerminal(buf)
5444endfunc
5445
5446" CmdlineChanged shouldn't trigger if command-line text is unchanged
5447func Test_cmdline_changed()
5448  let g:cmdchg_count = 0
5449  let g:cmdprefix = ''
5450  augroup test_CmdlineAugrp | autocmd!
5451    autocmd CmdlineChanged * if getcmdline() =~ g:cmdprefix | let g:cmdchg_count += 1 | endif
5452  augroup END
5453
5454  " Disable char_avail so that wildtrigger() does not bail out
5455  call Ntest_override("char_avail", 1)
5456
5457  new
5458  cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR>
5459  set wildmenu
5460  set wildmode=full
5461
5462  let g:cmdprefix = 'echomsg'
5463  for trig in ["\<Tab>", "\<F8>"]
5464    let g:cmdchg_count = 0
5465    call feedkeys($":echomsg{trig}", "tx")
5466    call assert_equal(1, g:cmdchg_count) " once only for 'g', not again for <Tab>
5467  endfor
5468
5469  let g:cmdprefix = 'echo'
5470  for trig in ["\<Tab>", "\<F8>"]
5471    let g:cmdchg_count = 0
5472    call feedkeys($":ech{trig}", "tx")
5473    call assert_equal(1, g:cmdchg_count) " (once for 'h' and) once for 'o'
5474  endfor
5475
5476  set wildmode=noselect,full
5477  let g:cmdprefix = 'ech'
5478  for trig in ["\<Tab>", "\<F8>"]
5479    let g:cmdchg_count = 0
5480    call feedkeys($":ech{trig}", "tx")
5481    call assert_equal(1, g:cmdchg_count) " once for 'h', not again for <tab>
5482  endfor
5483
5484  command! -nargs=+ -complete=custom,TestComplete Test echo
5485
5486  func TestComplete(arglead, cmdline, cursorpos)
5487    return "AbC"
5488  endfunc
5489
5490  set wildoptions=fuzzy wildmode=full
5491  let g:cmdprefix = 'Test \(AbC\|abc\)'
5492  for trig in ["\<Tab>", "\<F8>"]
5493    let g:cmdchg_count = 0
5494    call feedkeys($":Test abc{trig}", "tx")
5495    call assert_equal(2, g:cmdchg_count) " once for 'c', again for 'AbC'
5496  endfor
5497
5498  bw!
5499  set wildmode& wildmenu& wildoptions&
5500  augroup test_CmdlineAugrp | autocmd! | augroup END
5501  unlet g:cmdchg_count
5502  unlet g:cmdprefix
5503  delfunc TestComplete
5504  delcommand Test
5505  call Ntest_override("char_avail", 0)
5506endfunc
5507
5508func Test_wildtrigger_update_screen()
5509  CheckScreendump
5510
5511  let lines =<< trim [SCRIPT]
5512    command! -nargs=* -complete=customlist,TestFn TestCmd echo
5513    func TestFn(cmdarg, b, c)
5514      if a:cmdarg == 'ax'
5515        return []
5516      else
5517        return map(range(1, 5), 'printf("abc%d", v:val)')
5518      endif
5519    endfunc
5520    set wildmode=noselect,full
5521    set wildoptions=pum
5522    set wildmenu
5523    cnoremap <F8> <C-R>=wildtrigger()[-1]<CR>
5524  [SCRIPT]
5525  call writefile(lines, 'XTest_wildtrigger', 'D')
5526  let buf = RunVimInTerminal('-S XTest_wildtrigger', {'rows': 10})
5527
5528  call term_sendkeys(buf, ":TestCmd a\<F8>")
5529  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_1', {})
5530
5531  " Typing a character when pum is open does not close the pum window
5532  " This is needed to prevent pum window from flickering during
5533  " ':h cmdline-autocompletion'.
5534  call term_sendkeys(buf, "x")
5535  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_2', {})
5536
5537  " pum is closed when no completion candidates are available
5538  call term_sendkeys(buf, "\<F8>")
5539  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_3', {})
5540
5541  call term_sendkeys(buf, "\<BS>\<F8>")
5542  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_1', {})
5543
5544  call term_sendkeys(buf, "x")
5545  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_2', {})
5546
5547  " pum is closed when leaving cmdline mode
5548  call term_sendkeys(buf, "\<Esc>")
5549  call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_4', {})
5550
5551  call StopVimInTerminal(buf)
5552endfunc
5553
5554" Issue #18035: long lines should not get listed twice in the menu when
5555" 'wildmode' contains 'noselect'
5556func Test_long_line_noselect()
5557  CheckScreendump
5558
5559  let lines =<< trim [SCRIPT]
5560    set wildmenu wildoptions=pum wildmode=noselect,full
5561    command -nargs=1 -complete=custom,Entries DoubleEntry echo
5562    func Entries(a, b, c)
5563      return 'loooooooooooooooong quite loooooooooooong, really loooooooooooong, probably too looooooooooooooooooooooooooong entry'
5564    endfunc
5565  [SCRIPT]
5566  call writefile(lines, 'XTest_wildmenu', 'D')
5567  let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8, 'cols': 60})
5568
5569  call term_sendkeys(buf, ":DoubleEntry \<Tab>")
5570  call VerifyScreenDump(buf, 'Test_long_line_noselect_1', {})
5571
5572  call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>")
5573  call VerifyScreenDump(buf, 'Test_long_line_noselect_2', {})
5574
5575  call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>\<C-N>")
5576  call VerifyScreenDump(buf, 'Test_long_line_noselect_3', {})
5577
5578  " clean up
5579  call term_sendkeys(buf, "\<Esc>")
5580  call StopVimInTerminal(buf)
5581endfunc
5582
5583func Test_CmdlineLeave_vchar_keys()
5584  func OnLeave()
5585    let g:leave_key = v:char
5586  endfunction
5587
5588  new
5589  for event in ["CmdlineLeavePre", "CmdlineLeave"]
5590    exec "autocmd" event "* :call OnLeave()"
5591    for key in ["\<C-C>", "\<Esc>", "\<CR>"]
5592      call feedkeys($":echo{key}", 'tx')
5593      call assert_equal(key, g:leave_key)
5594    endfor
5595    exec "autocmd!" event
5596  endfor
5597  bwipe!
5598  delfunc OnLeave
5599  unlet g:leave_key
5600endfunc
5601
5602" Skip wildmenu during history navigation via Up/Down keys
5603func Test_skip_wildtrigger_hist_navigation()
5604  call Ntest_override("char_avail", 1)
5605  set wildmenu wildmode=noselect,full
5606  augroup TestSkipWildtrigger | autocmd!
5607    autocmd CmdlineChanged : call wildtrigger()
5608  augroup END
5609  cnoremap <expr> <Up>   wildmenumode() ? "\<C-E>\<Up>"   : "\<Up>"
5610  cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"
5611
5612  call feedkeys(":echom \"foo\"", "tx")
5613  call feedkeys(":echom \"foobar\"", "tx")
5614
5615  call feedkeys(":ech\<Up>\<C-B>\"\<CR>", "tx")
5616  call assert_equal('"echom "foobar"', @:)
5617  call feedkeys(":ech\<Up>\<Up>\<C-B>\"\<CR>", "tx")
5618  call assert_equal('"echom "foo"', @:)
5619  call feedkeys(":ech\<Up>\<Up>\<Down>\<C-B>\"\<CR>", "tx")
5620  call assert_equal('"echom "foobar"', @:)
5621  call feedkeys(":ech\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", "tx")
5622  call assert_equal('"ech', @:)
5623
5624  call Ntest_override("char_avail", 0)
5625  set wildmenu& wildmode& wildoptions&
5626  augroup TestSkipWildtrigger | autocmd! | augroup END
5627  cunmap <Up>
5628  cunmap <Down>
5629endfunc
5630
5631" Issue 18298: wildmenu should be dismissed after wildtrigger and whitespace
5632func Test_update_screen_after_wildtrigger()
5633  CheckScreendump
5634  let lines =<< trim [SCRIPT]
5635    call test_override("char_avail", 1)
5636    set wildmode=noselect:lastused,full wildmenu wildoptions=pum
5637    autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif
5638  [SCRIPT]
5639  call writefile(lines, 'XTest_wildtrigger', 'D')
5640  let buf = RunVimInTerminal('-S XTest_wildtrigger', {'rows': 10})
5641
5642  call term_sendkeys(buf, ":term foo")
5643  call TermWait(buf, 50)
5644  call VerifyScreenDump(buf, 'Test_update_screen_wildtrigger_1', {})
5645
5646  call term_sendkeys(buf, "\<esc>")
5647  call StopVimInTerminal(buf)
5648endfunc
5649
5650func Test_breaklist_args_fails()
5651  call assert_match('No breakpoints defined', execute(':breaklist'))
5652  call assert_fails(':breaklist extra', 'E488:')
5653endfunc
5654
5655func Test_rulerformat_empty()
5656  set ruler rulerformat=%!'%{}%'
5657  try
5658    redraw
5659  catch
5660  endtry
5661  set ruler&
5662  set rulerformat&
5663endfunc
5664
5665func Test_cmdline_complete_with_space()
5666  call mkdir('Xspc', 'R')
5667  let save_cwd = getcwd()
5668  cd Xspc
5669  call writefile([], 'foo bar')
5670  call writefile([], 'baz')
5671  call writefile([], 'bz')
5672
5673  " This should expand to foo\ bar, not add 3 space separated
5674  " files: foo baz bz
5675  call feedkeys(":badd foo b\<C-A>\<C-B>\"\<CR>", 'xt')
5676  call assert_equal('"badd foo\ bar', @:)
5677
5678  call chdir(save_cwd)
5679endfunc
5680
5681func Test_wildmode_noinsert()
5682  command! -nargs=1 -complete=custom,T MyCmd echo
5683  func T(a, c, p)
5684    return "oneA\noneB\noneC"
5685  endfunc
5686
5687  set wildmenu wildoptions=pum wildmode=noinsert,full wildchar=<Tab>
5688  call feedkeys(":MyCmd o\<Tab>\<C-B>\"\<CR>", 'xt')
5689  call assert_equal('"MyCmd o', @:)
5690  call feedkeys(":MyCmd o\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
5691  call assert_equal('"MyCmd oneB', @:)
5692  call feedkeys(":MyCmd o\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
5693  call assert_equal('"MyCmd oneC', @:)
5694
5695  call feedkeys(":MyCmd o\<Tab>\<C-Y>\<C-B>\"\<CR>", 'xt')
5696  call assert_equal('"MyCmd oneA', @:)
5697
5698  " CTRL-P from highlighted first item returns to original text
5699  call feedkeys(":MyCmd o\<Tab>\<C-P>\<C-B>\"\<CR>", 'xt')
5700  call assert_equal('"MyCmd o', @:)
5701  " Another CTRL-P wraps to the last match
5702  call feedkeys(":MyCmd o\<Tab>\<C-P>\<C-P>\<C-B>\"\<CR>", 'xt')
5703  call assert_equal('"MyCmd oneC', @:)
5704
5705  set wildoptions=
5706  call feedkeys(":MyCmd o\<Tab>\<C-B>\"\<CR>", 'xt')
5707  call assert_equal('"MyCmd o', @:)
5708  call feedkeys(":MyCmd o\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
5709  call assert_equal('"MyCmd oneB', @:)
5710
5711  call feedkeys(":MyCmd o\<Tab>\<C-Y>\<C-B>\"\<CR>", 'xt')
5712  call assert_equal('"MyCmd oneA', @:)
5713  call feedkeys(":MyCmd o\<Tab>\<C-E>\<C-B>\"\<CR>", 'xt')
5714  call assert_equal('"MyCmd o', @:)
5715
5716  " 'nowildmenu' should make 'noinsert' ineffective
5717  set nowildmenu
5718  call feedkeys(":MyCmd o\<Tab>\<C-B>\"\<CR>", 'xt')
5719  call assert_equal('"MyCmd oneA', @:)
5720
5721  " 'noselect' takes precedence over 'noinsert'
5722  set wildmenu wildoptions=pum wildmode=noselect:noinsert,full
5723  call feedkeys(":MyCmd o\<Tab>\<C-B>\"\<CR>", 'xt')
5724  call assert_equal('"MyCmd o', @:)
5725  call feedkeys(":MyCmd o\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
5726  call assert_equal('"MyCmd oneA', @:)
5727  call feedkeys(":MyCmd o\<Tab>\<C-Y>\<C-B>\"\<CR>", 'xt')
5728  call assert_equal('"MyCmd o', @:)
5729
5730  set wildmode=noinsert
5731  call feedkeys(":MyCmd o\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
5732  call assert_equal('"MyCmd o', @:)
5733
5734  set wildmode=noinsert,full
5735  call feedkeys(":MyCmd o\<Tab>\<C-N>\<C-B>\"\<CR>", 'xt')
5736  call assert_equal('"MyCmd oneB', @:)
5737  call feedkeys(":MyCmd o\<Tab>\<C-E>\<C-B>\"\<CR>", 'xt')
5738  call assert_equal('"MyCmd o', @:)
5739
5740  " 'longest' takes precedence over 'noinsert'
5741  set wildmode=noinsert:longest
5742  call feedkeys(":MyCmd o\<Tab>\<C-B>\"\<CR>", 'xt')
5743  call assert_equal('"MyCmd one', @:)
5744
5745  set wildmode&
5746  call feedkeys(":set wildmode=noi\<Tab>\<C-B>\"\<CR>", 'xt')
5747  call assert_equal('"set wildmode=noinsert', @:)
5748
5749  set wildmode=noinsert:lastused,full
5750  call assert_equal('noinsert:lastused,full', &wildmode)
5751  call assert_fails('set wildmode=noinser', 'E474:')
5752
5753  " Single match with 'noinsert': item shown highlighted, C-Y commits
5754  command! -nargs=1 -complete=custom,T1 MyCmd1 echo
5755  func T1(a, c, p)
5756    return "oneA"
5757  endfunc
5758  set wildmenu wildoptions=pum wildmode=noinsert,full
5759  call feedkeys(":MyCmd1 o\<Tab>\<C-B>\"\<CR>", 'xt')
5760  call assert_equal('"MyCmd1 o', @:)
5761  call feedkeys(":MyCmd1 o\<Tab>\<C-Y>\<C-B>\"\<CR>", 'xt')
5762  call assert_equal('"MyCmd1 oneA', @:)
5763  delcommand MyCmd1
5764  delfunc T1
5765
5766  set wildmenu& wildoptions& wildmode& wildchar&
5767  delcommand MyCmd
5768  delfunc T
5769endfunc
5770
5771func Test_cmdline_compl_env_var_wildcard()
5772  CheckUnix
5773
5774  let d = tempname()
5775  call mkdir(d .. '/[x]', 'pR')
5776  call writefile(['hello'], d .. '/[x]/file.txt')
5777  let $XWILD = d .. '/[x]'
5778
5779  call feedkeys(":e $XWILD/fi\<Tab>\<C-B>\"\<CR>", 'xt')
5780  call assert_match('\[x\]/file\.txt$', @:)
5781  call assert_equal([d .. '/[x]/file.txt'], glob('$XWILD/*', 0, 1))
5782
5783  edit $XWILD/file.txt
5784  call assert_equal('hello', getline(1))
5785  bwipe!
5786
5787  if has('profile')
5788    let prof = d .. '/[x]/prof.out'
5789    profile start $XWILD/prof.out
5790    profile stop
5791    call assert_true(filereadable(prof))
5792    call delete(prof)
5793  endif
5794
5795  unlet $XWILD
5796endfunc
5797
5798" vim: shiftwidth=2 sts=2 expandtab