blob: 20f932b308c2d2f260b61361673191dfb5cef767 [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
Bram Moolenaar37db6422019-03-28 21:26:23 +0100155 " cleanup
156 %bwipe
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000157 call delete('Xdir1', 'rf')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200158 set nowildmenu
159endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100160
Bram Moolenaara60053b2020-09-03 16:50:13 +0200161func Test_wildmenu_screendump()
162 CheckScreendump
163
164 let lines =<< trim [SCRIPT]
165 set wildmenu hlsearch
166 [SCRIPT]
167 call writefile(lines, 'XTest_wildmenu')
168
169 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
170 call term_sendkeys(buf, ":vim\<Tab>")
171 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
172
173 call term_sendkeys(buf, "\<Tab>")
174 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
175
176 call term_sendkeys(buf, "\<Tab>")
177 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
178
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100179 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
181 call term_sendkeys(buf, "\<Esc>")
182
183 " clean up
184 call StopVimInTerminal(buf)
185 call delete('XTest_wildmenu')
186endfunc
187
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100188func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100189 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
190 call assert_equal('"map <unique> <silent>', getreg(':'))
191 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
192 call assert_equal('"map <script> <unique>', getreg(':'))
193 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
194 call assert_equal('"map <expr> <script>', getreg(':'))
195 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
196 call assert_equal('"map <buffer> <expr>', getreg(':'))
197 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
198 call assert_equal('"map <nowait> <buffer>', getreg(':'))
199 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
200 call assert_equal('"map <special> <nowait>', getreg(':'))
201 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
202 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200203
Bram Moolenaar1776a282019-05-03 16:05:41 +0200204 map <Middle>x middle
205
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200206 map ,f commaf
207 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200208 map <Left> left
209 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200210 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
211 call assert_equal('"map ,f', getreg(':'))
212 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
213 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200214 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
215 call assert_equal('"map <Left>', getreg(':'))
216 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200217 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200218 unmap ,f
219 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200220 unmap <Left>
221 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200222
223 set cpo-=< cpo-=B cpo-=k
224 map <Left> left
225 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
226 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200227 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200228 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200229 unmap <Left>
230
231 set cpo+=<
232 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200233 exe "set t_k6=\<Esc>[17~"
234 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200235 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
236 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200237 if !has('gui_running')
238 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
239 call assert_equal("\"map <F6>x", getreg(':'))
240 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200241 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200242 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200243 set cpo-=<
244
245 set cpo+=B
246 map <Left> left
247 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
248 call assert_equal('"map <Left>', getreg(':'))
249 unmap <Left>
250 set cpo-=B
251
252 set cpo+=k
253 map <Left> left
254 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
255 call assert_equal('"map <Left>', getreg(':'))
256 unmap <Left>
257 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200258
Bram Moolenaar531be472020-09-23 22:38:05 +0200259 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
260
Bram Moolenaar1776a282019-05-03 16:05:41 +0200261 unmap <Middle>x
262 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100263endfunc
264
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100265func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100266 hi Aardig ctermfg=green
267 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000268 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100269 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000270 call assert_equal('"match none', @:)
271 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
272 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100273endfunc
274
275func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100276 hi Aardig ctermfg=green
277 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
278 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200279 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
280 call assert_equal('"hi default Aardig', getreg(':'))
281 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
282 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100283 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
284 call assert_equal('"hi link', getreg(':'))
285 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
286 call assert_equal('"hi default', getreg(':'))
287 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
288 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200289 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
290 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
291 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
292 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200293
294 " A cleared group does not show up in completions.
295 hi Anders ctermfg=green
296 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
297 hi clear Aardig
298 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
299 hi clear Anders
300 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100301endfunc
302
Bram Moolenaar75e15672020-06-28 13:10:22 +0200303" Test for command-line expansion of "hi Ni " (easter egg)
304func Test_highlight_easter_egg()
305 call test_override('ui_delay', 1)
306 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
307 call assert_equal("\"hi Ni \<Tab>", @:)
308 call test_override('ALL', 0)
309endfunc
310
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200311func Test_getcompletion()
312 let groupcount = len(getcompletion('', 'event'))
313 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200314 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200315 call assert_true(matchcount > 0)
316 call assert_true(groupcount > matchcount)
317
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200318 if has('menu')
319 source $VIMRUNTIME/menu.vim
320 let matchcount = len(getcompletion('', 'menu'))
321 call assert_true(matchcount > 0)
322 call assert_equal(['File.'], getcompletion('File', 'menu'))
323 call assert_true(matchcount > 0)
324 let matchcount = len(getcompletion('File.', 'menu'))
325 call assert_true(matchcount > 0)
326 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200327
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200328 let l = getcompletion('v:n', 'var')
329 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200330 let l = getcompletion('v:notexists', 'var')
331 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200332
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200333 args a.c b.c
334 let l = getcompletion('', 'arglist')
335 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000336 let l = getcompletion('a.', 'buffer')
337 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200338 %argdelete
339
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200340 let l = getcompletion('', 'augroup')
341 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200342 let l = getcompletion('blahblah', 'augroup')
343 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200344
345 let l = getcompletion('', 'behave')
346 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200347 let l = getcompletion('not', 'behave')
348 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200349
350 let l = getcompletion('', 'color')
351 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200352 let l = getcompletion('dirty', 'color')
353 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200354
355 let l = getcompletion('', 'command')
356 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200357 let l = getcompletion('awake', 'command')
358 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200359
360 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200361 call assert_true(index(l, 'samples/') >= 0)
362 let l = getcompletion('NoMatch', 'dir')
363 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200364
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100365 if glob('~/*') !=# ''
366 let l = getcompletion('~/', 'dir')
367 call assert_true(l[0][0] ==# '~')
368 endif
369
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200370 let l = getcompletion('exe', 'expression')
371 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200372 let l = getcompletion('kill', 'expression')
373 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200374
375 let l = getcompletion('tag', 'function')
376 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200377 let l = getcompletion('paint', 'function')
378 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200379
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200380 let Flambda = {-> 'hello'}
381 let l = getcompletion('', 'function')
382 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200383 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200384
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200385 let l = getcompletion('run', 'file')
386 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200387 let l = getcompletion('walk', 'file')
388 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200389 set wildignore=*.vim
390 let l = getcompletion('run', 'file', 1)
391 call assert_true(index(l, 'runtest.vim') < 0)
392 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000393 " Directory name with space character
394 call mkdir('Xdir with space')
395 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
396 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
397 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200398
399 let l = getcompletion('ha', 'filetype')
400 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200401 let l = getcompletion('horse', 'filetype')
402 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200403
404 let l = getcompletion('z', 'syntax')
405 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200406 let l = getcompletion('emacs', 'syntax')
407 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200408
409 let l = getcompletion('jikes', 'compiler')
410 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200411 let l = getcompletion('break', 'compiler')
412 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200413
414 let l = getcompletion('last', 'help')
415 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200416 let l = getcompletion('giveup', 'help')
417 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200418
419 let l = getcompletion('time', 'option')
420 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200421 let l = getcompletion('space', 'option')
422 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200423
424 let l = getcompletion('er', 'highlight')
425 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200426 let l = getcompletion('dark', 'highlight')
427 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200428
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200429 let l = getcompletion('', 'messages')
430 call assert_true(index(l, 'clear') >= 0)
431 let l = getcompletion('not', 'messages')
432 call assert_equal([], l)
433
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200434 let l = getcompletion('', 'mapclear')
435 call assert_true(index(l, '<buffer>') >= 0)
436 let l = getcompletion('not', 'mapclear')
437 call assert_equal([], l)
438
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200439 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200440 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200441 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
442 let root = has('win32') ? 'C:\\' : '/'
443 let l = getcompletion(root, 'shellcmd')
444 let expected = map(filter(glob(root . '*', 0, 1),
445 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
446 call assert_equal(expected, l)
447
Bram Moolenaarb650b982016-08-05 20:35:13 +0200448 if has('cscope')
449 let l = getcompletion('', 'cscope')
450 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
451 call assert_equal(cmds, l)
452 " using cmdline completion must not change the result
453 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
454 let l = getcompletion('', 'cscope')
455 call assert_equal(cmds, l)
456 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
457 let l = getcompletion('find ', 'cscope')
458 call assert_equal(keys, l)
459 endif
460
Bram Moolenaar7522f692016-08-06 14:12:50 +0200461 if has('signs')
462 sign define Testing linehl=Comment
463 let l = getcompletion('', 'sign')
464 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
465 call assert_equal(cmds, l)
466 " using cmdline completion must not change the result
467 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
468 let l = getcompletion('', 'sign')
469 call assert_equal(cmds, l)
470 let l = getcompletion('list ', 'sign')
471 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000472 let l = getcompletion('de*', 'sign')
473 call assert_equal(['define'], l)
474 let l = getcompletion('p?', 'sign')
475 call assert_equal(['place'], l)
476 let l = getcompletion('j.', 'sign')
477 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200478 endif
479
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200480 " Command line completion tests
481 let l = getcompletion('cd ', 'cmdline')
482 call assert_true(index(l, 'samples/') >= 0)
483 let l = getcompletion('cd NoMatch', 'cmdline')
484 call assert_equal([], l)
485 let l = getcompletion('let v:n', 'cmdline')
486 call assert_true(index(l, 'v:null') >= 0)
487 let l = getcompletion('let v:notexists', 'cmdline')
488 call assert_equal([], l)
489 let l = getcompletion('call tag', 'cmdline')
490 call assert_true(index(l, 'taglist(') >= 0)
491 let l = getcompletion('call paint', 'cmdline')
492 call assert_equal([], l)
493
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100494 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000495 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100496 return "oneA\noneB\noneC"
497 endfunc
498 command -nargs=1 -complete=custom,T MyCmd
499 let l = getcompletion('MyCmd ', 'cmdline')
500 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000501 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100502
503 delcommand MyCmd
504 delfunc T
ii144785fe02021-11-21 12:13:56 +0000505 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100506
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200507 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200508 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509 if has('cmdline_hist')
510 call add(names, 'history')
511 endif
512 if has('gettext')
513 call add(names, 'locale')
514 endif
515 if has('profile')
516 call add(names, 'syntime')
517 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200518
519 set tags=Xtags
520 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
521
522 for name in names
523 let matchcount = len(getcompletion('', name))
524 call assert_true(matchcount >= 0, 'No matches for ' . name)
525 endfor
526
527 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200528 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200529
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000530 edit a~b
531 enew
532 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
533 bw a~b
534
535 if has('unix')
536 edit Xtest\
537 enew
538 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
539 bw Xtest\
540 endif
541
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200542 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200543 call assert_fails('call getcompletion("", "burp")', 'E475:')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200544 call assert_fails('call getcompletion("abc", [])', 'E475:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200545endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200546
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000547func Test_complete_autoload_error()
548 let save_rtp = &rtp
549 let lines =<< trim END
550 vim9script
551 export def Complete(..._): string
552 return 'match'
553 enddef
554 echo this will cause an error
555 END
556 call mkdir('Xdir/autoload', 'p')
557 call writefile(lines, 'Xdir/autoload/script.vim')
558 exe 'set rtp+=' .. getcwd() .. '/Xdir'
559
560 let lines =<< trim END
561 vim9script
562 import autoload 'script.vim'
563 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
564 &wildcharm = char2nr("\<Tab>")
565 feedkeys(":Cmd \<Tab>", 'xt')
566 END
567 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
568
569 let &rtp = save_rtp
570 call delete('Xdir', 'rf')
571endfunc
572
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100573func Test_fullcommand()
574 let tests = {
575 \ '': '',
576 \ ':': '',
577 \ ':::': '',
578 \ ':::5': '',
579 \ 'not_a_cmd': '',
580 \ 'Check': '',
581 \ 'syntax': 'syntax',
582 \ ':syntax': 'syntax',
583 \ '::::syntax': 'syntax',
584 \ 'sy': 'syntax',
585 \ 'syn': 'syntax',
586 \ 'synt': 'syntax',
587 \ ':sy': 'syntax',
588 \ '::::sy': 'syntax',
589 \ 'match': 'match',
590 \ '2match': 'match',
591 \ '3match': 'match',
592 \ 'aboveleft': 'aboveleft',
593 \ 'abo': 'aboveleft',
594 \ 's': 'substitute',
595 \ '5s': 'substitute',
596 \ ':5s': 'substitute',
597 \ "'<,'>s": 'substitute',
598 \ ":'<,'>s": 'substitute',
599 \ 'CheckUni': 'CheckUnix',
600 \ 'CheckUnix': 'CheckUnix',
601 \ }
602
603 for [in, want] in items(tests)
604 call assert_equal(want, fullcommand(in))
605 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200606 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100607
608 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200609
610 command -buffer BufferLocalCommand :
611 command GlobalCommand :
612 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
613 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
614 delcommand BufferLocalCommand
615 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100616endfunc
617
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200618func Test_shellcmd_completion()
619 let save_path = $PATH
620
621 call mkdir('Xpathdir/Xpathsubdir', 'p')
622 call writefile([''], 'Xpathdir/Xfile.exe')
623 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
624
625 " Set PATH to example directory without trailing slash.
626 let $PATH = getcwd() . '/Xpathdir'
627
628 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
629 " dirs in the PATH, even though they won't be executed. We check that only
630 " subdirs of the PWD and executables from the PATH are included in the
631 " suggestions.
632 let actual = getcompletion('X', 'shellcmd')
633 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
634 call insert(expected, 'Xfile.exe')
635 call assert_equal(expected, actual)
636
637 call delete('Xpathdir', 'rf')
638 let $PATH = save_path
639endfunc
640
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200641func Test_expand_star_star()
642 call mkdir('a/b', 'p')
643 call writefile(['asdfasdf'], 'a/b/fileXname')
644 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000645 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200646 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200647 call delete('a', 'rf')
648endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100649
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100650func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100651 let @a = "def"
652 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
653 call assert_equal('"abc def ghi', @:)
654
655 new
656 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
657
658 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
659 call assert_equal('"aaa asdf bbb', @:)
660
661 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
662 call assert_equal('"aaa /tmp/some bbb', @:)
663
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200664 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
665 call assert_equal('"aaa '.getline(1).' bbb', @:)
666
Bram Moolenaar21efc362016-12-03 14:05:49 +0100667 set incsearch
668 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
669 call assert_equal('"aaa verylongword bbb', @:)
670
671 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
672 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100673
674 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
675 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100676 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200677
678 " Error while typing a command used to cause that it was not executed
679 " in the end.
680 new
681 try
682 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
683 catch /^Vim\%((\a\+)\)\=:E32/
684 " ignore error E32
685 endtry
686 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100687
Bram Moolenaar578fe942020-02-27 21:32:51 +0100688 " Try to paste an invalid register using <C-R>
689 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
690 call assert_equal('"onetwo', @:)
691
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100692 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100693 let @a = "xy\<C-H>z"
694 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
695 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100696 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
697 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100698 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
699 call assert_equal("\"xy\<C-H>z", @:)
700
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100701 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
702 let @a = "xy\<C-V>z"
703 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
704 call assert_equal('"xyz', @:)
705 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
706 call assert_equal("\"xy\<C-V>z", @:)
707
Bram Moolenaar578fe942020-02-27 21:32:51 +0100708 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
709
Bram Moolenaar72532d32018-04-07 19:09:09 +0200710 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100711endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100712
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100713func Test_cmdline_remove_char()
714 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100715
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100716 for e in ['utf8', 'latin1']
717 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100718
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100719 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
720 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100721
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100722 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
723 call assert_equal('"abcdef', @:)
724
725 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
726 call assert_equal('"abc ghi', @:, e)
727
728 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
729 call assert_equal('"def', @:, e)
730 endfor
731
732 let &encoding = encoding_save
733endfunc
734
735func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200736 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100737
738 set keymap=esperanto
739 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
740 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
741 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100742endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100743
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100744func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100745 new
746 2;'(
747 2;')
748 quit
749endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100750
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100751func Test_illegal_address2()
752 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
753 new
754 source Xtest.vim
755 " Trigger calling validate_cursor()
756 diffsp Xtest.vim
757 quit!
758 bwipe!
759 call delete('Xtest.vim')
760endfunc
761
Bram Moolenaarba47b512017-01-24 21:18:19 +0100762func Test_cmdline_complete_wildoptions()
763 help
764 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
765 let a = join(sort(split(@:)),' ')
766 set wildoptions=tagfile
767 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
768 let b = join(sort(split(@:)),' ')
769 call assert_equal(a, b)
770 bw!
771endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100772
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200773func Test_cmdline_complete_user_cmd()
774 command! -complete=color -nargs=1 Foo :
775 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
776 call assert_equal('"Foo blue', @:)
777 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
778 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000779 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
780 call assert_equal('"Foo a blue', @:)
781 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
782 call assert_equal('"Foo b\', @:)
783 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
784 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200785 delcommand Foo
786endfunc
787
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100788func s:ScriptLocalFunction()
789 echo 'yes'
790endfunc
791
792func Test_cmdline_complete_user_func()
793 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200794 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100795 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
796 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100797
798 " g: prefix also works
799 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
800 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200801
802 " using g: prefix does not result in just "g:" matches from a lambda
803 let Fx = { a -> a }
804 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
805 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200806
807 " existence of script-local dict function does not break user function name
808 " completion
809 function s:a_dict_func() dict
810 endfunction
811 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
812 call assert_match('"call Test_cmdline_complete_user_', @:)
813 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100814endfunc
815
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200816func Test_cmdline_complete_user_names()
817 if has('unix') && executable('whoami')
818 let whoami = systemlist('whoami')[0]
819 let first_letter = whoami[0]
820 if len(first_letter) > 0
821 " Trying completion of :e ~x where x is the first letter of
822 " the user name should complete to at least the user name.
823 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
824 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
825 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200826 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200827 " Just in case: check that the system has an Administrator account.
828 let names = system('net user')
829 if names =~ 'Administrator'
830 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100831 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200832 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100833 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200834 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200835 else
836 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200837 endif
838endfunc
839
Bram Moolenaar297610b2019-12-27 17:20:55 +0100840func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200841 CheckExecutable whoami
842 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
843 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100844endfunc
845
Bram Moolenaar8b633132020-03-20 18:20:51 +0100846func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200847 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
848 call assert_equal(lang, v:lc_time)
849
850 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
851 call assert_equal(lang, v:ctype)
852
853 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
854 call assert_equal(lang, v:collate)
855
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200856 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200857 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200858
859 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200860 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200861
Bram Moolenaarec680282020-06-12 19:35:32 +0200862 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200863
Bram Moolenaarec680282020-06-12 19:35:32 +0200864 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
865 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200866
Bram Moolenaarec680282020-06-12 19:35:32 +0200867 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
868 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200869
Bram Moolenaarec680282020-06-12 19:35:32 +0200870 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
871 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200872
873 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
874 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200875endfunc
876
Bram Moolenaar297610b2019-12-27 17:20:55 +0100877func Test_cmdline_complete_env_variable()
878 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100879 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
880 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100881 unlet $X_VIM_TEST_COMPLETE_ENV
882endfunc
883
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100884func Test_cmdline_complete_expression()
885 let g:SomeVar = 'blah'
886 for cmd in ['exe', 'echo', 'echon', 'echomsg']
887 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
888 call assert_match('"' .. cmd .. ' SomeVar', @:)
889 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
890 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
891 endfor
892 unlet g:SomeVar
893endfunc
894
Bram Moolenaar47016f52021-08-26 16:39:58 +0200895" Unique function name for completion below
896func s:WeirdFunc()
897 echo 'weird'
898endfunc
899
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100900" Test for various command-line completion
901func Test_cmdline_complete_various()
902 " completion for a command starting with a comment
903 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
904 call assert_equal("\" :|\"\<C-A>", @:)
905
906 " completion for a range followed by a comment
907 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
908 call assert_equal("\"1,2\"\<C-A>", @:)
909
910 " completion for :k command
911 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
912 call assert_equal("\"ka\<C-A>", @:)
913
914 " completion for short version of the :s command
915 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
916 call assert_equal("\"sI \<C-A>", @:)
917
918 " completion for :write command
919 call mkdir('Xdir')
920 call writefile(['one'], 'Xdir/Xfile1')
921 let save_cwd = getcwd()
922 cd Xdir
923 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
924 call assert_equal("\"w >> Xfile1", @:)
925 call chdir(save_cwd)
926 call delete('Xdir', 'rf')
927
928 " completion for :w ! and :r ! commands
929 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
930 call assert_equal("\"w !invalid_xyz_cmd", @:)
931 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
932 call assert_equal("\"r !invalid_xyz_cmd", @:)
933
934 " completion for :>> and :<< commands
935 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
936 call assert_equal("\">>>\<C-A>", @:)
937 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
938 call assert_equal("\"<<<\<C-A>", @:)
939
940 " completion for command with +cmd argument
941 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
942 call assert_equal("\"buffer +/pat Xabc", @:)
943 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
944 call assert_equal("\"buffer +/pat\<C-A>", @:)
945
946 " completion for a command with a trailing comment
947 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
948 call assert_equal("\"ls \" comment\<C-A>", @:)
949
950 " completion for a command with a trailing command
951 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
952 call assert_equal("\"ls | ls", @:)
953
954 " completion for a command with an CTRL-V escaped argument
955 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
956 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
957
958 " completion for a command that doesn't take additional arguments
959 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
960 call assert_equal("\"all abc\<C-A>", @:)
961
962 " completion for a command with a command modifier
963 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
964 call assert_equal("\"topleft new", @:)
965
Bram Moolenaare70e12b2021-06-13 17:20:08 +0200966 " completion for vim9 and legacy commands
967 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
968 call assert_equal("\"vim9 call strlen(", @:)
969 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
970 call assert_equal("\"legac call strlen(", @:)
971
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200972 " completion for the :disassemble command
973 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
974 call assert_equal("\"disas debug", @:)
975 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
976 call assert_equal("\"disas profile", @:)
977 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
978 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
979 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
980 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +0200981 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
982 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +0200983
Bram Moolenaar47016f52021-08-26 16:39:58 +0200984 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +0200985 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +0200986
naohiro onodfe04db2021-09-12 15:45:10 +0200987 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
988 call assert_match('"disas <SNR>\d\+_', @:)
989 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
990 call assert_match('"disas debug <SNR>\d\+_', @:)
991
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100992 " completion for the :match command
993 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
994 call assert_equal("\"match Search /pat/\<C-A>", @:)
995
Bram Moolenaar24ebd832020-03-16 21:25:24 +0100996 " completion for the :doautocmd command
997 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
998 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
999
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001000 " completion of autocmd group after comma
1001 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1002 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1003
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001004 " completion of file name in :doautocmd
1005 call writefile([], 'Xfile1')
1006 call writefile([], 'Xfile2')
1007 call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt')
1008 call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:)
1009 call delete('Xfile1')
1010 call delete('Xfile2')
1011
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001012 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001013 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001014 augroup END
1015 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001016 call assert_equal("\"augroup XTest.test", @:)
1017 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1018 call assert_equal("\"au XTest.test", @:)
1019 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001020
1021 " completion for the :unlet command
1022 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1023 call assert_equal("\"unlet one two", @:)
1024
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001025 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001026 " FIXME: what should happen on MS-Windows?
1027 if !has('win32')
1028 edit \{someFile}
1029 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1030 call assert_equal("\"buf {someFile}", @:)
1031 bwipe {someFile}
1032 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001033
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001034 " completion for the :bdelete command
1035 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1036 call assert_equal("\"bdel a b c", @:)
1037
1038 " completion for the :mapclear command
1039 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1040 call assert_equal("\"mapclear <buffer>", @:)
1041
1042 " completion for user defined commands with menu names
1043 menu Test.foo :ls<CR>
1044 com -nargs=* -complete=menu MyCmd
1045 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1046 call assert_equal('"MyCmd Test.', @:)
1047 delcom MyCmd
1048 unmenu Test
1049
1050 " completion for user defined commands with mappings
1051 mapclear
1052 map <F3> :ls<CR>
1053 com -nargs=* -complete=mapping MyCmd
1054 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001055 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001056 mapclear
1057 delcom MyCmd
1058
1059 " completion for :set path= with multiple backslashes
1060 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1061 call assert_equal('"set path=a\\\ b', @:)
1062
1063 " completion for :set dir= with a backslash
1064 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1065 call assert_equal('"set dir=a\ b', @:)
1066
1067 " completion for the :py3 commands
1068 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1069 call assert_equal('"py3 py3do py3file', @:)
1070
Bram Moolenaardf749a22021-03-28 15:29:43 +02001071 " completion for the :vim9 commands
1072 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1073 call assert_equal('"vim9cmd vim9script', @:)
1074
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001075 " redir @" is not the start of a comment. So complete after that
1076 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1077 call assert_equal('"redir @" | cwindow', @:)
1078
1079 " completion after a backtick
1080 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1081 call assert_equal('"e `a1b2c', @:)
1082
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001083 " completion for :language command with an invalid argument
1084 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1085 call assert_equal("\"language dummy \t", @:)
1086
1087 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001088 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1089 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001090
1091 " completion with ambiguous user defined commands
1092 com TCmd1 echo 'TCmd1'
1093 com TCmd2 echo 'TCmd2'
1094 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1095 call assert_equal('"TCmd ', @:)
1096 delcom TCmd1
1097 delcom TCmd2
1098
1099 " completion after a range followed by a pipe (|) character
1100 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1101 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001102
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001103 " completion after a :global command
1104 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1105 call assert_equal('"g/a/chistory', @:)
1106 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"g/a\\/chist\t", @:)
1108
Bram Moolenaar9c929712020-09-07 22:05:28 +02001109 " use <Esc> as the 'wildchar' for completion
1110 set wildchar=<Esc>
1111 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1112 call assert_equal('"g/a\xb/clearjumps', @:)
1113 " pressing <esc> twice should cancel the command
1114 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1115 call assert_equal('"g/a\xb/clearjumps', @:)
1116 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001117
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001118 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001119 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001120 call writefile([], '~Xtest')
1121 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1122 call assert_equal('"e \~Xtest', @:)
1123 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001124
1125 " should be able to complete a file name that has a '*'
1126 call writefile([], 'Xx*Yy')
1127 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal('"e Xx\*Yy', @:)
1129 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001130
1131 " use a literal star
1132 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1133 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001134 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001135
1136 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1137 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001138endfunc
1139
1140" Test for 'wildignorecase'
1141func Test_cmdline_wildignorecase()
1142 CheckUnix
1143 call writefile([], 'XTEST')
1144 set wildignorecase
1145 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1146 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001147 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001148 let g:Sline = ''
1149 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1150 call assert_equal('"e xt', @:)
1151 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001152 set wildignorecase&
1153 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001154endfunc
1155
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001156func Test_cmdline_write_alternatefile()
1157 new
1158 call setline('.', ['one', 'two'])
1159 f foo.txt
1160 new
1161 f #-A
1162 call assert_equal('foo.txt-A', expand('%'))
1163 f #<-B.txt
1164 call assert_equal('foo-B.txt', expand('%'))
1165 f %<
1166 call assert_equal('foo-B', expand('%'))
1167 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001168 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001169 bw!
1170 f foo-B.txt
1171 f %<-A
1172 call assert_equal('foo-B-A', expand('%'))
1173 bw!
1174 bw!
1175endfunc
1176
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001177" using a leading backslash here
1178set cpo+=C
1179
1180func Test_cmdline_search_range()
1181 new
1182 call setline(1, ['a', 'b', 'c', 'd'])
1183 /d
1184 1,\/s/b/B/
1185 call assert_equal('B', getline(2))
1186
1187 /a
1188 $
1189 \?,4s/c/C/
1190 call assert_equal('C', getline(3))
1191
1192 call setline(1, ['a', 'b', 'c', 'd'])
1193 %s/c/c/
1194 1,\&s/b/B/
1195 call assert_equal('B', getline(2))
1196
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001197 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001198 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001199
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001200 bwipe!
1201endfunc
1202
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001203" Test for the tick mark (') in an excmd range
1204func Test_tick_mark_in_range()
1205 " If only the tick is passed as a range and no command is specified, there
1206 " should not be an error
1207 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001208 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001209 call assert_fails("',print", 'E78:')
1210endfunc
1211
1212" Test for using a line number followed by a search pattern as range
1213func Test_lnum_and_pattern_as_range()
1214 new
1215 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1216 let @" = ''
1217 2/foo/yank
1218 call assert_equal("foo 3\n", @")
1219 call assert_equal(1, line('.'))
1220 close!
1221endfunc
1222
Bram Moolenaar65189a12017-02-06 22:22:17 +01001223" Tests for getcmdline(), getcmdpos() and getcmdtype()
1224func Check_cmdline(cmdtype)
1225 call assert_equal('MyCmd a', getcmdline())
1226 call assert_equal(8, getcmdpos())
1227 call assert_equal(a:cmdtype, getcmdtype())
1228 return ''
1229endfunc
1230
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001231set cpo&
1232
Bram Moolenaar65189a12017-02-06 22:22:17 +01001233func Test_getcmdtype()
1234 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1235
1236 let cmdtype = ''
1237 debuggreedy
1238 call feedkeys(":debug echo 'test'\<CR>", "t")
1239 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1240 call feedkeys("cont\<CR>", "xt")
1241 0debuggreedy
1242 call assert_equal('>', cmdtype)
1243
1244 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1245 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1246
1247 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001248 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001249
1250 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1251
1252 cnoremap <expr> <F6> Check_cmdline('=')
1253 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1254 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001255
1256 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001257endfunc
1258
Bram Moolenaar81612b72018-06-23 14:55:03 +02001259func Test_getcmdwintype()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001260 CheckFeature cmdwin
1261
Bram Moolenaar81612b72018-06-23 14:55:03 +02001262 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1263 call assert_equal('/', a)
1264
1265 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1266 call assert_equal('?', a)
1267
1268 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1269 call assert_equal(':', a)
1270
1271 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1272 call assert_equal(':', a)
1273
1274 call assert_equal('', getcmdwintype())
1275endfunc
1276
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001277func Test_getcmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001278 CheckFeature cmdwin
1279
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001280 let s:seq = []
1281 augroup CmdWin
1282 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1283 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1284 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1285 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1286 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1287 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1288
1289 let org_winid = win_getid()
1290 let org_bufnr = bufnr()
1291 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1292 call assert_equal(':', a)
1293 call assert_equal([
1294 \ 'WinLeave ' .. org_winid,
1295 \ 'WinEnter ' .. s:cmd_winid,
1296 \ 'BufLeave ' .. org_bufnr,
1297 \ 'BufEnter ' .. s:cmd_bufnr,
1298 \ 'CmdWinEnter ' .. s:cmd_winid,
1299 \ 'CmdWinLeave ' .. s:cmd_winid,
1300 \ 'BufLeave ' .. s:cmd_bufnr,
1301 \ 'WinLeave ' .. s:cmd_winid,
1302 \ 'WinEnter ' .. org_winid,
1303 \ 'BufEnter ' .. org_bufnr,
1304 \ ], s:seq)
1305
1306 au!
1307 augroup END
1308endfunc
1309
Bram Moolenaar52604f22017-04-07 16:17:39 +02001310func Test_verbosefile()
1311 set verbosefile=Xlog
1312 echomsg 'foo'
1313 echomsg 'bar'
1314 set verbosefile=
1315 let log = readfile('Xlog')
1316 call assert_match("foo\nbar", join(log, "\n"))
1317 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001318 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001319 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001320 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001321endfunc
1322
Bram Moolenaar4facea32019-10-12 20:17:40 +02001323func Test_verbose_option()
1324 CheckScreendump
1325
1326 let lines =<< trim [SCRIPT]
1327 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1328 call feedkeys("\r", 't') " for the hit-enter prompt
1329 set verbose=20
1330 [SCRIPT]
1331 call writefile(lines, 'XTest_verbose')
1332
1333 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001334 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001335 call term_sendkeys(buf, ":DoSomething\<CR>")
1336 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1337
1338 " clean up
1339 call StopVimInTerminal(buf)
1340 call delete('XTest_verbose')
1341endfunc
1342
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001343func Test_setcmdpos()
1344 func InsertTextAtPos(text, pos)
1345 call assert_equal(0, setcmdpos(a:pos))
1346 return a:text
1347 endfunc
1348
1349 " setcmdpos() with position in the middle of the command line.
1350 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1351 call assert_equal('"1ab2', @:)
1352
1353 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1354 call assert_equal('"1b2a', @:)
1355
1356 " setcmdpos() with position beyond the end of the command line.
1357 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1358 call assert_equal('"12ab', @:)
1359
1360 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001361 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001362endfunc
1363
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001364func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001365 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001366 let encoding_save = &encoding
1367
1368 for e in encodings
1369 exe 'set encoding=' . e
1370
1371 " Test overstrike in the middle of the command line.
1372 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001373 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001374
1375 " Test overstrike going beyond end of command line.
1376 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001377 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001378
1379 " Test toggling insert/overstrike a few times.
1380 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001381 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001382 endfor
1383
Bram Moolenaar30276f22019-01-24 17:59:39 +01001384 " Test overstrike with multi-byte characters.
1385 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001386 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001387
1388 let &encoding = encoding_save
1389endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001390
1391func Test_cmdwin_bug()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001392 CheckFeature cmdwin
1393
Bram Moolenaara046b372019-09-15 17:26:07 +02001394 let winid = win_getid()
1395 sp
1396 try
1397 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1398 catch /^Vim\%((\a\+)\)\=:E11/
1399 endtry
1400 bw!
1401endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +01001402
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001403func Test_cmdwin_restore()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001404 CheckFeature cmdwin
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001405 CheckScreendump
1406
1407 let lines =<< trim [SCRIPT]
Egor Zvorykin125ffd22021-11-17 14:01:14 +00001408 augroup vimHints | au! | augroup END
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001409 call setline(1, range(30))
1410 2split
1411 [SCRIPT]
1412 call writefile(lines, 'XTest_restore')
1413
1414 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001415 call TermWait(buf, 50)
Bram Moolenaar1c329c02019-10-27 20:37:35 +01001416 call term_sendkeys(buf, "q:")
1417 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1418
1419 " normal restore
1420 call term_sendkeys(buf, ":q\<CR>")
1421 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1422
1423 " restore after setting 'lines' with one window
1424 call term_sendkeys(buf, ":close\<CR>")
1425 call term_sendkeys(buf, "q:")
1426 call term_sendkeys(buf, ":set lines=18\<CR>")
1427 call term_sendkeys(buf, ":q\<CR>")
1428 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1429
1430 " clean up
1431 call StopVimInTerminal(buf)
1432 call delete('XTest_restore')
1433endfunc
1434
Bram Moolenaare5b44862021-05-30 13:54:03 +02001435func Test_cmdwin_no_terminal()
1436 CheckFeature cmdwin
1437 CheckFeature terminal
Bram Moolenaar0b496482021-05-30 14:21:57 +02001438 CheckNotMSWindows
Bram Moolenaare5b44862021-05-30 13:54:03 +02001439
1440 let buf = RunVimInTerminal('', {'rows': 12})
1441 call TermWait(buf, 50)
1442 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1443 call term_sendkeys(buf, "q:")
1444 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1445 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1446 call term_sendkeys(buf, ":q\<CR>")
1447 call StopVimInTerminal(buf)
1448endfunc
1449
Bram Moolenaar52410572019-10-27 05:12:45 +01001450func Test_buffers_lastused()
1451 " check that buffers are sorted by time when wildmode has lastused
1452 call test_settime(1550020000) " middle
1453 edit bufa
1454 enew
1455 call test_settime(1550030000) " newest
1456 edit bufb
1457 enew
1458 call test_settime(1550010000) " oldest
1459 edit bufc
1460 enew
1461 call test_settime(0)
1462 enew
1463
1464 call assert_equal(['bufa', 'bufb', 'bufc'],
1465 \ getcompletion('', 'buffer'))
1466
1467 let save_wildmode = &wildmode
1468 set wildmode=full:lastused
1469
1470 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1471 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1472 call assert_equal('b bufb', X)
1473 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1474 call assert_equal('b bufa', X)
1475 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1476 call assert_equal('b bufc', X)
1477 enew
1478
1479 edit other
1480 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1481 call assert_equal('b bufb', X)
1482 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1483 call assert_equal('b bufa', X)
1484 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1485 call assert_equal('b bufc', X)
1486 enew
1487
1488 let &wildmode = save_wildmode
1489
1490 bwipeout bufa
1491 bwipeout bufb
1492 bwipeout bufc
1493endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001494
1495func Test_cmdwin_feedkeys()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001496 CheckFeature cmdwin
1497
Bram Moolenaar85db5472019-12-04 15:11:08 +01001498 " This should not generate E488
1499 call feedkeys("q:\<CR>", 'x')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001500 " Using feedkeys with q: only should automatically close the cmd window
1501 call feedkeys('q:', 'xt')
1502 call assert_equal(1, winnr('$'))
1503 call assert_equal('', getcmdwintype())
Bram Moolenaar85db5472019-12-04 15:11:08 +01001504endfunc
Bram Moolenaar309976e2019-12-05 18:16:33 +01001505
1506" Tests for the issues fixed in 7.4.441.
1507" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1508func Test_cmdwin_cedit()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001509 CheckFeature cmdwin
1510
Bram Moolenaar309976e2019-12-05 18:16:33 +01001511 exe "set cedit=\<C-c>"
1512 normal! :
1513 call assert_equal(1, winnr('$'))
1514
1515 let g:cmd_wintype = ''
1516 func CmdWinType()
1517 let g:cmd_wintype = getcmdwintype()
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001518 let g:wintype = win_gettype()
Bram Moolenaar309976e2019-12-05 18:16:33 +01001519 return ''
1520 endfunc
1521
1522 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1523 echo input('')
1524 call assert_equal('@', g:cmd_wintype)
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +01001525 call assert_equal('command', g:wintype)
Bram Moolenaar309976e2019-12-05 18:16:33 +01001526
1527 set cedit&vim
1528 delfunc CmdWinType
1529endfunc
1530
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001531" Test for CmdwinEnter autocmd
1532func Test_cmdwin_autocmd()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001533 CheckFeature cmdwin
1534
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001535 augroup CmdWin
1536 au!
Bram Moolenaarb63f3ca2021-01-30 21:40:03 +01001537 autocmd BufLeave * if &buftype == '' | update | endif
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001538 autocmd CmdwinEnter * startinsert
1539 augroup END
1540
1541 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1542 call assert_equal('xyz', @:)
1543
1544 augroup CmdWin
1545 au!
1546 augroup END
1547 augroup! CmdWin
1548endfunc
1549
Bram Moolenaar479950f2020-01-19 15:45:17 +01001550func Test_cmdlineclear_tabenter()
1551 CheckScreendump
1552
1553 let lines =<< trim [SCRIPT]
1554 call setline(1, range(30))
1555 [SCRIPT]
1556
1557 call writefile(lines, 'XtestCmdlineClearTabenter')
1558 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001559 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001560 " in one tab make the command line higher with CTRL-W -
1561 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1562 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1563
1564 call StopVimInTerminal(buf)
1565 call delete('XtestCmdlineClearTabenter')
1566endfunc
1567
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001568" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001569func Test_cmdline_expand_special()
1570 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001571 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001572 call assert_fails('e <afile>', 'E495:')
1573 call assert_fails('e <abuf>', 'E496:')
1574 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001575
1576 call writefile([], 'Xfile.cpp')
1577 call writefile([], 'Xfile.java')
1578 new Xfile.cpp
1579 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1580 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1581 close
1582 call delete('Xfile.cpp')
1583 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001584endfunc
1585
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001586func Test_cmdwin_jump_to_win()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001587 CheckFeature cmdwin
1588
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001589 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1590 new
1591 set modified
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001592 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001593 close!
1594 call feedkeys("q/:close\<CR>", "xt")
1595 call assert_equal(1, winnr('$'))
1596 call feedkeys("q/:exit\<CR>", "xt")
1597 call assert_equal(1, winnr('$'))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001598
1599 " opening command window twice should fail
1600 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1601 call assert_equal(1, winnr('$'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001602endfunc
1603
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00001604func Test_cmdwin_tabpage()
1605 tabedit
1606 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1607 tabclose!
1608endfunc
1609
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001610func Test_cmdwin_interrupted()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001611 CheckFeature cmdwin
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001612 CheckScreendump
1613
1614 " aborting the :smile output caused the cmdline window to use the current
1615 " buffer.
1616 let lines =<< trim [SCRIPT]
1617 au WinNew * smile
1618 [SCRIPT]
1619 call writefile(lines, 'XTest_cmdwin')
1620
1621 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001622 " open cmdwin
1623 call term_sendkeys(buf, "q:")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001624 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001625 " quit more prompt for :smile command
1626 call term_sendkeys(buf, "q")
Bram Moolenaarc82dd862020-06-07 17:30:33 +02001627 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
Bram Moolenaar9b7cce22020-06-06 15:14:08 +02001628 " execute a simple command
1629 call term_sendkeys(buf, "aecho 'done'\<CR>")
1630 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1631
1632 " clean up
1633 call StopVimInTerminal(buf)
1634 call delete('XTest_cmdwin')
1635endfunc
1636
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001637" Test for backtick expression in the command line
1638func Test_cmd_backtick()
1639 %argd
1640 argadd `=['a', 'b', 'c']`
1641 call assert_equal(['a', 'b', 'c'], argv())
1642 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001643
1644 argadd `echo abc def`
1645 call assert_equal(['abc def'], argv())
1646 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001647endfunc
1648
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001649" Test for the :! command
1650func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001651 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001652
1653 let lines =<< trim [SCRIPT]
1654 " Test for no previous command
1655 call assert_fails('!!', 'E34:')
1656 set nomore
1657 " Test for cmdline expansion with :!
1658 call setline(1, 'foo!')
1659 silent !echo <cWORD> > Xfile.out
1660 call assert_equal(['foo!'], readfile('Xfile.out'))
1661 " Test for using previous command
1662 silent !echo \! !
1663 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1664 call writefile(v:errors, 'Xresult')
1665 call delete('Xfile.out')
1666 qall!
1667 [SCRIPT]
1668 call writefile(lines, 'Xscript')
1669 if RunVim([], [], '--clean -S Xscript')
1670 call assert_equal([], readfile('Xresult'))
1671 endif
1672 call delete('Xscript')
1673 call delete('Xresult')
1674endfunc
1675
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001676" Test error: "E135: *Filter* Autocommands must not change current buffer"
1677func Test_cmd_bang_E135()
1678 new
1679 call setline(1, ['a', 'b', 'c', 'd'])
1680 augroup test_cmd_filter_E135
1681 au!
1682 autocmd FilterReadPost * help
1683 augroup END
1684 call assert_fails('2,3!echo "x"', 'E135:')
1685
1686 augroup test_cmd_filter_E135
1687 au!
1688 augroup END
1689 %bwipe!
1690endfunc
1691
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001692" Test for using ~ for home directory in cmdline completion matches
1693func Test_cmdline_expand_home()
1694 call mkdir('Xdir')
1695 call writefile([], 'Xdir/Xfile1')
1696 call writefile([], 'Xdir/Xfile2')
1697 cd Xdir
1698 let save_HOME = $HOME
1699 let $HOME = getcwd()
1700 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1701 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1702 let $HOME = save_HOME
1703 cd ..
1704 call delete('Xdir', 'rf')
1705endfunc
1706
Bram Moolenaar578fe942020-02-27 21:32:51 +01001707" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1708" or insert mode (when 'insertmode' is set)
1709func Test_cmdline_ctrl_g()
1710 new
1711 call setline(1, 'abc')
1712 call cursor(1, 3)
1713 " If command line is entered from insert mode, using C-\ C-G should back to
1714 " insert mode
1715 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1716 call assert_equal('abxyc', getline(1))
1717 call assert_equal(4, col('.'))
1718
1719 " If command line is entered in 'insertmode', using C-\ C-G should back to
1720 " 'insertmode'
1721 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1722 call assert_equal('ab12xyc', getline(1))
1723 close!
1724endfunc
1725
Bram Moolenaar578fe942020-02-27 21:32:51 +01001726" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001727func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001728 func T(a, c, p)
1729 return "oneA\noneB\noneC"
1730 endfunc
1731 command -nargs=1 -complete=custom,T MyCmd
1732
Bram Moolenaar578fe942020-02-27 21:32:51 +01001733 set nowildmenu
1734 set wildmode=full,list
1735 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001736 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001737 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001738 call assert_equal('"MyCmd oneA', @:)
1739
1740 set wildmode=longest,full
1741 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1742 call assert_equal('"MyCmd one', @:)
1743 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1744 call assert_equal('"MyCmd oneC', @:)
1745
1746 set wildmode=longest
1747 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1748 call assert_equal('"MyCmd one', @:)
1749
1750 set wildmode=list:longest
1751 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001752 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001753 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001754 call assert_equal('"MyCmd one', @:)
1755
1756 set wildmode=""
1757 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1758 call assert_equal('"MyCmd oneA', @:)
1759
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001760 " Test for wildmode=longest with 'fileignorecase' set
1761 set wildmode=longest
1762 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001763 argadd AAA AAAA AAAAA
1764 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1765 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001766 set fileignorecase&
1767
1768 " Test for listing files with wildmode=list
1769 set wildmode=list
1770 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001771 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001772 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001773 call assert_equal('"b A', @:)
1774
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001775 " when using longest completion match, matches shorter than the argument
1776 " should be ignored (happens with :help)
1777 set wildmode=longest,full
1778 set wildmenu
1779 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1780 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001781 " non existing file
1782 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1783 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001784 set wildmenu&
1785
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001786 " Test for longest file name completion with 'fileignorecase'
1787 " On MS-Windows, file names are case insensitive.
1788 if has('unix')
1789 call writefile([], 'XTESTfoo')
1790 call writefile([], 'Xtestbar')
1791 set nofileignorecase
1792 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1793 call assert_equal('"e XTESTfoo', @:)
1794 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1795 call assert_equal('"e Xtestbar', @:)
1796 set fileignorecase
1797 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1798 call assert_equal('"e Xtest', @:)
1799 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1800 call assert_equal('"e Xtest', @:)
1801 set fileignorecase&
1802 call delete('XTESTfoo')
1803 call delete('Xtestbar')
1804 endif
1805
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001806 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001807 delcommand MyCmd
1808 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001809 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001810 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001811endfunc
1812
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001813func Test_wildmode()
1814 " Test with utf-8 encoding
1815 call Wildmode_tests()
1816
1817 " Test with latin1 encoding
1818 let save_encoding = &encoding
1819 set encoding=latin1
1820 call Wildmode_tests()
1821 let &encoding = save_encoding
1822endfunc
1823
Bram Moolenaar578fe942020-02-27 21:32:51 +01001824" Test for interrupting the command-line completion
1825func Test_interrupt_compl()
1826 func F(lead, cmdl, p)
1827 if a:lead =~ 'tw'
1828 call interrupt()
1829 return
1830 endif
1831 return "one\ntwo\nthree"
1832 endfunc
1833 command -nargs=1 -complete=custom,F Tcmd
1834
1835 set nowildmenu
1836 set wildmode=full
1837 let interrupted = 0
1838 try
1839 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1840 catch /^Vim:Interrupt$/
1841 let interrupted = 1
1842 endtry
1843 call assert_equal(1, interrupted)
1844
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001845 let interrupted = 0
1846 try
1847 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1848 catch /^Vim:Interrupt$/
1849 let interrupted = 1
1850 endtry
1851 call assert_equal(1, interrupted)
1852
Bram Moolenaar578fe942020-02-27 21:32:51 +01001853 delcommand Tcmd
1854 delfunc F
1855 set wildmode&
1856endfunc
1857
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001858" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001859func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001860 let str = ":one two\<C-U>"
1861 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001862 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001863 let str ..= "\<Left>five\<Right>"
1864 let str ..= "\<Home>two "
1865 let str ..= "\<C-Left>one "
1866 let str ..= "\<C-Right> three"
1867 let str ..= "\<End>\<S-Left>four "
1868 let str ..= "\<S-Right> six"
1869 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1870 call feedkeys(str, 'xt')
1871 call assert_equal("\"one two three four five six seven", @:)
1872endfunc
1873
1874" Test for moving the cursor on the / command line in 'rightleft' mode
1875func Test_cmdline_edit_rightleft()
1876 CheckFeature rightleft
1877 set rightleft
1878 set rightleftcmd=search
1879 let str = "/one two\<C-U>"
1880 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001881 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001882 let str ..= "\<Right>five\<Left>"
1883 let str ..= "\<Home>two "
1884 let str ..= "\<C-Right>one "
1885 let str ..= "\<C-Left> three"
1886 let str ..= "\<End>\<S-Right>four "
1887 let str ..= "\<S-Left> six"
1888 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1889 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1890 call assert_equal("\"one two three four five six seven", @/)
1891 set rightleftcmd&
1892 set rightleft&
1893endfunc
1894
1895" Test for using <C-\>e in the command line to evaluate an expression
1896func Test_cmdline_expr()
1897 " Evaluate an expression from the beginning of a command line
1898 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1899 call assert_equal('"hello', @:)
1900
1901 " Use an invalid expression for <C-\>e
1902 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1903
1904 " Insert literal <CTRL-\> in the command line
1905 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1906 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001907endfunc
1908
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001909" Test for 'imcmdline' and 'imsearch'
1910" This test doesn't actually test the input method functionality.
1911func Test_cmdline_inputmethod()
1912 new
1913 call setline(1, ['', 'abc', ''])
1914 set imcmdline
1915
1916 call feedkeys(":\"abc\<CR>", 'xt')
1917 call assert_equal("\"abc", @:)
1918 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1919 call assert_equal("\"abc", @:)
1920 call feedkeys("/abc\<CR>", 'xt')
1921 call assert_equal([2, 1], [line('.'), col('.')])
1922 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1923 call assert_equal([2, 1], [line('.'), col('.')])
1924
1925 set imsearch=2
1926 call cursor(1, 1)
1927 call feedkeys("/abc\<CR>", 'xt')
1928 call assert_equal([2, 1], [line('.'), col('.')])
1929 call cursor(1, 1)
1930 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1931 call assert_equal([2, 1], [line('.'), col('.')])
1932 set imdisable
1933 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1934 call assert_equal([2, 1], [line('.'), col('.')])
1935 set imdisable&
1936 set imsearch&
1937
1938 set imcmdline&
1939 %bwipe!
1940endfunc
1941
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001942" Test for recursively getting multiple command line inputs
1943func Test_cmdwin_multi_input()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001944 CheckFeature cmdwin
1945
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001946 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
1947 call assert_equal('"cyan', @:)
1948endfunc
1949
1950" Test for using CTRL-_ in the command line with 'allowrevins'
1951func Test_cmdline_revins()
1952 CheckNotMSWindows
1953 CheckFeature rightleft
1954 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1955 call assert_equal("\"abc\<c-_>", @:)
1956 set allowrevins
1957 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1958 call assert_equal('"abcñèæ', @:)
1959 set allowrevins&
1960endfunc
1961
1962" Test for typing UTF-8 composing characters in the command line
1963func Test_cmdline_composing_chars()
1964 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1965 call assert_equal('"ゔ', @:)
1966endfunc
1967
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001968" Test for normal mode commands not supported in the cmd window
1969func Test_cmdwin_blocked_commands()
Bram Moolenaar21829c52021-01-26 22:42:21 +01001970 CheckFeature cmdwin
1971
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001972 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
1973 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
1974 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
1975 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
1976 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
1977 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
Bram Moolenaar951a2fb2020-06-07 19:38:10 +02001978 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
1979 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
1980 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
1981 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
1982 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
1983 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
1984 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
1985 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
1986 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
1987 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
1988 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
1989 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
1990 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
1991 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
1992 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
1993 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
1994 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
1995 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
1996 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
1997 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
1998 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001999endfunc
2000
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002001" Close the Cmd-line window in insert mode using CTRL-C
2002func Test_cmdwin_insert_mode_close()
Bram Moolenaar21829c52021-01-26 22:42:21 +01002003 CheckFeature cmdwin
2004
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002005 %bw!
2006 let s = ''
2007 exe "normal q:a\<C-C>let s='Hello'\<CR>"
2008 call assert_equal('Hello', s)
2009 call assert_equal(1, winnr('$'))
2010endfunc
2011
Bram Moolenaar0e717042020-04-27 19:29:01 +02002012" test that ";" works to find a match at the start of the first line
2013func Test_zero_line_search()
2014 new
2015 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2016 call cursor(1,1)
2017 0;/pattern/d
2018 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2019 q!
2020endfunc
2021
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002022func Test_read_shellcmd()
2023 CheckUnix
2024 if executable('ls')
2025 " There should be ls in the $PATH
2026 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2027 call assert_match('^"r! .*\<ls\>', @:)
2028 endif
2029
2030 if executable('rm')
2031 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2032 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2033 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002034
2035 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2036 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2037 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002038 endif
2039endfunc
2040
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002041" Test for going up and down the directory tree using 'wildmenu'
2042func Test_wildmenu_dirstack()
2043 CheckUnix
2044 %bw!
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002045 call mkdir('Xdir1/dir2/dir3/dir4', 'p')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002046 call writefile([], 'Xdir1/file1_1.txt')
2047 call writefile([], 'Xdir1/file1_2.txt')
2048 call writefile([], 'Xdir1/dir2/file2_1.txt')
2049 call writefile([], 'Xdir1/dir2/file2_2.txt')
2050 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
2051 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002052 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
2053 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002054 set wildmenu
2055
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002056 cd Xdir1/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002057 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002058 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002059 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002060 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002061 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002062 call assert_equal('"e ../../dir3/', @:)
2063 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2064 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002065 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002066 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002067 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002068 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002069 cd -
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002070 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2071 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
2072
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002073 call delete('Xdir1', 'rf')
2074 set wildmenu&
2075endfunc
2076
obcat71c6f7a2021-05-13 20:23:10 +02002077" Test for recalling newer or older cmdline from history with <Up>, <Down>,
2078" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
2079func Test_recalling_cmdline()
2080 CheckFeature cmdline_hist
2081
2082 let g:cmdlines = []
2083 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2084
2085 let histories = [
2086 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
2087 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
2088 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
2089 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
2090 "\ TODO: {'name': 'debug', ...}
2091 \]
2092 let keypairs = [
2093 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
2094 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
2095 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
2096 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
2097 \]
2098 let prefix = 'vi'
2099 for h in histories
2100 call histadd(h.name, 'vim')
2101 call histadd(h.name, 'virtue')
2102 call histadd(h.name, 'Virgo')
2103 call histadd(h.name, 'vogue')
2104 call histadd(h.name, 'emacs')
2105 for k in keypairs
2106 let g:cmdlines = []
2107 let keyseqs = h.enter
2108 \ .. prefix
2109 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2110 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2111 \ .. h.exit
2112 call feedkeys(keyseqs, 'xt')
2113 call histdel(h.name, -1) " delete the history added by feedkeys above
2114 let expect = k.prefixmatch
2115 \ ? ['virtue', 'vim', 'virtue', prefix]
2116 \ : ['emacs', 'vogue', 'emacs', prefix]
2117 call assert_equal(expect, g:cmdlines)
2118 endfor
2119 endfor
2120
2121 unlet g:cmdlines
2122 cunmap <Plug>(save-cmdline)
2123endfunc
2124
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002125func Test_cmd_map_cmdlineChanged()
2126 let g:log = []
2127 cnoremap <F1> l<Cmd><CR>s
2128 augroup test
2129 autocmd!
2130 autocmd CmdlineChanged : let g:log += [getcmdline()]
2131 augroup END
2132
2133 call feedkeys(":\<F1>\<CR>", 'xt')
2134 call assert_equal(['l', 'ls'], g:log)
2135
Bram Moolenaar796139a2021-05-18 21:38:45 +02002136 let @b = 'b'
2137 cnoremap <F1> a<C-R>b
2138 let g:log = []
2139 call feedkeys(":\<F1>\<CR>", 'xt')
2140 call assert_equal(['a', 'ab'], g:log)
2141
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002142 unlet g:log
2143 cunmap <F1>
2144 augroup test
2145 autocmd!
2146 augroup END
2147endfunc
2148
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002149" Test for the 'suffixes' option
2150func Test_suffixes_opt()
2151 call writefile([], 'Xfile')
2152 call writefile([], 'Xfile.c')
2153 call writefile([], 'Xfile.o')
2154 set suffixes=
2155 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2156 call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002157 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2158 call assert_equal('"e Xfile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002159 set suffixes=.c
2160 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2161 call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002162 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2163 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002164 set suffixes=,,
2165 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
2166 call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002167 call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2168 call assert_equal('"e Xfile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002169 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002170 " Test for getcompletion() with different patterns
2171 call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
2172 call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002173 call delete('Xfile')
2174 call delete('Xfile.c')
2175 call delete('Xfile.o')
2176endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002177
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002178" Test for using a popup menu for the command line completion matches
2179" (wildoptions=pum)
2180func Test_wildmenu_pum()
2181 CheckRunVimInTerminal
2182
2183 let commands =<< trim [CODE]
2184 set wildmenu
2185 set wildoptions=pum
2186 set shm+=I
2187 set noruler
2188 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002189
2190 func CmdCompl(a, b, c)
2191 return repeat(['aaaa'], 120)
2192 endfunc
2193 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002194
2195 func MyStatusLine() abort
2196 return 'status'
2197 endfunc
2198 func SetupStatusline()
2199 set statusline=%!MyStatusLine()
2200 set laststatus=2
2201 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002202
2203 func MyTabLine()
2204 return 'my tab line'
2205 endfunc
2206 func SetupTabline()
2207 set statusline=
2208 set tabline=%!MyTabLine()
2209 set showtabline=2
2210 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002211
2212 func DoFeedKeys()
2213 let &wildcharm = char2nr("\t")
2214 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2215 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002216 [CODE]
2217 call writefile(commands, 'Xtest')
2218
2219 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2220
2221 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002222 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2223
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002224 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002225 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002226 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2227
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002228 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002229 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002230 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2231
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002232 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002233 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2235
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002236 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002237 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002238 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2239
2240 " pressing <C-E> should end completion and go back to the original match
2241 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002242 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2243
2244 " pressing <C-Y> should select the current match and end completion
2245 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002246 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2247
2248 " With 'wildmode' set to 'longest,full', completing a match should display
2249 " the longest match, the wildmenu should not be displayed.
2250 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2251 call TermWait(buf)
2252 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002253 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2254
2255 " pressing <Tab> should display the wildmenu
2256 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002257 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2258
2259 " pressing <Tab> second time should select the next entry in the menu
2260 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002261 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2262
2263 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002264 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002265 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2267
2268 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002269 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2270
2271 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002272 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2273
2274 " Directory name completion
2275 call mkdir('Xdir/XdirA/XdirB', 'p')
2276 call writefile([], 'Xdir/XfileA')
2277 call writefile([], 'Xdir/XdirA/XfileB')
2278 call writefile([], 'Xdir/XdirA/XdirB/XfileC')
2279
2280 call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002281 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2282
2283 " Pressing <Right> on a directory name should go into that directory
2284 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002285 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2286
2287 " Pressing <Left> on a directory name should go to the parent directory
2288 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002289 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2290
2291 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002292 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002293 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002294 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2295
2296 " Pressing <C-D> when the popup menu is displayed should remove the popup
2297 " menu
2298 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002299 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2300
2301 " Pressing <S-Tab> should open the popup menu with the last entry selected
2302 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002303 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2304
2305 " Pressing <Esc> should close the popup menu and cancel the cmd line
2306 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002307 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2308
2309 " Typing a character when the popup is open, should close the popup
2310 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002311 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2312
2313 " When the popup is open, entering the cmdline window should close the popup
2314 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2316 call term_sendkeys(buf, ":q\<CR>")
2317
2318 " After the last popup menu item, <C-N> should show the original string
2319 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002320 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2321
2322 " Use the popup menu for the command name
2323 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002324 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2325
2326 " Pressing the left arrow should remove the popup menu
2327 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002328 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2329
2330 " Pressing <BS> should remove the popup menu and erase the last character
2331 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002332 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2333
2334 " Pressing <C-W> should remove the popup menu and erase the previous word
2335 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002336 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2337
2338 " Pressing <C-U> should remove the popup menu and erase the entire line
2339 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2341
2342 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2343 " the cmdline from history
2344 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002345 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2346
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002347 " Check "list" still works
2348 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2349 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002350 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2351 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2353
rbtnn68cc2b82022-02-09 11:55:47 +00002354 " Tests a directory name contained full-width characters.
2355 call mkdir('Xdir/あいう', 'p')
2356 call writefile([], 'Xdir/あいう/abc')
2357 call writefile([], 'Xdir/あいう/xyz')
2358 call writefile([], 'Xdir/あいう/123')
2359
2360 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
2361 call term_sendkeys(buf, ":\<C-U>e Xdir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002362 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2363
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002364 " Pressing <C-A> when the popup menu is displayed should list all the
2365 " matches and pressing a key after that should remove the popup menu
2366 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2367 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2368 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2369
2370 " Pressing <C-A> when the popup menu is displayed should list all the
2371 " matches and pressing <Left> after that should move the cursor
2372 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2373 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2374 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2375
2376 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2377 " should be displayed correctly on the screen.
2378 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2379 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2380
2381 " After using <C-A> to expand all the filename matches, pressing <Up>
2382 " should not open the popup menu again.
2383 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xdir/XdirA\<CR>")
2384 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2385 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2386 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2387
2388 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2389 " crash Vim
2390 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2391 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2392
Bram Moolenaar414acd32022-02-10 21:09:45 +00002393 " After removing the pum the command line is redrawn
2394 call term_sendkeys(buf, ":edit foo\<CR>")
2395 call term_sendkeys(buf, ":edit bar\<CR>")
2396 call term_sendkeys(buf, ":ls\<CR>")
2397 call term_sendkeys(buf, ":com\<Tab> ")
2398 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002399 call term_sendkeys(buf, "\<C-U>\<CR>")
2400
2401 " Esc still works to abort the command when 'statusline' is set
2402 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2403 call term_sendkeys(buf, ":si\<Tab>")
2404 call term_sendkeys(buf, "\<Esc>")
2405 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002406
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002407 " Esc still works to abort the command when 'tabline' is set
2408 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2409 call term_sendkeys(buf, ":si\<Tab>")
2410 call term_sendkeys(buf, "\<Esc>")
2411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2412
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002413 " popup is cleared also when 'lazyredraw' is set
2414 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2415 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2416 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2417 call term_sendkeys(buf, "\<Esc>")
2418
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002419 call term_sendkeys(buf, "\<C-U>\<CR>")
2420 call StopVimInTerminal(buf)
2421 call delete('Xtest')
2422 call delete('Xdir', 'rf')
2423endfunc
2424
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002425" Test for wildmenumode() with the cmdline popup menu
2426func Test_wildmenumode_with_pum()
2427 set wildmenu
2428 set wildoptions=pum
2429 cnoremap <expr> <F2> wildmenumode()
2430 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2431 call assert_equal('"sign define10', @:)
2432 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2433 call assert_equal('"sign define jump list place undefine unplace0', @:)
2434 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2435 call assert_equal('"sign 0', @:)
2436 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2437 call assert_equal('"sign define0', @:)
2438 set nowildmenu wildoptions&
2439 cunmap <F2>
2440endfunc
2441
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002442" Test for completion after a :substitute command followed by a pipe (|)
2443" character
2444func Test_cmdline_complete_substitute()
2445 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2446 call assert_equal("\"s | \t", @:)
2447 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2448 call assert_equal("\"s/ | \t", @:)
2449 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2450 call assert_equal("\"s/one | \t", @:)
2451 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2452 call assert_equal("\"s/one/ | \t", @:)
2453 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2454 call assert_equal("\"s/one/two | \t", @:)
2455 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2456 call assert_equal('"s/one/two/ | chistory', @:)
2457 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2458 call assert_equal("\"s/one/two/g \t", @:)
2459 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2460 call assert_equal("\"s/one/two/g | chistory", @:)
2461 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2462 call assert_equal("\"s/one/t\\/ | \t", @:)
2463 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2464 call assert_equal('"s/one/t"o/ | chistory', @:)
2465 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2466 call assert_equal('"s/one/t|o/ | chistory', @:)
2467 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2468 call assert_equal("\"&\t", @:)
2469endfunc
2470
2471" Test for the :dlist command completion
2472func Test_cmdline_complete_dlist()
2473 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2474 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2475 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2476 call assert_equal("\"dlist 10 /pat/ \t", @:)
2477 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2478 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2479 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2480 call assert_equal("\"dlist 10 /pat\\\t", @:)
2481 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2482 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2483endfunc
2484
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002485" argument list (only for :argdel) fuzzy completion
2486func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002487 argadd change.py count.py charge.py
2488 set wildoptions&
2489 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2490 call assert_equal('"argdel cge', @:)
2491 set wildoptions=fuzzy
2492 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2493 call assert_equal('"argdel change.py charge.py', @:)
2494 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002495 set wildoptions&
2496endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002497
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002498" autocmd group name fuzzy completion
2499func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002500 set wildoptions&
2501 augroup MyFuzzyGroup
2502 augroup END
2503 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2504 call assert_equal('"augroup mfg', @:)
2505 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2506 call assert_equal('"augroup MyFuzzyGroup', @:)
2507 set wildoptions=fuzzy
2508 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2509 call assert_equal('"augroup MyFuzzyGroup', @:)
2510 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2511 call assert_equal('"augroup My*p', @:)
2512 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002513 set wildoptions&
2514endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002515
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002516" buffer name fuzzy completion
2517func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002518 set wildoptions&
2519 edit SomeFile.txt
2520 enew
2521 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2522 call assert_equal('"b SF', @:)
2523 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2524 call assert_equal('"b SomeFile.txt', @:)
2525 set wildoptions=fuzzy
2526 call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx')
2527 call assert_equal('"b SomeFile.txt', @:)
2528 call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2529 call assert_equal('"b S*File.txt', @:)
2530 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002531 set wildoptions&
2532endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002533
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002534" buffer name (full path) fuzzy completion
2535func Test_fuzzy_completion_bufname_fullpath()
2536 CheckUnix
2537 set wildoptions&
2538 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2539 edit Xcmd/Xstate/Xfile.js
2540 cd Xcmd/Xstate
2541 enew
2542 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2543 call assert_equal('"b CmdStateFile', @:)
2544 set wildoptions=fuzzy
2545 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2546 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2547 cd -
2548 call delete('Xcmd', 'rf')
2549 set wildoptions&
2550endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002551
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002552" :behave suboptions fuzzy completion
2553func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002554 set wildoptions&
2555 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2556 call assert_equal('"behave xm', @:)
2557 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2558 call assert_equal('"behave xterm', @:)
2559 set wildoptions=fuzzy
2560 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2561 call assert_equal('"behave xterm', @:)
2562 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2563 call assert_equal('"behave xt*m', @:)
2564 let g:Sline = ''
2565 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2566 call assert_equal('mswin', g:Sline)
2567 call assert_equal('"behave win', @:)
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" " colorscheme name fuzzy completion - NOT supported
2572" func Test_fuzzy_completion_colorscheme()
2573" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002574
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002575" built-in command name fuzzy completion
2576func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002577 set wildoptions&
2578 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2579 call assert_equal('"sbwin', @:)
2580 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2581 call assert_equal('"sbrewind', @:)
2582 set wildoptions=fuzzy
2583 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2584 call assert_equal('"sbrewind', @:)
2585 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2586 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002587 set wildoptions&
2588endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002589
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002590" " compiler name fuzzy completion - NOT supported
2591" func Test_fuzzy_completion_compiler()
2592" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002593
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002594" :cscope suboptions fuzzy completion
2595func Test_fuzzy_completion_cscope()
2596 CheckFeature cscope
2597 set wildoptions&
2598 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2599 call assert_equal('"cscope ret', @:)
2600 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"cscope reset', @:)
2602 set wildoptions=fuzzy
2603 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2604 call assert_equal('"cscope reset', @:)
2605 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2606 call assert_equal('"cscope re*t', @:)
2607 set wildoptions&
2608endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002609
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002610" :diffget/:diffput buffer name fuzzy completion
2611func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002612 new SomeBuffer
2613 diffthis
2614 new OtherBuffer
2615 diffthis
2616 set wildoptions&
2617 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2618 call assert_equal('"diffget sbuf', @:)
2619 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2620 call assert_equal('"diffput sbuf', @:)
2621 set wildoptions=fuzzy
2622 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2623 call assert_equal('"diffget SomeBuffer', @:)
2624 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2625 call assert_equal('"diffput SomeBuffer', @:)
2626 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002627 set wildoptions&
2628endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002629
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002630" " directory name fuzzy completion - NOT supported
2631" func Test_fuzzy_completion_dirname()
2632" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002633
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002634" environment variable name fuzzy completion
2635func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002636 set wildoptions&
2637 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2638 call assert_equal('"echo $VUT', @:)
2639 set wildoptions=fuzzy
2640 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2641 call assert_equal('"echo $VIMRUNTIME', @:)
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" autocmd event fuzzy completion
2646func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002647 set wildoptions&
2648 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2649 call assert_equal('"autocmd BWout', @:)
2650 set wildoptions=fuzzy
2651 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2652 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002653 set wildoptions&
2654endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002655
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002656" vim expression fuzzy completion
2657func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002658 let g:PerPlaceCount = 10
2659 set wildoptions&
2660 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2661 call assert_equal('"let c = ppc', @:)
2662 set wildoptions=fuzzy
2663 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2664 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002665 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002666endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002667
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002668" " file name fuzzy completion - NOT supported
2669" func Test_fuzzy_completion_filename()
2670" endfunc
2671
2672" " files in path fuzzy completion - NOT supported
2673" func Test_fuzzy_completion_filesinpath()
2674" endfunc
2675
2676" " filetype name fuzzy completion - NOT supported
2677" func Test_fuzzy_completion_filetype()
2678" endfunc
2679
2680" user defined function name completion
2681func Test_fuzzy_completion_userdefined_func()
2682 set wildoptions&
2683 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2684 call assert_equal('"call Test_f_u_f', @:)
2685 set wildoptions=fuzzy
2686 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2687 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2688 set wildoptions&
2689endfunc
2690
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002691" <SNR> functions should be sorted to the end
2692func Test_fuzzy_completion_userdefined_snr_func()
2693 func s:Sendmail()
2694 endfunc
2695 func SendSomemail()
2696 endfunc
2697 func S1e2n3dmail()
2698 endfunc
2699 set wildoptions=fuzzy
2700 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002701 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002702 set wildoptions&
2703 delfunc s:Sendmail
2704 delfunc SendSomemail
2705 delfunc S1e2n3dmail
2706endfunc
2707
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002708" user defined command name completion
2709func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002710 set wildoptions&
2711 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2712 call assert_equal('"MsFeat', @:)
2713 set wildoptions=fuzzy
2714 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2715 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002716 set wildoptions&
2717endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002718
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002719" " :help tag fuzzy completion - NOT supported
2720" func Test_fuzzy_completion_helptag()
2721" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002722
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002723" highlight group name fuzzy completion
2724func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002725 set wildoptions&
2726 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2727 call assert_equal('"highlight SKey', @:)
2728 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2729 call assert_equal('"highlight SpecialKey', @:)
2730 set wildoptions=fuzzy
2731 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2732 call assert_equal('"highlight SpecialKey', @:)
2733 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2734 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002735 set wildoptions&
2736endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002737
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002738" :history suboptions fuzzy completion
2739func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002740 set wildoptions&
2741 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2742 call assert_equal('"history dg', @:)
2743 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"history search', @:)
2745 set wildoptions=fuzzy
2746 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2747 call assert_equal('"history debug', @:)
2748 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2749 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002750 set wildoptions&
2751endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002752
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002753" :language locale name fuzzy completion
2754func Test_fuzzy_completion_lang()
2755 CheckUnix
2756 set wildoptions&
2757 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2758 call assert_equal('"lang psx', @:)
2759 set wildoptions=fuzzy
2760 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal('"lang POSIX', @:)
2762 set wildoptions&
2763endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002764
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002765" :mapclear buffer argument fuzzy completion
2766func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002767 set wildoptions&
2768 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2769 call assert_equal('"mapclear buf', @:)
2770 set wildoptions=fuzzy
2771 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2772 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002773 set wildoptions&
2774endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002775
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002776" map name fuzzy completion
2777func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002778 " test regex completion works
2779 set wildoptions=fuzzy
2780 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2781 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002782 nmap <plug>MyLongMap :p<CR>
2783 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2784 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2785 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2786 call assert_equal("\"nmap MLM \t", @:)
2787 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2788 call assert_equal("\"nmap <F2> one two \t", @:)
2789 " duplicate entries should be removed
2790 vmap <plug>MyLongMap :<C-U>#<CR>
2791 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2792 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2793 nunmap <plug>MyLongMap
2794 vunmap <plug>MyLongMap
2795 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2796 call assert_equal("\"nmap ABC\t", @:)
2797 " results should be sorted by best match
2798 nmap <Plug>format :
2799 nmap <Plug>goformat :
2800 nmap <Plug>TestFOrmat :
2801 nmap <Plug>fendoff :
2802 nmap <Plug>state :
2803 nmap <Plug>FendingOff :
2804 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2805 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2806 nunmap <Plug>format
2807 nunmap <Plug>goformat
2808 nunmap <Plug>TestFOrmat
2809 nunmap <Plug>fendoff
2810 nunmap <Plug>state
2811 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002812 set wildoptions&
2813endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002814
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002815" abbreviation fuzzy completion
2816func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002817 set wildoptions=fuzzy
2818 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2819 call assert_equal("\"iabbr <nowait>", @:)
2820 iabbr WaitForCompletion WFC
2821 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2822 call assert_equal("\"iabbr WaitForCompletion", @:)
2823 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal("\"iabbr a1z\t", @:)
2825 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002826 set wildoptions&
2827endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002828
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002829" menu name fuzzy completion
2830func Test_fuzzy_completion_menu()
2831 CheckGui
2832 set wildoptions&
2833 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"menu pup', @:)
2835 set wildoptions=fuzzy
2836 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2837 call assert_equal('"menu PopUp.', @:)
2838 set wildoptions&
2839endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002840
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002841" :messages suboptions fuzzy completion
2842func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002843 set wildoptions&
2844 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2845 call assert_equal('"messages clr', @:)
2846 set wildoptions=fuzzy
2847 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2848 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002849 set wildoptions&
2850endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002851
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002852" :set option name fuzzy completion
2853func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002854 set wildoptions&
2855 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"set brkopt', @:)
2857 set wildoptions=fuzzy
2858 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2859 call assert_equal('"set breakindentopt', @:)
2860 set wildoptions&
2861 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2862 call assert_equal('"set fixendofline', @:)
2863 set wildoptions=fuzzy
2864 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2865 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002866 set wildoptions&
2867endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002868
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002869" :set <term_option>
2870func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002871 set wildoptions&
2872 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2873 call assert_equal('"set t_EC', @:)
2874 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal('"set <t_EC>', @:)
2876 set wildoptions=fuzzy
2877 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2878 call assert_equal('"set t_EC', @:)
2879 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2880 call assert_equal('"set <t_EC>', @:)
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" " :packadd directory name fuzzy completion - NOT supported
2885" func Test_fuzzy_completion_packadd()
2886" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002887
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002888" " shell command name fuzzy completion - NOT supported
2889" func Test_fuzzy_completion_shellcmd()
2890" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002891
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002892" :sign suboptions fuzzy completion
2893func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002894 set wildoptions&
2895 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2896 call assert_equal('"sign ufe', @:)
2897 set wildoptions=fuzzy
2898 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002900 set wildoptions&
2901endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002902
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903" :syntax suboptions fuzzy completion
2904func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905 set wildoptions&
2906 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2907 call assert_equal('"syntax kwd', @:)
2908 set wildoptions=fuzzy
2909 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2910 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002911 set wildoptions&
2912endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002913
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002914" syntax group name fuzzy completion
2915func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002916 set wildoptions&
2917 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2918 call assert_equal('"syntax list mpar', @:)
2919 set wildoptions=fuzzy
2920 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2921 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002922 set wildoptions&
2923endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002924
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002925" :syntime suboptions fuzzy completion
2926func Test_fuzzy_completion_syntime()
2927 CheckFeature profile
2928 set wildoptions&
2929 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2930 call assert_equal('"syntime clr', @:)
2931 set wildoptions=fuzzy
2932 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"syntime clear', @:)
2934 set wildoptions&
2935endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002936
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002937" " tag name fuzzy completion - NOT supported
2938" func Test_fuzzy_completion_tagname()
2939" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941" " tag name and file fuzzy completion - NOT supported
2942" func Test_fuzzy_completion_tagfile()
2943" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002944
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002945" " user names fuzzy completion - how to test this functionality?
2946" func Test_fuzzy_completion_username()
2947" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002948
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949" user defined variable name fuzzy completion
2950func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002951 let g:SomeVariable=10
2952 set wildoptions&
2953 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"let SVar', @:)
2955 set wildoptions=fuzzy
2956 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958 set wildoptions&
2959endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961" Test for sorting the results by the best match
2962func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002963 %bw!
2964 command T123format :
2965 command T123goformat :
2966 command T123TestFOrmat :
2967 command T123fendoff :
2968 command T123state :
2969 command T123FendingOff :
2970 set wildoptions=fuzzy
2971 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2973 delcommand T123format
2974 delcommand T123goformat
2975 delcommand T123TestFOrmat
2976 delcommand T123fendoff
2977 delcommand T123state
2978 delcommand T123FendingOff
2979 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980 set wildoptions&
2981endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002982
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002983" Test for fuzzy completion of a command with lower case letters and a number
2984func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002985 command Foo2Bar :
2986 set wildoptions=fuzzy
2987 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal('"Foo2Bar', @:)
2989 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2990 call assert_equal('"Foo2Bar', @:)
2991 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2992 call assert_equal('"Foo2Bar', @:)
2993 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002994 set wildoptions&
2995endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002996
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002997" Test for command completion for a command starting with 'k'
2998func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002999 command KillKillKill :
3000 set wildoptions&
3001 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal("\"killkill\<Tab>", @:)
3003 set wildoptions=fuzzy
3004 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3005 call assert_equal('"KillKillKill', @:)
3006 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003007 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003008endfunc
3009
3010" Test for fuzzy completion for user defined custom completion function
3011func Test_fuzzy_completion_custom_func()
3012 func Tcompl(a, c, p)
3013 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3014 endfunc
3015 command -nargs=* -complete=custom,Tcompl Fuzzy :
3016 set wildoptions&
3017 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal("\"Fuzzy format", @:)
3019 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3020 call assert_equal("\"Fuzzy xy", @:)
3021 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3022 call assert_equal("\"Fuzzy ttt", @:)
3023 set wildoptions=fuzzy
3024 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3026 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3028 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal("\"Fuzzy xy", @:)
3030 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal("\"Fuzzy TestFOrmat", @:)
3032 delcom Fuzzy
3033 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003034endfunc
3035
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003036" Test for :breakadd argument completion
3037func Test_cmdline_complete_breakadd()
3038 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3039 call assert_equal("\"breakadd expr file func here", @:)
3040 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal("\"breakadd expr", @:)
3042 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal("\"breakadd expr", @:)
3044 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal("\"breakadd here", @:)
3046 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal("\"breakadd here", @:)
3048 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal("\"breakadd abc", @:)
3050 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3051 let l = getcompletion('not', 'breakpoint')
3052 call assert_equal([], l)
3053
3054 " Test for :breakadd file [lnum] <file>
3055 call writefile([], 'Xscript')
3056 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal("\"breakadd file Xscript", @:)
3058 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3059 call assert_equal("\"breakadd file Xscript", @:)
3060 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal("\"breakadd file 20 Xscript", @:)
3062 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3063 call assert_equal("\"breakadd file 20 Xscript", @:)
3064 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3065 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3066 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal("\"breakadd file 20\t", @:)
3068 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_equal("\"breakadd file 20x\t", @:)
3070 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3071 call assert_equal("\"breakadd file Xscript ", @:)
3072 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal("\"breakadd file X1B2C3", @:)
3074 call delete('Xscript')
3075
3076 " Test for :breakadd func [lnum] <function>
3077 func Xbreak_func()
3078 endfunc
3079 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal("\"breakadd func Xbreak_func", @:)
3081 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal("\"breakadd func Xbreak_func", @:)
3083 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3085 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3087 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3089 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"breakadd func 20\t", @:)
3091 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal("\"breakadd func 20x\t", @:)
3093 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"breakadd func Xbreak_func ", @:)
3095 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3096 call assert_equal("\"breakadd func X1B2C3", @:)
3097 delfunc Xbreak_func
3098
3099 " Test for :breakadd expr <expression>
3100 let g:Xtest_var = 10
3101 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"breakadd expr Xtest_var", @:)
3103 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakadd expr Xtest_var", @:)
3105 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakadd expr Xtest_var ", @:)
3107 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakadd expr X1B2C3", @:)
3109 unlet g:Xtest_var
3110
3111 " Test for :breakadd here
3112 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3113 call assert_equal("\"breakadd here Xtest", @:)
3114 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3115 call assert_equal("\"breakadd here Xtest", @:)
3116 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal("\"breakadd here ", @:)
3118endfunc
3119
3120" Test for :breakdel argument completion
3121func Test_cmdline_complete_breakdel()
3122 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal("\"breakdel file func here", @:)
3124 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3125 call assert_equal("\"breakdel file", @:)
3126 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3127 call assert_equal("\"breakdel file", @:)
3128 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3129 call assert_equal("\"breakdel here", @:)
3130 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3131 call assert_equal("\"breakdel here", @:)
3132 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3133 call assert_equal("\"breakdel abc", @:)
3134
3135 " Test for :breakdel file [lnum] <file>
3136 call writefile([], 'Xscript')
3137 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakdel file Xscript", @:)
3139 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakdel file Xscript", @:)
3141 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakdel file 20 Xscript", @:)
3143 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakdel file 20 Xscript", @:)
3145 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3147 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakdel file 20\t", @:)
3149 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakdel file 20x\t", @:)
3151 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakdel file Xscript ", @:)
3153 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakdel file X1B2C3", @:)
3155 call delete('Xscript')
3156
3157 " Test for :breakdel func [lnum] <function>
3158 func Xbreak_func()
3159 endfunc
3160 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3161 call assert_equal("\"breakdel func Xbreak_func", @:)
3162 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal("\"breakdel func Xbreak_func", @:)
3164 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3165 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3166 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3168 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3170 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal("\"breakdel func 20\t", @:)
3172 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal("\"breakdel func 20x\t", @:)
3174 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"breakdel func Xbreak_func ", @:)
3176 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal("\"breakdel func X1B2C3", @:)
3178 delfunc Xbreak_func
3179
3180 " Test for :breakdel here
3181 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal("\"breakdel here Xtest", @:)
3183 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakdel here Xtest", @:)
3185 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003187endfunc
3188
Bram Moolenaar309976e2019-12-05 18:16:33 +01003189" vim: shiftwidth=2 sts=2 expandtab