blob: dc781f8e10cbda0dad87c36884d2285e2d07b296 [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
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000555func Test_complete_autoload_error()
556 let save_rtp = &rtp
557 let lines =<< trim END
558 vim9script
559 export def Complete(..._): string
560 return 'match'
561 enddef
562 echo this will cause an error
563 END
564 call mkdir('Xdir/autoload', 'p')
565 call writefile(lines, 'Xdir/autoload/script.vim')
566 exe 'set rtp+=' .. getcwd() .. '/Xdir'
567
568 let lines =<< trim END
569 vim9script
570 import autoload 'script.vim'
571 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
572 &wildcharm = char2nr("\<Tab>")
573 feedkeys(":Cmd \<Tab>", 'xt')
574 END
575 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
576
577 let &rtp = save_rtp
578 call delete('Xdir', 'rf')
579endfunc
580
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100581func Test_fullcommand()
582 let tests = {
583 \ '': '',
584 \ ':': '',
585 \ ':::': '',
586 \ ':::5': '',
587 \ 'not_a_cmd': '',
588 \ 'Check': '',
589 \ 'syntax': 'syntax',
590 \ ':syntax': 'syntax',
591 \ '::::syntax': 'syntax',
592 \ 'sy': 'syntax',
593 \ 'syn': 'syntax',
594 \ 'synt': 'syntax',
595 \ ':sy': 'syntax',
596 \ '::::sy': 'syntax',
597 \ 'match': 'match',
598 \ '2match': 'match',
599 \ '3match': 'match',
600 \ 'aboveleft': 'aboveleft',
601 \ 'abo': 'aboveleft',
602 \ 's': 'substitute',
603 \ '5s': 'substitute',
604 \ ':5s': 'substitute',
605 \ "'<,'>s": 'substitute',
606 \ ":'<,'>s": 'substitute',
607 \ 'CheckUni': 'CheckUnix',
608 \ 'CheckUnix': 'CheckUnix',
609 \ }
610
611 for [in, want] in items(tests)
612 call assert_equal(want, fullcommand(in))
613 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200614 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100615
616 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200617
618 command -buffer BufferLocalCommand :
619 command GlobalCommand :
620 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
621 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
622 delcommand BufferLocalCommand
623 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100624endfunc
625
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200626func Test_shellcmd_completion()
627 let save_path = $PATH
628
629 call mkdir('Xpathdir/Xpathsubdir', 'p')
630 call writefile([''], 'Xpathdir/Xfile.exe')
631 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
632
633 " Set PATH to example directory without trailing slash.
634 let $PATH = getcwd() . '/Xpathdir'
635
636 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
637 " dirs in the PATH, even though they won't be executed. We check that only
638 " subdirs of the PWD and executables from the PATH are included in the
639 " suggestions.
640 let actual = getcompletion('X', 'shellcmd')
641 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
642 call insert(expected, 'Xfile.exe')
643 call assert_equal(expected, actual)
644
645 call delete('Xpathdir', 'rf')
646 let $PATH = save_path
647endfunc
648
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200649func Test_expand_star_star()
650 call mkdir('a/b', 'p')
651 call writefile(['asdfasdf'], 'a/b/fileXname')
652 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000653 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200654 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200655 call delete('a', 'rf')
656endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100657
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100658func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100659 let @a = "def"
660 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
661 call assert_equal('"abc def ghi', @:)
662
663 new
664 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
665
666 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
667 call assert_equal('"aaa asdf bbb', @:)
668
669 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
670 call assert_equal('"aaa /tmp/some bbb', @:)
671
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200672 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
673 call assert_equal('"aaa '.getline(1).' bbb', @:)
674
Bram Moolenaar21efc362016-12-03 14:05:49 +0100675 set incsearch
676 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
677 call assert_equal('"aaa verylongword bbb', @:)
678
679 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
680 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100681
682 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
683 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100684 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200685
686 " Error while typing a command used to cause that it was not executed
687 " in the end.
688 new
689 try
690 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
691 catch /^Vim\%((\a\+)\)\=:E32/
692 " ignore error E32
693 endtry
694 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100695
Bram Moolenaar578fe942020-02-27 21:32:51 +0100696 " Try to paste an invalid register using <C-R>
697 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
698 call assert_equal('"onetwo', @:)
699
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100700 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100701 let @a = "xy\<C-H>z"
702 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
703 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100704 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
705 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100706 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
707 call assert_equal("\"xy\<C-H>z", @:)
708
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100709 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
710 let @a = "xy\<C-V>z"
711 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
712 call assert_equal('"xyz', @:)
713 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
714 call assert_equal("\"xy\<C-V>z", @:)
715
Bram Moolenaar578fe942020-02-27 21:32:51 +0100716 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
717
Bram Moolenaar72532d32018-04-07 19:09:09 +0200718 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100719endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100720
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100721func Test_cmdline_remove_char()
722 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100723
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100724 for e in ['utf8', 'latin1']
725 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100726
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100727 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
728 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100729
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100730 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
731 call assert_equal('"abcdef', @:)
732
733 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
734 call assert_equal('"abc ghi', @:, e)
735
736 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
737 call assert_equal('"def', @:, e)
738 endfor
739
740 let &encoding = encoding_save
741endfunc
742
743func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200744 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100745
746 set keymap=esperanto
747 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
748 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
749 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100750endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100751
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100752func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100753 new
754 2;'(
755 2;')
756 quit
757endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100758
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100759func Test_illegal_address2()
760 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
761 new
762 source Xtest.vim
763 " Trigger calling validate_cursor()
764 diffsp Xtest.vim
765 quit!
766 bwipe!
767 call delete('Xtest.vim')
768endfunc
769
Bram Moolenaarba47b512017-01-24 21:18:19 +0100770func Test_cmdline_complete_wildoptions()
771 help
772 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
773 let a = join(sort(split(@:)),' ')
774 set wildoptions=tagfile
775 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
776 let b = join(sort(split(@:)),' ')
777 call assert_equal(a, b)
778 bw!
779endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100780
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200781func Test_cmdline_complete_user_cmd()
782 command! -complete=color -nargs=1 Foo :
783 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
784 call assert_equal('"Foo blue', @:)
785 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
786 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000787 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
788 call assert_equal('"Foo a blue', @:)
789 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
790 call assert_equal('"Foo b\', @:)
791 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
792 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200793 delcommand Foo
794endfunc
795
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100796func s:ScriptLocalFunction()
797 echo 'yes'
798endfunc
799
800func Test_cmdline_complete_user_func()
801 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200802 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100803 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
804 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100805
806 " g: prefix also works
807 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
808 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200809
810 " using g: prefix does not result in just "g:" matches from a lambda
811 let Fx = { a -> a }
812 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
813 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200814
815 " existence of script-local dict function does not break user function name
816 " completion
817 function s:a_dict_func() dict
818 endfunction
819 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
820 call assert_match('"call Test_cmdline_complete_user_', @:)
821 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100822endfunc
823
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200824func Test_cmdline_complete_user_names()
825 if has('unix') && executable('whoami')
826 let whoami = systemlist('whoami')[0]
827 let first_letter = whoami[0]
828 if len(first_letter) > 0
829 " Trying completion of :e ~x where x is the first letter of
830 " the user name should complete to at least the user name.
831 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
832 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
833 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200834 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200835 " Just in case: check that the system has an Administrator account.
836 let names = system('net user')
837 if names =~ 'Administrator'
838 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100839 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200840 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100841 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200842 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200843 else
844 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200845 endif
846endfunc
847
Bram Moolenaar297610b2019-12-27 17:20:55 +0100848func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200849 CheckExecutable whoami
850 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
851 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100852endfunc
853
Bram Moolenaar8b633132020-03-20 18:20:51 +0100854func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200855 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
856 call assert_equal(lang, v:lc_time)
857
858 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
859 call assert_equal(lang, v:ctype)
860
861 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
862 call assert_equal(lang, v:collate)
863
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200864 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200865 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200866
867 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200868 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200869
Bram Moolenaarec680282020-06-12 19:35:32 +0200870 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200871
Bram Moolenaarec680282020-06-12 19:35:32 +0200872 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
873 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200874
Bram Moolenaarec680282020-06-12 19:35:32 +0200875 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
876 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200877
Bram Moolenaarec680282020-06-12 19:35:32 +0200878 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
879 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200880
881 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
882 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200883endfunc
884
Bram Moolenaar297610b2019-12-27 17:20:55 +0100885func Test_cmdline_complete_env_variable()
886 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100887 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
888 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100889 unlet $X_VIM_TEST_COMPLETE_ENV
890endfunc
891
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100892func Test_cmdline_complete_expression()
893 let g:SomeVar = 'blah'
894 for cmd in ['exe', 'echo', 'echon', 'echomsg']
895 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
896 call assert_match('"' .. cmd .. ' SomeVar', @:)
897 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
898 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
899 endfor
900 unlet g:SomeVar
901endfunc
902
Bram Moolenaar47016f52021-08-26 16:39:58 +0200903" Unique function name for completion below
904func s:WeirdFunc()
905 echo 'weird'
906endfunc
907
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100908" Test for various command-line completion
909func Test_cmdline_complete_various()
910 " completion for a command starting with a comment
911 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
912 call assert_equal("\" :|\"\<C-A>", @:)
913
914 " completion for a range followed by a comment
915 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
916 call assert_equal("\"1,2\"\<C-A>", @:)
917
918 " completion for :k command
919 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
920 call assert_equal("\"ka\<C-A>", @:)
921
922 " completion for short version of the :s command
923 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
924 call assert_equal("\"sI \<C-A>", @:)
925
926 " completion for :write command
927 call mkdir('Xdir')
928 call writefile(['one'], 'Xdir/Xfile1')
929 let save_cwd = getcwd()
930 cd Xdir
931 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
932 call assert_equal("\"w >> Xfile1", @:)
933 call chdir(save_cwd)
934 call delete('Xdir', 'rf')
935
936 " completion for :w ! and :r ! commands
937 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
938 call assert_equal("\"w !invalid_xyz_cmd", @:)
939 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
940 call assert_equal("\"r !invalid_xyz_cmd", @:)
941
942 " completion for :>> and :<< commands
943 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
944 call assert_equal("\">>>\<C-A>", @:)
945 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
946 call assert_equal("\"<<<\<C-A>", @:)
947
948 " completion for command with +cmd argument
949 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
950 call assert_equal("\"buffer +/pat Xabc", @:)
951 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
952 call assert_equal("\"buffer +/pat\<C-A>", @:)
953
954 " completion for a command with a trailing comment
955 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
956 call assert_equal("\"ls \" comment\<C-A>", @:)
957
958 " completion for a command with a trailing command
959 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
960 call assert_equal("\"ls | ls", @:)
961
962 " completion for a command with an CTRL-V escaped argument
963 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
964 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
965
966 " completion for a command that doesn't take additional arguments
967 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
968 call assert_equal("\"all abc\<C-A>", @:)
969
970 " completion for a command with a command modifier
971 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
972 call assert_equal("\"topleft new", @:)
973
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200974 " completion for vim9 and legacy commands
975 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
976 call assert_equal("\"vim9 call strlen(", @:)
977 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
978 call assert_equal("\"legac call strlen(", @:)
979
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200980 " completion for the :disassemble command
981 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
982 call assert_equal("\"disas debug", @:)
983 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
984 call assert_equal("\"disas profile", @:)
985 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
986 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
987 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
988 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +0200989 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
990 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200991
Bram Moolenaar47016f52021-08-26 16:39:58 +0200992 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +0200993 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +0200994
naohiro onodfe04db2021-09-12 15:45:10 +0200995 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
996 call assert_match('"disas <SNR>\d\+_', @:)
997 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
998 call assert_match('"disas debug <SNR>\d\+_', @:)
999
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001000 " completion for the :match command
1001 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1002 call assert_equal("\"match Search /pat/\<C-A>", @:)
1003
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001004 " completion for the :doautocmd command
1005 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1006 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1007
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001008 " completion of autocmd group after comma
1009 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1010 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1011
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001012 " completion of file name in :doautocmd
1013 call writefile([], 'Xfile1')
1014 call writefile([], 'Xfile2')
1015 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
1016 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
1017 call delete('Xfile1')
1018 call delete('Xfile2')
1019
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001020 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001021 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001022 augroup END
1023 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001024 call assert_equal("\"augroup XTest.test", @:)
1025 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1026 call assert_equal("\"au XTest.test", @:)
1027 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001028
1029 " completion for the :unlet command
1030 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1031 call assert_equal("\"unlet one two", @:)
1032
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001033 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001034 " FIXME: what should happen on MS-Windows?
1035 if !has('win32')
1036 edit \{someFile}
1037 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1038 call assert_equal("\"buf {someFile}", @:)
1039 bwipe {someFile}
1040 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001041
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001042 " completion for the :bdelete command
1043 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1044 call assert_equal("\"bdel a b c", @:)
1045
1046 " completion for the :mapclear command
1047 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1048 call assert_equal("\"mapclear <buffer>", @:)
1049
1050 " completion for user defined commands with menu names
1051 menu Test.foo :ls<CR>
1052 com -nargs=* -complete=menu MyCmd
1053 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1054 call assert_equal('"MyCmd Test.', @:)
1055 delcom MyCmd
1056 unmenu Test
1057
1058 " completion for user defined commands with mappings
1059 mapclear
1060 map <F3> :ls<CR>
1061 com -nargs=* -complete=mapping MyCmd
1062 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001063 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001064 mapclear
1065 delcom MyCmd
1066
1067 " completion for :set path= with multiple backslashes
1068 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1069 call assert_equal('"set path=a\\\ b', @:)
1070
1071 " completion for :set dir= with a backslash
1072 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1073 call assert_equal('"set dir=a\ b', @:)
1074
1075 " completion for the :py3 commands
1076 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1077 call assert_equal('"py3 py3do py3file', @:)
1078
Bram Moolenaardf749a22021-03-28 15:29:43 +02001079 " completion for the :vim9 commands
1080 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1081 call assert_equal('"vim9cmd vim9script', @:)
1082
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001083 " redir @" is not the start of a comment. So complete after that
1084 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1085 call assert_equal('"redir @" | cwindow', @:)
1086
1087 " completion after a backtick
1088 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1089 call assert_equal('"e `a1b2c', @:)
1090
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001091 " completion for :language command with an invalid argument
1092 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"language dummy \t", @:)
1094
1095 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001096 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1097 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001098
1099 " completion with ambiguous user defined commands
1100 com TCmd1 echo 'TCmd1'
1101 com TCmd2 echo 'TCmd2'
1102 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1103 call assert_equal('"TCmd ', @:)
1104 delcom TCmd1
1105 delcom TCmd2
1106
1107 " completion after a range followed by a pipe (|) character
1108 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1109 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001110
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001111 " completion after a :global command
1112 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1113 call assert_equal('"g/a/chistory', @:)
1114 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"g/a\\/chist\t", @:)
1116
Bram Moolenaar9c929712020-09-07 22:05:28 +02001117 " use <Esc> as the 'wildchar' for completion
1118 set wildchar=<Esc>
1119 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1120 call assert_equal('"g/a\xb/clearjumps', @:)
1121 " pressing <esc> twice should cancel the command
1122 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1123 call assert_equal('"g/a\xb/clearjumps', @:)
1124 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001125
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001126 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001127 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001128 call writefile([], '~Xtest')
1129 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1130 call assert_equal('"e \~Xtest', @:)
1131 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001132
1133 " should be able to complete a file name that has a '*'
1134 call writefile([], 'Xx*Yy')
1135 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1136 call assert_equal('"e Xx\*Yy', @:)
1137 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001138
1139 " use a literal star
1140 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1141 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001142 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001143
1144 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001146endfunc
1147
1148" Test for 'wildignorecase'
1149func Test_cmdline_wildignorecase()
1150 CheckUnix
1151 call writefile([], 'XTEST')
1152 set wildignorecase
1153 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1154 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001155 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001156 let g:Sline = ''
1157 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1158 call assert_equal('"e xt', @:)
1159 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001160 set wildignorecase&
1161 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001162endfunc
1163
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001164func Test_cmdline_write_alternatefile()
1165 new
1166 call setline('.', ['one', 'two'])
1167 f foo.txt
1168 new
1169 f #-A
1170 call assert_equal('foo.txt-A', expand('%'))
1171 f #<-B.txt
1172 call assert_equal('foo-B.txt', expand('%'))
1173 f %<
1174 call assert_equal('foo-B', expand('%'))
1175 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001176 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001177 bw!
1178 f foo-B.txt
1179 f %<-A
1180 call assert_equal('foo-B-A', expand('%'))
1181 bw!
1182 bw!
1183endfunc
1184
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001185" using a leading backslash here
1186set cpo+=C
1187
1188func Test_cmdline_search_range()
1189 new
1190 call setline(1, ['a', 'b', 'c', 'd'])
1191 /d
1192 1,\/s/b/B/
1193 call assert_equal('B', getline(2))
1194
1195 /a
1196 $
1197 \?,4s/c/C/
1198 call assert_equal('C', getline(3))
1199
1200 call setline(1, ['a', 'b', 'c', 'd'])
1201 %s/c/c/
1202 1,\&s/b/B/
1203 call assert_equal('B', getline(2))
1204
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001205 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001206 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001207
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001208 bwipe!
1209endfunc
1210
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001211" Test for the tick mark (') in an excmd range
1212func Test_tick_mark_in_range()
1213 " If only the tick is passed as a range and no command is specified, there
1214 " should not be an error
1215 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001216 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001217 call assert_fails("',print", 'E78:')
1218endfunc
1219
1220" Test for using a line number followed by a search pattern as range
1221func Test_lnum_and_pattern_as_range()
1222 new
1223 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1224 let @" = ''
1225 2/foo/yank
1226 call assert_equal("foo 3\n", @")
1227 call assert_equal(1, line('.'))
1228 close!
1229endfunc
1230
Bram Moolenaar65189a12017-02-06 22:22:17 +01001231" Tests for getcmdline(), getcmdpos() and getcmdtype()
1232func Check_cmdline(cmdtype)
1233 call assert_equal('MyCmd a', getcmdline())
1234 call assert_equal(8, getcmdpos())
1235 call assert_equal(a:cmdtype, getcmdtype())
1236 return ''
1237endfunc
1238
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001239set cpo&
1240
Bram Moolenaar65189a12017-02-06 22:22:17 +01001241func Test_getcmdtype()
1242 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1243
1244 let cmdtype = ''
1245 debuggreedy
1246 call feedkeys(":debug echo 'test'\<CR>", "t")
1247 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1248 call feedkeys("cont\<CR>", "xt")
1249 0debuggreedy
1250 call assert_equal('>', cmdtype)
1251
1252 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1253 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1254
1255 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001256 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001257
1258 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1259
1260 cnoremap <expr> <F6> Check_cmdline('=')
1261 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1262 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001263
1264 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001265endfunc
1266
Bram Moolenaar81612b72018-06-23 14:55:03 +02001267func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001268 CheckFeature cmdwin
1269
Bram Moolenaar81612b72018-06-23 14:55:03 +02001270 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1271 call assert_equal('/', a)
1272
1273 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1274 call assert_equal('?', a)
1275
1276 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1277 call assert_equal(':', a)
1278
1279 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1280 call assert_equal(':', a)
1281
1282 call assert_equal('', getcmdwintype())
1283endfunc
1284
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001285func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001286 CheckFeature cmdwin
1287
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001288 let s:seq = []
1289 augroup CmdWin
1290 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1291 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1292 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1293 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1294 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1295 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1296
1297 let org_winid = win_getid()
1298 let org_bufnr = bufnr()
1299 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1300 call assert_equal(':', a)
1301 call assert_equal([
1302 \ 'WinLeave ' .. org_winid,
1303 \ 'WinEnter ' .. s:cmd_winid,
1304 \ 'BufLeave ' .. org_bufnr,
1305 \ 'BufEnter ' .. s:cmd_bufnr,
1306 \ 'CmdWinEnter ' .. s:cmd_winid,
1307 \ 'CmdWinLeave ' .. s:cmd_winid,
1308 \ 'BufLeave ' .. s:cmd_bufnr,
1309 \ 'WinLeave ' .. s:cmd_winid,
1310 \ 'WinEnter ' .. org_winid,
1311 \ 'BufEnter ' .. org_bufnr,
1312 \ ], s:seq)
1313
1314 au!
1315 augroup END
1316endfunc
1317
Bram Moolenaar52604f22017-04-07 16:17:39 +02001318func Test_verbosefile()
1319 set verbosefile=Xlog
1320 echomsg 'foo'
1321 echomsg 'bar'
1322 set verbosefile=
1323 let log = readfile('Xlog')
1324 call assert_match("foo\nbar", join(log, "\n"))
1325 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001326 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001327 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001328 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001329endfunc
1330
Bram Moolenaar4facea32019-10-12 20:17:40 +02001331func Test_verbose_option()
1332 CheckScreendump
1333
1334 let lines =<< trim [SCRIPT]
1335 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1336 call feedkeys("\r", 't') " for the hit-enter prompt
1337 set verbose=20
1338 [SCRIPT]
1339 call writefile(lines, 'XTest_verbose')
1340
1341 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001342 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001343 call term_sendkeys(buf, ":DoSomething\<CR>")
1344 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1345
1346 " clean up
1347 call StopVimInTerminal(buf)
1348 call delete('XTest_verbose')
1349endfunc
1350
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001351func Test_setcmdpos()
1352 func InsertTextAtPos(text, pos)
1353 call assert_equal(0, setcmdpos(a:pos))
1354 return a:text
1355 endfunc
1356
1357 " setcmdpos() with position in the middle of the command line.
1358 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1359 call assert_equal('"1ab2', @:)
1360
1361 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1362 call assert_equal('"1b2a', @:)
1363
1364 " setcmdpos() with position beyond the end of the command line.
1365 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1366 call assert_equal('"12ab', @:)
1367
1368 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001369 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001370endfunc
1371
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001372func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001373 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001374 let encoding_save = &encoding
1375
1376 for e in encodings
1377 exe 'set encoding=' . e
1378
1379 " Test overstrike in the middle of the command line.
1380 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001381 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001382
1383 " Test overstrike going beyond end of command line.
1384 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001385 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001386
1387 " Test toggling insert/overstrike a few times.
1388 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001389 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001390 endfor
1391
Bram Moolenaar30276f22019-01-24 17:59:39 +01001392 " Test overstrike with multi-byte characters.
1393 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001394 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001395
1396 let &encoding = encoding_save
1397endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001398
1399func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001400 CheckFeature cmdwin
1401
Bram Moolenaara046b372019-09-15 17:26:07 +02001402 let winid = win_getid()
1403 sp
1404 try
1405 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1406 catch /^Vim\%((\a\+)\)\=:E11/
1407 endtry
1408 bw!
1409endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001410
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001411func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001412 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001413 CheckScreendump
1414
1415 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001416 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001417 call setline(1, range(30))
1418 2split
1419 [SCRIPT]
1420 call writefile(lines, 'XTest_restore')
1421
1422 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001423 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001424 call term_sendkeys(buf, "q:")
1425 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1426
1427 " normal restore
1428 call term_sendkeys(buf, ":q\<CR>")
1429 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1430
1431 " restore after setting 'lines' with one window
1432 call term_sendkeys(buf, ":close\<CR>")
1433 call term_sendkeys(buf, "q:")
1434 call term_sendkeys(buf, ":set lines=18\<CR>")
1435 call term_sendkeys(buf, ":q\<CR>")
1436 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1437
1438 " clean up
1439 call StopVimInTerminal(buf)
1440 call delete('XTest_restore')
1441endfunc
1442
Bram Moolenaare5b44862021-05-30 13:54:03 +02001443func Test_cmdwin_no_terminal()
1444 CheckFeature cmdwin
1445 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001446 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001447
1448 let buf = RunVimInTerminal('', {'rows': 12})
1449 call TermWait(buf, 50)
1450 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1451 call term_sendkeys(buf, "q:")
1452 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1453 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1454 call term_sendkeys(buf, ":q\<CR>")
1455 call StopVimInTerminal(buf)
1456endfunc
1457
Bram Moolenaar52410572019-10-27 05:12:45 +01001458func Test_buffers_lastused()
1459 " check that buffers are sorted by time when wildmode has lastused
1460 call test_settime(1550020000) " middle
1461 edit bufa
1462 enew
1463 call test_settime(1550030000) " newest
1464 edit bufb
1465 enew
1466 call test_settime(1550010000) " oldest
1467 edit bufc
1468 enew
1469 call test_settime(0)
1470 enew
1471
1472 call assert_equal(['bufa', 'bufb', 'bufc'],
1473 \ getcompletion('', 'buffer'))
1474
1475 let save_wildmode = &wildmode
1476 set wildmode=full:lastused
1477
1478 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1479 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1480 call assert_equal('b bufb', X)
1481 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1482 call assert_equal('b bufa', X)
1483 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1484 call assert_equal('b bufc', X)
1485 enew
1486
1487 edit other
1488 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1489 call assert_equal('b bufb', X)
1490 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1491 call assert_equal('b bufa', X)
1492 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1493 call assert_equal('b bufc', X)
1494 enew
1495
1496 let &wildmode = save_wildmode
1497
1498 bwipeout bufa
1499 bwipeout bufb
1500 bwipeout bufc
1501endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001502
1503func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001504 CheckFeature cmdwin
1505
Bram Moolenaar85db5472019-12-04 15:11:08 +01001506 " This should not generate E488
1507 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001508 " Using feedkeys with q: only should automatically close the cmd window
1509 call feedkeys('q:', 'xt')
1510 call assert_equal(1, winnr('$'))
1511 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001512endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001513
1514" Tests for the issues fixed in 7.4.441.
1515" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1516func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001517 CheckFeature cmdwin
1518
Bram Moolenaar309976e2019-12-05 18:16:33 +01001519 exe "set cedit=\<C-c>"
1520 normal! :
1521 call assert_equal(1, winnr('$'))
1522
1523 let g:cmd_wintype = ''
1524 func CmdWinType()
1525 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001526 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001527 return ''
1528 endfunc
1529
1530 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1531 echo input('')
1532 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001533 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001534
1535 set cedit&vim
1536 delfunc CmdWinType
1537endfunc
1538
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001539" Test for CmdwinEnter autocmd
1540func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001541 CheckFeature cmdwin
1542
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001543 augroup CmdWin
1544 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001545 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001546 autocmd CmdwinEnter * startinsert
1547 augroup END
1548
1549 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1550 call assert_equal('xyz', @:)
1551
1552 augroup CmdWin
1553 au!
1554 augroup END
1555 augroup! CmdWin
1556endfunc
1557
Bram Moolenaar479950f2020-01-19 15:45:17 +01001558func Test_cmdlineclear_tabenter()
1559 CheckScreendump
1560
1561 let lines =<< trim [SCRIPT]
1562 call setline(1, range(30))
1563 [SCRIPT]
1564
1565 call writefile(lines, 'XtestCmdlineClearTabenter')
1566 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001567 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001568 " in one tab make the command line higher with CTRL-W -
1569 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1570 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1571
1572 call StopVimInTerminal(buf)
1573 call delete('XtestCmdlineClearTabenter')
1574endfunc
1575
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001576" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001577func Test_cmdline_expand_special()
1578 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001579 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001580 call assert_fails('e <afile>', 'E495:')
1581 call assert_fails('e <abuf>', 'E496:')
1582 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001583
1584 call writefile([], 'Xfile.cpp')
1585 call writefile([], 'Xfile.java')
1586 new Xfile.cpp
1587 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1588 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1589 close
1590 call delete('Xfile.cpp')
1591 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001592endfunc
1593
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001594func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001595 CheckFeature cmdwin
1596
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001597 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1598 new
1599 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001600 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001601 close!
1602 call feedkeys("q/:close\<CR>", "xt")
1603 call assert_equal(1, winnr('$'))
1604 call feedkeys("q/:exit\<CR>", "xt")
1605 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001606
1607 " opening command window twice should fail
1608 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1609 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001610endfunc
1611
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00001612func Test_cmdwin_tabpage()
1613 tabedit
1614 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1615 tabclose!
1616endfunc
1617
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001618func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001619 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001620 CheckScreendump
1621
1622 " aborting the :smile output caused the cmdline window to use the current
1623 " buffer.
1624 let lines =<< trim [SCRIPT]
1625 au WinNew * smile
1626 [SCRIPT]
1627 call writefile(lines, 'XTest_cmdwin')
1628
1629 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001630 " open cmdwin
1631 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001632 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001633 " quit more prompt for :smile command
1634 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001635 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001636 " execute a simple command
1637 call term_sendkeys(buf, "aecho 'done'\<CR>")
1638 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1639
1640 " clean up
1641 call StopVimInTerminal(buf)
1642 call delete('XTest_cmdwin')
1643endfunc
1644
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001645" Test for backtick expression in the command line
1646func Test_cmd_backtick()
1647 %argd
1648 argadd `=['a', 'b', 'c']`
1649 call assert_equal(['a', 'b', 'c'], argv())
1650 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001651
1652 argadd `echo abc def`
1653 call assert_equal(['abc def'], argv())
1654 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001655endfunc
1656
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001657" Test for the :! command
1658func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001659 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001660
1661 let lines =<< trim [SCRIPT]
1662 " Test for no previous command
1663 call assert_fails('!!', 'E34:')
1664 set nomore
1665 " Test for cmdline expansion with :!
1666 call setline(1, 'foo!')
1667 silent !echo <cWORD> > Xfile.out
1668 call assert_equal(['foo!'], readfile('Xfile.out'))
1669 " Test for using previous command
1670 silent !echo \! !
1671 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1672 call writefile(v:errors, 'Xresult')
1673 call delete('Xfile.out')
1674 qall!
1675 [SCRIPT]
1676 call writefile(lines, 'Xscript')
1677 if RunVim([], [], '--clean -S Xscript')
1678 call assert_equal([], readfile('Xresult'))
1679 endif
1680 call delete('Xscript')
1681 call delete('Xresult')
1682endfunc
1683
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001684" Test error: "E135: *Filter* Autocommands must not change current buffer"
1685func Test_cmd_bang_E135()
1686 new
1687 call setline(1, ['a', 'b', 'c', 'd'])
1688 augroup test_cmd_filter_E135
1689 au!
1690 autocmd FilterReadPost * help
1691 augroup END
1692 call assert_fails('2,3!echo "x"', 'E135:')
1693
1694 augroup test_cmd_filter_E135
1695 au!
1696 augroup END
1697 %bwipe!
1698endfunc
1699
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001700" Test for using ~ for home directory in cmdline completion matches
1701func Test_cmdline_expand_home()
1702 call mkdir('Xdir')
1703 call writefile([], 'Xdir/Xfile1')
1704 call writefile([], 'Xdir/Xfile2')
1705 cd Xdir
1706 let save_HOME = $HOME
1707 let $HOME = getcwd()
1708 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1709 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1710 let $HOME = save_HOME
1711 cd ..
1712 call delete('Xdir', 'rf')
1713endfunc
1714
Bram Moolenaar578fe942020-02-27 21:32:51 +01001715" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1716" or insert mode (when 'insertmode' is set)
1717func Test_cmdline_ctrl_g()
1718 new
1719 call setline(1, 'abc')
1720 call cursor(1, 3)
1721 " If command line is entered from insert mode, using C-\ C-G should back to
1722 " insert mode
1723 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1724 call assert_equal('abxyc', getline(1))
1725 call assert_equal(4, col('.'))
1726
1727 " If command line is entered in 'insertmode', using C-\ C-G should back to
1728 " 'insertmode'
1729 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1730 call assert_equal('ab12xyc', getline(1))
1731 close!
1732endfunc
1733
Bram Moolenaar578fe942020-02-27 21:32:51 +01001734" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001735func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001736 func T(a, c, p)
1737 return "oneA\noneB\noneC"
1738 endfunc
1739 command -nargs=1 -complete=custom,T MyCmd
1740
Bram Moolenaar578fe942020-02-27 21:32:51 +01001741 set nowildmenu
1742 set wildmode=full,list
1743 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001744 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001745 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001746 call assert_equal('"MyCmd oneA', @:)
1747
1748 set wildmode=longest,full
1749 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1750 call assert_equal('"MyCmd one', @:)
1751 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1752 call assert_equal('"MyCmd oneC', @:)
1753
1754 set wildmode=longest
1755 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1756 call assert_equal('"MyCmd one', @:)
1757
1758 set wildmode=list:longest
1759 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001760 call feedkeys(":MyCmd \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 one', @:)
1763
1764 set wildmode=""
1765 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"MyCmd oneA', @:)
1767
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001768 " Test for wildmode=longest with 'fileignorecase' set
1769 set wildmode=longest
1770 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001771 argadd AAA AAAA AAAAA
1772 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1773 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001774 set fileignorecase&
1775
1776 " Test for listing files with wildmode=list
1777 set wildmode=list
1778 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001779 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001780 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001781 call assert_equal('"b A', @:)
1782
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001783 " when using longest completion match, matches shorter than the argument
1784 " should be ignored (happens with :help)
1785 set wildmode=longest,full
1786 set wildmenu
1787 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1788 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001789 " non existing file
1790 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1791 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001792 set wildmenu&
1793
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001794 " Test for longest file name completion with 'fileignorecase'
1795 " On MS-Windows, file names are case insensitive.
1796 if has('unix')
1797 call writefile([], 'XTESTfoo')
1798 call writefile([], 'Xtestbar')
1799 set nofileignorecase
1800 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1801 call assert_equal('"e XTESTfoo', @:)
1802 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1803 call assert_equal('"e Xtestbar', @:)
1804 set fileignorecase
1805 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1806 call assert_equal('"e Xtest', @:)
1807 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1808 call assert_equal('"e Xtest', @:)
1809 set fileignorecase&
1810 call delete('XTESTfoo')
1811 call delete('Xtestbar')
1812 endif
1813
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001814 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001815 delcommand MyCmd
1816 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001817 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001818 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001819endfunc
1820
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001821func Test_wildmode()
1822 " Test with utf-8 encoding
1823 call Wildmode_tests()
1824
1825 " Test with latin1 encoding
1826 let save_encoding = &encoding
1827 set encoding=latin1
1828 call Wildmode_tests()
1829 let &encoding = save_encoding
1830endfunc
1831
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001832func Test_custom_complete_autoload()
1833 call mkdir('Xdir/autoload', 'p')
1834 let save_rtp = &rtp
1835 exe 'set rtp=' .. getcwd() .. '/Xdir'
1836 let lines =<< trim END
1837 func vim8#Complete(a, c, p)
1838 return "oneA\noneB\noneC"
1839 endfunc
1840 END
1841 call writefile(lines, 'Xdir/autoload/vim8.vim')
1842
1843 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1844 set nowildmenu
1845 set wildmode=full,list
1846 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1847 call assert_equal('"MyCmd oneA oneB oneC', @:)
1848
1849 let &rtp = save_rtp
1850 set wildmode& wildmenu&
1851 delcommand MyCmd
1852 call delete('Xdir', 'rf')
1853endfunc
1854
Bram Moolenaar578fe942020-02-27 21:32:51 +01001855" Test for interrupting the command-line completion
1856func Test_interrupt_compl()
1857 func F(lead, cmdl, p)
1858 if a:lead =~ 'tw'
1859 call interrupt()
1860 return
1861 endif
1862 return "one\ntwo\nthree"
1863 endfunc
1864 command -nargs=1 -complete=custom,F Tcmd
1865
1866 set nowildmenu
1867 set wildmode=full
1868 let interrupted = 0
1869 try
1870 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1871 catch /^Vim:Interrupt$/
1872 let interrupted = 1
1873 endtry
1874 call assert_equal(1, interrupted)
1875
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001876 let interrupted = 0
1877 try
1878 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1879 catch /^Vim:Interrupt$/
1880 let interrupted = 1
1881 endtry
1882 call assert_equal(1, interrupted)
1883
Bram Moolenaar578fe942020-02-27 21:32:51 +01001884 delcommand Tcmd
1885 delfunc F
1886 set wildmode&
1887endfunc
1888
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001889" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001890func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001891 let str = ":one two\<C-U>"
1892 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001893 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001894 let str ..= "\<Left>five\<Right>"
1895 let str ..= "\<Home>two "
1896 let str ..= "\<C-Left>one "
1897 let str ..= "\<C-Right> three"
1898 let str ..= "\<End>\<S-Left>four "
1899 let str ..= "\<S-Right> six"
1900 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1901 call feedkeys(str, 'xt')
1902 call assert_equal("\"one two three four five six seven", @:)
1903endfunc
1904
1905" Test for moving the cursor on the / command line in 'rightleft' mode
1906func Test_cmdline_edit_rightleft()
1907 CheckFeature rightleft
1908 set rightleft
1909 set rightleftcmd=search
1910 let str = "/one two\<C-U>"
1911 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001912 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001913 let str ..= "\<Right>five\<Left>"
1914 let str ..= "\<Home>two "
1915 let str ..= "\<C-Right>one "
1916 let str ..= "\<C-Left> three"
1917 let str ..= "\<End>\<S-Right>four "
1918 let str ..= "\<S-Left> six"
1919 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1920 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1921 call assert_equal("\"one two three four five six seven", @/)
1922 set rightleftcmd&
1923 set rightleft&
1924endfunc
1925
1926" Test for using <C-\>e in the command line to evaluate an expression
1927func Test_cmdline_expr()
1928 " Evaluate an expression from the beginning of a command line
1929 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1930 call assert_equal('"hello', @:)
1931
1932 " Use an invalid expression for <C-\>e
1933 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1934
1935 " Insert literal <CTRL-\> in the command line
1936 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1937 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001938endfunc
1939
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001940" Test for 'imcmdline' and 'imsearch'
1941" This test doesn't actually test the input method functionality.
1942func Test_cmdline_inputmethod()
1943 new
1944 call setline(1, ['', 'abc', ''])
1945 set imcmdline
1946
1947 call feedkeys(":\"abc\<CR>", 'xt')
1948 call assert_equal("\"abc", @:)
1949 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1950 call assert_equal("\"abc", @:)
1951 call feedkeys("/abc\<CR>", 'xt')
1952 call assert_equal([2, 1], [line('.'), col('.')])
1953 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1954 call assert_equal([2, 1], [line('.'), col('.')])
1955
1956 set imsearch=2
1957 call cursor(1, 1)
1958 call feedkeys("/abc\<CR>", 'xt')
1959 call assert_equal([2, 1], [line('.'), col('.')])
1960 call cursor(1, 1)
1961 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1962 call assert_equal([2, 1], [line('.'), col('.')])
1963 set imdisable
1964 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1965 call assert_equal([2, 1], [line('.'), col('.')])
1966 set imdisable&
1967 set imsearch&
1968
1969 set imcmdline&
1970 %bwipe!
1971endfunc
1972
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001973" Test for recursively getting multiple command line inputs
1974func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001975 CheckFeature cmdwin
1976
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001977 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1978 call assert_equal('"cyan', @:)
1979endfunc
1980
1981" Test for using CTRL-_ in the command line with 'allowrevins'
1982func Test_cmdline_revins()
1983 CheckNotMSWindows
1984 CheckFeature rightleft
1985 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1986 call assert_equal("\"abc\<c-_>", @:)
1987 set allowrevins
1988 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1989 call assert_equal('"abcñèæ', @:)
1990 set allowrevins&
1991endfunc
1992
1993" Test for typing UTF-8 composing characters in the command line
1994func Test_cmdline_composing_chars()
1995 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1996 call assert_equal('"ゔ', @:)
1997endfunc
1998
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001999" Test for normal mode commands not supported in the cmd window
2000func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002001 CheckFeature cmdwin
2002
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002003 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
2004 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
2005 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
2006 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
2007 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
2008 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02002009 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
2010 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
2011 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
2012 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
2013 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
2014 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
2015 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
2016 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
2017 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
2018 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
2019 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
2020 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
2021 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
2022 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
2023 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
2024 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
2025 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
2026 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
2027 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
2028 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
2029 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002030endfunc
2031
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002032" Close the Cmd-line window in insert mode using CTRL-C
2033func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002034 CheckFeature cmdwin
2035
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002036 %bw!
2037 let s = ''
2038 exe "normal q:a\<C-C>let s='Hello'\<CR>"
2039 call assert_equal('Hello', s)
2040 call assert_equal(1, winnr('$'))
2041endfunc
2042
Bram Moolenaar0e717042020-04-27 19:29:01 +02002043" test that ";" works to find a match at the start of the first line
2044func Test_zero_line_search()
2045 new
2046 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2047 call cursor(1,1)
2048 0;/pattern/d
2049 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2050 q!
2051endfunc
2052
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002053func Test_read_shellcmd()
2054 CheckUnix
2055 if executable('ls')
2056 " There should be ls in the $PATH
2057 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2058 call assert_match('^"r! .*\<ls\>', @:)
2059 endif
2060
2061 if executable('rm')
2062 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2063 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2064 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002065
2066 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2067 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2068 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002069 endif
2070endfunc
2071
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002072" Test for going up and down the directory tree using 'wildmenu'
2073func Test_wildmenu_dirstack()
2074 CheckUnix
2075 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002076 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002077 call writefile([], 'Xdir1/file1_1.txt')
2078 call writefile([], 'Xdir1/file1_2.txt')
2079 call writefile([], 'Xdir1/dir2/file2_1.txt')
2080 call writefile([], 'Xdir1/dir2/file2_2.txt')
2081 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2082 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002083 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2084 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002085 set wildmenu
2086
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002087 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002088 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002089 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002090 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002091 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002092 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002093 call assert_equal('"e ../../dir3/', @:)
2094 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2095 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002096 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002097 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002098 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002099 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002100 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002101 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2102 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2103
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002104 call delete('Xdir1', 'rf')
2105 set wildmenu&
2106endfunc
2107
obcat71c6f7a2021-05-13 20:23:10 +02002108" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002109" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2110" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002111func Test_recalling_cmdline()
2112 CheckFeature cmdline_hist
2113
2114 let g:cmdlines = []
2115 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2116
2117 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002118 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2119 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2120 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2121 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002122 "\ TODO: {'name': 'debug', ...}
2123 \]
2124 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002125 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2126 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2127 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2128 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2129 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002130 \]
2131 let prefix = 'vi'
2132 for h in histories
2133 call histadd(h.name, 'vim')
2134 call histadd(h.name, 'virtue')
2135 call histadd(h.name, 'Virgo')
2136 call histadd(h.name, 'vogue')
2137 call histadd(h.name, 'emacs')
2138 for k in keypairs
2139 let g:cmdlines = []
2140 let keyseqs = h.enter
2141 \ .. prefix
2142 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2143 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2144 \ .. h.exit
2145 call feedkeys(keyseqs, 'xt')
2146 call histdel(h.name, -1) " delete the history added by feedkeys above
2147 let expect = k.prefixmatch
2148 \ ? ['virtue', 'vim', 'virtue', prefix]
2149 \ : ['emacs', 'vogue', 'emacs', prefix]
2150 call assert_equal(expect, g:cmdlines)
2151 endfor
2152 endfor
2153
2154 unlet g:cmdlines
2155 cunmap <Plug>(save-cmdline)
2156endfunc
2157
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002158func Test_cmd_map_cmdlineChanged()
2159 let g:log = []
2160 cnoremap <F1> l<Cmd><CR>s
2161 augroup test
2162 autocmd!
2163 autocmd CmdlineChanged : let g:log += [getcmdline()]
2164 augroup END
2165
2166 call feedkeys(":\<F1>\<CR>", 'xt')
2167 call assert_equal(['l', 'ls'], g:log)
2168
Bram Moolenaar796139a2021-05-18 21:38:45 +02002169 let @b = 'b'
2170 cnoremap <F1> a<C-R>b
2171 let g:log = []
2172 call feedkeys(":\<F1>\<CR>", 'xt')
2173 call assert_equal(['a', 'ab'], g:log)
2174
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002175 unlet g:log
2176 cunmap <F1>
2177 augroup test
2178 autocmd!
2179 augroup END
2180endfunc
2181
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002182" Test for the 'suffixes' option
2183func Test_suffixes_opt()
2184 call writefile([], 'Xfile')
2185 call writefile([], 'Xfile.c')
2186 call writefile([], 'Xfile.o')
2187 set suffixes=
2188 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2189 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002190 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002192 set suffixes=.c
2193 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2194 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002195 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2196 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002197 set suffixes=,,
2198 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2199 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002200 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2201 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002202 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002203 " Test for getcompletion() with different patterns
2204 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2205 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002206 call delete('Xfile')
2207 call delete('Xfile.c')
2208 call delete('Xfile.o')
2209endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002210
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002211" Test for using a popup menu for the command line completion matches
2212" (wildoptions=pum)
2213func Test_wildmenu_pum()
2214 CheckRunVimInTerminal
2215
2216 let commands =<< trim [CODE]
2217 set wildmenu
2218 set wildoptions=pum
2219 set shm+=I
2220 set noruler
2221 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002222
2223 func CmdCompl(a, b, c)
2224 return repeat(['aaaa'], 120)
2225 endfunc
2226 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002227
2228 func MyStatusLine() abort
2229 return 'status'
2230 endfunc
2231 func SetupStatusline()
2232 set statusline=%!MyStatusLine()
2233 set laststatus=2
2234 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002235
2236 func MyTabLine()
2237 return 'my tab line'
2238 endfunc
2239 func SetupTabline()
2240 set statusline=
2241 set tabline=%!MyTabLine()
2242 set showtabline=2
2243 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002244
2245 func DoFeedKeys()
2246 let &wildcharm = char2nr("\t")
2247 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2248 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002249 [CODE]
2250 call writefile(commands, 'Xtest')
2251
2252 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2253
2254 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002255 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2256
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002257 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002258 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002259 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2260
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002261 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002262 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002263 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2264
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002265 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2268
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002269 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002270 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2272
2273 " pressing <C-E> should end completion and go back to the original match
2274 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002275 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2276
2277 " pressing <C-Y> should select the current match and end completion
2278 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002279 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2280
2281 " With 'wildmode' set to 'longest,full', completing a match should display
2282 " the longest match, the wildmenu should not be displayed.
2283 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2284 call TermWait(buf)
2285 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002286 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2287
2288 " pressing <Tab> should display the wildmenu
2289 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002290 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2291
2292 " pressing <Tab> second time should select the next entry in the menu
2293 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002294 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2295
2296 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002297 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002298 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002299 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2300
2301 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2303
2304 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002305 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2306
2307 " Directory name completion
2308 call mkdir('Xdir/XdirA/XdirB', 'p')
2309 call writefile([], 'Xdir/XfileA')
2310 call writefile([], 'Xdir/XdirA/XfileB')
2311 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2312
2313 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002314 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2315
2316 " Pressing <Right> on a directory name should go into that directory
2317 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2319
2320 " Pressing <Left> on a directory name should go to the parent directory
2321 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2323
2324 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002325 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002327 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2328
2329 " Pressing <C-D> when the popup menu is displayed should remove the popup
2330 " menu
2331 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002332 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2333
2334 " Pressing <S-Tab> should open the popup menu with the last entry selected
2335 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002336 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2337
2338 " Pressing <Esc> should close the popup menu and cancel the cmd line
2339 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2341
2342 " Typing a character when the popup is open, should close the popup
2343 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002344 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2345
2346 " When the popup is open, entering the cmdline window should close the popup
2347 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002348 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2349 call term_sendkeys(buf, ":q\<CR>")
2350
2351 " After the last popup menu item, <C-N> should show the original string
2352 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2354
2355 " Use the popup menu for the command name
2356 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002357 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2358
2359 " Pressing the left arrow should remove the popup menu
2360 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002361 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2362
2363 " Pressing <BS> should remove the popup menu and erase the last character
2364 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002365 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2366
2367 " Pressing <C-W> should remove the popup menu and erase the previous word
2368 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002369 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2370
2371 " Pressing <C-U> should remove the popup menu and erase the entire line
2372 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002373 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2374
2375 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2376 " the cmdline from history
2377 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002378 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2379
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002380 " Check "list" still works
2381 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2382 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002383 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2384 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002385 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2386
rbtnn68cc2b82022-02-09 11:55:47 +00002387 " Tests a directory name contained full-width characters.
2388 call mkdir('Xdir/あいう', 'p')
2389 call writefile([], 'Xdir/あいう/abc')
2390 call writefile([], 'Xdir/あいう/xyz')
2391 call writefile([], 'Xdir/あいう/123')
2392
2393 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2394 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002395 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2396
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002397 " Pressing <C-A> when the popup menu is displayed should list all the
2398 " matches and pressing a key after that should remove the popup menu
2399 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2400 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2401 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2402
2403 " Pressing <C-A> when the popup menu is displayed should list all the
2404 " matches and pressing <Left> after that should move the cursor
2405 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2406 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2407 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2408
2409 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2410 " should be displayed correctly on the screen.
2411 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2412 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2413
2414 " After using <C-A> to expand all the filename matches, pressing <Up>
2415 " should not open the popup menu again.
2416 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2417 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2418 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2419 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2420
2421 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2422 " crash Vim
2423 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2424 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2425
Bram Moolenaar414acd32022-02-10 21:09:45 +00002426 " After removing the pum the command line is redrawn
2427 call term_sendkeys(buf, ":edit foo\<CR>")
2428 call term_sendkeys(buf, ":edit bar\<CR>")
2429 call term_sendkeys(buf, ":ls\<CR>")
2430 call term_sendkeys(buf, ":com\<Tab> ")
2431 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002432 call term_sendkeys(buf, "\<C-U>\<CR>")
2433
2434 " Esc still works to abort the command when 'statusline' is set
2435 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2436 call term_sendkeys(buf, ":si\<Tab>")
2437 call term_sendkeys(buf, "\<Esc>")
2438 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002439
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002440 " Esc still works to abort the command when 'tabline' is set
2441 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2442 call term_sendkeys(buf, ":si\<Tab>")
2443 call term_sendkeys(buf, "\<Esc>")
2444 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2445
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002446 " popup is cleared also when 'lazyredraw' is set
2447 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2448 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2449 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2450 call term_sendkeys(buf, "\<Esc>")
2451
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002452 " Pressing <PageDown> should scroll the menu downward
2453 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2454 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2455 call term_sendkeys(buf, "\<PageDown>")
2456 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2457 call term_sendkeys(buf, "\<PageDown>")
2458 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2459 call term_sendkeys(buf, "\<PageDown>")
2460 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2461 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2462 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2463
2464 " Pressing <PageUp> should scroll the menu upward
2465 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2466 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2467 call term_sendkeys(buf, "\<PageUp>")
2468 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2469 call term_sendkeys(buf, "\<PageUp>")
2470 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2471 call term_sendkeys(buf, "\<PageUp>")
2472 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2473
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002474 call term_sendkeys(buf, "\<C-U>\<CR>")
2475 call StopVimInTerminal(buf)
2476 call delete('Xtest')
2477 call delete('Xdir', 'rf')
2478endfunc
2479
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002480" Test for wildmenumode() with the cmdline popup menu
2481func Test_wildmenumode_with_pum()
2482 set wildmenu
2483 set wildoptions=pum
2484 cnoremap <expr> <F2> wildmenumode()
2485 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2486 call assert_equal('"sign define10', @:)
2487 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2488 call assert_equal('"sign define jump list place undefine unplace0', @:)
2489 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2490 call assert_equal('"sign 0', @:)
2491 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2492 call assert_equal('"sign define0', @:)
2493 set nowildmenu wildoptions&
2494 cunmap <F2>
2495endfunc
2496
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002497" Test for completion after a :substitute command followed by a pipe (|)
2498" character
2499func Test_cmdline_complete_substitute()
2500 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2501 call assert_equal("\"s | \t", @:)
2502 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2503 call assert_equal("\"s/ | \t", @:)
2504 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2505 call assert_equal("\"s/one | \t", @:)
2506 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2507 call assert_equal("\"s/one/ | \t", @:)
2508 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2509 call assert_equal("\"s/one/two | \t", @:)
2510 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2511 call assert_equal('"s/one/two/ | chistory', @:)
2512 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2513 call assert_equal("\"s/one/two/g \t", @:)
2514 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2515 call assert_equal("\"s/one/two/g | chistory", @:)
2516 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2517 call assert_equal("\"s/one/t\\/ | \t", @:)
2518 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2519 call assert_equal('"s/one/t"o/ | chistory', @:)
2520 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2521 call assert_equal('"s/one/t|o/ | chistory', @:)
2522 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2523 call assert_equal("\"&\t", @:)
2524endfunc
2525
2526" Test for the :dlist command completion
2527func Test_cmdline_complete_dlist()
2528 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2529 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2530 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2531 call assert_equal("\"dlist 10 /pat/ \t", @:)
2532 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2533 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2534 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2535 call assert_equal("\"dlist 10 /pat\\\t", @:)
2536 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2537 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2538endfunc
2539
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002540" argument list (only for :argdel) fuzzy completion
2541func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002542 argadd change.py count.py charge.py
2543 set wildoptions&
2544 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2545 call assert_equal('"argdel cge', @:)
2546 set wildoptions=fuzzy
2547 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2548 call assert_equal('"argdel change.py charge.py', @:)
2549 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002550 set wildoptions&
2551endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002552
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002553" autocmd group name fuzzy completion
2554func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002555 set wildoptions&
2556 augroup MyFuzzyGroup
2557 augroup END
2558 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2559 call assert_equal('"augroup mfg', @:)
2560 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2561 call assert_equal('"augroup MyFuzzyGroup', @:)
2562 set wildoptions=fuzzy
2563 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2564 call assert_equal('"augroup MyFuzzyGroup', @:)
2565 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2566 call assert_equal('"augroup My*p', @:)
2567 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002568 set wildoptions&
2569endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002570
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002571" buffer name fuzzy completion
2572func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002573 set wildoptions&
2574 edit SomeFile.txt
2575 enew
2576 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2577 call assert_equal('"b SF', @:)
2578 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2579 call assert_equal('"b SomeFile.txt', @:)
2580 set wildoptions=fuzzy
2581 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2582 call assert_equal('"b SomeFile.txt', @:)
2583 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2584 call assert_equal('"b S*File.txt', @:)
2585 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002586 set wildoptions&
2587endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002588
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002589" buffer name (full path) fuzzy completion
2590func Test_fuzzy_completion_bufname_fullpath()
2591 CheckUnix
2592 set wildoptions&
2593 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2594 edit Xcmd/Xstate/Xfile.js
2595 cd Xcmd/Xstate
2596 enew
2597 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2598 call assert_equal('"b CmdStateFile', @:)
2599 set wildoptions=fuzzy
2600 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2602 cd -
2603 call delete('Xcmd', 'rf')
2604 set wildoptions&
2605endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002606
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002607" :behave suboptions fuzzy completion
2608func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002609 set wildoptions&
2610 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2611 call assert_equal('"behave xm', @:)
2612 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2613 call assert_equal('"behave xterm', @:)
2614 set wildoptions=fuzzy
2615 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2616 call assert_equal('"behave xterm', @:)
2617 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2618 call assert_equal('"behave xt*m', @:)
2619 let g:Sline = ''
2620 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2621 call assert_equal('mswin', g:Sline)
2622 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002623 set wildoptions&
2624endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002625
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002626" " colorscheme name fuzzy completion - NOT supported
2627" func Test_fuzzy_completion_colorscheme()
2628" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002629
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002630" built-in command name fuzzy completion
2631func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002632 set wildoptions&
2633 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2634 call assert_equal('"sbwin', @:)
2635 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2636 call assert_equal('"sbrewind', @:)
2637 set wildoptions=fuzzy
2638 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2639 call assert_equal('"sbrewind', @:)
2640 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2641 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002642 set wildoptions&
2643endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002644
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002645" " compiler name fuzzy completion - NOT supported
2646" func Test_fuzzy_completion_compiler()
2647" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002648
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002649" :cscope suboptions fuzzy completion
2650func Test_fuzzy_completion_cscope()
2651 CheckFeature cscope
2652 set wildoptions&
2653 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2654 call assert_equal('"cscope ret', @:)
2655 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2656 call assert_equal('"cscope reset', @:)
2657 set wildoptions=fuzzy
2658 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2659 call assert_equal('"cscope reset', @:)
2660 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2661 call assert_equal('"cscope re*t', @:)
2662 set wildoptions&
2663endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002664
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002665" :diffget/:diffput buffer name fuzzy completion
2666func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002667 new SomeBuffer
2668 diffthis
2669 new OtherBuffer
2670 diffthis
2671 set wildoptions&
2672 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2673 call assert_equal('"diffget sbuf', @:)
2674 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2675 call assert_equal('"diffput sbuf', @:)
2676 set wildoptions=fuzzy
2677 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2678 call assert_equal('"diffget SomeBuffer', @:)
2679 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2680 call assert_equal('"diffput SomeBuffer', @:)
2681 %bw!
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" " directory name fuzzy completion - NOT supported
2686" func Test_fuzzy_completion_dirname()
2687" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002688
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002689" environment variable name fuzzy completion
2690func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002691 set wildoptions&
2692 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2693 call assert_equal('"echo $VUT', @:)
2694 set wildoptions=fuzzy
2695 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2696 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002697 set wildoptions&
2698endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002699
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002700" autocmd event fuzzy completion
2701func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002702 set wildoptions&
2703 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2704 call assert_equal('"autocmd BWout', @:)
2705 set wildoptions=fuzzy
2706 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2707 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002708 set wildoptions&
2709endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002710
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002711" vim expression fuzzy completion
2712func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002713 let g:PerPlaceCount = 10
2714 set wildoptions&
2715 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2716 call assert_equal('"let c = ppc', @:)
2717 set wildoptions=fuzzy
2718 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2719 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002720 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002721endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002722
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002723" " file name fuzzy completion - NOT supported
2724" func Test_fuzzy_completion_filename()
2725" endfunc
2726
2727" " files in path fuzzy completion - NOT supported
2728" func Test_fuzzy_completion_filesinpath()
2729" endfunc
2730
2731" " filetype name fuzzy completion - NOT supported
2732" func Test_fuzzy_completion_filetype()
2733" endfunc
2734
2735" user defined function name completion
2736func Test_fuzzy_completion_userdefined_func()
2737 set wildoptions&
2738 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2739 call assert_equal('"call Test_f_u_f', @:)
2740 set wildoptions=fuzzy
2741 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2742 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2743 set wildoptions&
2744endfunc
2745
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002746" <SNR> functions should be sorted to the end
2747func Test_fuzzy_completion_userdefined_snr_func()
2748 func s:Sendmail()
2749 endfunc
2750 func SendSomemail()
2751 endfunc
2752 func S1e2n3dmail()
2753 endfunc
2754 set wildoptions=fuzzy
2755 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002756 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002757 set wildoptions&
2758 delfunc s:Sendmail
2759 delfunc SendSomemail
2760 delfunc S1e2n3dmail
2761endfunc
2762
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002763" user defined command name completion
2764func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002765 set wildoptions&
2766 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2767 call assert_equal('"MsFeat', @:)
2768 set wildoptions=fuzzy
2769 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002771 set wildoptions&
2772endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002773
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002774" " :help tag fuzzy completion - NOT supported
2775" func Test_fuzzy_completion_helptag()
2776" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002777
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002778" highlight group name fuzzy completion
2779func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002780 set wildoptions&
2781 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2782 call assert_equal('"highlight SKey', @:)
2783 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2784 call assert_equal('"highlight SpecialKey', @:)
2785 set wildoptions=fuzzy
2786 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2787 call assert_equal('"highlight SpecialKey', @:)
2788 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2789 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002790 set wildoptions&
2791endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002792
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002793" :history suboptions fuzzy completion
2794func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002795 set wildoptions&
2796 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2797 call assert_equal('"history dg', @:)
2798 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2799 call assert_equal('"history search', @:)
2800 set wildoptions=fuzzy
2801 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2802 call assert_equal('"history debug', @:)
2803 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2804 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002805 set wildoptions&
2806endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002807
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002808" :language locale name fuzzy completion
2809func Test_fuzzy_completion_lang()
2810 CheckUnix
2811 set wildoptions&
2812 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal('"lang psx', @:)
2814 set wildoptions=fuzzy
2815 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2816 call assert_equal('"lang POSIX', @:)
2817 set wildoptions&
2818endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002819
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002820" :mapclear buffer argument fuzzy completion
2821func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002822 set wildoptions&
2823 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal('"mapclear buf', @:)
2825 set wildoptions=fuzzy
2826 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2827 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002828 set wildoptions&
2829endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002830
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002831" map name fuzzy completion
2832func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002833 " test regex completion works
2834 set wildoptions=fuzzy
2835 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2836 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002837 nmap <plug>MyLongMap :p<CR>
2838 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2839 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2840 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal("\"nmap MLM \t", @:)
2842 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2843 call assert_equal("\"nmap <F2> one two \t", @:)
2844 " duplicate entries should be removed
2845 vmap <plug>MyLongMap :<C-U>#<CR>
2846 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2847 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2848 nunmap <plug>MyLongMap
2849 vunmap <plug>MyLongMap
2850 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2851 call assert_equal("\"nmap ABC\t", @:)
2852 " results should be sorted by best match
2853 nmap <Plug>format :
2854 nmap <Plug>goformat :
2855 nmap <Plug>TestFOrmat :
2856 nmap <Plug>fendoff :
2857 nmap <Plug>state :
2858 nmap <Plug>FendingOff :
2859 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2860 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2861 nunmap <Plug>format
2862 nunmap <Plug>goformat
2863 nunmap <Plug>TestFOrmat
2864 nunmap <Plug>fendoff
2865 nunmap <Plug>state
2866 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002867 set wildoptions&
2868endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002869
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870" abbreviation fuzzy completion
2871func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002872 set wildoptions=fuzzy
2873 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2874 call assert_equal("\"iabbr <nowait>", @:)
2875 iabbr WaitForCompletion WFC
2876 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2877 call assert_equal("\"iabbr WaitForCompletion", @:)
2878 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2879 call assert_equal("\"iabbr a1z\t", @:)
2880 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002881 set wildoptions&
2882endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002883
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002884" menu name fuzzy completion
2885func Test_fuzzy_completion_menu()
2886 CheckGui
2887 set wildoptions&
2888 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2889 call assert_equal('"menu pup', @:)
2890 set wildoptions=fuzzy
2891 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2892 call assert_equal('"menu PopUp.', @:)
2893 set wildoptions&
2894endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002895
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002896" :messages suboptions fuzzy completion
2897func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002898 set wildoptions&
2899 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2900 call assert_equal('"messages clr', @:)
2901 set wildoptions=fuzzy
2902 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2903 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002904 set wildoptions&
2905endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002906
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002907" :set option name fuzzy completion
2908func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002909 set wildoptions&
2910 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2911 call assert_equal('"set brkopt', @:)
2912 set wildoptions=fuzzy
2913 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal('"set breakindentopt', @:)
2915 set wildoptions&
2916 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal('"set fixendofline', @:)
2918 set wildoptions=fuzzy
2919 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"set fixendofline', @:)
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" :set <term_option>
2925func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926 set wildoptions&
2927 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2928 call assert_equal('"set t_EC', @:)
2929 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2930 call assert_equal('"set <t_EC>', @:)
2931 set wildoptions=fuzzy
2932 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"set t_EC', @:)
2934 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2935 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002936 set wildoptions&
2937endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002938
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002939" " :packadd directory name fuzzy completion - NOT supported
2940" func Test_fuzzy_completion_packadd()
2941" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002942
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002943" " shell command name fuzzy completion - NOT supported
2944" func Test_fuzzy_completion_shellcmd()
2945" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002946
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947" :sign suboptions fuzzy completion
2948func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949 set wildoptions&
2950 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"sign ufe', @:)
2952 set wildoptions=fuzzy
2953 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002955 set wildoptions&
2956endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002957
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958" :syntax suboptions fuzzy completion
2959func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960 set wildoptions&
2961 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2962 call assert_equal('"syntax kwd', @:)
2963 set wildoptions=fuzzy
2964 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2965 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002966 set wildoptions&
2967endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002968
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002969" syntax group name fuzzy completion
2970func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002971 set wildoptions&
2972 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2973 call assert_equal('"syntax list mpar', @:)
2974 set wildoptions=fuzzy
2975 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2976 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977 set wildoptions&
2978endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" :syntime suboptions fuzzy completion
2981func Test_fuzzy_completion_syntime()
2982 CheckFeature profile
2983 set wildoptions&
2984 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2985 call assert_equal('"syntime clr', @:)
2986 set wildoptions=fuzzy
2987 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal('"syntime clear', @:)
2989 set wildoptions&
2990endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002991
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002992" " tag name fuzzy completion - NOT supported
2993" func Test_fuzzy_completion_tagname()
2994" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002995
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002996" " tag name and file fuzzy completion - NOT supported
2997" func Test_fuzzy_completion_tagfile()
2998" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002999
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003000" " user names fuzzy completion - how to test this functionality?
3001" func Test_fuzzy_completion_username()
3002" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003003
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003004" user defined variable name fuzzy completion
3005func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003006 let g:SomeVariable=10
3007 set wildoptions&
3008 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3009 call assert_equal('"let SVar', @:)
3010 set wildoptions=fuzzy
3011 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3012 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003013 set wildoptions&
3014endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003015
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003016" Test for sorting the results by the best match
3017func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003018 %bw!
3019 command T123format :
3020 command T123goformat :
3021 command T123TestFOrmat :
3022 command T123fendoff :
3023 command T123state :
3024 command T123FendingOff :
3025 set wildoptions=fuzzy
3026 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3028 delcommand T123format
3029 delcommand T123goformat
3030 delcommand T123TestFOrmat
3031 delcommand T123fendoff
3032 delcommand T123state
3033 delcommand T123FendingOff
3034 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003035 set wildoptions&
3036endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003037
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003038" Test for fuzzy completion of a command with lower case letters and a number
3039func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003040 command Foo2Bar :
3041 set wildoptions=fuzzy
3042 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal('"Foo2Bar', @:)
3044 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal('"Foo2Bar', @:)
3046 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal('"Foo2Bar', @:)
3048 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003049 set wildoptions&
3050endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003051
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003052" Test for command completion for a command starting with 'k'
3053func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003054 command KillKillKill :
3055 set wildoptions&
3056 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal("\"killkill\<Tab>", @:)
3058 set wildoptions=fuzzy
3059 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal('"KillKillKill', @:)
3061 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003062 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003063endfunc
3064
3065" Test for fuzzy completion for user defined custom completion function
3066func Test_fuzzy_completion_custom_func()
3067 func Tcompl(a, c, p)
3068 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3069 endfunc
3070 command -nargs=* -complete=custom,Tcompl Fuzzy :
3071 set wildoptions&
3072 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal("\"Fuzzy format", @:)
3074 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal("\"Fuzzy xy", @:)
3076 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3077 call assert_equal("\"Fuzzy ttt", @:)
3078 set wildoptions=fuzzy
3079 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3081 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3083 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal("\"Fuzzy xy", @:)
3085 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal("\"Fuzzy TestFOrmat", @:)
3087 delcom Fuzzy
3088 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003089endfunc
3090
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003091" Test for :breakadd argument completion
3092func Test_cmdline_complete_breakadd()
3093 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"breakadd expr file func here", @:)
3095 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3096 call assert_equal("\"breakadd expr", @:)
3097 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal("\"breakadd expr", @:)
3099 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal("\"breakadd here", @:)
3101 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"breakadd here", @:)
3103 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakadd abc", @:)
3105 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3106 let l = getcompletion('not', 'breakpoint')
3107 call assert_equal([], l)
3108
3109 " Test for :breakadd file [lnum] <file>
3110 call writefile([], 'Xscript')
3111 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"breakadd file Xscript", @:)
3113 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"breakadd file Xscript", @:)
3115 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"breakadd file 20 Xscript", @:)
3117 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakadd file 20 Xscript", @:)
3119 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3121 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakadd file 20\t", @:)
3123 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"breakadd file 20x\t", @:)
3125 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakadd file Xscript ", @:)
3127 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakadd file X1B2C3", @:)
3129 call delete('Xscript')
3130
3131 " Test for :breakadd func [lnum] <function>
3132 func Xbreak_func()
3133 endfunc
3134 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3135 call assert_equal("\"breakadd func Xbreak_func", @:)
3136 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal("\"breakadd func Xbreak_func", @:)
3138 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3140 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3142 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3143 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3144 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal("\"breakadd func 20\t", @:)
3146 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal("\"breakadd func 20x\t", @:)
3148 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal("\"breakadd func Xbreak_func ", @:)
3150 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal("\"breakadd func X1B2C3", @:)
3152 delfunc Xbreak_func
3153
3154 " Test for :breakadd expr <expression>
3155 let g:Xtest_var = 10
3156 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal("\"breakadd expr Xtest_var", @:)
3158 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3159 call assert_equal("\"breakadd expr Xtest_var", @:)
3160 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3161 call assert_equal("\"breakadd expr Xtest_var ", @:)
3162 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal("\"breakadd expr X1B2C3", @:)
3164 unlet g:Xtest_var
3165
3166 " Test for :breakadd here
3167 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd here Xtest", @:)
3169 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal("\"breakadd here Xtest", @:)
3171 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal("\"breakadd here ", @:)
3173endfunc
3174
3175" Test for :breakdel argument completion
3176func Test_cmdline_complete_breakdel()
3177 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal("\"breakdel file func here", @:)
3179 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal("\"breakdel file", @:)
3181 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal("\"breakdel file", @:)
3183 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakdel here", @:)
3185 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"breakdel here", @:)
3187 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_equal("\"breakdel abc", @:)
3189
3190 " Test for :breakdel file [lnum] <file>
3191 call writefile([], 'Xscript')
3192 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"breakdel file Xscript", @:)
3194 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal("\"breakdel file Xscript", @:)
3196 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"breakdel file 20 Xscript", @:)
3198 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"breakdel file 20 Xscript", @:)
3200 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3202 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3203 call assert_equal("\"breakdel file 20\t", @:)
3204 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3205 call assert_equal("\"breakdel file 20x\t", @:)
3206 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3207 call assert_equal("\"breakdel file Xscript ", @:)
3208 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal("\"breakdel file X1B2C3", @:)
3210 call delete('Xscript')
3211
3212 " Test for :breakdel func [lnum] <function>
3213 func Xbreak_func()
3214 endfunc
3215 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3216 call assert_equal("\"breakdel func Xbreak_func", @:)
3217 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal("\"breakdel func Xbreak_func", @:)
3219 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3221 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3223 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3225 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel func 20\t", @:)
3227 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel func 20x\t", @:)
3229 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakdel func Xbreak_func ", @:)
3231 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal("\"breakdel func X1B2C3", @:)
3233 delfunc Xbreak_func
3234
3235 " Test for :breakdel here
3236 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal("\"breakdel here Xtest", @:)
3238 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3239 call assert_equal("\"breakdel here Xtest", @:)
3240 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003242endfunc
3243
Bram Moolenaar309976e2019-12-05 18:16:33 +01003244" vim: shiftwidth=2 sts=2 expandtab