blob: 8034bdb3e0a03c9df8340b87e80aee2356d2c1ef [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 Moolenaarcf5fdf72017-03-02 23:05:51 +0100196func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100197 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
198 call assert_equal('"map <unique> <silent>', getreg(':'))
199 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
200 call assert_equal('"map <script> <unique>', getreg(':'))
201 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
202 call assert_equal('"map <expr> <script>', getreg(':'))
203 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
204 call assert_equal('"map <buffer> <expr>', getreg(':'))
205 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
206 call assert_equal('"map <nowait> <buffer>', getreg(':'))
207 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
208 call assert_equal('"map <special> <nowait>', getreg(':'))
209 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
210 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200211
Bram Moolenaar1776a282019-05-03 16:05:41 +0200212 map <Middle>x middle
213
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200214 map ,f commaf
215 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200216 map <Left> left
217 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200218 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
219 call assert_equal('"map ,f', getreg(':'))
220 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
221 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200222 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
223 call assert_equal('"map <Left>', getreg(':'))
224 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200225 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200226 unmap ,f
227 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200228 unmap <Left>
229 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200230
231 set cpo-=< cpo-=B cpo-=k
232 map <Left> left
233 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
234 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200235 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200236 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200237 unmap <Left>
238
239 set cpo+=<
240 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200241 exe "set t_k6=\<Esc>[17~"
242 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200243 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
244 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200245 if !has('gui_running')
246 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
247 call assert_equal("\"map <F6>x", getreg(':'))
248 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200249 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200250 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200251 set cpo-=<
252
253 set cpo+=B
254 map <Left> left
255 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
256 call assert_equal('"map <Left>', getreg(':'))
257 unmap <Left>
258 set cpo-=B
259
260 set cpo+=k
261 map <Left> left
262 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
263 call assert_equal('"map <Left>', getreg(':'))
264 unmap <Left>
265 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200266
Bram Moolenaar531be472020-09-23 22:38:05 +0200267 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
268
Bram Moolenaar1776a282019-05-03 16:05:41 +0200269 unmap <Middle>x
270 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100271endfunc
272
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100273func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100274 hi Aardig ctermfg=green
275 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000276 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100277 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000278 call assert_equal('"match none', @:)
279 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
280 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100281endfunc
282
283func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100284 hi Aardig ctermfg=green
285 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
286 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200287 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
288 call assert_equal('"hi default Aardig', getreg(':'))
289 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
290 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100291 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
292 call assert_equal('"hi link', getreg(':'))
293 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
294 call assert_equal('"hi default', getreg(':'))
295 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
296 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200297 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
298 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
299 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
300 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200301
302 " A cleared group does not show up in completions.
303 hi Anders ctermfg=green
304 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
305 hi clear Aardig
306 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
307 hi clear Anders
308 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100309endfunc
310
Bram Moolenaar75e15672020-06-28 13:10:22 +0200311" Test for command-line expansion of "hi Ni " (easter egg)
312func Test_highlight_easter_egg()
313 call test_override('ui_delay', 1)
314 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
315 call assert_equal("\"hi Ni \<Tab>", @:)
316 call test_override('ALL', 0)
317endfunc
318
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200319func Test_getcompletion()
320 let groupcount = len(getcompletion('', 'event'))
321 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200322 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200323 call assert_true(matchcount > 0)
324 call assert_true(groupcount > matchcount)
325
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200326 if has('menu')
327 source $VIMRUNTIME/menu.vim
328 let matchcount = len(getcompletion('', 'menu'))
329 call assert_true(matchcount > 0)
330 call assert_equal(['File.'], getcompletion('File', 'menu'))
331 call assert_true(matchcount > 0)
332 let matchcount = len(getcompletion('File.', 'menu'))
333 call assert_true(matchcount > 0)
334 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200335
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200336 let l = getcompletion('v:n', 'var')
337 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200338 let l = getcompletion('v:notexists', 'var')
339 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200340
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200341 args a.c b.c
342 let l = getcompletion('', 'arglist')
343 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000344 let l = getcompletion('a.', 'buffer')
345 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200346 %argdelete
347
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200348 let l = getcompletion('', 'augroup')
349 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200350 let l = getcompletion('blahblah', 'augroup')
351 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200352
353 let l = getcompletion('', 'behave')
354 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200355 let l = getcompletion('not', 'behave')
356 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200357
358 let l = getcompletion('', 'color')
359 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200360 let l = getcompletion('dirty', 'color')
361 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200362
363 let l = getcompletion('', 'command')
364 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200365 let l = getcompletion('awake', 'command')
366 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200367
368 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200369 call assert_true(index(l, 'samples/') >= 0)
370 let l = getcompletion('NoMatch', 'dir')
371 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200372
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100373 if glob('~/*') !=# ''
374 let l = getcompletion('~/', 'dir')
375 call assert_true(l[0][0] ==# '~')
376 endif
377
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200378 let l = getcompletion('exe', 'expression')
379 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200380 let l = getcompletion('kill', 'expression')
381 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200382
383 let l = getcompletion('tag', 'function')
384 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200385 let l = getcompletion('paint', 'function')
386 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200387
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200388 let Flambda = {-> 'hello'}
389 let l = getcompletion('', 'function')
390 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200391 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200392
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200393 let l = getcompletion('run', 'file')
394 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200395 let l = getcompletion('walk', 'file')
396 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200397 set wildignore=*.vim
398 let l = getcompletion('run', 'file', 1)
399 call assert_true(index(l, 'runtest.vim') < 0)
400 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000401 " Directory name with space character
402 call mkdir('Xdir with space')
403 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
404 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
405 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200406
407 let l = getcompletion('ha', 'filetype')
408 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200409 let l = getcompletion('horse', 'filetype')
410 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200411
412 let l = getcompletion('z', 'syntax')
413 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200414 let l = getcompletion('emacs', 'syntax')
415 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200416
417 let l = getcompletion('jikes', 'compiler')
418 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200419 let l = getcompletion('break', 'compiler')
420 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200421
422 let l = getcompletion('last', 'help')
423 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200424 let l = getcompletion('giveup', 'help')
425 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200426
427 let l = getcompletion('time', 'option')
428 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200429 let l = getcompletion('space', 'option')
430 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200431
432 let l = getcompletion('er', 'highlight')
433 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200434 let l = getcompletion('dark', 'highlight')
435 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200436
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200437 let l = getcompletion('', 'messages')
438 call assert_true(index(l, 'clear') >= 0)
439 let l = getcompletion('not', 'messages')
440 call assert_equal([], l)
441
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200442 let l = getcompletion('', 'mapclear')
443 call assert_true(index(l, '<buffer>') >= 0)
444 let l = getcompletion('not', 'mapclear')
445 call assert_equal([], l)
446
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200447 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200448 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200449 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
450 let root = has('win32') ? 'C:\\' : '/'
451 let l = getcompletion(root, 'shellcmd')
452 let expected = map(filter(glob(root . '*', 0, 1),
453 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
454 call assert_equal(expected, l)
455
Bram Moolenaarb650b982016-08-05 20:35:13 +0200456 if has('cscope')
457 let l = getcompletion('', 'cscope')
458 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
459 call assert_equal(cmds, l)
460 " using cmdline completion must not change the result
461 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
462 let l = getcompletion('', 'cscope')
463 call assert_equal(cmds, l)
464 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
465 let l = getcompletion('find ', 'cscope')
466 call assert_equal(keys, l)
467 endif
468
Bram Moolenaar7522f692016-08-06 14:12:50 +0200469 if has('signs')
470 sign define Testing linehl=Comment
471 let l = getcompletion('', 'sign')
472 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
473 call assert_equal(cmds, l)
474 " using cmdline completion must not change the result
475 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
476 let l = getcompletion('', 'sign')
477 call assert_equal(cmds, l)
478 let l = getcompletion('list ', 'sign')
479 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000480 let l = getcompletion('de*', 'sign')
481 call assert_equal(['define'], l)
482 let l = getcompletion('p?', 'sign')
483 call assert_equal(['place'], l)
484 let l = getcompletion('j.', 'sign')
485 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200486 endif
487
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200488 " Command line completion tests
489 let l = getcompletion('cd ', 'cmdline')
490 call assert_true(index(l, 'samples/') >= 0)
491 let l = getcompletion('cd NoMatch', 'cmdline')
492 call assert_equal([], l)
493 let l = getcompletion('let v:n', 'cmdline')
494 call assert_true(index(l, 'v:null') >= 0)
495 let l = getcompletion('let v:notexists', 'cmdline')
496 call assert_equal([], l)
497 let l = getcompletion('call tag', 'cmdline')
498 call assert_true(index(l, 'taglist(') >= 0)
499 let l = getcompletion('call paint', 'cmdline')
500 call assert_equal([], l)
501
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100502 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000503 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100504 return "oneA\noneB\noneC"
505 endfunc
506 command -nargs=1 -complete=custom,T MyCmd
507 let l = getcompletion('MyCmd ', 'cmdline')
508 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000509 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100510
511 delcommand MyCmd
512 delfunc T
ii144785fe02021-11-21 12:13:56 +0000513 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100514
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200515 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200516 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200517 if has('cmdline_hist')
518 call add(names, 'history')
519 endif
520 if has('gettext')
521 call add(names, 'locale')
522 endif
523 if has('profile')
524 call add(names, 'syntime')
525 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200526
527 set tags=Xtags
528 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
529
530 for name in names
531 let matchcount = len(getcompletion('', name))
532 call assert_true(matchcount >= 0, 'No matches for ' . name)
533 endfor
534
535 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200536 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200537
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000538 edit a~b
539 enew
540 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
541 bw a~b
542
543 if has('unix')
544 edit Xtest\
545 enew
546 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
547 bw Xtest\
548 endif
549
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200550 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200551 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200552 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200553endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200554
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000555" Test for getcompletion() with "fuzzy" in 'wildoptions'
556func Test_getcompletion_wildoptions()
557 let save_wildoptions = &wildoptions
558 set wildoptions&
559 let l = getcompletion('space', 'option')
560 call assert_equal([], l)
561 let l = getcompletion('ier', 'command')
562 call assert_equal([], l)
563 set wildoptions=fuzzy
564 let l = getcompletion('space', 'option')
565 call assert_true(index(l, 'backspace') >= 0)
566 let l = getcompletion('ier', 'command')
567 call assert_true(index(l, 'compiler') >= 0)
568 let &wildoptions = save_wildoptions
569endfunc
570
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000571func Test_complete_autoload_error()
572 let save_rtp = &rtp
573 let lines =<< trim END
574 vim9script
575 export def Complete(..._): string
576 return 'match'
577 enddef
578 echo this will cause an error
579 END
580 call mkdir('Xdir/autoload', 'p')
581 call writefile(lines, 'Xdir/autoload/script.vim')
582 exe 'set rtp+=' .. getcwd() .. '/Xdir'
583
584 let lines =<< trim END
585 vim9script
586 import autoload 'script.vim'
587 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
588 &wildcharm = char2nr("\<Tab>")
589 feedkeys(":Cmd \<Tab>", 'xt')
590 END
591 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
592
593 let &rtp = save_rtp
594 call delete('Xdir', 'rf')
595endfunc
596
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100597func Test_fullcommand()
598 let tests = {
599 \ '': '',
600 \ ':': '',
601 \ ':::': '',
602 \ ':::5': '',
603 \ 'not_a_cmd': '',
604 \ 'Check': '',
605 \ 'syntax': 'syntax',
606 \ ':syntax': 'syntax',
607 \ '::::syntax': 'syntax',
608 \ 'sy': 'syntax',
609 \ 'syn': 'syntax',
610 \ 'synt': 'syntax',
611 \ ':sy': 'syntax',
612 \ '::::sy': 'syntax',
613 \ 'match': 'match',
614 \ '2match': 'match',
615 \ '3match': 'match',
616 \ 'aboveleft': 'aboveleft',
617 \ 'abo': 'aboveleft',
618 \ 's': 'substitute',
619 \ '5s': 'substitute',
620 \ ':5s': 'substitute',
621 \ "'<,'>s": 'substitute',
622 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100623 \ 'CheckLin': 'CheckLinux',
624 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100625 \ }
626
627 for [in, want] in items(tests)
628 call assert_equal(want, fullcommand(in))
629 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200630 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100631
632 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200633
634 command -buffer BufferLocalCommand :
635 command GlobalCommand :
636 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
637 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
638 delcommand BufferLocalCommand
639 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100640endfunc
641
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200642func Test_shellcmd_completion()
643 let save_path = $PATH
644
645 call mkdir('Xpathdir/Xpathsubdir', 'p')
646 call writefile([''], 'Xpathdir/Xfile.exe')
647 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
648
649 " Set PATH to example directory without trailing slash.
650 let $PATH = getcwd() . '/Xpathdir'
651
652 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
653 " dirs in the PATH, even though they won't be executed. We check that only
654 " subdirs of the PWD and executables from the PATH are included in the
655 " suggestions.
656 let actual = getcompletion('X', 'shellcmd')
657 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
658 call insert(expected, 'Xfile.exe')
659 call assert_equal(expected, actual)
660
661 call delete('Xpathdir', 'rf')
662 let $PATH = save_path
663endfunc
664
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200665func Test_expand_star_star()
666 call mkdir('a/b', 'p')
667 call writefile(['asdfasdf'], 'a/b/fileXname')
668 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000669 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200670 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200671 call delete('a', 'rf')
672endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100673
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100674func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100675 let @a = "def"
676 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
677 call assert_equal('"abc def ghi', @:)
678
679 new
680 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
681
682 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
683 call assert_equal('"aaa asdf bbb', @:)
684
685 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
686 call assert_equal('"aaa /tmp/some bbb', @:)
687
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200688 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
689 call assert_equal('"aaa '.getline(1).' bbb', @:)
690
Bram Moolenaar21efc362016-12-03 14:05:49 +0100691 set incsearch
692 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
693 call assert_equal('"aaa verylongword bbb', @:)
694
695 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
696 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100697
698 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
699 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100700 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200701
702 " Error while typing a command used to cause that it was not executed
703 " in the end.
704 new
705 try
706 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
707 catch /^Vim\%((\a\+)\)\=:E32/
708 " ignore error E32
709 endtry
710 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100711
Bram Moolenaar578fe942020-02-27 21:32:51 +0100712 " Try to paste an invalid register using <C-R>
713 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
714 call assert_equal('"onetwo', @:)
715
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100716 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100717 let @a = "xy\<C-H>z"
718 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
719 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100720 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
721 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100722 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
723 call assert_equal("\"xy\<C-H>z", @:)
724
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100725 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
726 let @a = "xy\<C-V>z"
727 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
728 call assert_equal('"xyz', @:)
729 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
730 call assert_equal("\"xy\<C-V>z", @:)
731
Bram Moolenaar578fe942020-02-27 21:32:51 +0100732 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
733
Bram Moolenaar72532d32018-04-07 19:09:09 +0200734 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100735endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100736
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100737func Test_cmdline_remove_char()
738 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100739
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100740 for e in ['utf8', 'latin1']
741 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100742
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100743 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
744 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100745
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100746 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
747 call assert_equal('"abcdef', @:)
748
749 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
750 call assert_equal('"abc ghi', @:, e)
751
752 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
753 call assert_equal('"def', @:, e)
754 endfor
755
756 let &encoding = encoding_save
757endfunc
758
759func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200760 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100761
762 set keymap=esperanto
763 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
764 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
765 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100766endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100767
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100768func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100769 new
770 2;'(
771 2;')
772 quit
773endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100774
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100775func Test_illegal_address2()
776 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
777 new
778 source Xtest.vim
779 " Trigger calling validate_cursor()
780 diffsp Xtest.vim
781 quit!
782 bwipe!
783 call delete('Xtest.vim')
784endfunc
785
Bram Moolenaarba47b512017-01-24 21:18:19 +0100786func Test_cmdline_complete_wildoptions()
787 help
788 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
789 let a = join(sort(split(@:)),' ')
790 set wildoptions=tagfile
791 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
792 let b = join(sort(split(@:)),' ')
793 call assert_equal(a, b)
794 bw!
795endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100796
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200797func Test_cmdline_complete_user_cmd()
798 command! -complete=color -nargs=1 Foo :
799 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
800 call assert_equal('"Foo blue', @:)
801 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
802 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000803 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
804 call assert_equal('"Foo a blue', @:)
805 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
806 call assert_equal('"Foo b\', @:)
807 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
808 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200809 delcommand Foo
810endfunc
811
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100812func s:ScriptLocalFunction()
813 echo 'yes'
814endfunc
815
816func Test_cmdline_complete_user_func()
817 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200818 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100819 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
820 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100821
822 " g: prefix also works
823 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
824 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200825
826 " using g: prefix does not result in just "g:" matches from a lambda
827 let Fx = { a -> a }
828 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
829 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200830
831 " existence of script-local dict function does not break user function name
832 " completion
833 function s:a_dict_func() dict
834 endfunction
835 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
836 call assert_match('"call Test_cmdline_complete_user_', @:)
837 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100838endfunc
839
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200840func Test_cmdline_complete_user_names()
841 if has('unix') && executable('whoami')
842 let whoami = systemlist('whoami')[0]
843 let first_letter = whoami[0]
844 if len(first_letter) > 0
845 " Trying completion of :e ~x where x is the first letter of
846 " the user name should complete to at least the user name.
847 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
848 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
849 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200850 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200851 " Just in case: check that the system has an Administrator account.
852 let names = system('net user')
853 if names =~ 'Administrator'
854 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100855 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200856 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100857 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200858 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200859 else
860 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200861 endif
862endfunc
863
Bram Moolenaar297610b2019-12-27 17:20:55 +0100864func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200865 CheckExecutable whoami
866 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
867 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100868endfunc
869
Bram Moolenaar8b633132020-03-20 18:20:51 +0100870func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200871 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
872 call assert_equal(lang, v:lc_time)
873
874 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
875 call assert_equal(lang, v:ctype)
876
877 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
878 call assert_equal(lang, v:collate)
879
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200880 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200881 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200882
883 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200884 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200885
Bram Moolenaarec680282020-06-12 19:35:32 +0200886 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200887
Bram Moolenaarec680282020-06-12 19:35:32 +0200888 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
889 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200890
Bram Moolenaarec680282020-06-12 19:35:32 +0200891 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
892 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200893
Bram Moolenaarec680282020-06-12 19:35:32 +0200894 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
895 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200896
897 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
898 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200899endfunc
900
Bram Moolenaar297610b2019-12-27 17:20:55 +0100901func Test_cmdline_complete_env_variable()
902 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100903 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
904 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100905 unlet $X_VIM_TEST_COMPLETE_ENV
906endfunc
907
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100908func Test_cmdline_complete_expression()
909 let g:SomeVar = 'blah'
910 for cmd in ['exe', 'echo', 'echon', 'echomsg']
911 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
912 call assert_match('"' .. cmd .. ' SomeVar', @:)
913 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
914 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
915 endfor
916 unlet g:SomeVar
917endfunc
918
Bram Moolenaar47016f52021-08-26 16:39:58 +0200919" Unique function name for completion below
920func s:WeirdFunc()
921 echo 'weird'
922endfunc
923
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100924" Test for various command-line completion
925func Test_cmdline_complete_various()
926 " completion for a command starting with a comment
927 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
928 call assert_equal("\" :|\"\<C-A>", @:)
929
930 " completion for a range followed by a comment
931 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
932 call assert_equal("\"1,2\"\<C-A>", @:)
933
934 " completion for :k command
935 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
936 call assert_equal("\"ka\<C-A>", @:)
937
938 " completion for short version of the :s command
939 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
940 call assert_equal("\"sI \<C-A>", @:)
941
942 " completion for :write command
943 call mkdir('Xdir')
944 call writefile(['one'], 'Xdir/Xfile1')
945 let save_cwd = getcwd()
946 cd Xdir
947 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
948 call assert_equal("\"w >> Xfile1", @:)
949 call chdir(save_cwd)
950 call delete('Xdir', 'rf')
951
952 " completion for :w ! and :r ! commands
953 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
954 call assert_equal("\"w !invalid_xyz_cmd", @:)
955 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
956 call assert_equal("\"r !invalid_xyz_cmd", @:)
957
958 " completion for :>> and :<< commands
959 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
960 call assert_equal("\">>>\<C-A>", @:)
961 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
962 call assert_equal("\"<<<\<C-A>", @:)
963
964 " completion for command with +cmd argument
965 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
966 call assert_equal("\"buffer +/pat Xabc", @:)
967 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
968 call assert_equal("\"buffer +/pat\<C-A>", @:)
969
970 " completion for a command with a trailing comment
971 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
972 call assert_equal("\"ls \" comment\<C-A>", @:)
973
974 " completion for a command with a trailing command
975 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
976 call assert_equal("\"ls | ls", @:)
977
978 " completion for a command with an CTRL-V escaped argument
979 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
980 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
981
982 " completion for a command that doesn't take additional arguments
983 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
984 call assert_equal("\"all abc\<C-A>", @:)
985
986 " completion for a command with a command modifier
987 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
988 call assert_equal("\"topleft new", @:)
989
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200990 " completion for vim9 and legacy commands
991 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
992 call assert_equal("\"vim9 call strlen(", @:)
993 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
994 call assert_equal("\"legac call strlen(", @:)
995
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200996 " completion for the :disassemble command
997 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
998 call assert_equal("\"disas debug", @:)
999 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1000 call assert_equal("\"disas profile", @:)
1001 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1002 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1003 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1004 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001005 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1006 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001007
Bram Moolenaar47016f52021-08-26 16:39:58 +02001008 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001009 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001010
naohiro onodfe04db2021-09-12 15:45:10 +02001011 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1012 call assert_match('"disas <SNR>\d\+_', @:)
1013 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1014 call assert_match('"disas debug <SNR>\d\+_', @:)
1015
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001016 " completion for the :match command
1017 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1018 call assert_equal("\"match Search /pat/\<C-A>", @:)
1019
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001020 " completion for the :doautocmd command
1021 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1022 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1023
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001024 " completion of autocmd group after comma
1025 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1026 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1027
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001028 " completion of file name in :doautocmd
1029 call writefile([], 'Xfile1')
1030 call writefile([], 'Xfile2')
1031 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
1032 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
1033 call delete('Xfile1')
1034 call delete('Xfile2')
1035
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001036 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001037 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001038 augroup END
1039 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001040 call assert_equal("\"augroup XTest.test", @:)
1041 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1042 call assert_equal("\"au XTest.test", @:)
1043 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001044
1045 " completion for the :unlet command
1046 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1047 call assert_equal("\"unlet one two", @:)
1048
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001049 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001050 " FIXME: what should happen on MS-Windows?
1051 if !has('win32')
1052 edit \{someFile}
1053 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1054 call assert_equal("\"buf {someFile}", @:)
1055 bwipe {someFile}
1056 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001057
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001058 " completion for the :bdelete command
1059 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1060 call assert_equal("\"bdel a b c", @:)
1061
1062 " completion for the :mapclear command
1063 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1064 call assert_equal("\"mapclear <buffer>", @:)
1065
1066 " completion for user defined commands with menu names
1067 menu Test.foo :ls<CR>
1068 com -nargs=* -complete=menu MyCmd
1069 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1070 call assert_equal('"MyCmd Test.', @:)
1071 delcom MyCmd
1072 unmenu Test
1073
1074 " completion for user defined commands with mappings
1075 mapclear
1076 map <F3> :ls<CR>
1077 com -nargs=* -complete=mapping MyCmd
1078 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001079 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001080 mapclear
1081 delcom MyCmd
1082
1083 " completion for :set path= with multiple backslashes
1084 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1085 call assert_equal('"set path=a\\\ b', @:)
1086
1087 " completion for :set dir= with a backslash
1088 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal('"set dir=a\ b', @:)
1090
1091 " completion for the :py3 commands
1092 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal('"py3 py3do py3file', @:)
1094
Bram Moolenaardf749a22021-03-28 15:29:43 +02001095 " completion for the :vim9 commands
1096 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal('"vim9cmd vim9script', @:)
1098
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001099 " redir @" is not the start of a comment. So complete after that
1100 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1101 call assert_equal('"redir @" | cwindow', @:)
1102
1103 " completion after a backtick
1104 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1105 call assert_equal('"e `a1b2c', @:)
1106
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001107 " completion for :language command with an invalid argument
1108 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1109 call assert_equal("\"language dummy \t", @:)
1110
1111 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001112 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1113 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001114
1115 " completion with ambiguous user defined commands
1116 com TCmd1 echo 'TCmd1'
1117 com TCmd2 echo 'TCmd2'
1118 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1119 call assert_equal('"TCmd ', @:)
1120 delcom TCmd1
1121 delcom TCmd2
1122
1123 " completion after a range followed by a pipe (|) character
1124 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1125 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001126
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001127 " completion after a :global command
1128 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1129 call assert_equal('"g/a/chistory', @:)
1130 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"g/a\\/chist\t", @:)
1132
Bram Moolenaar9c929712020-09-07 22:05:28 +02001133 " use <Esc> as the 'wildchar' for completion
1134 set wildchar=<Esc>
1135 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1136 call assert_equal('"g/a\xb/clearjumps', @:)
1137 " pressing <esc> twice should cancel the command
1138 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1139 call assert_equal('"g/a\xb/clearjumps', @:)
1140 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001141
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001142 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001143 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001144 call writefile([], '~Xtest')
1145 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1146 call assert_equal('"e \~Xtest', @:)
1147 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001148
1149 " should be able to complete a file name that has a '*'
1150 call writefile([], 'Xx*Yy')
1151 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1152 call assert_equal('"e Xx\*Yy', @:)
1153 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001154
1155 " use a literal star
1156 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001158 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001159
1160 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1161 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001162endfunc
1163
1164" Test for 'wildignorecase'
1165func Test_cmdline_wildignorecase()
1166 CheckUnix
1167 call writefile([], 'XTEST')
1168 set wildignorecase
1169 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001171 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001172 let g:Sline = ''
1173 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal('"e xt', @:)
1175 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001176 set wildignorecase&
1177 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001178endfunc
1179
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001180func Test_cmdline_write_alternatefile()
1181 new
1182 call setline('.', ['one', 'two'])
1183 f foo.txt
1184 new
1185 f #-A
1186 call assert_equal('foo.txt-A', expand('%'))
1187 f #<-B.txt
1188 call assert_equal('foo-B.txt', expand('%'))
1189 f %<
1190 call assert_equal('foo-B', expand('%'))
1191 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001192 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001193 bw!
1194 f foo-B.txt
1195 f %<-A
1196 call assert_equal('foo-B-A', expand('%'))
1197 bw!
1198 bw!
1199endfunc
1200
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001201" using a leading backslash here
1202set cpo+=C
1203
1204func Test_cmdline_search_range()
1205 new
1206 call setline(1, ['a', 'b', 'c', 'd'])
1207 /d
1208 1,\/s/b/B/
1209 call assert_equal('B', getline(2))
1210
1211 /a
1212 $
1213 \?,4s/c/C/
1214 call assert_equal('C', getline(3))
1215
1216 call setline(1, ['a', 'b', 'c', 'd'])
1217 %s/c/c/
1218 1,\&s/b/B/
1219 call assert_equal('B', getline(2))
1220
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001221 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001222 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001223
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001224 bwipe!
1225endfunc
1226
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001227" Test for the tick mark (') in an excmd range
1228func Test_tick_mark_in_range()
1229 " If only the tick is passed as a range and no command is specified, there
1230 " should not be an error
1231 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001232 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001233 call assert_fails("',print", 'E78:')
1234endfunc
1235
1236" Test for using a line number followed by a search pattern as range
1237func Test_lnum_and_pattern_as_range()
1238 new
1239 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1240 let @" = ''
1241 2/foo/yank
1242 call assert_equal("foo 3\n", @")
1243 call assert_equal(1, line('.'))
1244 close!
1245endfunc
1246
Bram Moolenaar65189a12017-02-06 22:22:17 +01001247" Tests for getcmdline(), getcmdpos() and getcmdtype()
1248func Check_cmdline(cmdtype)
1249 call assert_equal('MyCmd a', getcmdline())
1250 call assert_equal(8, getcmdpos())
1251 call assert_equal(a:cmdtype, getcmdtype())
1252 return ''
1253endfunc
1254
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001255set cpo&
1256
Bram Moolenaar65189a12017-02-06 22:22:17 +01001257func Test_getcmdtype()
1258 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1259
1260 let cmdtype = ''
1261 debuggreedy
1262 call feedkeys(":debug echo 'test'\<CR>", "t")
1263 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1264 call feedkeys("cont\<CR>", "xt")
1265 0debuggreedy
1266 call assert_equal('>', cmdtype)
1267
1268 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1269 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1270
1271 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001272 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001273
1274 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1275
1276 cnoremap <expr> <F6> Check_cmdline('=')
1277 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1278 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001279
1280 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001281endfunc
1282
Bram Moolenaar81612b72018-06-23 14:55:03 +02001283func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001284 CheckFeature cmdwin
1285
Bram Moolenaar81612b72018-06-23 14:55:03 +02001286 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1287 call assert_equal('/', a)
1288
1289 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1290 call assert_equal('?', a)
1291
1292 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1293 call assert_equal(':', a)
1294
1295 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1296 call assert_equal(':', a)
1297
1298 call assert_equal('', getcmdwintype())
1299endfunc
1300
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001301func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001302 CheckFeature cmdwin
1303
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001304 let s:seq = []
1305 augroup CmdWin
1306 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1307 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1308 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1309 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1310 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1311 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1312
1313 let org_winid = win_getid()
1314 let org_bufnr = bufnr()
1315 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1316 call assert_equal(':', a)
1317 call assert_equal([
1318 \ 'WinLeave ' .. org_winid,
1319 \ 'WinEnter ' .. s:cmd_winid,
1320 \ 'BufLeave ' .. org_bufnr,
1321 \ 'BufEnter ' .. s:cmd_bufnr,
1322 \ 'CmdWinEnter ' .. s:cmd_winid,
1323 \ 'CmdWinLeave ' .. s:cmd_winid,
1324 \ 'BufLeave ' .. s:cmd_bufnr,
1325 \ 'WinLeave ' .. s:cmd_winid,
1326 \ 'WinEnter ' .. org_winid,
1327 \ 'BufEnter ' .. org_bufnr,
1328 \ ], s:seq)
1329
1330 au!
1331 augroup END
1332endfunc
1333
Bram Moolenaar52604f22017-04-07 16:17:39 +02001334func Test_verbosefile()
1335 set verbosefile=Xlog
1336 echomsg 'foo'
1337 echomsg 'bar'
1338 set verbosefile=
1339 let log = readfile('Xlog')
1340 call assert_match("foo\nbar", join(log, "\n"))
1341 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001342 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001343 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001344 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001345endfunc
1346
Bram Moolenaar4facea32019-10-12 20:17:40 +02001347func Test_verbose_option()
1348 CheckScreendump
1349
1350 let lines =<< trim [SCRIPT]
1351 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1352 call feedkeys("\r", 't') " for the hit-enter prompt
1353 set verbose=20
1354 [SCRIPT]
1355 call writefile(lines, 'XTest_verbose')
1356
1357 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001358 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001359 call term_sendkeys(buf, ":DoSomething\<CR>")
1360 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1361
1362 " clean up
1363 call StopVimInTerminal(buf)
1364 call delete('XTest_verbose')
1365endfunc
1366
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001367func Test_setcmdpos()
1368 func InsertTextAtPos(text, pos)
1369 call assert_equal(0, setcmdpos(a:pos))
1370 return a:text
1371 endfunc
1372
1373 " setcmdpos() with position in the middle of the command line.
1374 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1375 call assert_equal('"1ab2', @:)
1376
1377 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1378 call assert_equal('"1b2a', @:)
1379
1380 " setcmdpos() with position beyond the end of the command line.
1381 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1382 call assert_equal('"12ab', @:)
1383
1384 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001385 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001386endfunc
1387
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001388func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001389 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001390 let encoding_save = &encoding
1391
1392 for e in encodings
1393 exe 'set encoding=' . e
1394
1395 " Test overstrike in the middle of the command line.
1396 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001397 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001398
1399 " Test overstrike going beyond end of command line.
1400 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001401 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001402
1403 " Test toggling insert/overstrike a few times.
1404 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001405 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001406 endfor
1407
Bram Moolenaar30276f22019-01-24 17:59:39 +01001408 " Test overstrike with multi-byte characters.
1409 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001410 call assert_equal('"abcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001411
1412 let &encoding = encoding_save
1413endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001414
1415func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001416 CheckFeature cmdwin
1417
Bram Moolenaara046b372019-09-15 17:26:07 +02001418 let winid = win_getid()
1419 sp
1420 try
1421 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1422 catch /^Vim\%((\a\+)\)\=:E11/
1423 endtry
1424 bw!
1425endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001426
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001427func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001428 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001429 CheckScreendump
1430
1431 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001432 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001433 call setline(1, range(30))
1434 2split
1435 [SCRIPT]
1436 call writefile(lines, 'XTest_restore')
1437
1438 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001439 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001440 call term_sendkeys(buf, "q:")
1441 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1442
1443 " normal restore
1444 call term_sendkeys(buf, ":q\<CR>")
1445 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1446
1447 " restore after setting 'lines' with one window
1448 call term_sendkeys(buf, ":close\<CR>")
1449 call term_sendkeys(buf, "q:")
1450 call term_sendkeys(buf, ":set lines=18\<CR>")
1451 call term_sendkeys(buf, ":q\<CR>")
1452 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1453
1454 " clean up
1455 call StopVimInTerminal(buf)
1456 call delete('XTest_restore')
1457endfunc
1458
Bram Moolenaare5b44862021-05-30 13:54:03 +02001459func Test_cmdwin_no_terminal()
1460 CheckFeature cmdwin
1461 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001462 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001463
1464 let buf = RunVimInTerminal('', {'rows': 12})
1465 call TermWait(buf, 50)
1466 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1467 call term_sendkeys(buf, "q:")
1468 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1469 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1470 call term_sendkeys(buf, ":q\<CR>")
1471 call StopVimInTerminal(buf)
1472endfunc
1473
Bram Moolenaar52410572019-10-27 05:12:45 +01001474func Test_buffers_lastused()
1475 " check that buffers are sorted by time when wildmode has lastused
1476 call test_settime(1550020000) " middle
1477 edit bufa
1478 enew
1479 call test_settime(1550030000) " newest
1480 edit bufb
1481 enew
1482 call test_settime(1550010000) " oldest
1483 edit bufc
1484 enew
1485 call test_settime(0)
1486 enew
1487
1488 call assert_equal(['bufa', 'bufb', 'bufc'],
1489 \ getcompletion('', 'buffer'))
1490
1491 let save_wildmode = &wildmode
1492 set wildmode=full:lastused
1493
1494 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1495 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1496 call assert_equal('b bufb', X)
1497 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1498 call assert_equal('b bufa', X)
1499 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1500 call assert_equal('b bufc', X)
1501 enew
1502
1503 edit other
1504 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1505 call assert_equal('b bufb', X)
1506 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1507 call assert_equal('b bufa', X)
1508 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1509 call assert_equal('b bufc', X)
1510 enew
1511
1512 let &wildmode = save_wildmode
1513
1514 bwipeout bufa
1515 bwipeout bufb
1516 bwipeout bufc
1517endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001518
1519func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001520 CheckFeature cmdwin
1521
Bram Moolenaar85db5472019-12-04 15:11:08 +01001522 " This should not generate E488
1523 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001524 " Using feedkeys with q: only should automatically close the cmd window
1525 call feedkeys('q:', 'xt')
1526 call assert_equal(1, winnr('$'))
1527 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001528endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001529
1530" Tests for the issues fixed in 7.4.441.
1531" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1532func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001533 CheckFeature cmdwin
1534
Bram Moolenaar309976e2019-12-05 18:16:33 +01001535 exe "set cedit=\<C-c>"
1536 normal! :
1537 call assert_equal(1, winnr('$'))
1538
1539 let g:cmd_wintype = ''
1540 func CmdWinType()
1541 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001542 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001543 return ''
1544 endfunc
1545
1546 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1547 echo input('')
1548 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001549 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001550
1551 set cedit&vim
1552 delfunc CmdWinType
1553endfunc
1554
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001555" Test for CmdwinEnter autocmd
1556func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001557 CheckFeature cmdwin
1558
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001559 augroup CmdWin
1560 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001561 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001562 autocmd CmdwinEnter * startinsert
1563 augroup END
1564
1565 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1566 call assert_equal('xyz', @:)
1567
1568 augroup CmdWin
1569 au!
1570 augroup END
1571 augroup! CmdWin
1572endfunc
1573
Bram Moolenaar479950f2020-01-19 15:45:17 +01001574func Test_cmdlineclear_tabenter()
1575 CheckScreendump
1576
1577 let lines =<< trim [SCRIPT]
1578 call setline(1, range(30))
1579 [SCRIPT]
1580
1581 call writefile(lines, 'XtestCmdlineClearTabenter')
1582 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001583 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001584 " in one tab make the command line higher with CTRL-W -
1585 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1586 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1587
1588 call StopVimInTerminal(buf)
1589 call delete('XtestCmdlineClearTabenter')
1590endfunc
1591
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001592" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001593func Test_cmdline_expand_special()
1594 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001595 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001596 call assert_fails('e <afile>', 'E495:')
1597 call assert_fails('e <abuf>', 'E496:')
1598 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001599
1600 call writefile([], 'Xfile.cpp')
1601 call writefile([], 'Xfile.java')
1602 new Xfile.cpp
1603 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1604 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1605 close
1606 call delete('Xfile.cpp')
1607 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001608endfunc
1609
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001610func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001611 CheckFeature cmdwin
1612
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001613 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1614 new
1615 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001616 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001617 close!
1618 call feedkeys("q/:close\<CR>", "xt")
1619 call assert_equal(1, winnr('$'))
1620 call feedkeys("q/:exit\<CR>", "xt")
1621 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001622
1623 " opening command window twice should fail
1624 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1625 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001626endfunc
1627
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00001628func Test_cmdwin_tabpage()
1629 tabedit
1630 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1631 tabclose!
1632endfunc
1633
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001634func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001635 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001636 CheckScreendump
1637
1638 " aborting the :smile output caused the cmdline window to use the current
1639 " buffer.
1640 let lines =<< trim [SCRIPT]
1641 au WinNew * smile
1642 [SCRIPT]
1643 call writefile(lines, 'XTest_cmdwin')
1644
1645 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001646 " open cmdwin
1647 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001648 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001649 " quit more prompt for :smile command
1650 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001651 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001652 " execute a simple command
1653 call term_sendkeys(buf, "aecho 'done'\<CR>")
1654 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1655
1656 " clean up
1657 call StopVimInTerminal(buf)
1658 call delete('XTest_cmdwin')
1659endfunc
1660
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001661" Test for backtick expression in the command line
1662func Test_cmd_backtick()
1663 %argd
1664 argadd `=['a', 'b', 'c']`
1665 call assert_equal(['a', 'b', 'c'], argv())
1666 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001667
1668 argadd `echo abc def`
1669 call assert_equal(['abc def'], argv())
1670 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001671endfunc
1672
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001673" Test for the :! command
1674func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001675 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001676
1677 let lines =<< trim [SCRIPT]
1678 " Test for no previous command
1679 call assert_fails('!!', 'E34:')
1680 set nomore
1681 " Test for cmdline expansion with :!
1682 call setline(1, 'foo!')
1683 silent !echo <cWORD> > Xfile.out
1684 call assert_equal(['foo!'], readfile('Xfile.out'))
1685 " Test for using previous command
1686 silent !echo \! !
1687 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1688 call writefile(v:errors, 'Xresult')
1689 call delete('Xfile.out')
1690 qall!
1691 [SCRIPT]
1692 call writefile(lines, 'Xscript')
1693 if RunVim([], [], '--clean -S Xscript')
1694 call assert_equal([], readfile('Xresult'))
1695 endif
1696 call delete('Xscript')
1697 call delete('Xresult')
1698endfunc
1699
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001700" Test error: "E135: *Filter* Autocommands must not change current buffer"
1701func Test_cmd_bang_E135()
1702 new
1703 call setline(1, ['a', 'b', 'c', 'd'])
1704 augroup test_cmd_filter_E135
1705 au!
1706 autocmd FilterReadPost * help
1707 augroup END
1708 call assert_fails('2,3!echo "x"', 'E135:')
1709
1710 augroup test_cmd_filter_E135
1711 au!
1712 augroup END
1713 %bwipe!
1714endfunc
1715
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001716" Test for using ~ for home directory in cmdline completion matches
1717func Test_cmdline_expand_home()
1718 call mkdir('Xdir')
1719 call writefile([], 'Xdir/Xfile1')
1720 call writefile([], 'Xdir/Xfile2')
1721 cd Xdir
1722 let save_HOME = $HOME
1723 let $HOME = getcwd()
1724 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1725 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1726 let $HOME = save_HOME
1727 cd ..
1728 call delete('Xdir', 'rf')
1729endfunc
1730
Bram Moolenaar578fe942020-02-27 21:32:51 +01001731" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1732" or insert mode (when 'insertmode' is set)
1733func Test_cmdline_ctrl_g()
1734 new
1735 call setline(1, 'abc')
1736 call cursor(1, 3)
1737 " If command line is entered from insert mode, using C-\ C-G should back to
1738 " insert mode
1739 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1740 call assert_equal('abxyc', getline(1))
1741 call assert_equal(4, col('.'))
1742
1743 " If command line is entered in 'insertmode', using C-\ C-G should back to
1744 " 'insertmode'
1745 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1746 call assert_equal('ab12xyc', getline(1))
1747 close!
1748endfunc
1749
Bram Moolenaar578fe942020-02-27 21:32:51 +01001750" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001751func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001752 func T(a, c, p)
1753 return "oneA\noneB\noneC"
1754 endfunc
1755 command -nargs=1 -complete=custom,T MyCmd
1756
Bram Moolenaar578fe942020-02-27 21:32:51 +01001757 set nowildmenu
1758 set wildmode=full,list
1759 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001760 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001761 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001762 call assert_equal('"MyCmd oneA', @:)
1763
1764 set wildmode=longest,full
1765 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"MyCmd one', @:)
1767 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1768 call assert_equal('"MyCmd oneC', @:)
1769
1770 set wildmode=longest
1771 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1772 call assert_equal('"MyCmd one', @:)
1773
1774 set wildmode=list:longest
1775 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001776 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001777 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001778 call assert_equal('"MyCmd one', @:)
1779
1780 set wildmode=""
1781 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1782 call assert_equal('"MyCmd oneA', @:)
1783
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001784 " Test for wildmode=longest with 'fileignorecase' set
1785 set wildmode=longest
1786 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001787 argadd AAA AAAA AAAAA
1788 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1789 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001790 set fileignorecase&
1791
1792 " Test for listing files with wildmode=list
1793 set wildmode=list
1794 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001795 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001796 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001797 call assert_equal('"b A', @:)
1798
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001799 " when using longest completion match, matches shorter than the argument
1800 " should be ignored (happens with :help)
1801 set wildmode=longest,full
1802 set wildmenu
1803 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1804 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001805 " non existing file
1806 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1807 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001808 set wildmenu&
1809
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001810 " Test for longest file name completion with 'fileignorecase'
1811 " On MS-Windows, file names are case insensitive.
1812 if has('unix')
1813 call writefile([], 'XTESTfoo')
1814 call writefile([], 'Xtestbar')
1815 set nofileignorecase
1816 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1817 call assert_equal('"e XTESTfoo', @:)
1818 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1819 call assert_equal('"e Xtestbar', @:)
1820 set fileignorecase
1821 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1822 call assert_equal('"e Xtest', @:)
1823 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1824 call assert_equal('"e Xtest', @:)
1825 set fileignorecase&
1826 call delete('XTESTfoo')
1827 call delete('Xtestbar')
1828 endif
1829
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001830 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001831 delcommand MyCmd
1832 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001833 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001834 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001835endfunc
1836
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001837func Test_wildmode()
1838 " Test with utf-8 encoding
1839 call Wildmode_tests()
1840
1841 " Test with latin1 encoding
1842 let save_encoding = &encoding
1843 set encoding=latin1
1844 call Wildmode_tests()
1845 let &encoding = save_encoding
1846endfunc
1847
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001848func Test_custom_complete_autoload()
1849 call mkdir('Xdir/autoload', 'p')
1850 let save_rtp = &rtp
1851 exe 'set rtp=' .. getcwd() .. '/Xdir'
1852 let lines =<< trim END
1853 func vim8#Complete(a, c, p)
1854 return "oneA\noneB\noneC"
1855 endfunc
1856 END
1857 call writefile(lines, 'Xdir/autoload/vim8.vim')
1858
1859 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1860 set nowildmenu
1861 set wildmode=full,list
1862 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1863 call assert_equal('"MyCmd oneA oneB oneC', @:)
1864
1865 let &rtp = save_rtp
1866 set wildmode& wildmenu&
1867 delcommand MyCmd
1868 call delete('Xdir', 'rf')
1869endfunc
1870
Bram Moolenaar578fe942020-02-27 21:32:51 +01001871" Test for interrupting the command-line completion
1872func Test_interrupt_compl()
1873 func F(lead, cmdl, p)
1874 if a:lead =~ 'tw'
1875 call interrupt()
1876 return
1877 endif
1878 return "one\ntwo\nthree"
1879 endfunc
1880 command -nargs=1 -complete=custom,F Tcmd
1881
1882 set nowildmenu
1883 set wildmode=full
1884 let interrupted = 0
1885 try
1886 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1887 catch /^Vim:Interrupt$/
1888 let interrupted = 1
1889 endtry
1890 call assert_equal(1, interrupted)
1891
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001892 let interrupted = 0
1893 try
1894 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1895 catch /^Vim:Interrupt$/
1896 let interrupted = 1
1897 endtry
1898 call assert_equal(1, interrupted)
1899
Bram Moolenaar578fe942020-02-27 21:32:51 +01001900 delcommand Tcmd
1901 delfunc F
1902 set wildmode&
1903endfunc
1904
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001905" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001906func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001907 let str = ":one two\<C-U>"
1908 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001909 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001910 let str ..= "\<Left>five\<Right>"
1911 let str ..= "\<Home>two "
1912 let str ..= "\<C-Left>one "
1913 let str ..= "\<C-Right> three"
1914 let str ..= "\<End>\<S-Left>four "
1915 let str ..= "\<S-Right> six"
1916 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1917 call feedkeys(str, 'xt')
1918 call assert_equal("\"one two three four five six seven", @:)
1919endfunc
1920
1921" Test for moving the cursor on the / command line in 'rightleft' mode
1922func Test_cmdline_edit_rightleft()
1923 CheckFeature rightleft
1924 set rightleft
1925 set rightleftcmd=search
1926 let str = "/one two\<C-U>"
1927 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001928 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001929 let str ..= "\<Right>five\<Left>"
1930 let str ..= "\<Home>two "
1931 let str ..= "\<C-Right>one "
1932 let str ..= "\<C-Left> three"
1933 let str ..= "\<End>\<S-Right>four "
1934 let str ..= "\<S-Left> six"
1935 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1936 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1937 call assert_equal("\"one two three four five six seven", @/)
1938 set rightleftcmd&
1939 set rightleft&
1940endfunc
1941
1942" Test for using <C-\>e in the command line to evaluate an expression
1943func Test_cmdline_expr()
1944 " Evaluate an expression from the beginning of a command line
1945 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1946 call assert_equal('"hello', @:)
1947
1948 " Use an invalid expression for <C-\>e
1949 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1950
1951 " Insert literal <CTRL-\> in the command line
1952 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1953 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001954endfunc
1955
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001956" Test for 'imcmdline' and 'imsearch'
1957" This test doesn't actually test the input method functionality.
1958func Test_cmdline_inputmethod()
1959 new
1960 call setline(1, ['', 'abc', ''])
1961 set imcmdline
1962
1963 call feedkeys(":\"abc\<CR>", 'xt')
1964 call assert_equal("\"abc", @:)
1965 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1966 call assert_equal("\"abc", @:)
1967 call feedkeys("/abc\<CR>", 'xt')
1968 call assert_equal([2, 1], [line('.'), col('.')])
1969 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1970 call assert_equal([2, 1], [line('.'), col('.')])
1971
1972 set imsearch=2
1973 call cursor(1, 1)
1974 call feedkeys("/abc\<CR>", 'xt')
1975 call assert_equal([2, 1], [line('.'), col('.')])
1976 call cursor(1, 1)
1977 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1978 call assert_equal([2, 1], [line('.'), col('.')])
1979 set imdisable
1980 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1981 call assert_equal([2, 1], [line('.'), col('.')])
1982 set imdisable&
1983 set imsearch&
1984
1985 set imcmdline&
1986 %bwipe!
1987endfunc
1988
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001989" Test for recursively getting multiple command line inputs
1990func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001991 CheckFeature cmdwin
1992
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001993 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1994 call assert_equal('"cyan', @:)
1995endfunc
1996
1997" Test for using CTRL-_ in the command line with 'allowrevins'
1998func Test_cmdline_revins()
1999 CheckNotMSWindows
2000 CheckFeature rightleft
2001 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2002 call assert_equal("\"abc\<c-_>", @:)
2003 set allowrevins
2004 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2005 call assert_equal('"abcñèæ', @:)
2006 set allowrevins&
2007endfunc
2008
2009" Test for typing UTF-8 composing characters in the command line
2010func Test_cmdline_composing_chars()
2011 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2012 call assert_equal('"ゔ', @:)
2013endfunc
2014
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002015" Test for normal mode commands not supported in the cmd window
2016func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002017 CheckFeature cmdwin
2018
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002019 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
2020 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
2021 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
2022 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
2023 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
2024 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02002025 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
2026 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
2027 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
2028 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
2029 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
2030 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
2031 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
2032 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
2033 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
2034 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
2035 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
2036 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
2037 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
2038 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
2039 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
2040 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
2041 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
2042 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
2043 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
2044 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
2045 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002046endfunc
2047
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002048" Close the Cmd-line window in insert mode using CTRL-C
2049func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002050 CheckFeature cmdwin
2051
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002052 %bw!
2053 let s = ''
2054 exe "normal q:a\<C-C>let s='Hello'\<CR>"
2055 call assert_equal('Hello', s)
2056 call assert_equal(1, winnr('$'))
2057endfunc
2058
Bram Moolenaar0e717042020-04-27 19:29:01 +02002059" test that ";" works to find a match at the start of the first line
2060func Test_zero_line_search()
2061 new
2062 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2063 call cursor(1,1)
2064 0;/pattern/d
2065 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2066 q!
2067endfunc
2068
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002069func Test_read_shellcmd()
2070 CheckUnix
2071 if executable('ls')
2072 " There should be ls in the $PATH
2073 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2074 call assert_match('^"r! .*\<ls\>', @:)
2075 endif
2076
2077 if executable('rm')
2078 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2079 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2080 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002081
2082 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2083 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2084 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002085 endif
2086endfunc
2087
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002088" Test for going up and down the directory tree using 'wildmenu'
2089func Test_wildmenu_dirstack()
2090 CheckUnix
2091 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002092 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002093 call writefile([], 'Xdir1/file1_1.txt')
2094 call writefile([], 'Xdir1/file1_2.txt')
2095 call writefile([], 'Xdir1/dir2/file2_1.txt')
2096 call writefile([], 'Xdir1/dir2/file2_2.txt')
2097 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2098 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002099 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2100 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002101 set wildmenu
2102
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002103 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002104 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002105 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002106 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002107 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002108 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002109 call assert_equal('"e ../../dir3/', @:)
2110 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2111 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002112 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002113 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002114 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002115 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002116 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002117 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2118 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2119
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002120 call delete('Xdir1', 'rf')
2121 set wildmenu&
2122endfunc
2123
obcat71c6f7a2021-05-13 20:23:10 +02002124" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002125" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2126" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002127func Test_recalling_cmdline()
2128 CheckFeature cmdline_hist
2129
2130 let g:cmdlines = []
2131 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2132
2133 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002134 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2135 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2136 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2137 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002138 "\ TODO: {'name': 'debug', ...}
2139 \]
2140 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002141 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2142 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2143 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2144 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2145 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002146 \]
2147 let prefix = 'vi'
2148 for h in histories
2149 call histadd(h.name, 'vim')
2150 call histadd(h.name, 'virtue')
2151 call histadd(h.name, 'Virgo')
2152 call histadd(h.name, 'vogue')
2153 call histadd(h.name, 'emacs')
2154 for k in keypairs
2155 let g:cmdlines = []
2156 let keyseqs = h.enter
2157 \ .. prefix
2158 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2159 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2160 \ .. h.exit
2161 call feedkeys(keyseqs, 'xt')
2162 call histdel(h.name, -1) " delete the history added by feedkeys above
2163 let expect = k.prefixmatch
2164 \ ? ['virtue', 'vim', 'virtue', prefix]
2165 \ : ['emacs', 'vogue', 'emacs', prefix]
2166 call assert_equal(expect, g:cmdlines)
2167 endfor
2168 endfor
2169
2170 unlet g:cmdlines
2171 cunmap <Plug>(save-cmdline)
2172endfunc
2173
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002174func Test_cmd_map_cmdlineChanged()
2175 let g:log = []
2176 cnoremap <F1> l<Cmd><CR>s
2177 augroup test
2178 autocmd!
2179 autocmd CmdlineChanged : let g:log += [getcmdline()]
2180 augroup END
2181
2182 call feedkeys(":\<F1>\<CR>", 'xt')
2183 call assert_equal(['l', 'ls'], g:log)
2184
Bram Moolenaar796139a2021-05-18 21:38:45 +02002185 let @b = 'b'
2186 cnoremap <F1> a<C-R>b
2187 let g:log = []
2188 call feedkeys(":\<F1>\<CR>", 'xt')
2189 call assert_equal(['a', 'ab'], g:log)
2190
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002191 unlet g:log
2192 cunmap <F1>
2193 augroup test
2194 autocmd!
2195 augroup END
2196endfunc
2197
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002198" Test for the 'suffixes' option
2199func Test_suffixes_opt()
2200 call writefile([], 'Xfile')
2201 call writefile([], 'Xfile.c')
2202 call writefile([], 'Xfile.o')
2203 set suffixes=
2204 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2205 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002206 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2207 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002208 set suffixes=.c
2209 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2210 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002211 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2212 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002213 set suffixes=,,
2214 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2215 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002216 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2217 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002218 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002219 " Test for getcompletion() with different patterns
2220 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2221 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002222 call delete('Xfile')
2223 call delete('Xfile.c')
2224 call delete('Xfile.o')
2225endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002226
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227" Test for using a popup menu for the command line completion matches
2228" (wildoptions=pum)
2229func Test_wildmenu_pum()
2230 CheckRunVimInTerminal
2231
2232 let commands =<< trim [CODE]
2233 set wildmenu
2234 set wildoptions=pum
2235 set shm+=I
2236 set noruler
2237 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002238
2239 func CmdCompl(a, b, c)
2240 return repeat(['aaaa'], 120)
2241 endfunc
2242 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002243
2244 func MyStatusLine() abort
2245 return 'status'
2246 endfunc
2247 func SetupStatusline()
2248 set statusline=%!MyStatusLine()
2249 set laststatus=2
2250 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002251
2252 func MyTabLine()
2253 return 'my tab line'
2254 endfunc
2255 func SetupTabline()
2256 set statusline=
2257 set tabline=%!MyTabLine()
2258 set showtabline=2
2259 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002260
2261 func DoFeedKeys()
2262 let &wildcharm = char2nr("\t")
2263 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2264 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002265 [CODE]
2266 call writefile(commands, 'Xtest')
2267
2268 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2269
2270 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2272
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002273 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002275 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2276
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002277 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002278 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002279 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2280
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002281 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002282 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002283 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2284
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002285 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002286 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002287 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2288
2289 " pressing <C-E> should end completion and go back to the original match
2290 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002291 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2292
2293 " pressing <C-Y> should select the current match and end completion
2294 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002295 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2296
2297 " With 'wildmode' set to 'longest,full', completing a match should display
2298 " the longest match, the wildmenu should not be displayed.
2299 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2300 call TermWait(buf)
2301 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2303
2304 " pressing <Tab> should display the wildmenu
2305 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002306 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2307
2308 " pressing <Tab> second time should select the next entry in the menu
2309 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002310 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2311
2312 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002313 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002314 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2316
2317 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2319
2320 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2322
2323 " Directory name completion
2324 call mkdir('Xdir/XdirA/XdirB', 'p')
2325 call writefile([], 'Xdir/XfileA')
2326 call writefile([], 'Xdir/XdirA/XfileB')
2327 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2328
2329 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2331
2332 " Pressing <Right> on a directory name should go into that directory
2333 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2335
2336 " Pressing <Left> on a directory name should go to the parent directory
2337 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2339
2340 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002341 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002342 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002343 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2344
2345 " Pressing <C-D> when the popup menu is displayed should remove the popup
2346 " menu
2347 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002348 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2349
2350 " Pressing <S-Tab> should open the popup menu with the last entry selected
2351 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2353
2354 " Pressing <Esc> should close the popup menu and cancel the cmd line
2355 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002356 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2357
2358 " Typing a character when the popup is open, should close the popup
2359 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2361
2362 " When the popup is open, entering the cmdline window should close the popup
2363 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002364 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2365 call term_sendkeys(buf, ":q\<CR>")
2366
2367 " After the last popup menu item, <C-N> should show the original string
2368 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002369 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2370
2371 " Use the popup menu for the command name
2372 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002373 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2374
2375 " Pressing the left arrow should remove the popup menu
2376 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002377 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2378
2379 " Pressing <BS> should remove the popup menu and erase the last character
2380 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002381 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2382
2383 " Pressing <C-W> should remove the popup menu and erase the previous word
2384 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002385 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2386
2387 " Pressing <C-U> should remove the popup menu and erase the entire line
2388 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002389 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2390
2391 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2392 " the cmdline from history
2393 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002394 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2395
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002396 " Check "list" still works
2397 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2398 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002399 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2400 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002401 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2402
rbtnn68cc2b82022-02-09 11:55:47 +00002403 " Tests a directory name contained full-width characters.
2404 call mkdir('Xdir/あいう', 'p')
2405 call writefile([], 'Xdir/あいう/abc')
2406 call writefile([], 'Xdir/あいう/xyz')
2407 call writefile([], 'Xdir/あいう/123')
2408
2409 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2410 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2412
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002413 " Pressing <C-A> when the popup menu is displayed should list all the
2414 " matches and pressing a key after that should remove the popup menu
2415 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2416 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2417 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2418
2419 " Pressing <C-A> when the popup menu is displayed should list all the
2420 " matches and pressing <Left> after that should move the cursor
2421 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2422 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2423 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2424
2425 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2426 " should be displayed correctly on the screen.
2427 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2428 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2429
2430 " After using <C-A> to expand all the filename matches, pressing <Up>
2431 " should not open the popup menu again.
2432 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2433 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2434 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2435 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2436
2437 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2438 " crash Vim
2439 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2440 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2441
Bram Moolenaar414acd32022-02-10 21:09:45 +00002442 " After removing the pum the command line is redrawn
2443 call term_sendkeys(buf, ":edit foo\<CR>")
2444 call term_sendkeys(buf, ":edit bar\<CR>")
2445 call term_sendkeys(buf, ":ls\<CR>")
2446 call term_sendkeys(buf, ":com\<Tab> ")
2447 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002448 call term_sendkeys(buf, "\<C-U>\<CR>")
2449
2450 " Esc still works to abort the command when 'statusline' is set
2451 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2452 call term_sendkeys(buf, ":si\<Tab>")
2453 call term_sendkeys(buf, "\<Esc>")
2454 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002455
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002456 " Esc still works to abort the command when 'tabline' is set
2457 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2458 call term_sendkeys(buf, ":si\<Tab>")
2459 call term_sendkeys(buf, "\<Esc>")
2460 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2461
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002462 " popup is cleared also when 'lazyredraw' is set
2463 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2464 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2465 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2466 call term_sendkeys(buf, "\<Esc>")
2467
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002468 " Pressing <PageDown> should scroll the menu downward
2469 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2470 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2471 call term_sendkeys(buf, "\<PageDown>")
2472 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2473 call term_sendkeys(buf, "\<PageDown>")
2474 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2475 call term_sendkeys(buf, "\<PageDown>")
2476 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2477 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2478 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2479
2480 " Pressing <PageUp> should scroll the menu upward
2481 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2482 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2483 call term_sendkeys(buf, "\<PageUp>")
2484 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2485 call term_sendkeys(buf, "\<PageUp>")
2486 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2487 call term_sendkeys(buf, "\<PageUp>")
2488 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2489
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002490 call term_sendkeys(buf, "\<C-U>\<CR>")
2491 call StopVimInTerminal(buf)
2492 call delete('Xtest')
2493 call delete('Xdir', 'rf')
2494endfunc
2495
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002496" Test for wildmenumode() with the cmdline popup menu
2497func Test_wildmenumode_with_pum()
2498 set wildmenu
2499 set wildoptions=pum
2500 cnoremap <expr> <F2> wildmenumode()
2501 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2502 call assert_equal('"sign define10', @:)
2503 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2504 call assert_equal('"sign define jump list place undefine unplace0', @:)
2505 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2506 call assert_equal('"sign 0', @:)
2507 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2508 call assert_equal('"sign define0', @:)
2509 set nowildmenu wildoptions&
2510 cunmap <F2>
2511endfunc
2512
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002513" Test for opening the cmdline completion popup menu from the terminal window.
2514" The popup menu should be positioned correctly over the status line of the
2515" bottom-most window.
2516func Test_wildmenu_pum_from_terminal()
2517 CheckRunVimInTerminal
2518 let python = PythonProg()
2519 call CheckPython(python)
2520
2521 %bw!
2522 let cmds = ['set wildmenu wildoptions=pum']
2523 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2524 call add(cmds, "call term_start('" .. pcmd .. "')")
2525 call writefile(cmds, 'Xtest')
2526 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2527 call term_sendkeys(buf, "\r\r\r")
2528 call term_wait(buf)
2529 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2530 call term_wait(buf)
2531 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2532 call term_wait(buf)
2533 call StopVimInTerminal(buf)
2534 call delete('Xtest')
2535endfunc
2536
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002537" Test for completion after a :substitute command followed by a pipe (|)
2538" character
2539func Test_cmdline_complete_substitute()
2540 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2541 call assert_equal("\"s | \t", @:)
2542 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2543 call assert_equal("\"s/ | \t", @:)
2544 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2545 call assert_equal("\"s/one | \t", @:)
2546 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2547 call assert_equal("\"s/one/ | \t", @:)
2548 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2549 call assert_equal("\"s/one/two | \t", @:)
2550 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2551 call assert_equal('"s/one/two/ | chistory', @:)
2552 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2553 call assert_equal("\"s/one/two/g \t", @:)
2554 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2555 call assert_equal("\"s/one/two/g | chistory", @:)
2556 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2557 call assert_equal("\"s/one/t\\/ | \t", @:)
2558 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2559 call assert_equal('"s/one/t"o/ | chistory', @:)
2560 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2561 call assert_equal('"s/one/t|o/ | chistory', @:)
2562 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2563 call assert_equal("\"&\t", @:)
2564endfunc
2565
2566" Test for the :dlist command completion
2567func Test_cmdline_complete_dlist()
2568 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2569 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2570 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2571 call assert_equal("\"dlist 10 /pat/ \t", @:)
2572 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2573 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2574 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2575 call assert_equal("\"dlist 10 /pat\\\t", @:)
2576 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2577 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2578endfunc
2579
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002580" argument list (only for :argdel) fuzzy completion
2581func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002582 argadd change.py count.py charge.py
2583 set wildoptions&
2584 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2585 call assert_equal('"argdel cge', @:)
2586 set wildoptions=fuzzy
2587 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2588 call assert_equal('"argdel change.py charge.py', @:)
2589 %argdelete
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" autocmd group name fuzzy completion
2594func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002595 set wildoptions&
2596 augroup MyFuzzyGroup
2597 augroup END
2598 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2599 call assert_equal('"augroup mfg', @:)
2600 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"augroup MyFuzzyGroup', @:)
2602 set wildoptions=fuzzy
2603 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2604 call assert_equal('"augroup MyFuzzyGroup', @:)
2605 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2606 call assert_equal('"augroup My*p', @:)
2607 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002608 set wildoptions&
2609endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002610
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002611" buffer name fuzzy completion
2612func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002613 set wildoptions&
2614 edit SomeFile.txt
2615 enew
2616 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2617 call assert_equal('"b SF', @:)
2618 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2619 call assert_equal('"b SomeFile.txt', @:)
2620 set wildoptions=fuzzy
2621 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2622 call assert_equal('"b SomeFile.txt', @:)
2623 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2624 call assert_equal('"b S*File.txt', @:)
2625 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002626 set wildoptions&
2627endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002628
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002629" buffer name (full path) fuzzy completion
2630func Test_fuzzy_completion_bufname_fullpath()
2631 CheckUnix
2632 set wildoptions&
2633 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2634 edit Xcmd/Xstate/Xfile.js
2635 cd Xcmd/Xstate
2636 enew
2637 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2638 call assert_equal('"b CmdStateFile', @:)
2639 set wildoptions=fuzzy
2640 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2641 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2642 cd -
2643 call delete('Xcmd', 'rf')
2644 set wildoptions&
2645endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002646
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002647" :behave suboptions fuzzy completion
2648func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002649 set wildoptions&
2650 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2651 call assert_equal('"behave xm', @:)
2652 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2653 call assert_equal('"behave xterm', @:)
2654 set wildoptions=fuzzy
2655 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2656 call assert_equal('"behave xterm', @:)
2657 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2658 call assert_equal('"behave xt*m', @:)
2659 let g:Sline = ''
2660 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2661 call assert_equal('mswin', g:Sline)
2662 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002663 set wildoptions&
2664endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002665
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002666" " colorscheme name fuzzy completion - NOT supported
2667" func Test_fuzzy_completion_colorscheme()
2668" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002669
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002670" built-in command name fuzzy completion
2671func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002672 set wildoptions&
2673 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2674 call assert_equal('"sbwin', @:)
2675 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2676 call assert_equal('"sbrewind', @:)
2677 set wildoptions=fuzzy
2678 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2679 call assert_equal('"sbrewind', @:)
2680 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002682 set wildoptions&
2683endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002684
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002685" " compiler name fuzzy completion - NOT supported
2686" func Test_fuzzy_completion_compiler()
2687" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002688
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002689" :cscope suboptions fuzzy completion
2690func Test_fuzzy_completion_cscope()
2691 CheckFeature cscope
2692 set wildoptions&
2693 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2694 call assert_equal('"cscope ret', @:)
2695 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2696 call assert_equal('"cscope reset', @:)
2697 set wildoptions=fuzzy
2698 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2699 call assert_equal('"cscope reset', @:)
2700 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2701 call assert_equal('"cscope re*t', @:)
2702 set wildoptions&
2703endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002704
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002705" :diffget/:diffput buffer name fuzzy completion
2706func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002707 new SomeBuffer
2708 diffthis
2709 new OtherBuffer
2710 diffthis
2711 set wildoptions&
2712 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2713 call assert_equal('"diffget sbuf', @:)
2714 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2715 call assert_equal('"diffput sbuf', @:)
2716 set wildoptions=fuzzy
2717 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"diffget SomeBuffer', @:)
2719 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2720 call assert_equal('"diffput SomeBuffer', @:)
2721 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002722 set wildoptions&
2723endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002724
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002725" " directory name fuzzy completion - NOT supported
2726" func Test_fuzzy_completion_dirname()
2727" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002729" environment variable name fuzzy completion
2730func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002731 set wildoptions&
2732 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal('"echo $VUT', @:)
2734 set wildoptions=fuzzy
2735 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2736 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002737 set wildoptions&
2738endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002739
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002740" autocmd event fuzzy completion
2741func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002742 set wildoptions&
2743 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"autocmd BWout', @:)
2745 set wildoptions=fuzzy
2746 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2747 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002748 set wildoptions&
2749endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002750
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002751" vim expression fuzzy completion
2752func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002753 let g:PerPlaceCount = 10
2754 set wildoptions&
2755 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2756 call assert_equal('"let c = ppc', @:)
2757 set wildoptions=fuzzy
2758 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2759 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002760 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002761endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002762
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002763" " file name fuzzy completion - NOT supported
2764" func Test_fuzzy_completion_filename()
2765" endfunc
2766
2767" " files in path fuzzy completion - NOT supported
2768" func Test_fuzzy_completion_filesinpath()
2769" endfunc
2770
2771" " filetype name fuzzy completion - NOT supported
2772" func Test_fuzzy_completion_filetype()
2773" endfunc
2774
2775" user defined function name completion
2776func Test_fuzzy_completion_userdefined_func()
2777 set wildoptions&
2778 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2779 call assert_equal('"call Test_f_u_f', @:)
2780 set wildoptions=fuzzy
2781 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2782 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2783 set wildoptions&
2784endfunc
2785
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002786" <SNR> functions should be sorted to the end
2787func Test_fuzzy_completion_userdefined_snr_func()
2788 func s:Sendmail()
2789 endfunc
2790 func SendSomemail()
2791 endfunc
2792 func S1e2n3dmail()
2793 endfunc
2794 set wildoptions=fuzzy
2795 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002796 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002797 set wildoptions&
2798 delfunc s:Sendmail
2799 delfunc SendSomemail
2800 delfunc S1e2n3dmail
2801endfunc
2802
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002803" user defined command name completion
2804func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002805 set wildoptions&
2806 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2807 call assert_equal('"MsFeat', @:)
2808 set wildoptions=fuzzy
2809 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002811 set wildoptions&
2812endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002813
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002814" " :help tag fuzzy completion - NOT supported
2815" func Test_fuzzy_completion_helptag()
2816" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002817
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818" highlight group name fuzzy completion
2819func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820 set wildoptions&
2821 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2822 call assert_equal('"highlight SKey', @:)
2823 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal('"highlight SpecialKey', @:)
2825 set wildoptions=fuzzy
2826 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2827 call assert_equal('"highlight SpecialKey', @:)
2828 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2829 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830 set wildoptions&
2831endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002833" :history suboptions fuzzy completion
2834func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002835 set wildoptions&
2836 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2837 call assert_equal('"history dg', @:)
2838 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2839 call assert_equal('"history search', @:)
2840 set wildoptions=fuzzy
2841 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2842 call assert_equal('"history debug', @:)
2843 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002845 set wildoptions&
2846endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002847
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002848" :language locale name fuzzy completion
2849func Test_fuzzy_completion_lang()
2850 CheckUnix
2851 set wildoptions&
2852 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2853 call assert_equal('"lang psx', @:)
2854 set wildoptions=fuzzy
2855 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"lang POSIX', @:)
2857 set wildoptions&
2858endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002859
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002860" :mapclear buffer argument fuzzy completion
2861func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002862 set wildoptions&
2863 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2864 call assert_equal('"mapclear buf', @:)
2865 set wildoptions=fuzzy
2866 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2867 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002868 set wildoptions&
2869endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002870
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002871" map name fuzzy completion
2872func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002873 " test regex completion works
2874 set wildoptions=fuzzy
2875 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2876 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002877 nmap <plug>MyLongMap :p<CR>
2878 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2879 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2880 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2881 call assert_equal("\"nmap MLM \t", @:)
2882 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2883 call assert_equal("\"nmap <F2> one two \t", @:)
2884 " duplicate entries should be removed
2885 vmap <plug>MyLongMap :<C-U>#<CR>
2886 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2887 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2888 nunmap <plug>MyLongMap
2889 vunmap <plug>MyLongMap
2890 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2891 call assert_equal("\"nmap ABC\t", @:)
2892 " results should be sorted by best match
2893 nmap <Plug>format :
2894 nmap <Plug>goformat :
2895 nmap <Plug>TestFOrmat :
2896 nmap <Plug>fendoff :
2897 nmap <Plug>state :
2898 nmap <Plug>FendingOff :
2899 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2900 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2901 nunmap <Plug>format
2902 nunmap <Plug>goformat
2903 nunmap <Plug>TestFOrmat
2904 nunmap <Plug>fendoff
2905 nunmap <Plug>state
2906 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002907 set wildoptions&
2908endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002909
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002910" abbreviation fuzzy completion
2911func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002912 set wildoptions=fuzzy
2913 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal("\"iabbr <nowait>", @:)
2915 iabbr WaitForCompletion WFC
2916 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal("\"iabbr WaitForCompletion", @:)
2918 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2919 call assert_equal("\"iabbr a1z\t", @:)
2920 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002921 set wildoptions&
2922endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002923
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002924" menu name fuzzy completion
2925func Test_fuzzy_completion_menu()
2926 CheckGui
2927 set wildoptions&
2928 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2929 call assert_equal('"menu pup', @:)
2930 set wildoptions=fuzzy
2931 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2932 call assert_equal('"menu PopUp.', @:)
2933 set wildoptions&
2934endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002935
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002936" :messages suboptions fuzzy completion
2937func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002938 set wildoptions&
2939 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2940 call assert_equal('"messages clr', @:)
2941 set wildoptions=fuzzy
2942 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2943 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944 set wildoptions&
2945endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002946
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947" :set option name fuzzy completion
2948func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949 set wildoptions&
2950 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"set brkopt', @:)
2952 set wildoptions=fuzzy
2953 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"set breakindentopt', @:)
2955 set wildoptions&
2956 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"set fixendofline', @:)
2958 set wildoptions=fuzzy
2959 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2960 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961 set wildoptions&
2962endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002963
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002964" :set <term_option>
2965func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002966 set wildoptions&
2967 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal('"set t_EC', @:)
2969 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal('"set <t_EC>', @:)
2971 set wildoptions=fuzzy
2972 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2973 call assert_equal('"set t_EC', @:)
2974 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2975 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002976 set wildoptions&
2977endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002978
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002979" " :packadd directory name fuzzy completion - NOT supported
2980" func Test_fuzzy_completion_packadd()
2981" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002982
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002983" " shell command name fuzzy completion - NOT supported
2984" func Test_fuzzy_completion_shellcmd()
2985" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002986
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002987" :sign suboptions fuzzy completion
2988func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002989 set wildoptions&
2990 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal('"sign ufe', @:)
2992 set wildoptions=fuzzy
2993 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002995 set wildoptions&
2996endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002997
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002998" :syntax suboptions fuzzy completion
2999func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003000 set wildoptions&
3001 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal('"syntax kwd', @:)
3003 set wildoptions=fuzzy
3004 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3005 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003006 set wildoptions&
3007endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003008
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003009" syntax group name fuzzy completion
3010func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003011 set wildoptions&
3012 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"syntax list mpar', @:)
3014 set wildoptions=fuzzy
3015 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3016 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003017 set wildoptions&
3018endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003019
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003020" :syntime suboptions fuzzy completion
3021func Test_fuzzy_completion_syntime()
3022 CheckFeature profile
3023 set wildoptions&
3024 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal('"syntime clr', @:)
3026 set wildoptions=fuzzy
3027 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal('"syntime clear', @:)
3029 set wildoptions&
3030endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003031
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003032" " tag name fuzzy completion - NOT supported
3033" func Test_fuzzy_completion_tagname()
3034" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003035
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003036" " tag name and file fuzzy completion - NOT supported
3037" func Test_fuzzy_completion_tagfile()
3038" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003039
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003040" " user names fuzzy completion - how to test this functionality?
3041" func Test_fuzzy_completion_username()
3042" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003043
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003044" user defined variable name fuzzy completion
3045func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003046 let g:SomeVariable=10
3047 set wildoptions&
3048 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"let SVar', @:)
3050 set wildoptions=fuzzy
3051 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003053 set wildoptions&
3054endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003055
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003056" Test for sorting the results by the best match
3057func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003058 %bw!
3059 command T123format :
3060 command T123goformat :
3061 command T123TestFOrmat :
3062 command T123fendoff :
3063 command T123state :
3064 command T123FendingOff :
3065 set wildoptions=fuzzy
3066 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3068 delcommand T123format
3069 delcommand T123goformat
3070 delcommand T123TestFOrmat
3071 delcommand T123fendoff
3072 delcommand T123state
3073 delcommand T123FendingOff
3074 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003075 set wildoptions&
3076endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003077
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003078" Test for fuzzy completion of a command with lower case letters and a number
3079func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003080 command Foo2Bar :
3081 set wildoptions=fuzzy
3082 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal('"Foo2Bar', @:)
3084 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal('"Foo2Bar', @:)
3086 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3087 call assert_equal('"Foo2Bar', @:)
3088 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003089 set wildoptions&
3090endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003091
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003092" Test for command completion for a command starting with 'k'
3093func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003094 command KillKillKill :
3095 set wildoptions&
3096 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal("\"killkill\<Tab>", @:)
3098 set wildoptions=fuzzy
3099 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal('"KillKillKill', @:)
3101 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003102 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003103endfunc
3104
3105" Test for fuzzy completion for user defined custom completion function
3106func Test_fuzzy_completion_custom_func()
3107 func Tcompl(a, c, p)
3108 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3109 endfunc
3110 command -nargs=* -complete=custom,Tcompl Fuzzy :
3111 set wildoptions&
3112 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3113 call assert_equal("\"Fuzzy format", @:)
3114 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3115 call assert_equal("\"Fuzzy xy", @:)
3116 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal("\"Fuzzy ttt", @:)
3118 set wildoptions=fuzzy
3119 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3121 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3123 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"Fuzzy xy", @:)
3125 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"Fuzzy TestFOrmat", @:)
3127 delcom Fuzzy
3128 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003129endfunc
3130
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003131" Test for :breakadd argument completion
3132func Test_cmdline_complete_breakadd()
3133 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakadd expr file func here", @:)
3135 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"breakadd expr", @:)
3137 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakadd expr", @:)
3139 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakadd here", @:)
3141 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakadd here", @:)
3143 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakadd abc", @:)
3145 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3146 let l = getcompletion('not', 'breakpoint')
3147 call assert_equal([], l)
3148
3149 " Test for :breakadd file [lnum] <file>
3150 call writefile([], 'Xscript')
3151 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakadd file Xscript", @:)
3153 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakadd file Xscript", @:)
3155 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakadd file 20 Xscript", @:)
3157 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakadd file 20 Xscript", @:)
3159 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3161 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd file 20\t", @:)
3163 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakadd file 20x\t", @:)
3165 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"breakadd file Xscript ", @:)
3167 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd file X1B2C3", @:)
3169 call delete('Xscript')
3170
3171 " Test for :breakadd func [lnum] <function>
3172 func Xbreak_func()
3173 endfunc
3174 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"breakadd func Xbreak_func", @:)
3176 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal("\"breakadd func Xbreak_func", @:)
3178 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3180 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3182 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3184 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal("\"breakadd func 20\t", @:)
3186 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"breakadd func 20x\t", @:)
3188 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal("\"breakadd func Xbreak_func ", @:)
3190 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal("\"breakadd func X1B2C3", @:)
3192 delfunc Xbreak_func
3193
3194 " Test for :breakadd expr <expression>
3195 let g:Xtest_var = 10
3196 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"breakadd expr Xtest_var", @:)
3198 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"breakadd expr Xtest_var", @:)
3200 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"breakadd expr Xtest_var ", @:)
3202 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3203 call assert_equal("\"breakadd expr X1B2C3", @:)
3204 unlet g:Xtest_var
3205
3206 " Test for :breakadd here
3207 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"breakadd here Xtest", @:)
3209 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"breakadd here Xtest", @:)
3211 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal("\"breakadd here ", @:)
3213endfunc
3214
3215" Test for :breakdel argument completion
3216func Test_cmdline_complete_breakdel()
3217 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal("\"breakdel file func here", @:)
3219 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel file", @:)
3221 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel file", @:)
3223 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel here", @:)
3225 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel here", @:)
3227 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel abc", @:)
3229
3230 " Test for :breakdel file [lnum] <file>
3231 call writefile([], 'Xscript')
3232 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal("\"breakdel file Xscript", @:)
3234 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal("\"breakdel file Xscript", @:)
3236 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal("\"breakdel file 20 Xscript", @:)
3238 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3239 call assert_equal("\"breakdel file 20 Xscript", @:)
3240 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3242 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal("\"breakdel file 20\t", @:)
3244 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal("\"breakdel file 20x\t", @:)
3246 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal("\"breakdel file Xscript ", @:)
3248 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal("\"breakdel file X1B2C3", @:)
3250 call delete('Xscript')
3251
3252 " Test for :breakdel func [lnum] <function>
3253 func Xbreak_func()
3254 endfunc
3255 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal("\"breakdel func Xbreak_func", @:)
3257 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakdel func Xbreak_func", @:)
3259 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3261 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3263 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3265 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal("\"breakdel func 20\t", @:)
3267 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3268 call assert_equal("\"breakdel func 20x\t", @:)
3269 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3270 call assert_equal("\"breakdel func Xbreak_func ", @:)
3271 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal("\"breakdel func X1B2C3", @:)
3273 delfunc Xbreak_func
3274
3275 " Test for :breakdel here
3276 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3277 call assert_equal("\"breakdel here Xtest", @:)
3278 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3279 call assert_equal("\"breakdel here Xtest", @:)
3280 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3281 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003282endfunc
3283
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003284" Test for :scriptnames argument completion
3285func Test_cmdline_complete_scriptnames()
3286 set wildmenu
3287 call writefile(['let a = 1'], 'Xa1b2c3.vim')
3288 source Xa1b2c3.vim
3289 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3290 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3291 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3292 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3293 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal("\"script b2c3", @:)
3295 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3296 call assert_match("\"script 2\<Tab>$", @:)
3297 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3298 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3299 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3300 call assert_equal("\"script ", @:)
3301 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3302 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3303 new
3304 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3305 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3306 bw!
3307 call delete('Xa1b2c3.vim')
3308 set wildmenu&
3309endfunc
3310
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003311" Test for expanding 2-letter and 3-letter :substitute command arguments.
3312" These commands don't accept an argument.
3313func Test_cmdline_complete_substitute_short()
3314 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3315 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3316 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3317 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3318 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3319 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3321 endfor
3322endfunc
3323
Bram Moolenaar309976e2019-12-05 18:16:33 +01003324" vim: shiftwidth=2 sts=2 expandtab