blob: 92adbd10b6b617a8002ff52a534d59e8f8c6795a [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
23 call writefile(['testfile'], 'Xtestfile')
24 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030 call delete('Xtestfile')
31endfunc
32
33func Test_complete_list()
34 " We can't see the output, but at least we check the code runs properly.
35 call feedkeys(":e test\<C-D>\r", "tx")
36 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010037
38 " If a command doesn't support completion, then CTRL-D should be literally
39 " used.
40 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
41 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000042
43 " Test for displaying the tail of the completion matches
44 set wildmode=longest,full
45 call mkdir('Xtest')
46 call writefile([], 'Xtest/a.c')
47 call writefile([], 'Xtest/a.h')
48 let g:Sline = ''
49 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
50 call assert_equal('a.c a.h', g:Sline)
51 call assert_equal('"e Xtest/', @:)
52 if has('win32')
53 " Test for 'completeslash'
54 set completeslash=backslash
55 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
56 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000057 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
58 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000059 set completeslash=slash
60 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
61 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000062 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
63 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000064 set completeslash&
65 endif
66
67 " Test for displaying the tail with wildcards
68 let g:Sline = ''
69 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
70 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
71 call assert_equal('"e Xtes?/', @:)
72 let g:Sline = ''
73 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
74 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
75 call assert_equal('"e Xtes*/', @:)
76 let g:Sline = ''
77 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
78 call assert_equal(':e Xtes[/', g:Sline)
79 call assert_equal('"e Xtes[/', @:)
80
81 call delete('Xtest', 'rf')
82 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020083endfunc
84
85func Test_complete_wildmenu()
Bram Moolenaar37db6422019-03-28 21:26:23 +010086 call mkdir('Xdir1/Xdir2', 'p')
87 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
88 call writefile(['testfile2'], 'Xdir1/Xtestfile2')
89 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
90 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020091 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010092
93 " Pressing <Tab> completes, and moves to next files when pressing again.
94 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
95 call assert_equal('testfile1', getline(1))
96 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020097 call assert_equal('testfile2', getline(1))
98
Bram Moolenaar37db6422019-03-28 21:26:23 +010099 " <S-Tab> is like <Tab> but begin with the last match and then go to
100 " previous.
101 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
102 call assert_equal('testfile2', getline(1))
103 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
104 call assert_equal('testfile1', getline(1))
105
106 " <Left>/<Right> to move to previous/next file.
107 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
108 call assert_equal('testfile1', getline(1))
109 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
110 call assert_equal('testfile2', getline(1))
111 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
112 call assert_equal('testfile1', getline(1))
113
114 " <Up>/<Down> to go up/down directories.
115 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
116 call assert_equal('testfile3', getline(1))
117 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
118 call assert_equal('testfile1', getline(1))
119
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100120 " this fails in some Unix GUIs, not sure why
121 if !has('unix') || !has('gui_running')
122 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
123 " different than 'wildchar'.
124 set wildcharm=<C-Z>
125 cnoremap <C-J> <Down><C-Z>
126 cnoremap <C-K> <Up><C-Z>
127 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx')
128 call assert_equal('testfile3', getline(1))
129 call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
130 call assert_equal('testfile1', getline(1))
131 set wildcharm=0
132 cunmap <C-J>
133 cunmap <C-K>
134 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100135
Bram Moolenaar578fe942020-02-27 21:32:51 +0100136 " Test for canceling the wild menu by adding a character
137 redrawstatus
138 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
139 call assert_equal('"e Xdir1/Xdir2/x', @:)
140
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 " Completion using a relative path
142 cd Xdir1/Xdir2
143 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
144 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
145 cd -
146
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000147 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100148 cnoremap <expr> <F2> wildmenumode()
149 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +0000150 call assert_equal('"cd Xdir1/0', @:)
151 call feedkeys(":e Xdir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
152 call assert_equal('"e Xdir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100153 cunmap <F2>
154
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000155 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
156 " After this pressing <Left> or <Right> should not change the selection.
157 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
158 call assert_equal('"sign define', @:)
159 call histadd('cmd', 'TestWildMenu')
160 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
161 call assert_equal('"TestWildMenu', @:)
162
Bram Moolenaar37db6422019-03-28 21:26:23 +0100163 " cleanup
164 %bwipe
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000165 call delete('Xdir1', 'rf')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200166 set nowildmenu
167endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100168
Bram Moolenaara60053b2020-09-03 16:50:13 +0200169func Test_wildmenu_screendump()
170 CheckScreendump
171
172 let lines =<< trim [SCRIPT]
173 set wildmenu hlsearch
174 [SCRIPT]
175 call writefile(lines, 'XTest_wildmenu')
176
177 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
178 call term_sendkeys(buf, ":vim\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
183
184 call term_sendkeys(buf, "\<Tab>")
185 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
186
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100187 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200188 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
189 call term_sendkeys(buf, "\<Esc>")
190
191 " clean up
192 call StopVimInTerminal(buf)
193 call delete('XTest_wildmenu')
194endfunc
195
Bram Moolenaara653e532022-04-19 11:38:24 +0100196func Test_redraw_in_autocmd()
197 CheckScreendump
198
199 let lines =<< trim END
200 set cmdheight=2
201 autocmd CmdlineChanged * redraw
202 END
203 call writefile(lines, 'XTest_redraw')
204
205 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
206 call term_sendkeys(buf, ":for i in range(3)\<CR>")
207 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
208
209 call term_sendkeys(buf, "let i =")
210 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
211
212 " clean up
213 call term_sendkeys(buf, "\<CR>")
214 call StopVimInTerminal(buf)
215 call delete('XTest_redraw')
216endfunc
217
Bram Moolenaarf797e302022-08-11 13:17:30 +0100218func Test_changing_cmdheight()
219 CheckScreendump
220
221 let lines =<< trim END
222 set cmdheight=1 laststatus=2
223 END
224 call writefile(lines, 'XTest_cmdheight')
225
226 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
227 call term_sendkeys(buf, ":resize -3\<CR>")
228 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
229
230 " using the space available doesn't change the status line
231 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
232 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
233
234 " using more space moves the status line up
235 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
236 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
237
238 " reducing cmdheight moves status line down
239 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
240 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
241
242 " clean up
243 call StopVimInTerminal(buf)
244 call delete('XTest_cmdheight')
245endfunc
246
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100247func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100248 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
249 call assert_equal('"map <unique> <silent>', getreg(':'))
250 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
251 call assert_equal('"map <script> <unique>', getreg(':'))
252 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
253 call assert_equal('"map <expr> <script>', getreg(':'))
254 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
255 call assert_equal('"map <buffer> <expr>', getreg(':'))
256 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
257 call assert_equal('"map <nowait> <buffer>', getreg(':'))
258 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
259 call assert_equal('"map <special> <nowait>', getreg(':'))
260 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
261 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200262
Bram Moolenaar1776a282019-05-03 16:05:41 +0200263 map <Middle>x middle
264
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200265 map ,f commaf
266 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200267 map <Left> left
268 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200269 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
270 call assert_equal('"map ,f', getreg(':'))
271 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
272 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200273 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
274 call assert_equal('"map <Left>', getreg(':'))
275 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200276 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200277 unmap ,f
278 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200279 unmap <Left>
280 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200281
282 set cpo-=< cpo-=B cpo-=k
283 map <Left> left
284 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
285 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200286 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200287 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200288 unmap <Left>
289
290 set cpo+=<
291 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200292 exe "set t_k6=\<Esc>[17~"
293 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200294 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
295 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200296 if !has('gui_running')
297 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
298 call assert_equal("\"map <F6>x", getreg(':'))
299 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200300 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200301 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200302 set cpo-=<
303
304 set cpo+=B
305 map <Left> left
306 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
307 call assert_equal('"map <Left>', getreg(':'))
308 unmap <Left>
309 set cpo-=B
310
311 set cpo+=k
312 map <Left> left
313 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <Left>', getreg(':'))
315 unmap <Left>
316 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200317
Bram Moolenaar531be472020-09-23 22:38:05 +0200318 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
319
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 unmap <Middle>x
321 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100322endfunc
323
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100324func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100325 hi Aardig ctermfg=green
326 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000327 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100328 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000329 call assert_equal('"match none', @:)
330 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
331 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100332endfunc
333
334func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100335 hi Aardig ctermfg=green
336 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
337 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200338 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
339 call assert_equal('"hi default Aardig', getreg(':'))
340 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
341 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100342 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
343 call assert_equal('"hi link', getreg(':'))
344 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
345 call assert_equal('"hi default', getreg(':'))
346 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
347 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200348 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
349 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
350 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
351 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200352
353 " A cleared group does not show up in completions.
354 hi Anders ctermfg=green
355 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
356 hi clear Aardig
357 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
358 hi clear Anders
359 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100360endfunc
361
Bram Moolenaar75e15672020-06-28 13:10:22 +0200362" Test for command-line expansion of "hi Ni " (easter egg)
363func Test_highlight_easter_egg()
364 call test_override('ui_delay', 1)
365 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
366 call assert_equal("\"hi Ni \<Tab>", @:)
367 call test_override('ALL', 0)
368endfunc
369
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200370func Test_getcompletion()
371 let groupcount = len(getcompletion('', 'event'))
372 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200373 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200374 call assert_true(matchcount > 0)
375 call assert_true(groupcount > matchcount)
376
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200377 if has('menu')
378 source $VIMRUNTIME/menu.vim
379 let matchcount = len(getcompletion('', 'menu'))
380 call assert_true(matchcount > 0)
381 call assert_equal(['File.'], getcompletion('File', 'menu'))
382 call assert_true(matchcount > 0)
383 let matchcount = len(getcompletion('File.', 'menu'))
384 call assert_true(matchcount > 0)
385 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200386
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200387 let l = getcompletion('v:n', 'var')
388 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200389 let l = getcompletion('v:notexists', 'var')
390 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200391
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200392 args a.c b.c
393 let l = getcompletion('', 'arglist')
394 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000395 let l = getcompletion('a.', 'buffer')
396 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200397 %argdelete
398
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200399 let l = getcompletion('', 'augroup')
400 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200401 let l = getcompletion('blahblah', 'augroup')
402 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200403
404 let l = getcompletion('', 'behave')
405 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200406 let l = getcompletion('not', 'behave')
407 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200408
409 let l = getcompletion('', 'color')
410 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200411 let l = getcompletion('dirty', 'color')
412 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200413
414 let l = getcompletion('', 'command')
415 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200416 let l = getcompletion('awake', 'command')
417 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200418
419 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200420 call assert_true(index(l, 'samples/') >= 0)
421 let l = getcompletion('NoMatch', 'dir')
422 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200423
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100424 if glob('~/*') !=# ''
425 let l = getcompletion('~/', 'dir')
426 call assert_true(l[0][0] ==# '~')
427 endif
428
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200429 let l = getcompletion('exe', 'expression')
430 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200431 let l = getcompletion('kill', 'expression')
432 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200433
434 let l = getcompletion('tag', 'function')
435 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200436 let l = getcompletion('paint', 'function')
437 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200438
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200439 let Flambda = {-> 'hello'}
440 let l = getcompletion('', 'function')
441 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200442 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200443
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200444 let l = getcompletion('run', 'file')
445 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200446 let l = getcompletion('walk', 'file')
447 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200448 set wildignore=*.vim
449 let l = getcompletion('run', 'file', 1)
450 call assert_true(index(l, 'runtest.vim') < 0)
451 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000452 " Directory name with space character
453 call mkdir('Xdir with space')
454 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
455 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
456 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200457
458 let l = getcompletion('ha', 'filetype')
459 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200460 let l = getcompletion('horse', 'filetype')
461 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200462
463 let l = getcompletion('z', 'syntax')
464 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200465 let l = getcompletion('emacs', 'syntax')
466 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467
468 let l = getcompletion('jikes', 'compiler')
469 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200470 let l = getcompletion('break', 'compiler')
471 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200472
473 let l = getcompletion('last', 'help')
474 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200475 let l = getcompletion('giveup', 'help')
476 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200477
478 let l = getcompletion('time', 'option')
479 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200480 let l = getcompletion('space', 'option')
481 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482
483 let l = getcompletion('er', 'highlight')
484 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200485 let l = getcompletion('dark', 'highlight')
486 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200488 let l = getcompletion('', 'messages')
489 call assert_true(index(l, 'clear') >= 0)
490 let l = getcompletion('not', 'messages')
491 call assert_equal([], l)
492
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200493 let l = getcompletion('', 'mapclear')
494 call assert_true(index(l, '<buffer>') >= 0)
495 let l = getcompletion('not', 'mapclear')
496 call assert_equal([], l)
497
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200498 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200499 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200500 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
501 let root = has('win32') ? 'C:\\' : '/'
502 let l = getcompletion(root, 'shellcmd')
503 let expected = map(filter(glob(root . '*', 0, 1),
504 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
505 call assert_equal(expected, l)
506
Bram Moolenaarb650b982016-08-05 20:35:13 +0200507 if has('cscope')
508 let l = getcompletion('', 'cscope')
509 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
510 call assert_equal(cmds, l)
511 " using cmdline completion must not change the result
512 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
513 let l = getcompletion('', 'cscope')
514 call assert_equal(cmds, l)
515 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
516 let l = getcompletion('find ', 'cscope')
517 call assert_equal(keys, l)
518 endif
519
Bram Moolenaar7522f692016-08-06 14:12:50 +0200520 if has('signs')
521 sign define Testing linehl=Comment
522 let l = getcompletion('', 'sign')
523 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
524 call assert_equal(cmds, l)
525 " using cmdline completion must not change the result
526 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
527 let l = getcompletion('', 'sign')
528 call assert_equal(cmds, l)
529 let l = getcompletion('list ', 'sign')
530 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000531 let l = getcompletion('de*', 'sign')
532 call assert_equal(['define'], l)
533 let l = getcompletion('p?', 'sign')
534 call assert_equal(['place'], l)
535 let l = getcompletion('j.', 'sign')
536 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200537 endif
538
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200539 " Command line completion tests
540 let l = getcompletion('cd ', 'cmdline')
541 call assert_true(index(l, 'samples/') >= 0)
542 let l = getcompletion('cd NoMatch', 'cmdline')
543 call assert_equal([], l)
544 let l = getcompletion('let v:n', 'cmdline')
545 call assert_true(index(l, 'v:null') >= 0)
546 let l = getcompletion('let v:notexists', 'cmdline')
547 call assert_equal([], l)
548 let l = getcompletion('call tag', 'cmdline')
549 call assert_true(index(l, 'taglist(') >= 0)
550 let l = getcompletion('call paint', 'cmdline')
551 call assert_equal([], l)
552
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100553 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000554 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100555 return "oneA\noneB\noneC"
556 endfunc
557 command -nargs=1 -complete=custom,T MyCmd
558 let l = getcompletion('MyCmd ', 'cmdline')
559 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000560 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100561
562 delcommand MyCmd
563 delfunc T
ii144785fe02021-11-21 12:13:56 +0000564 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100565
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200566 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200567 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200568 if has('cmdline_hist')
569 call add(names, 'history')
570 endif
571 if has('gettext')
572 call add(names, 'locale')
573 endif
574 if has('profile')
575 call add(names, 'syntime')
576 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200577
578 set tags=Xtags
579 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
580
581 for name in names
582 let matchcount = len(getcompletion('', name))
583 call assert_true(matchcount >= 0, 'No matches for ' . name)
584 endfor
585
586 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200587 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200588
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000589 edit a~b
590 enew
591 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
592 bw a~b
593
594 if has('unix')
595 edit Xtest\
596 enew
597 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
598 bw Xtest\
599 endif
600
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200601 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200602 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200603 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200604endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200605
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000606" Test for getcompletion() with "fuzzy" in 'wildoptions'
607func Test_getcompletion_wildoptions()
608 let save_wildoptions = &wildoptions
609 set wildoptions&
610 let l = getcompletion('space', 'option')
611 call assert_equal([], l)
612 let l = getcompletion('ier', 'command')
613 call assert_equal([], l)
614 set wildoptions=fuzzy
615 let l = getcompletion('space', 'option')
616 call assert_true(index(l, 'backspace') >= 0)
617 let l = getcompletion('ier', 'command')
618 call assert_true(index(l, 'compiler') >= 0)
619 let &wildoptions = save_wildoptions
620endfunc
621
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000622func Test_complete_autoload_error()
623 let save_rtp = &rtp
624 let lines =<< trim END
625 vim9script
626 export def Complete(..._): string
627 return 'match'
628 enddef
629 echo this will cause an error
630 END
631 call mkdir('Xdir/autoload', 'p')
632 call writefile(lines, 'Xdir/autoload/script.vim')
633 exe 'set rtp+=' .. getcwd() .. '/Xdir'
634
635 let lines =<< trim END
636 vim9script
637 import autoload 'script.vim'
638 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
639 &wildcharm = char2nr("\<Tab>")
640 feedkeys(":Cmd \<Tab>", 'xt')
641 END
642 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
643
644 let &rtp = save_rtp
645 call delete('Xdir', 'rf')
646endfunc
647
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100648func Test_fullcommand()
649 let tests = {
650 \ '': '',
651 \ ':': '',
652 \ ':::': '',
653 \ ':::5': '',
654 \ 'not_a_cmd': '',
655 \ 'Check': '',
656 \ 'syntax': 'syntax',
657 \ ':syntax': 'syntax',
658 \ '::::syntax': 'syntax',
659 \ 'sy': 'syntax',
660 \ 'syn': 'syntax',
661 \ 'synt': 'syntax',
662 \ ':sy': 'syntax',
663 \ '::::sy': 'syntax',
664 \ 'match': 'match',
665 \ '2match': 'match',
666 \ '3match': 'match',
667 \ 'aboveleft': 'aboveleft',
668 \ 'abo': 'aboveleft',
669 \ 's': 'substitute',
670 \ '5s': 'substitute',
671 \ ':5s': 'substitute',
672 \ "'<,'>s": 'substitute',
673 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100674 \ 'CheckLin': 'CheckLinux',
675 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100676 \ }
677
678 for [in, want] in items(tests)
679 call assert_equal(want, fullcommand(in))
680 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200681 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100682
683 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200684
685 command -buffer BufferLocalCommand :
686 command GlobalCommand :
687 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
688 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
689 delcommand BufferLocalCommand
690 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100691endfunc
692
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200693func Test_shellcmd_completion()
694 let save_path = $PATH
695
696 call mkdir('Xpathdir/Xpathsubdir', 'p')
697 call writefile([''], 'Xpathdir/Xfile.exe')
698 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
699
700 " Set PATH to example directory without trailing slash.
701 let $PATH = getcwd() . '/Xpathdir'
702
703 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
704 " dirs in the PATH, even though they won't be executed. We check that only
705 " subdirs of the PWD and executables from the PATH are included in the
706 " suggestions.
707 let actual = getcompletion('X', 'shellcmd')
708 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
709 call insert(expected, 'Xfile.exe')
710 call assert_equal(expected, actual)
711
712 call delete('Xpathdir', 'rf')
713 let $PATH = save_path
714endfunc
715
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200716func Test_expand_star_star()
717 call mkdir('a/b', 'p')
718 call writefile(['asdfasdf'], 'a/b/fileXname')
719 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000720 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200721 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200722 call delete('a', 'rf')
723endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100724
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100725func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100726 let @a = "def"
727 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
728 call assert_equal('"abc def ghi', @:)
729
730 new
731 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
732
733 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
734 call assert_equal('"aaa asdf bbb', @:)
735
736 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
737 call assert_equal('"aaa /tmp/some bbb', @:)
738
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200739 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
740 call assert_equal('"aaa '.getline(1).' bbb', @:)
741
Bram Moolenaar21efc362016-12-03 14:05:49 +0100742 set incsearch
743 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
744 call assert_equal('"aaa verylongword bbb', @:)
745
746 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
747 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100748
749 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
750 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100751 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200752
753 " Error while typing a command used to cause that it was not executed
754 " in the end.
755 new
756 try
757 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
758 catch /^Vim\%((\a\+)\)\=:E32/
759 " ignore error E32
760 endtry
761 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100762
Bram Moolenaar578fe942020-02-27 21:32:51 +0100763 " Try to paste an invalid register using <C-R>
764 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
765 call assert_equal('"onetwo', @:)
766
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100767 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100768 let @a = "xy\<C-H>z"
769 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
770 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100771 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
772 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100773 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
774 call assert_equal("\"xy\<C-H>z", @:)
775
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100776 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
777 let @a = "xy\<C-V>z"
778 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
779 call assert_equal('"xyz', @:)
780 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
781 call assert_equal("\"xy\<C-V>z", @:)
782
Bram Moolenaar578fe942020-02-27 21:32:51 +0100783 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
784
Bram Moolenaar72532d32018-04-07 19:09:09 +0200785 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100786endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100787
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100788func Test_cmdline_remove_char()
789 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100790
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100791 for e in ['utf8', 'latin1']
792 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100793
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100794 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
795 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100796
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100797 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
798 call assert_equal('"abcdef', @:)
799
800 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
801 call assert_equal('"abc ghi', @:, e)
802
803 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
804 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100805
806 " This was going before the start in latin1.
807 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100808 endfor
809
810 let &encoding = encoding_save
811endfunc
812
813func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200814 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100815
816 set keymap=esperanto
817 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
818 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
819 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100820endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100821
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100822func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100823 new
824 2;'(
825 2;')
826 quit
827endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100828
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100829func Test_illegal_address2()
830 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
831 new
832 source Xtest.vim
833 " Trigger calling validate_cursor()
834 diffsp Xtest.vim
835 quit!
836 bwipe!
837 call delete('Xtest.vim')
838endfunc
839
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100840func Test_mark_from_line_zero()
841 " this was reading past the end of the first (empty) line
842 new
843 norm oxxxx
844 call assert_fails("0;'(", 'E20:')
845 bwipe!
846endfunc
847
Bram Moolenaarba47b512017-01-24 21:18:19 +0100848func Test_cmdline_complete_wildoptions()
849 help
850 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
851 let a = join(sort(split(@:)),' ')
852 set wildoptions=tagfile
853 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
854 let b = join(sort(split(@:)),' ')
855 call assert_equal(a, b)
856 bw!
857endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100858
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200859func Test_cmdline_complete_user_cmd()
860 command! -complete=color -nargs=1 Foo :
861 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
862 call assert_equal('"Foo blue', @:)
863 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
864 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000865 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
866 call assert_equal('"Foo a blue', @:)
867 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
868 call assert_equal('"Foo b\', @:)
869 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
870 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200871 delcommand Foo
872endfunc
873
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100874func Test_complete_user_cmd()
875 command FooBar echo 'global'
876 command -buffer FooBar echo 'local'
877 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
878 call assert_equal('"FooBar', @:)
879
880 delcommand -buffer FooBar
881 delcommand FooBar
882endfunc
883
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100884func s:ScriptLocalFunction()
885 echo 'yes'
886endfunc
887
888func Test_cmdline_complete_user_func()
889 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200890 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100891 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
892 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100893
894 " g: prefix also works
895 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
896 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200897
898 " using g: prefix does not result in just "g:" matches from a lambda
899 let Fx = { a -> a }
900 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
901 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200902
903 " existence of script-local dict function does not break user function name
904 " completion
905 function s:a_dict_func() dict
906 endfunction
907 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
908 call assert_match('"call Test_cmdline_complete_user_', @:)
909 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100910endfunc
911
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200912func Test_cmdline_complete_user_names()
913 if has('unix') && executable('whoami')
914 let whoami = systemlist('whoami')[0]
915 let first_letter = whoami[0]
916 if len(first_letter) > 0
917 " Trying completion of :e ~x where x is the first letter of
918 " the user name should complete to at least the user name.
919 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
920 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
921 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200922 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200923 " Just in case: check that the system has an Administrator account.
924 let names = system('net user')
925 if names =~ 'Administrator'
926 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100927 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200928 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100929 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200930 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200931 else
932 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200933 endif
934endfunc
935
Bram Moolenaar297610b2019-12-27 17:20:55 +0100936func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200937 CheckExecutable whoami
938 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
939 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100940endfunc
941
Bram Moolenaar8b633132020-03-20 18:20:51 +0100942func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200943 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
944 call assert_equal(lang, v:lc_time)
945
946 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
947 call assert_equal(lang, v:ctype)
948
949 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
950 call assert_equal(lang, v:collate)
951
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200952 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200953 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200954
955 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200956 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200957
Bram Moolenaarec680282020-06-12 19:35:32 +0200958 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200959
Bram Moolenaarec680282020-06-12 19:35:32 +0200960 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
961 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200962
Bram Moolenaarec680282020-06-12 19:35:32 +0200963 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
964 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200965
Bram Moolenaarec680282020-06-12 19:35:32 +0200966 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
967 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200968
969 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
970 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200971endfunc
972
Bram Moolenaar297610b2019-12-27 17:20:55 +0100973func Test_cmdline_complete_env_variable()
974 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100975 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
976 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100977 unlet $X_VIM_TEST_COMPLETE_ENV
978endfunc
979
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100980func Test_cmdline_complete_expression()
981 let g:SomeVar = 'blah'
982 for cmd in ['exe', 'echo', 'echon', 'echomsg']
983 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
984 call assert_match('"' .. cmd .. ' SomeVar', @:)
985 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
986 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
987 endfor
988 unlet g:SomeVar
989endfunc
990
Bram Moolenaar47016f52021-08-26 16:39:58 +0200991" Unique function name for completion below
992func s:WeirdFunc()
993 echo 'weird'
994endfunc
995
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100996" Test for various command-line completion
997func Test_cmdline_complete_various()
998 " completion for a command starting with a comment
999 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1000 call assert_equal("\" :|\"\<C-A>", @:)
1001
1002 " completion for a range followed by a comment
1003 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1004 call assert_equal("\"1,2\"\<C-A>", @:)
1005
1006 " completion for :k command
1007 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1008 call assert_equal("\"ka\<C-A>", @:)
1009
1010 " completion for short version of the :s command
1011 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1012 call assert_equal("\"sI \<C-A>", @:)
1013
1014 " completion for :write command
1015 call mkdir('Xdir')
1016 call writefile(['one'], 'Xdir/Xfile1')
1017 let save_cwd = getcwd()
1018 cd Xdir
1019 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1020 call assert_equal("\"w >> Xfile1", @:)
1021 call chdir(save_cwd)
1022 call delete('Xdir', 'rf')
1023
1024 " completion for :w ! and :r ! commands
1025 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1026 call assert_equal("\"w !invalid_xyz_cmd", @:)
1027 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1028 call assert_equal("\"r !invalid_xyz_cmd", @:)
1029
1030 " completion for :>> and :<< commands
1031 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1032 call assert_equal("\">>>\<C-A>", @:)
1033 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1034 call assert_equal("\"<<<\<C-A>", @:)
1035
1036 " completion for command with +cmd argument
1037 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1038 call assert_equal("\"buffer +/pat Xabc", @:)
1039 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1040 call assert_equal("\"buffer +/pat\<C-A>", @:)
1041
1042 " completion for a command with a trailing comment
1043 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1044 call assert_equal("\"ls \" comment\<C-A>", @:)
1045
1046 " completion for a command with a trailing command
1047 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1048 call assert_equal("\"ls | ls", @:)
1049
1050 " completion for a command with an CTRL-V escaped argument
1051 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1052 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1053
1054 " completion for a command that doesn't take additional arguments
1055 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1056 call assert_equal("\"all abc\<C-A>", @:)
1057
1058 " completion for a command with a command modifier
1059 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1060 call assert_equal("\"topleft new", @:)
1061
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001062 " completion for vim9 and legacy commands
1063 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1064 call assert_equal("\"vim9 call strlen(", @:)
1065 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1066 call assert_equal("\"legac call strlen(", @:)
1067
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001068 " completion for the :disassemble command
1069 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1070 call assert_equal("\"disas debug", @:)
1071 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1072 call assert_equal("\"disas profile", @:)
1073 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1074 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1075 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1076 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001077 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1078 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001079
Bram Moolenaar47016f52021-08-26 16:39:58 +02001080 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001081 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001082
naohiro onodfe04db2021-09-12 15:45:10 +02001083 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1084 call assert_match('"disas <SNR>\d\+_', @:)
1085 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1086 call assert_match('"disas debug <SNR>\d\+_', @:)
1087
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001088 " completion for the :match command
1089 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1090 call assert_equal("\"match Search /pat/\<C-A>", @:)
1091
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001092 " completion for the :doautocmd command
1093 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1094 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1095
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001096 " completion of autocmd group after comma
1097 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1098 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1099
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001100 " completion of file name in :doautocmd
1101 call writefile([], 'Xfile1')
1102 call writefile([], 'Xfile2')
1103 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
1104 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
1105 call delete('Xfile1')
1106 call delete('Xfile2')
1107
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001108 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001109 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001110 augroup END
1111 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001112 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001113
1114 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001115 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1116 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001117 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1118 call assert_equal("\"au XTest.test", @:)
1119
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001120 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001121
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001122 " autocmd pattern completion
1123 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1124 call assert_equal("\"au BufEnter *.py\t", @:)
1125
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001126 " completion for the :unlet command
1127 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal("\"unlet one two", @:)
1129
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001130 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001131 " FIXME: what should happen on MS-Windows?
1132 if !has('win32')
1133 edit \{someFile}
1134 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\"buf {someFile}", @:)
1136 bwipe {someFile}
1137 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001138
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001139 " completion for the :bdelete command
1140 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1141 call assert_equal("\"bdel a b c", @:)
1142
1143 " completion for the :mapclear command
1144 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal("\"mapclear <buffer>", @:)
1146
1147 " completion for user defined commands with menu names
1148 menu Test.foo :ls<CR>
1149 com -nargs=* -complete=menu MyCmd
1150 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1151 call assert_equal('"MyCmd Test.', @:)
1152 delcom MyCmd
1153 unmenu Test
1154
1155 " completion for user defined commands with mappings
1156 mapclear
1157 map <F3> :ls<CR>
1158 com -nargs=* -complete=mapping MyCmd
1159 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001160 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001161 mapclear
1162 delcom MyCmd
1163
1164 " completion for :set path= with multiple backslashes
1165 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal('"set path=a\\\ b', @:)
1167
1168 " completion for :set dir= with a backslash
1169 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal('"set dir=a\ b', @:)
1171
1172 " completion for the :py3 commands
1173 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal('"py3 py3do py3file', @:)
1175
Bram Moolenaardf749a22021-03-28 15:29:43 +02001176 " completion for the :vim9 commands
1177 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1178 call assert_equal('"vim9cmd vim9script', @:)
1179
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001180 " redir @" is not the start of a comment. So complete after that
1181 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1182 call assert_equal('"redir @" | cwindow', @:)
1183
1184 " completion after a backtick
1185 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1186 call assert_equal('"e `a1b2c', @:)
1187
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001188 " completion for :language command with an invalid argument
1189 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1190 call assert_equal("\"language dummy \t", @:)
1191
1192 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001193 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1194 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001195
1196 " completion with ambiguous user defined commands
1197 com TCmd1 echo 'TCmd1'
1198 com TCmd2 echo 'TCmd2'
1199 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1200 call assert_equal('"TCmd ', @:)
1201 delcom TCmd1
1202 delcom TCmd2
1203
1204 " completion after a range followed by a pipe (|) character
1205 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1206 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001207
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001208 " completion after a :global command
1209 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1210 call assert_equal('"g/a/chistory', @:)
1211 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"g/a\\/chist\t", @:)
1213
Bram Moolenaar9c929712020-09-07 22:05:28 +02001214 " use <Esc> as the 'wildchar' for completion
1215 set wildchar=<Esc>
1216 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1217 call assert_equal('"g/a\xb/clearjumps', @:)
1218 " pressing <esc> twice should cancel the command
1219 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1220 call assert_equal('"g/a\xb/clearjumps', @:)
1221 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001222
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001223 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001224 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001225 call writefile([], '~Xtest')
1226 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1227 call assert_equal('"e \~Xtest', @:)
1228 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001229
1230 " should be able to complete a file name that has a '*'
1231 call writefile([], 'Xx*Yy')
1232 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1233 call assert_equal('"e Xx\*Yy', @:)
1234 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001235
1236 " use a literal star
1237 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1238 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001239 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001240
1241 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1242 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001243endfunc
1244
1245" Test for 'wildignorecase'
1246func Test_cmdline_wildignorecase()
1247 CheckUnix
1248 call writefile([], 'XTEST')
1249 set wildignorecase
1250 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1251 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001252 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001253 let g:Sline = ''
1254 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1255 call assert_equal('"e xt', @:)
1256 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001257 set wildignorecase&
1258 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001259endfunc
1260
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001261func Test_cmdline_write_alternatefile()
1262 new
1263 call setline('.', ['one', 'two'])
1264 f foo.txt
1265 new
1266 f #-A
1267 call assert_equal('foo.txt-A', expand('%'))
1268 f #<-B.txt
1269 call assert_equal('foo-B.txt', expand('%'))
1270 f %<
1271 call assert_equal('foo-B', expand('%'))
1272 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001273 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001274 bw!
1275 f foo-B.txt
1276 f %<-A
1277 call assert_equal('foo-B-A', expand('%'))
1278 bw!
1279 bw!
1280endfunc
1281
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001282" using a leading backslash here
1283set cpo+=C
1284
1285func Test_cmdline_search_range()
1286 new
1287 call setline(1, ['a', 'b', 'c', 'd'])
1288 /d
1289 1,\/s/b/B/
1290 call assert_equal('B', getline(2))
1291
1292 /a
1293 $
1294 \?,4s/c/C/
1295 call assert_equal('C', getline(3))
1296
1297 call setline(1, ['a', 'b', 'c', 'd'])
1298 %s/c/c/
1299 1,\&s/b/B/
1300 call assert_equal('B', getline(2))
1301
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001302 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001303 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001304
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001305 bwipe!
1306endfunc
1307
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001308" Test for the tick mark (') in an excmd range
1309func Test_tick_mark_in_range()
1310 " If only the tick is passed as a range and no command is specified, there
1311 " should not be an error
1312 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001313 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001314 call assert_fails("',print", 'E78:')
1315endfunc
1316
1317" Test for using a line number followed by a search pattern as range
1318func Test_lnum_and_pattern_as_range()
1319 new
1320 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1321 let @" = ''
1322 2/foo/yank
1323 call assert_equal("foo 3\n", @")
1324 call assert_equal(1, line('.'))
1325 close!
1326endfunc
1327
Bram Moolenaar65189a12017-02-06 22:22:17 +01001328" Tests for getcmdline(), getcmdpos() and getcmdtype()
1329func Check_cmdline(cmdtype)
1330 call assert_equal('MyCmd a', getcmdline())
1331 call assert_equal(8, getcmdpos())
1332 call assert_equal(a:cmdtype, getcmdtype())
1333 return ''
1334endfunc
1335
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001336set cpo&
1337
Bram Moolenaar65189a12017-02-06 22:22:17 +01001338func Test_getcmdtype()
1339 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1340
1341 let cmdtype = ''
1342 debuggreedy
1343 call feedkeys(":debug echo 'test'\<CR>", "t")
1344 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1345 call feedkeys("cont\<CR>", "xt")
1346 0debuggreedy
1347 call assert_equal('>', cmdtype)
1348
1349 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1350 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1351
1352 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001353 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001354
1355 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1356
1357 cnoremap <expr> <F6> Check_cmdline('=')
1358 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1359 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001360
1361 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001362endfunc
1363
Bram Moolenaar52604f22017-04-07 16:17:39 +02001364func Test_verbosefile()
1365 set verbosefile=Xlog
1366 echomsg 'foo'
1367 echomsg 'bar'
1368 set verbosefile=
1369 let log = readfile('Xlog')
1370 call assert_match("foo\nbar", join(log, "\n"))
1371 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001372 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001373 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001374 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001375endfunc
1376
Bram Moolenaar4facea32019-10-12 20:17:40 +02001377func Test_verbose_option()
1378 CheckScreendump
1379
1380 let lines =<< trim [SCRIPT]
1381 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1382 call feedkeys("\r", 't') " for the hit-enter prompt
1383 set verbose=20
1384 [SCRIPT]
1385 call writefile(lines, 'XTest_verbose')
1386
1387 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001388 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001389 call term_sendkeys(buf, ":DoSomething\<CR>")
1390 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1391
1392 " clean up
1393 call StopVimInTerminal(buf)
1394 call delete('XTest_verbose')
1395endfunc
1396
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001397func Test_setcmdpos()
1398 func InsertTextAtPos(text, pos)
1399 call assert_equal(0, setcmdpos(a:pos))
1400 return a:text
1401 endfunc
1402
1403 " setcmdpos() with position in the middle of the command line.
1404 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1405 call assert_equal('"1ab2', @:)
1406
1407 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1408 call assert_equal('"1b2a', @:)
1409
1410 " setcmdpos() with position beyond the end of the command line.
1411 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1412 call assert_equal('"12ab', @:)
1413
1414 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001415 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001416endfunc
1417
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001418func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001419 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001420 let encoding_save = &encoding
1421
1422 for e in encodings
1423 exe 'set encoding=' . e
1424
1425 " Test overstrike in the middle of the command line.
1426 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001427 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001428
1429 " Test overstrike going beyond end of command line.
1430 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001431 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001432
1433 " Test toggling insert/overstrike a few times.
1434 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001435 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001436 endfor
1437
Bram Moolenaar30276f22019-01-24 17:59:39 +01001438 " Test overstrike with multi-byte characters.
1439 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001440 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001441
1442 let &encoding = encoding_save
1443endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001444
Bram Moolenaar52410572019-10-27 05:12:45 +01001445func Test_buffers_lastused()
1446 " check that buffers are sorted by time when wildmode has lastused
1447 call test_settime(1550020000) " middle
1448 edit bufa
1449 enew
1450 call test_settime(1550030000) " newest
1451 edit bufb
1452 enew
1453 call test_settime(1550010000) " oldest
1454 edit bufc
1455 enew
1456 call test_settime(0)
1457 enew
1458
1459 call assert_equal(['bufa', 'bufb', 'bufc'],
1460 \ getcompletion('', 'buffer'))
1461
1462 let save_wildmode = &wildmode
1463 set wildmode=full:lastused
1464
1465 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1466 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1467 call assert_equal('b bufb', X)
1468 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1469 call assert_equal('b bufa', X)
1470 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1471 call assert_equal('b bufc', X)
1472 enew
1473
1474 edit other
1475 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1476 call assert_equal('b bufb', X)
1477 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1478 call assert_equal('b bufa', X)
1479 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1480 call assert_equal('b bufc', X)
1481 enew
1482
1483 let &wildmode = save_wildmode
1484
1485 bwipeout bufa
1486 bwipeout bufb
1487 bwipeout bufc
1488endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001489
Bram Moolenaar479950f2020-01-19 15:45:17 +01001490func Test_cmdlineclear_tabenter()
1491 CheckScreendump
1492
1493 let lines =<< trim [SCRIPT]
1494 call setline(1, range(30))
1495 [SCRIPT]
1496
1497 call writefile(lines, 'XtestCmdlineClearTabenter')
1498 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001499 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001500 " in one tab make the command line higher with CTRL-W -
1501 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1502 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1503
1504 call StopVimInTerminal(buf)
1505 call delete('XtestCmdlineClearTabenter')
1506endfunc
1507
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001508" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001509func Test_cmdline_expand_special()
1510 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001511 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001512 call assert_fails('e <afile>', 'E495:')
1513 call assert_fails('e <abuf>', 'E496:')
1514 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001515
1516 call writefile([], 'Xfile.cpp')
1517 call writefile([], 'Xfile.java')
1518 new Xfile.cpp
1519 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1520 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1521 close
1522 call delete('Xfile.cpp')
1523 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001524endfunc
1525
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001526" Test for backtick expression in the command line
1527func Test_cmd_backtick()
1528 %argd
1529 argadd `=['a', 'b', 'c']`
1530 call assert_equal(['a', 'b', 'c'], argv())
1531 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001532
1533 argadd `echo abc def`
1534 call assert_equal(['abc def'], argv())
1535 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001536endfunc
1537
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001538" Test for the :! command
1539func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001540 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001541
1542 let lines =<< trim [SCRIPT]
1543 " Test for no previous command
1544 call assert_fails('!!', 'E34:')
1545 set nomore
1546 " Test for cmdline expansion with :!
1547 call setline(1, 'foo!')
1548 silent !echo <cWORD> > Xfile.out
1549 call assert_equal(['foo!'], readfile('Xfile.out'))
1550 " Test for using previous command
1551 silent !echo \! !
1552 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1553 call writefile(v:errors, 'Xresult')
1554 call delete('Xfile.out')
1555 qall!
1556 [SCRIPT]
1557 call writefile(lines, 'Xscript')
1558 if RunVim([], [], '--clean -S Xscript')
1559 call assert_equal([], readfile('Xresult'))
1560 endif
1561 call delete('Xscript')
1562 call delete('Xresult')
1563endfunc
1564
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001565" Test error: "E135: *Filter* Autocommands must not change current buffer"
1566func Test_cmd_bang_E135()
1567 new
1568 call setline(1, ['a', 'b', 'c', 'd'])
1569 augroup test_cmd_filter_E135
1570 au!
1571 autocmd FilterReadPost * help
1572 augroup END
1573 call assert_fails('2,3!echo "x"', 'E135:')
1574
1575 augroup test_cmd_filter_E135
1576 au!
1577 augroup END
1578 %bwipe!
1579endfunc
1580
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001581" Test for using ~ for home directory in cmdline completion matches
1582func Test_cmdline_expand_home()
1583 call mkdir('Xdir')
1584 call writefile([], 'Xdir/Xfile1')
1585 call writefile([], 'Xdir/Xfile2')
1586 cd Xdir
1587 let save_HOME = $HOME
1588 let $HOME = getcwd()
1589 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1590 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1591 let $HOME = save_HOME
1592 cd ..
1593 call delete('Xdir', 'rf')
1594endfunc
1595
Bram Moolenaar578fe942020-02-27 21:32:51 +01001596" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1597" or insert mode (when 'insertmode' is set)
1598func Test_cmdline_ctrl_g()
1599 new
1600 call setline(1, 'abc')
1601 call cursor(1, 3)
1602 " If command line is entered from insert mode, using C-\ C-G should back to
1603 " insert mode
1604 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1605 call assert_equal('abxyc', getline(1))
1606 call assert_equal(4, col('.'))
1607
1608 " If command line is entered in 'insertmode', using C-\ C-G should back to
1609 " 'insertmode'
1610 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1611 call assert_equal('ab12xyc', getline(1))
1612 close!
1613endfunc
1614
Bram Moolenaar578fe942020-02-27 21:32:51 +01001615" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001616func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001617 func T(a, c, p)
1618 return "oneA\noneB\noneC"
1619 endfunc
1620 command -nargs=1 -complete=custom,T MyCmd
1621
Bram Moolenaar578fe942020-02-27 21:32:51 +01001622 set nowildmenu
1623 set wildmode=full,list
1624 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001625 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001626 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001627 call assert_equal('"MyCmd oneA', @:)
1628
1629 set wildmode=longest,full
1630 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1631 call assert_equal('"MyCmd one', @:)
1632 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1633 call assert_equal('"MyCmd oneC', @:)
1634
1635 set wildmode=longest
1636 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1637 call assert_equal('"MyCmd one', @:)
1638
1639 set wildmode=list:longest
1640 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001641 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001642 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001643 call assert_equal('"MyCmd one', @:)
1644
1645 set wildmode=""
1646 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1647 call assert_equal('"MyCmd oneA', @:)
1648
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001649 " Test for wildmode=longest with 'fileignorecase' set
1650 set wildmode=longest
1651 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001652 argadd AAA AAAA AAAAA
1653 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1654 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001655 set fileignorecase&
1656
1657 " Test for listing files with wildmode=list
1658 set wildmode=list
1659 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001660 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001661 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001662 call assert_equal('"b A', @:)
1663
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001664 " when using longest completion match, matches shorter than the argument
1665 " should be ignored (happens with :help)
1666 set wildmode=longest,full
1667 set wildmenu
1668 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1669 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001670 " non existing file
1671 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1672 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001673 set wildmenu&
1674
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001675 " Test for longest file name completion with 'fileignorecase'
1676 " On MS-Windows, file names are case insensitive.
1677 if has('unix')
1678 call writefile([], 'XTESTfoo')
1679 call writefile([], 'Xtestbar')
1680 set nofileignorecase
1681 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1682 call assert_equal('"e XTESTfoo', @:)
1683 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1684 call assert_equal('"e Xtestbar', @:)
1685 set fileignorecase
1686 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1687 call assert_equal('"e Xtest', @:)
1688 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1689 call assert_equal('"e Xtest', @:)
1690 set fileignorecase&
1691 call delete('XTESTfoo')
1692 call delete('Xtestbar')
1693 endif
1694
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001695 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001696 delcommand MyCmd
1697 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001698 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001699 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001700endfunc
1701
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001702func Test_wildmode()
1703 " Test with utf-8 encoding
1704 call Wildmode_tests()
1705
1706 " Test with latin1 encoding
1707 let save_encoding = &encoding
1708 set encoding=latin1
1709 call Wildmode_tests()
1710 let &encoding = save_encoding
1711endfunc
1712
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001713func Test_custom_complete_autoload()
1714 call mkdir('Xdir/autoload', 'p')
1715 let save_rtp = &rtp
1716 exe 'set rtp=' .. getcwd() .. '/Xdir'
1717 let lines =<< trim END
1718 func vim8#Complete(a, c, p)
1719 return "oneA\noneB\noneC"
1720 endfunc
1721 END
1722 call writefile(lines, 'Xdir/autoload/vim8.vim')
1723
1724 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1725 set nowildmenu
1726 set wildmode=full,list
1727 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1728 call assert_equal('"MyCmd oneA oneB oneC', @:)
1729
1730 let &rtp = save_rtp
1731 set wildmode& wildmenu&
1732 delcommand MyCmd
1733 call delete('Xdir', 'rf')
1734endfunc
1735
Bram Moolenaar578fe942020-02-27 21:32:51 +01001736" Test for interrupting the command-line completion
1737func Test_interrupt_compl()
1738 func F(lead, cmdl, p)
1739 if a:lead =~ 'tw'
1740 call interrupt()
1741 return
1742 endif
1743 return "one\ntwo\nthree"
1744 endfunc
1745 command -nargs=1 -complete=custom,F Tcmd
1746
1747 set nowildmenu
1748 set wildmode=full
1749 let interrupted = 0
1750 try
1751 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1752 catch /^Vim:Interrupt$/
1753 let interrupted = 1
1754 endtry
1755 call assert_equal(1, interrupted)
1756
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001757 let interrupted = 0
1758 try
1759 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1760 catch /^Vim:Interrupt$/
1761 let interrupted = 1
1762 endtry
1763 call assert_equal(1, interrupted)
1764
Bram Moolenaar578fe942020-02-27 21:32:51 +01001765 delcommand Tcmd
1766 delfunc F
1767 set wildmode&
1768endfunc
1769
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001770" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001771func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001772 let str = ":one two\<C-U>"
1773 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001774 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001775 let str ..= "\<Left>five\<Right>"
1776 let str ..= "\<Home>two "
1777 let str ..= "\<C-Left>one "
1778 let str ..= "\<C-Right> three"
1779 let str ..= "\<End>\<S-Left>four "
1780 let str ..= "\<S-Right> six"
1781 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1782 call feedkeys(str, 'xt')
1783 call assert_equal("\"one two three four five six seven", @:)
1784endfunc
1785
1786" Test for moving the cursor on the / command line in 'rightleft' mode
1787func Test_cmdline_edit_rightleft()
1788 CheckFeature rightleft
1789 set rightleft
1790 set rightleftcmd=search
1791 let str = "/one two\<C-U>"
1792 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001793 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001794 let str ..= "\<Right>five\<Left>"
1795 let str ..= "\<Home>two "
1796 let str ..= "\<C-Right>one "
1797 let str ..= "\<C-Left> three"
1798 let str ..= "\<End>\<S-Right>four "
1799 let str ..= "\<S-Left> six"
1800 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1801 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1802 call assert_equal("\"one two three four five six seven", @/)
1803 set rightleftcmd&
1804 set rightleft&
1805endfunc
1806
1807" Test for using <C-\>e in the command line to evaluate an expression
1808func Test_cmdline_expr()
1809 " Evaluate an expression from the beginning of a command line
1810 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1811 call assert_equal('"hello', @:)
1812
1813 " Use an invalid expression for <C-\>e
1814 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1815
1816 " Insert literal <CTRL-\> in the command line
1817 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1818 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001819endfunc
1820
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001821" This was making the insert position negative
1822func Test_cmdline_expr_register()
1823 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1824endfunc
1825
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001826" Test for 'imcmdline' and 'imsearch'
1827" This test doesn't actually test the input method functionality.
1828func Test_cmdline_inputmethod()
1829 new
1830 call setline(1, ['', 'abc', ''])
1831 set imcmdline
1832
1833 call feedkeys(":\"abc\<CR>", 'xt')
1834 call assert_equal("\"abc", @:)
1835 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1836 call assert_equal("\"abc", @:)
1837 call feedkeys("/abc\<CR>", 'xt')
1838 call assert_equal([2, 1], [line('.'), col('.')])
1839 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1840 call assert_equal([2, 1], [line('.'), col('.')])
1841
1842 set imsearch=2
1843 call cursor(1, 1)
1844 call feedkeys("/abc\<CR>", 'xt')
1845 call assert_equal([2, 1], [line('.'), col('.')])
1846 call cursor(1, 1)
1847 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1848 call assert_equal([2, 1], [line('.'), col('.')])
1849 set imdisable
1850 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1851 call assert_equal([2, 1], [line('.'), col('.')])
1852 set imdisable&
1853 set imsearch&
1854
1855 set imcmdline&
1856 %bwipe!
1857endfunc
1858
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001859" Test for using CTRL-_ in the command line with 'allowrevins'
1860func Test_cmdline_revins()
1861 CheckNotMSWindows
1862 CheckFeature rightleft
1863 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1864 call assert_equal("\"abc\<c-_>", @:)
1865 set allowrevins
1866 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1867 call assert_equal('"abcñèæ', @:)
1868 set allowrevins&
1869endfunc
1870
1871" Test for typing UTF-8 composing characters in the command line
1872func Test_cmdline_composing_chars()
1873 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1874 call assert_equal('"ゔ', @:)
1875endfunc
1876
Bram Moolenaar0e717042020-04-27 19:29:01 +02001877" test that ";" works to find a match at the start of the first line
1878func Test_zero_line_search()
1879 new
1880 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1881 call cursor(1,1)
1882 0;/pattern/d
1883 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1884 q!
1885endfunc
1886
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001887func Test_read_shellcmd()
1888 CheckUnix
1889 if executable('ls')
1890 " There should be ls in the $PATH
1891 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1892 call assert_match('^"r! .*\<ls\>', @:)
1893 endif
1894
1895 if executable('rm')
1896 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1897 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1898 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001899
1900 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1901 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1902 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001903 endif
1904endfunc
1905
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001906" Test for going up and down the directory tree using 'wildmenu'
1907func Test_wildmenu_dirstack()
1908 CheckUnix
1909 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001910 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001911 call writefile([], 'Xdir1/file1_1.txt')
1912 call writefile([], 'Xdir1/file1_2.txt')
1913 call writefile([], 'Xdir1/dir2/file2_1.txt')
1914 call writefile([], 'Xdir1/dir2/file2_2.txt')
1915 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
1916 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001917 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
1918 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001919 set wildmenu
1920
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001921 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001922 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001923 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001924 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001925 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001926 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001927 call assert_equal('"e ../../dir3/', @:)
1928 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1929 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001930 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001931 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001932 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001933 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001934 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001935 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1936 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
1937
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001938 call delete('Xdir1', 'rf')
1939 set wildmenu&
1940endfunc
1941
obcat71c6f7a2021-05-13 20:23:10 +02001942" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001943" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
1944" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02001945func Test_recalling_cmdline()
1946 CheckFeature cmdline_hist
1947
1948 let g:cmdlines = []
1949 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1950
1951 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001952 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
1953 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
1954 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
1955 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02001956 "\ TODO: {'name': 'debug', ...}
1957 \]
1958 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001959 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
1960 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
1961 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
1962 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
1963 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02001964 \]
1965 let prefix = 'vi'
1966 for h in histories
1967 call histadd(h.name, 'vim')
1968 call histadd(h.name, 'virtue')
1969 call histadd(h.name, 'Virgo')
1970 call histadd(h.name, 'vogue')
1971 call histadd(h.name, 'emacs')
1972 for k in keypairs
1973 let g:cmdlines = []
1974 let keyseqs = h.enter
1975 \ .. prefix
1976 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
1977 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
1978 \ .. h.exit
1979 call feedkeys(keyseqs, 'xt')
1980 call histdel(h.name, -1) " delete the history added by feedkeys above
1981 let expect = k.prefixmatch
1982 \ ? ['virtue', 'vim', 'virtue', prefix]
1983 \ : ['emacs', 'vogue', 'emacs', prefix]
1984 call assert_equal(expect, g:cmdlines)
1985 endfor
1986 endfor
1987
1988 unlet g:cmdlines
1989 cunmap <Plug>(save-cmdline)
1990endfunc
1991
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02001992func Test_cmd_map_cmdlineChanged()
1993 let g:log = []
1994 cnoremap <F1> l<Cmd><CR>s
1995 augroup test
1996 autocmd!
1997 autocmd CmdlineChanged : let g:log += [getcmdline()]
1998 augroup END
1999
2000 call feedkeys(":\<F1>\<CR>", 'xt')
2001 call assert_equal(['l', 'ls'], g:log)
2002
Bram Moolenaar796139a2021-05-18 21:38:45 +02002003 let @b = 'b'
2004 cnoremap <F1> a<C-R>b
2005 let g:log = []
2006 call feedkeys(":\<F1>\<CR>", 'xt')
2007 call assert_equal(['a', 'ab'], g:log)
2008
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002009 unlet g:log
2010 cunmap <F1>
2011 augroup test
2012 autocmd!
2013 augroup END
2014endfunc
2015
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002016" Test for the 'suffixes' option
2017func Test_suffixes_opt()
2018 call writefile([], 'Xfile')
2019 call writefile([], 'Xfile.c')
2020 call writefile([], 'Xfile.o')
2021 set suffixes=
2022 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2023 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002024 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2025 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002026 set suffixes=.c
2027 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2028 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002029 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2030 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002031 set suffixes=,,
2032 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2033 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002034 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2035 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002036 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002037 " Test for getcompletion() with different patterns
2038 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2039 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002040 call delete('Xfile')
2041 call delete('Xfile.c')
2042 call delete('Xfile.o')
2043endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002044
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002045" Test for using a popup menu for the command line completion matches
2046" (wildoptions=pum)
2047func Test_wildmenu_pum()
2048 CheckRunVimInTerminal
2049
2050 let commands =<< trim [CODE]
2051 set wildmenu
2052 set wildoptions=pum
2053 set shm+=I
2054 set noruler
2055 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002056
2057 func CmdCompl(a, b, c)
2058 return repeat(['aaaa'], 120)
2059 endfunc
2060 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002061
2062 func MyStatusLine() abort
2063 return 'status'
2064 endfunc
2065 func SetupStatusline()
2066 set statusline=%!MyStatusLine()
2067 set laststatus=2
2068 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002069
2070 func MyTabLine()
2071 return 'my tab line'
2072 endfunc
2073 func SetupTabline()
2074 set statusline=
2075 set tabline=%!MyTabLine()
2076 set showtabline=2
2077 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002078
2079 func DoFeedKeys()
2080 let &wildcharm = char2nr("\t")
2081 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2082 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002083 [CODE]
2084 call writefile(commands, 'Xtest')
2085
2086 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2087
2088 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002089 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2090
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002091 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002092 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002093 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2094
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002095 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002096 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002097 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2098
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002099 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002100 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002101 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2102
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002103 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002104 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002105 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2106
2107 " pressing <C-E> should end completion and go back to the original match
2108 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002109 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2110
2111 " pressing <C-Y> should select the current match and end completion
2112 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002113 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2114
2115 " With 'wildmode' set to 'longest,full', completing a match should display
2116 " the longest match, the wildmenu should not be displayed.
2117 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2118 call TermWait(buf)
2119 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002120 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2121
2122 " pressing <Tab> should display the wildmenu
2123 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002124 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2125
2126 " pressing <Tab> second time should select the next entry in the menu
2127 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002128 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2129
2130 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002131 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002132 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002133 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2134
2135 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002136 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2137
2138 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002139 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2140
2141 " Directory name completion
2142 call mkdir('Xdir/XdirA/XdirB', 'p')
2143 call writefile([], 'Xdir/XfileA')
2144 call writefile([], 'Xdir/XdirA/XfileB')
2145 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2146
2147 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002148 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2149
2150 " Pressing <Right> on a directory name should go into that directory
2151 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002152 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2153
2154 " Pressing <Left> on a directory name should go to the parent directory
2155 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002156 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2157
2158 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002159 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002160 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002161 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2162
2163 " Pressing <C-D> when the popup menu is displayed should remove the popup
2164 " menu
2165 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002166 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2167
2168 " Pressing <S-Tab> should open the popup menu with the last entry selected
2169 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002170 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2171
2172 " Pressing <Esc> should close the popup menu and cancel the cmd line
2173 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002174 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2175
2176 " Typing a character when the popup is open, should close the popup
2177 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002178 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2179
2180 " When the popup is open, entering the cmdline window should close the popup
2181 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002182 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2183 call term_sendkeys(buf, ":q\<CR>")
2184
2185 " After the last popup menu item, <C-N> should show the original string
2186 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002187 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2188
2189 " Use the popup menu for the command name
2190 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002191 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2192
2193 " Pressing the left arrow should remove the popup menu
2194 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002195 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2196
2197 " Pressing <BS> should remove the popup menu and erase the last character
2198 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002199 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2200
2201 " Pressing <C-W> should remove the popup menu and erase the previous word
2202 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002203 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2204
2205 " Pressing <C-U> should remove the popup menu and erase the entire line
2206 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002207 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2208
2209 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2210 " the cmdline from history
2211 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002212 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2213
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002214 " Check "list" still works
2215 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2216 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002217 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2218 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002219 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2220
rbtnn68cc2b82022-02-09 11:55:47 +00002221 " Tests a directory name contained full-width characters.
2222 call mkdir('Xdir/あいう', 'p')
2223 call writefile([], 'Xdir/あいう/abc')
2224 call writefile([], 'Xdir/あいう/xyz')
2225 call writefile([], 'Xdir/あいう/123')
2226
2227 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2228 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002229 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2230
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002231 " Pressing <C-A> when the popup menu is displayed should list all the
2232 " matches and pressing a key after that should remove the popup menu
2233 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2234 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2235 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2236
2237 " Pressing <C-A> when the popup menu is displayed should list all the
2238 " matches and pressing <Left> after that should move the cursor
2239 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2240 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2241 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2242
2243 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2244 " should be displayed correctly on the screen.
2245 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2246 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2247
2248 " After using <C-A> to expand all the filename matches, pressing <Up>
2249 " should not open the popup menu again.
2250 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2251 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2252 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2253 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2254
2255 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2256 " crash Vim
2257 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2259
Bram Moolenaar414acd32022-02-10 21:09:45 +00002260 " After removing the pum the command line is redrawn
2261 call term_sendkeys(buf, ":edit foo\<CR>")
2262 call term_sendkeys(buf, ":edit bar\<CR>")
2263 call term_sendkeys(buf, ":ls\<CR>")
2264 call term_sendkeys(buf, ":com\<Tab> ")
2265 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002266 call term_sendkeys(buf, "\<C-U>\<CR>")
2267
2268 " Esc still works to abort the command when 'statusline' is set
2269 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2270 call term_sendkeys(buf, ":si\<Tab>")
2271 call term_sendkeys(buf, "\<Esc>")
2272 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002273
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002274 " Esc still works to abort the command when 'tabline' is set
2275 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2276 call term_sendkeys(buf, ":si\<Tab>")
2277 call term_sendkeys(buf, "\<Esc>")
2278 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2279
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002280 " popup is cleared also when 'lazyredraw' is set
2281 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2282 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2283 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2284 call term_sendkeys(buf, "\<Esc>")
2285
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002286 " Pressing <PageDown> should scroll the menu downward
2287 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2288 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2289 call term_sendkeys(buf, "\<PageDown>")
2290 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2291 call term_sendkeys(buf, "\<PageDown>")
2292 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2293 call term_sendkeys(buf, "\<PageDown>")
2294 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2295 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2296 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2297
2298 " Pressing <PageUp> should scroll the menu upward
2299 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2300 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2301 call term_sendkeys(buf, "\<PageUp>")
2302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2303 call term_sendkeys(buf, "\<PageUp>")
2304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2305 call term_sendkeys(buf, "\<PageUp>")
2306 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2307
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002308 call term_sendkeys(buf, "\<C-U>\<CR>")
2309 call StopVimInTerminal(buf)
2310 call delete('Xtest')
2311 call delete('Xdir', 'rf')
2312endfunc
2313
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002314" Test for wildmenumode() with the cmdline popup menu
2315func Test_wildmenumode_with_pum()
2316 set wildmenu
2317 set wildoptions=pum
2318 cnoremap <expr> <F2> wildmenumode()
2319 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2320 call assert_equal('"sign define10', @:)
2321 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2322 call assert_equal('"sign define jump list place undefine unplace0', @:)
2323 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2324 call assert_equal('"sign 0', @:)
2325 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2326 call assert_equal('"sign define0', @:)
2327 set nowildmenu wildoptions&
2328 cunmap <F2>
2329endfunc
2330
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002331func Test_wildmenu_with_pum_foldexpr()
2332 CheckRunVimInTerminal
2333
2334 let lines =<< trim END
2335 call setline(1, ['folded one', 'folded two', 'some more text'])
2336 func MyFoldText()
2337 return 'foo'
2338 endfunc
2339 set foldtext=MyFoldText() wildoptions=pum
2340 normal ggzfj
2341 END
2342 call writefile(lines, 'Xpumfold')
2343 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2344 call term_sendkeys(buf, ":set\<Tab>")
2345 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2346
2347 call term_sendkeys(buf, "\<Esc>")
2348 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2349
2350 call StopVimInTerminal(buf)
2351 call delete('Xpumfold')
2352endfunc
2353
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002354" Test for opening the cmdline completion popup menu from the terminal window.
2355" The popup menu should be positioned correctly over the status line of the
2356" bottom-most window.
2357func Test_wildmenu_pum_from_terminal()
2358 CheckRunVimInTerminal
2359 let python = PythonProg()
2360 call CheckPython(python)
2361
2362 %bw!
2363 let cmds = ['set wildmenu wildoptions=pum']
2364 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2365 call add(cmds, "call term_start('" .. pcmd .. "')")
2366 call writefile(cmds, 'Xtest')
2367 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2368 call term_sendkeys(buf, "\r\r\r")
2369 call term_wait(buf)
2370 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2371 call term_wait(buf)
2372 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2373 call term_wait(buf)
2374 call StopVimInTerminal(buf)
2375 call delete('Xtest')
2376endfunc
2377
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002378" Test for completion after a :substitute command followed by a pipe (|)
2379" character
2380func Test_cmdline_complete_substitute()
2381 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2382 call assert_equal("\"s | \t", @:)
2383 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2384 call assert_equal("\"s/ | \t", @:)
2385 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2386 call assert_equal("\"s/one | \t", @:)
2387 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2388 call assert_equal("\"s/one/ | \t", @:)
2389 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2390 call assert_equal("\"s/one/two | \t", @:)
2391 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2392 call assert_equal('"s/one/two/ | chistory', @:)
2393 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2394 call assert_equal("\"s/one/two/g \t", @:)
2395 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2396 call assert_equal("\"s/one/two/g | chistory", @:)
2397 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2398 call assert_equal("\"s/one/t\\/ | \t", @:)
2399 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2400 call assert_equal('"s/one/t"o/ | chistory', @:)
2401 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2402 call assert_equal('"s/one/t|o/ | chistory', @:)
2403 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2404 call assert_equal("\"&\t", @:)
2405endfunc
2406
2407" Test for the :dlist command completion
2408func Test_cmdline_complete_dlist()
2409 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2410 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2411 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2412 call assert_equal("\"dlist 10 /pat/ \t", @:)
2413 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2414 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2415 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2416 call assert_equal("\"dlist 10 /pat\\\t", @:)
2417 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2418 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2419endfunc
2420
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002421" argument list (only for :argdel) fuzzy completion
2422func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002423 argadd change.py count.py charge.py
2424 set wildoptions&
2425 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2426 call assert_equal('"argdel cge', @:)
2427 set wildoptions=fuzzy
2428 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2429 call assert_equal('"argdel change.py charge.py', @:)
2430 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002431 set wildoptions&
2432endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002433
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002434" autocmd group name fuzzy completion
2435func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002436 set wildoptions&
2437 augroup MyFuzzyGroup
2438 augroup END
2439 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2440 call assert_equal('"augroup mfg', @:)
2441 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2442 call assert_equal('"augroup MyFuzzyGroup', @:)
2443 set wildoptions=fuzzy
2444 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2445 call assert_equal('"augroup MyFuzzyGroup', @:)
2446 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2447 call assert_equal('"augroup My*p', @:)
2448 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002449 set wildoptions&
2450endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002451
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002452" buffer name fuzzy completion
2453func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002454 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002455 " Use a long name to reduce the risk of matching a random directory name
2456 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002457 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002458 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2459 call assert_equal('"b SRFWL', @:)
2460 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2461 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002462 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002463 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2464 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2465 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2466 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002467 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002468 set wildoptions&
2469endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002470
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002471" buffer name (full path) fuzzy completion
2472func Test_fuzzy_completion_bufname_fullpath()
2473 CheckUnix
2474 set wildoptions&
2475 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2476 edit Xcmd/Xstate/Xfile.js
2477 cd Xcmd/Xstate
2478 enew
2479 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2480 call assert_equal('"b CmdStateFile', @:)
2481 set wildoptions=fuzzy
2482 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2483 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2484 cd -
2485 call delete('Xcmd', 'rf')
2486 set wildoptions&
2487endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002488
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002489" :behave suboptions fuzzy completion
2490func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002491 set wildoptions&
2492 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2493 call assert_equal('"behave xm', @:)
2494 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2495 call assert_equal('"behave xterm', @:)
2496 set wildoptions=fuzzy
2497 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2498 call assert_equal('"behave xterm', @:)
2499 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2500 call assert_equal('"behave xt*m', @:)
2501 let g:Sline = ''
2502 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2503 call assert_equal('mswin', g:Sline)
2504 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002505 set wildoptions&
2506endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002507
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002508" " colorscheme name fuzzy completion - NOT supported
2509" func Test_fuzzy_completion_colorscheme()
2510" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002511
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002512" built-in command name fuzzy completion
2513func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002514 set wildoptions&
2515 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2516 call assert_equal('"sbwin', @:)
2517 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2518 call assert_equal('"sbrewind', @:)
2519 set wildoptions=fuzzy
2520 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2521 call assert_equal('"sbrewind', @:)
2522 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2523 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002524 set wildoptions&
2525endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002526
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002527" " compiler name fuzzy completion - NOT supported
2528" func Test_fuzzy_completion_compiler()
2529" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002530
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002531" :cscope suboptions fuzzy completion
2532func Test_fuzzy_completion_cscope()
2533 CheckFeature cscope
2534 set wildoptions&
2535 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2536 call assert_equal('"cscope ret', @:)
2537 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2538 call assert_equal('"cscope reset', @:)
2539 set wildoptions=fuzzy
2540 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2541 call assert_equal('"cscope reset', @:)
2542 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2543 call assert_equal('"cscope re*t', @:)
2544 set wildoptions&
2545endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002546
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002547" :diffget/:diffput buffer name fuzzy completion
2548func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002549 new SomeBuffer
2550 diffthis
2551 new OtherBuffer
2552 diffthis
2553 set wildoptions&
2554 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2555 call assert_equal('"diffget sbuf', @:)
2556 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2557 call assert_equal('"diffput sbuf', @:)
2558 set wildoptions=fuzzy
2559 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2560 call assert_equal('"diffget SomeBuffer', @:)
2561 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2562 call assert_equal('"diffput SomeBuffer', @:)
2563 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002564 set wildoptions&
2565endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002566
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002567" " directory name fuzzy completion - NOT supported
2568" func Test_fuzzy_completion_dirname()
2569" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002570
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002571" environment variable name fuzzy completion
2572func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002573 set wildoptions&
2574 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2575 call assert_equal('"echo $VUT', @:)
2576 set wildoptions=fuzzy
2577 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2578 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002579 set wildoptions&
2580endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002581
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002582" autocmd event fuzzy completion
2583func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002584 set wildoptions&
2585 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2586 call assert_equal('"autocmd BWout', @:)
2587 set wildoptions=fuzzy
2588 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2589 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002590 set wildoptions&
2591endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002592
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002593" vim expression fuzzy completion
2594func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002595 let g:PerPlaceCount = 10
2596 set wildoptions&
2597 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2598 call assert_equal('"let c = ppc', @:)
2599 set wildoptions=fuzzy
2600 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002602 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002603endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002604
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002605" " file name fuzzy completion - NOT supported
2606" func Test_fuzzy_completion_filename()
2607" endfunc
2608
2609" " files in path fuzzy completion - NOT supported
2610" func Test_fuzzy_completion_filesinpath()
2611" endfunc
2612
2613" " filetype name fuzzy completion - NOT supported
2614" func Test_fuzzy_completion_filetype()
2615" endfunc
2616
2617" user defined function name completion
2618func Test_fuzzy_completion_userdefined_func()
2619 set wildoptions&
2620 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2621 call assert_equal('"call Test_f_u_f', @:)
2622 set wildoptions=fuzzy
2623 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2624 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2625 set wildoptions&
2626endfunc
2627
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002628" <SNR> functions should be sorted to the end
2629func Test_fuzzy_completion_userdefined_snr_func()
2630 func s:Sendmail()
2631 endfunc
2632 func SendSomemail()
2633 endfunc
2634 func S1e2n3dmail()
2635 endfunc
2636 set wildoptions=fuzzy
2637 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002638 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002639 set wildoptions&
2640 delfunc s:Sendmail
2641 delfunc SendSomemail
2642 delfunc S1e2n3dmail
2643endfunc
2644
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002645" user defined command name completion
2646func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002647 set wildoptions&
2648 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2649 call assert_equal('"MsFeat', @:)
2650 set wildoptions=fuzzy
2651 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2652 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002653 set wildoptions&
2654endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002655
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002656" " :help tag fuzzy completion - NOT supported
2657" func Test_fuzzy_completion_helptag()
2658" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002659
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002660" highlight group name fuzzy completion
2661func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002662 set wildoptions&
2663 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2664 call assert_equal('"highlight SKey', @:)
2665 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2666 call assert_equal('"highlight SpecialKey', @:)
2667 set wildoptions=fuzzy
2668 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2669 call assert_equal('"highlight SpecialKey', @:)
2670 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2671 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002672 set wildoptions&
2673endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002674
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002675" :history suboptions fuzzy completion
2676func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002677 set wildoptions&
2678 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2679 call assert_equal('"history dg', @:)
2680 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal('"history search', @:)
2682 set wildoptions=fuzzy
2683 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2684 call assert_equal('"history debug', @:)
2685 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2686 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002687 set wildoptions&
2688endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002689
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002690" :language locale name fuzzy completion
2691func Test_fuzzy_completion_lang()
2692 CheckUnix
2693 set wildoptions&
2694 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2695 call assert_equal('"lang psx', @:)
2696 set wildoptions=fuzzy
2697 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2698 call assert_equal('"lang POSIX', @:)
2699 set wildoptions&
2700endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002701
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002702" :mapclear buffer argument fuzzy completion
2703func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002704 set wildoptions&
2705 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2706 call assert_equal('"mapclear buf', @:)
2707 set wildoptions=fuzzy
2708 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2709 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002710 set wildoptions&
2711endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002712
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002713" map name fuzzy completion
2714func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002715 " test regex completion works
2716 set wildoptions=fuzzy
2717 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002719 nmap <plug>MyLongMap :p<CR>
2720 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2721 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2722 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal("\"nmap MLM \t", @:)
2724 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal("\"nmap <F2> one two \t", @:)
2726 " duplicate entries should be removed
2727 vmap <plug>MyLongMap :<C-U>#<CR>
2728 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2729 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2730 nunmap <plug>MyLongMap
2731 vunmap <plug>MyLongMap
2732 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal("\"nmap ABC\t", @:)
2734 " results should be sorted by best match
2735 nmap <Plug>format :
2736 nmap <Plug>goformat :
2737 nmap <Plug>TestFOrmat :
2738 nmap <Plug>fendoff :
2739 nmap <Plug>state :
2740 nmap <Plug>FendingOff :
2741 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2742 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2743 nunmap <Plug>format
2744 nunmap <Plug>goformat
2745 nunmap <Plug>TestFOrmat
2746 nunmap <Plug>fendoff
2747 nunmap <Plug>state
2748 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002749 set wildoptions&
2750endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002751
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002752" abbreviation fuzzy completion
2753func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002754 set wildoptions=fuzzy
2755 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2756 call assert_equal("\"iabbr <nowait>", @:)
2757 iabbr WaitForCompletion WFC
2758 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2759 call assert_equal("\"iabbr WaitForCompletion", @:)
2760 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal("\"iabbr a1z\t", @:)
2762 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002763 set wildoptions&
2764endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002765
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002766" menu name fuzzy completion
2767func Test_fuzzy_completion_menu()
2768 CheckGui
2769 set wildoptions&
2770 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2771 call assert_equal('"menu pup', @:)
2772 set wildoptions=fuzzy
2773 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2774 call assert_equal('"menu PopUp.', @:)
2775 set wildoptions&
2776endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002777
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002778" :messages suboptions fuzzy completion
2779func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002780 set wildoptions&
2781 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2782 call assert_equal('"messages clr', @:)
2783 set wildoptions=fuzzy
2784 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2785 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002786 set wildoptions&
2787endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002788
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002789" :set option name fuzzy completion
2790func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002791 set wildoptions&
2792 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2793 call assert_equal('"set brkopt', @:)
2794 set wildoptions=fuzzy
2795 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2796 call assert_equal('"set breakindentopt', @:)
2797 set wildoptions&
2798 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2799 call assert_equal('"set fixendofline', @:)
2800 set wildoptions=fuzzy
2801 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2802 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002803 set wildoptions&
2804endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002805
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002806" :set <term_option>
2807func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002808 set wildoptions&
2809 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"set t_EC', @:)
2811 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2812 call assert_equal('"set <t_EC>', @:)
2813 set wildoptions=fuzzy
2814 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2815 call assert_equal('"set t_EC', @:)
2816 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2817 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818 set wildoptions&
2819endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002821" " :packadd directory name fuzzy completion - NOT supported
2822" func Test_fuzzy_completion_packadd()
2823" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002824
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002825" " shell command name fuzzy completion - NOT supported
2826" func Test_fuzzy_completion_shellcmd()
2827" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002828
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002829" :sign suboptions fuzzy completion
2830func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002831 set wildoptions&
2832 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2833 call assert_equal('"sign ufe', @:)
2834 set wildoptions=fuzzy
2835 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2836 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837 set wildoptions&
2838endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002839
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002840" :syntax suboptions fuzzy completion
2841func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002842 set wildoptions&
2843 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"syntax kwd', @:)
2845 set wildoptions=fuzzy
2846 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2847 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002848 set wildoptions&
2849endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002850
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002851" syntax group name fuzzy completion
2852func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002853 set wildoptions&
2854 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2855 call assert_equal('"syntax list mpar', @:)
2856 set wildoptions=fuzzy
2857 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002859 set wildoptions&
2860endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002861
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002862" :syntime suboptions fuzzy completion
2863func Test_fuzzy_completion_syntime()
2864 CheckFeature profile
2865 set wildoptions&
2866 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2867 call assert_equal('"syntime clr', @:)
2868 set wildoptions=fuzzy
2869 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2870 call assert_equal('"syntime clear', @:)
2871 set wildoptions&
2872endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002873
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002874" " tag name fuzzy completion - NOT supported
2875" func Test_fuzzy_completion_tagname()
2876" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002877
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002878" " tag name and file fuzzy completion - NOT supported
2879" func Test_fuzzy_completion_tagfile()
2880" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002881
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002882" " user names fuzzy completion - how to test this functionality?
2883" func Test_fuzzy_completion_username()
2884" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002885
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002886" user defined variable name fuzzy completion
2887func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002888 let g:SomeVariable=10
2889 set wildoptions&
2890 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2891 call assert_equal('"let SVar', @:)
2892 set wildoptions=fuzzy
2893 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2894 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002895 set wildoptions&
2896endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002897
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002898" Test for sorting the results by the best match
2899func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002900 %bw!
2901 command T123format :
2902 command T123goformat :
2903 command T123TestFOrmat :
2904 command T123fendoff :
2905 command T123state :
2906 command T123FendingOff :
2907 set wildoptions=fuzzy
2908 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2909 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2910 delcommand T123format
2911 delcommand T123goformat
2912 delcommand T123TestFOrmat
2913 delcommand T123fendoff
2914 delcommand T123state
2915 delcommand T123FendingOff
2916 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002917 set wildoptions&
2918endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002919
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002920" Test for fuzzy completion of a command with lower case letters and a number
2921func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002922 command Foo2Bar :
2923 set wildoptions=fuzzy
2924 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2925 call assert_equal('"Foo2Bar', @:)
2926 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2927 call assert_equal('"Foo2Bar', @:)
2928 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2929 call assert_equal('"Foo2Bar', @:)
2930 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002931 set wildoptions&
2932endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002933
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002934" Test for command completion for a command starting with 'k'
2935func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002936 command KillKillKill :
2937 set wildoptions&
2938 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal("\"killkill\<Tab>", @:)
2940 set wildoptions=fuzzy
2941 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2942 call assert_equal('"KillKillKill', @:)
2943 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002944 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002945endfunc
2946
2947" Test for fuzzy completion for user defined custom completion function
2948func Test_fuzzy_completion_custom_func()
2949 func Tcompl(a, c, p)
2950 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
2951 endfunc
2952 command -nargs=* -complete=custom,Tcompl Fuzzy :
2953 set wildoptions&
2954 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2955 call assert_equal("\"Fuzzy format", @:)
2956 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal("\"Fuzzy xy", @:)
2958 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2959 call assert_equal("\"Fuzzy ttt", @:)
2960 set wildoptions=fuzzy
2961 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
2962 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
2963 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2964 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
2965 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal("\"Fuzzy xy", @:)
2967 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal("\"Fuzzy TestFOrmat", @:)
2969 delcom Fuzzy
2970 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002971endfunc
2972
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00002973" Test for :breakadd argument completion
2974func Test_cmdline_complete_breakadd()
2975 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
2976 call assert_equal("\"breakadd expr file func here", @:)
2977 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
2978 call assert_equal("\"breakadd expr", @:)
2979 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
2980 call assert_equal("\"breakadd expr", @:)
2981 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
2982 call assert_equal("\"breakadd here", @:)
2983 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal("\"breakadd here", @:)
2985 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
2986 call assert_equal("\"breakadd abc", @:)
2987 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
2988 let l = getcompletion('not', 'breakpoint')
2989 call assert_equal([], l)
2990
2991 " Test for :breakadd file [lnum] <file>
2992 call writefile([], 'Xscript')
2993 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal("\"breakadd file Xscript", @:)
2995 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal("\"breakadd file Xscript", @:)
2997 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal("\"breakadd file 20 Xscript", @:)
2999 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3000 call assert_equal("\"breakadd file 20 Xscript", @:)
3001 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3003 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3004 call assert_equal("\"breakadd file 20\t", @:)
3005 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3006 call assert_equal("\"breakadd file 20x\t", @:)
3007 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3008 call assert_equal("\"breakadd file Xscript ", @:)
3009 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal("\"breakadd file X1B2C3", @:)
3011 call delete('Xscript')
3012
3013 " Test for :breakadd func [lnum] <function>
3014 func Xbreak_func()
3015 endfunc
3016 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3017 call assert_equal("\"breakadd func Xbreak_func", @:)
3018 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3019 call assert_equal("\"breakadd func Xbreak_func", @:)
3020 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3021 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3022 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3023 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3024 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3026 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal("\"breakadd func 20\t", @:)
3028 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal("\"breakadd func 20x\t", @:)
3030 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal("\"breakadd func Xbreak_func ", @:)
3032 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal("\"breakadd func X1B2C3", @:)
3034 delfunc Xbreak_func
3035
3036 " Test for :breakadd expr <expression>
3037 let g:Xtest_var = 10
3038 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3039 call assert_equal("\"breakadd expr Xtest_var", @:)
3040 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal("\"breakadd expr Xtest_var", @:)
3042 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal("\"breakadd expr Xtest_var ", @:)
3044 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal("\"breakadd expr X1B2C3", @:)
3046 unlet g:Xtest_var
3047
3048 " Test for :breakadd here
3049 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal("\"breakadd here Xtest", @:)
3051 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal("\"breakadd here Xtest", @:)
3053 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal("\"breakadd here ", @:)
3055endfunc
3056
3057" Test for :breakdel argument completion
3058func Test_cmdline_complete_breakdel()
3059 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal("\"breakdel file func here", @:)
3061 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3062 call assert_equal("\"breakdel file", @:)
3063 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal("\"breakdel file", @:)
3065 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3066 call assert_equal("\"breakdel here", @:)
3067 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3068 call assert_equal("\"breakdel here", @:)
3069 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal("\"breakdel abc", @:)
3071
3072 " Test for :breakdel file [lnum] <file>
3073 call writefile([], 'Xscript')
3074 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal("\"breakdel file Xscript", @:)
3076 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3077 call assert_equal("\"breakdel file Xscript", @:)
3078 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal("\"breakdel file 20 Xscript", @:)
3080 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal("\"breakdel file 20 Xscript", @:)
3082 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3084 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal("\"breakdel file 20\t", @:)
3086 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3087 call assert_equal("\"breakdel file 20x\t", @:)
3088 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3089 call assert_equal("\"breakdel file Xscript ", @:)
3090 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3091 call assert_equal("\"breakdel file X1B2C3", @:)
3092 call delete('Xscript')
3093
3094 " Test for :breakdel func [lnum] <function>
3095 func Xbreak_func()
3096 endfunc
3097 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal("\"breakdel func Xbreak_func", @:)
3099 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal("\"breakdel func Xbreak_func", @:)
3101 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3103 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3105 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3107 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakdel func 20\t", @:)
3109 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"breakdel func 20x\t", @:)
3111 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"breakdel func Xbreak_func ", @:)
3113 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"breakdel func X1B2C3", @:)
3115 delfunc Xbreak_func
3116
3117 " Test for :breakdel here
3118 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal("\"breakdel here Xtest", @:)
3120 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"breakdel here Xtest", @:)
3122 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003124endfunc
3125
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003126" Test for :scriptnames argument completion
3127func Test_cmdline_complete_scriptnames()
3128 set wildmenu
3129 call writefile(['let a = 1'], 'Xa1b2c3.vim')
3130 source Xa1b2c3.vim
3131 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3132 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3133 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3134 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3135 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"script b2c3", @:)
3137 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_match("\"script 2\<Tab>$", @:)
3139 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3141 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"script ", @:)
3143 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3144 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3145 new
3146 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3147 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3148 bw!
3149 call delete('Xa1b2c3.vim')
3150 set wildmenu&
3151endfunc
3152
Bram Moolenaard8893442022-05-06 20:38:47 +01003153" this was going over the end of IObuff
3154func Test_report_error_with_composing()
3155 let caught = 'no'
3156 try
3157 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3158 catch /E492:/
3159 let caught = 'yes'
3160 endtry
3161 call assert_equal('yes', caught)
3162endfunc
3163
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003164" Test for expanding 2-letter and 3-letter :substitute command arguments.
3165" These commands don't accept an argument.
3166func Test_cmdline_complete_substitute_short()
3167 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3168 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3169 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3170 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3171 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3172 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3174 endfor
3175endfunc
3176
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003177" Test for :! shell command argument completion
3178func Test_cmdline_complete_bang_cmd_argument()
3179 set wildoptions=fuzzy
3180 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3181 call assert_equal('"!vim test_cmdline.vim', @:)
3182 set wildoptions&
3183 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3184 call assert_equal('"!vim test_cmdline.vim', @:)
3185endfunc
3186
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003187func Check_completion()
3188 call assert_equal('let a', getcmdline())
3189 call assert_equal(6, getcmdpos())
3190 call assert_equal(7, getcmdscreenpos())
3191 call assert_equal('var', getcmdcompltype())
3192 return ''
3193endfunc
3194
3195func Test_screenpos_and_completion()
3196 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3197endfunc
3198
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003199func Test_recursive_register()
3200 let @= = ''
3201 silent! ?e/
3202 let caught = 'no'
3203 try
3204 normal //
3205 catch /E169:/
3206 let caught = 'yes'
3207 endtry
3208 call assert_equal('yes', caught)
3209endfunc
3210
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003211func Test_long_error_message()
3212 " the error should be truncated, not overrun IObuff
3213 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3214endfunc
3215
zeertzjq6791adc2022-07-26 20:42:25 +01003216func Test_cmdline_redraw_tabline()
3217 CheckRunVimInTerminal
3218
3219 let lines =<< trim END
3220 set showtabline=2
3221 autocmd CmdlineEnter * set tabline=foo
3222 END
3223 call writefile(lines, 'Xcmdline_redraw_tabline')
3224 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3225 call term_sendkeys(buf, ':')
3226 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3227
3228 call StopVimInTerminal(buf)
3229 call delete('Xcmdline_redraw_tabline')
3230endfunc
3231
Bram Moolenaar309976e2019-12-05 18:16:33 +01003232" vim: shiftwidth=2 sts=2 expandtab