blob: 80e82eaeb03fd6f60fb1e84d59ce1eda6b8171f3 [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 Moolenaar3b0d70f2022-08-29 22:31:20 +010086 call mkdir('Xwilddir1/Xdir2', 'p')
87 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
88 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
89 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
90 call writefile(['testfile3'], 'Xwilddir1/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.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010095 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010096 call feedkeys(":e Xwilddir1/\<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.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100103 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100104 call assert_equal('testfile1', getline(1))
105
106 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100111 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100112 call assert_equal('testfile1', getline(1))
113
114 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100117 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100118 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>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100129 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100130 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
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100138 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
139 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100140
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100142 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100143 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()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100149 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"cd Xwilddir1/0', @:)
151 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
152 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100153 cunmap <F2>
154
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000155 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
156 " After this pressing <Left> or <Right> should not change the selection.
157 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
158 call assert_equal('"sign define', @:)
159 call histadd('cmd', 'TestWildMenu')
160 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
161 call assert_equal('"TestWildMenu', @:)
162
Bram Moolenaar37db6422019-03-28 21:26:23 +0100163 " cleanup
164 %bwipe
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100165 call delete('Xwilddir1', 'rf')
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200166 set nowildmenu
167endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100168
Bram Moolenaara60053b2020-09-03 16:50:13 +0200169func Test_wildmenu_screendump()
170 CheckScreendump
171
172 let lines =<< trim [SCRIPT]
173 set wildmenu hlsearch
174 [SCRIPT]
175 call writefile(lines, 'XTest_wildmenu')
176
177 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
178 call term_sendkeys(buf, ":vim\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
183
184 call term_sendkeys(buf, "\<Tab>")
185 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
186
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100187 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200188 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
189 call term_sendkeys(buf, "\<Esc>")
190
191 " clean up
192 call StopVimInTerminal(buf)
193 call delete('XTest_wildmenu')
194endfunc
195
Bram Moolenaara653e532022-04-19 11:38:24 +0100196func Test_redraw_in_autocmd()
197 CheckScreendump
198
199 let lines =<< trim END
200 set cmdheight=2
201 autocmd CmdlineChanged * redraw
202 END
203 call writefile(lines, 'XTest_redraw')
204
205 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
206 call term_sendkeys(buf, ":for i in range(3)\<CR>")
207 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
208
209 call term_sendkeys(buf, "let i =")
210 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
211
212 " clean up
213 call term_sendkeys(buf, "\<CR>")
214 call StopVimInTerminal(buf)
215 call delete('XTest_redraw')
216endfunc
217
Bram Moolenaarf797e302022-08-11 13:17:30 +0100218func Test_changing_cmdheight()
219 CheckScreendump
220
221 let lines =<< trim END
222 set cmdheight=1 laststatus=2
223 END
224 call writefile(lines, 'XTest_cmdheight')
225
226 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
227 call term_sendkeys(buf, ":resize -3\<CR>")
228 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
229
230 " using the space available doesn't change the status line
231 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
232 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
233
234 " using more space moves the status line up
235 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
236 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
237
238 " reducing cmdheight moves status line down
239 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
240 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
241
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100242 " reducing window size and then setting cmdheight
243 call term_sendkeys(buf, ":resize -1\<CR>")
244 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
245 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
246
Bram Moolenaarf797e302022-08-11 13:17:30 +0100247 " clean up
248 call StopVimInTerminal(buf)
249 call delete('XTest_cmdheight')
250endfunc
251
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100252func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100253 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
254 call assert_equal('"map <unique> <silent>', getreg(':'))
255 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
256 call assert_equal('"map <script> <unique>', getreg(':'))
257 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
258 call assert_equal('"map <expr> <script>', getreg(':'))
259 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
260 call assert_equal('"map <buffer> <expr>', getreg(':'))
261 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
262 call assert_equal('"map <nowait> <buffer>', getreg(':'))
263 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
264 call assert_equal('"map <special> <nowait>', getreg(':'))
265 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
266 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200267
Bram Moolenaar1776a282019-05-03 16:05:41 +0200268 map <Middle>x middle
269
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200270 map ,f commaf
271 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200272 map <Left> left
273 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200274 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
275 call assert_equal('"map ,f', getreg(':'))
276 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
277 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200278 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
279 call assert_equal('"map <Left>', getreg(':'))
280 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200281 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200282 unmap ,f
283 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200284 unmap <Left>
285 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200286
287 set cpo-=< cpo-=B cpo-=k
288 map <Left> left
289 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
290 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200291 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200292 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200293 unmap <Left>
294
295 set cpo+=<
296 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200297 exe "set t_k6=\<Esc>[17~"
298 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200299 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
300 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200301 if !has('gui_running')
302 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
303 call assert_equal("\"map <F6>x", getreg(':'))
304 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200305 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200306 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200307 set cpo-=<
308
309 set cpo+=B
310 map <Left> left
311 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <Left>', getreg(':'))
313 unmap <Left>
314 set cpo-=B
315
316 set cpo+=k
317 map <Left> left
318 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
319 call assert_equal('"map <Left>', getreg(':'))
320 unmap <Left>
321 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200322
Bram Moolenaar531be472020-09-23 22:38:05 +0200323 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
324
Bram Moolenaar1776a282019-05-03 16:05:41 +0200325 unmap <Middle>x
326 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100327endfunc
328
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100329func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100330 hi Aardig ctermfg=green
331 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000332 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100333 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000334 call assert_equal('"match none', @:)
335 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
336 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100337endfunc
338
339func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100340 hi Aardig ctermfg=green
341 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200343 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"hi default Aardig', getreg(':'))
345 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100347 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"hi link', getreg(':'))
349 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
350 call assert_equal('"hi default', getreg(':'))
351 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
352 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200353 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
354 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
355 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
356 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200357
358 " A cleared group does not show up in completions.
359 hi Anders ctermfg=green
360 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
361 hi clear Aardig
362 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
363 hi clear Anders
364 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100365endfunc
366
Bram Moolenaar75e15672020-06-28 13:10:22 +0200367" Test for command-line expansion of "hi Ni " (easter egg)
368func Test_highlight_easter_egg()
369 call test_override('ui_delay', 1)
370 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
371 call assert_equal("\"hi Ni \<Tab>", @:)
372 call test_override('ALL', 0)
373endfunc
374
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200375func Test_getcompletion()
376 let groupcount = len(getcompletion('', 'event'))
377 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200378 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200379 call assert_true(matchcount > 0)
380 call assert_true(groupcount > matchcount)
381
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200382 if has('menu')
383 source $VIMRUNTIME/menu.vim
384 let matchcount = len(getcompletion('', 'menu'))
385 call assert_true(matchcount > 0)
386 call assert_equal(['File.'], getcompletion('File', 'menu'))
387 call assert_true(matchcount > 0)
388 let matchcount = len(getcompletion('File.', 'menu'))
389 call assert_true(matchcount > 0)
390 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200391
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200392 let l = getcompletion('v:n', 'var')
393 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200394 let l = getcompletion('v:notexists', 'var')
395 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200396
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200397 args a.c b.c
398 let l = getcompletion('', 'arglist')
399 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000400 let l = getcompletion('a.', 'buffer')
401 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200402 %argdelete
403
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200404 let l = getcompletion('', 'augroup')
405 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200406 let l = getcompletion('blahblah', 'augroup')
407 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200408
409 let l = getcompletion('', 'behave')
410 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200411 let l = getcompletion('not', 'behave')
412 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200413
414 let l = getcompletion('', 'color')
415 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200416 let l = getcompletion('dirty', 'color')
417 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200418
419 let l = getcompletion('', 'command')
420 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200421 let l = getcompletion('awake', 'command')
422 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200423
424 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200425 call assert_true(index(l, 'samples/') >= 0)
426 let l = getcompletion('NoMatch', 'dir')
427 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200428
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100429 if glob('~/*') !=# ''
430 let l = getcompletion('~/', 'dir')
431 call assert_true(l[0][0] ==# '~')
432 endif
433
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200434 let l = getcompletion('exe', 'expression')
435 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200436 let l = getcompletion('kill', 'expression')
437 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200438
439 let l = getcompletion('tag', 'function')
440 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200441 let l = getcompletion('paint', 'function')
442 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200443
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200444 let Flambda = {-> 'hello'}
445 let l = getcompletion('', 'function')
446 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200447 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200448
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200449 let l = getcompletion('run', 'file')
450 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200451 let l = getcompletion('walk', 'file')
452 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200453 set wildignore=*.vim
454 let l = getcompletion('run', 'file', 1)
455 call assert_true(index(l, 'runtest.vim') < 0)
456 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000457 " Directory name with space character
458 call mkdir('Xdir with space')
459 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
460 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
461 call delete('Xdir with space', 'd')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200462
463 let l = getcompletion('ha', 'filetype')
464 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200465 let l = getcompletion('horse', 'filetype')
466 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467
468 let l = getcompletion('z', 'syntax')
469 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200470 let l = getcompletion('emacs', 'syntax')
471 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200472
473 let l = getcompletion('jikes', 'compiler')
474 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200475 let l = getcompletion('break', 'compiler')
476 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200477
478 let l = getcompletion('last', 'help')
479 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200480 let l = getcompletion('giveup', 'help')
481 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482
483 let l = getcompletion('time', 'option')
484 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200485 let l = getcompletion('space', 'option')
486 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487
488 let l = getcompletion('er', 'highlight')
489 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200490 let l = getcompletion('dark', 'highlight')
491 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200492
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200493 let l = getcompletion('', 'messages')
494 call assert_true(index(l, 'clear') >= 0)
495 let l = getcompletion('not', 'messages')
496 call assert_equal([], l)
497
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200498 let l = getcompletion('', 'mapclear')
499 call assert_true(index(l, '<buffer>') >= 0)
500 let l = getcompletion('not', 'mapclear')
501 call assert_equal([], l)
502
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200503 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200504 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200505 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
506 let root = has('win32') ? 'C:\\' : '/'
507 let l = getcompletion(root, 'shellcmd')
508 let expected = map(filter(glob(root . '*', 0, 1),
509 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
510 call assert_equal(expected, l)
511
Bram Moolenaarb650b982016-08-05 20:35:13 +0200512 if has('cscope')
513 let l = getcompletion('', 'cscope')
514 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
515 call assert_equal(cmds, l)
516 " using cmdline completion must not change the result
517 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
518 let l = getcompletion('', 'cscope')
519 call assert_equal(cmds, l)
520 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
521 let l = getcompletion('find ', 'cscope')
522 call assert_equal(keys, l)
523 endif
524
Bram Moolenaar7522f692016-08-06 14:12:50 +0200525 if has('signs')
526 sign define Testing linehl=Comment
527 let l = getcompletion('', 'sign')
528 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
529 call assert_equal(cmds, l)
530 " using cmdline completion must not change the result
531 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
532 let l = getcompletion('', 'sign')
533 call assert_equal(cmds, l)
534 let l = getcompletion('list ', 'sign')
535 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000536 let l = getcompletion('de*', 'sign')
537 call assert_equal(['define'], l)
538 let l = getcompletion('p?', 'sign')
539 call assert_equal(['place'], l)
540 let l = getcompletion('j.', 'sign')
541 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200542 endif
543
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200544 " Command line completion tests
545 let l = getcompletion('cd ', 'cmdline')
546 call assert_true(index(l, 'samples/') >= 0)
547 let l = getcompletion('cd NoMatch', 'cmdline')
548 call assert_equal([], l)
549 let l = getcompletion('let v:n', 'cmdline')
550 call assert_true(index(l, 'v:null') >= 0)
551 let l = getcompletion('let v:notexists', 'cmdline')
552 call assert_equal([], l)
553 let l = getcompletion('call tag', 'cmdline')
554 call assert_true(index(l, 'taglist(') >= 0)
555 let l = getcompletion('call paint', 'cmdline')
556 call assert_equal([], l)
557
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100558 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000559 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100560 return "oneA\noneB\noneC"
561 endfunc
562 command -nargs=1 -complete=custom,T MyCmd
563 let l = getcompletion('MyCmd ', 'cmdline')
564 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000565 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100566
567 delcommand MyCmd
568 delfunc T
ii144785fe02021-11-21 12:13:56 +0000569 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100570
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200571 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200572 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200573 if has('cmdline_hist')
574 call add(names, 'history')
575 endif
576 if has('gettext')
577 call add(names, 'locale')
578 endif
579 if has('profile')
580 call add(names, 'syntime')
581 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200582
583 set tags=Xtags
584 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
585
586 for name in names
587 let matchcount = len(getcompletion('', name))
588 call assert_true(matchcount >= 0, 'No matches for ' . name)
589 endfor
590
591 call delete('Xtags')
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200592 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200593
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000594 edit a~b
595 enew
596 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
597 bw a~b
598
599 if has('unix')
600 edit Xtest\
601 enew
602 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
603 bw Xtest\
604 endif
605
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200606 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200607 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100608 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200609endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200610
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000611" Test for getcompletion() with "fuzzy" in 'wildoptions'
612func Test_getcompletion_wildoptions()
613 let save_wildoptions = &wildoptions
614 set wildoptions&
615 let l = getcompletion('space', 'option')
616 call assert_equal([], l)
617 let l = getcompletion('ier', 'command')
618 call assert_equal([], l)
619 set wildoptions=fuzzy
620 let l = getcompletion('space', 'option')
621 call assert_true(index(l, 'backspace') >= 0)
622 let l = getcompletion('ier', 'command')
623 call assert_true(index(l, 'compiler') >= 0)
624 let &wildoptions = save_wildoptions
625endfunc
626
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000627func Test_complete_autoload_error()
628 let save_rtp = &rtp
629 let lines =<< trim END
630 vim9script
631 export def Complete(..._): string
632 return 'match'
633 enddef
634 echo this will cause an error
635 END
636 call mkdir('Xdir/autoload', 'p')
637 call writefile(lines, 'Xdir/autoload/script.vim')
638 exe 'set rtp+=' .. getcwd() .. '/Xdir'
639
640 let lines =<< trim END
641 vim9script
642 import autoload 'script.vim'
643 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
644 &wildcharm = char2nr("\<Tab>")
645 feedkeys(":Cmd \<Tab>", 'xt')
646 END
647 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
648
649 let &rtp = save_rtp
650 call delete('Xdir', 'rf')
651endfunc
652
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100653func Test_fullcommand()
654 let tests = {
655 \ '': '',
656 \ ':': '',
657 \ ':::': '',
658 \ ':::5': '',
659 \ 'not_a_cmd': '',
660 \ 'Check': '',
661 \ 'syntax': 'syntax',
662 \ ':syntax': 'syntax',
663 \ '::::syntax': 'syntax',
664 \ 'sy': 'syntax',
665 \ 'syn': 'syntax',
666 \ 'synt': 'syntax',
667 \ ':sy': 'syntax',
668 \ '::::sy': 'syntax',
669 \ 'match': 'match',
670 \ '2match': 'match',
671 \ '3match': 'match',
672 \ 'aboveleft': 'aboveleft',
673 \ 'abo': 'aboveleft',
674 \ 's': 'substitute',
675 \ '5s': 'substitute',
676 \ ':5s': 'substitute',
677 \ "'<,'>s": 'substitute',
678 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100679 \ 'CheckLin': 'CheckLinux',
680 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100681 \ }
682
683 for [in, want] in items(tests)
684 call assert_equal(want, fullcommand(in))
685 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200686 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100687
688 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200689
690 command -buffer BufferLocalCommand :
691 command GlobalCommand :
692 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
693 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
694 delcommand BufferLocalCommand
695 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100696endfunc
697
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200698func Test_shellcmd_completion()
699 let save_path = $PATH
700
701 call mkdir('Xpathdir/Xpathsubdir', 'p')
702 call writefile([''], 'Xpathdir/Xfile.exe')
703 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
704
705 " Set PATH to example directory without trailing slash.
706 let $PATH = getcwd() . '/Xpathdir'
707
708 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
709 " dirs in the PATH, even though they won't be executed. We check that only
710 " subdirs of the PWD and executables from the PATH are included in the
711 " suggestions.
712 let actual = getcompletion('X', 'shellcmd')
713 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
714 call insert(expected, 'Xfile.exe')
715 call assert_equal(expected, actual)
716
717 call delete('Xpathdir', 'rf')
718 let $PATH = save_path
719endfunc
720
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200721func Test_expand_star_star()
722 call mkdir('a/b', 'p')
723 call writefile(['asdfasdf'], 'a/b/fileXname')
724 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000725 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200726 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200727 call delete('a', 'rf')
728endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100729
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100730func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100731 let @a = "def"
732 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
733 call assert_equal('"abc def ghi', @:)
734
735 new
736 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
737
738 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
739 call assert_equal('"aaa asdf bbb', @:)
740
741 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
742 call assert_equal('"aaa /tmp/some bbb', @:)
743
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200744 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
745 call assert_equal('"aaa '.getline(1).' bbb', @:)
746
Bram Moolenaar21efc362016-12-03 14:05:49 +0100747 set incsearch
748 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
749 call assert_equal('"aaa verylongword bbb', @:)
750
751 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
752 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100753
754 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
755 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100756 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200757
758 " Error while typing a command used to cause that it was not executed
759 " in the end.
760 new
761 try
762 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
763 catch /^Vim\%((\a\+)\)\=:E32/
764 " ignore error E32
765 endtry
766 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100767
Bram Moolenaar578fe942020-02-27 21:32:51 +0100768 " Try to paste an invalid register using <C-R>
769 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
770 call assert_equal('"onetwo', @:)
771
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100772 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100773 let @a = "xy\<C-H>z"
774 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
775 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100776 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
777 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100778 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
779 call assert_equal("\"xy\<C-H>z", @:)
780
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100781 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
782 let @a = "xy\<C-V>z"
783 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
784 call assert_equal('"xyz', @:)
785 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
786 call assert_equal("\"xy\<C-V>z", @:)
787
Bram Moolenaar578fe942020-02-27 21:32:51 +0100788 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
789
Bram Moolenaar72532d32018-04-07 19:09:09 +0200790 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100791endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100792
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100793func Test_cmdline_remove_char()
794 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100795
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100796 for e in ['utf8', 'latin1']
797 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100798
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100799 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
800 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100801
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100802 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
803 call assert_equal('"abcdef', @:)
804
805 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
806 call assert_equal('"abc ghi', @:, e)
807
808 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
809 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100810
811 " This was going before the start in latin1.
812 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100813 endfor
814
815 let &encoding = encoding_save
816endfunc
817
818func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200819 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100820
821 set keymap=esperanto
822 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
823 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
824 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100825endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100826
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100827func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100828 new
829 2;'(
830 2;')
831 quit
832endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100833
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100834func Test_illegal_address2()
835 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
836 new
837 source Xtest.vim
838 " Trigger calling validate_cursor()
839 diffsp Xtest.vim
840 quit!
841 bwipe!
842 call delete('Xtest.vim')
843endfunc
844
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100845func Test_mark_from_line_zero()
846 " this was reading past the end of the first (empty) line
847 new
848 norm oxxxx
849 call assert_fails("0;'(", 'E20:')
850 bwipe!
851endfunc
852
Bram Moolenaarba47b512017-01-24 21:18:19 +0100853func Test_cmdline_complete_wildoptions()
854 help
855 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
856 let a = join(sort(split(@:)),' ')
857 set wildoptions=tagfile
858 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
859 let b = join(sort(split(@:)),' ')
860 call assert_equal(a, b)
861 bw!
862endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100863
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200864func Test_cmdline_complete_user_cmd()
865 command! -complete=color -nargs=1 Foo :
866 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
867 call assert_equal('"Foo blue', @:)
868 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
869 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000870 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
871 call assert_equal('"Foo a blue', @:)
872 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
873 call assert_equal('"Foo b\', @:)
874 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
875 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200876 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100877
878 redraw
879 call assert_equal('~', Screenline(&lines - 1))
880 command! FooOne :
881 command! FooTwo :
882
883 set nowildmenu
884 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
885 call assert_equal('"FooOne', @:)
886 call assert_equal('~', Screenline(&lines - 1))
887
888 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
889 call assert_equal('"FooTwo', @:)
890 call assert_equal('~', Screenline(&lines - 1))
891
892 delcommand FooOne
893 delcommand FooTwo
894 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200895endfunc
896
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100897func Test_complete_user_cmd()
898 command FooBar echo 'global'
899 command -buffer FooBar echo 'local'
900 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
901 call assert_equal('"FooBar', @:)
902
903 delcommand -buffer FooBar
904 delcommand FooBar
905endfunc
906
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100907func s:ScriptLocalFunction()
908 echo 'yes'
909endfunc
910
911func Test_cmdline_complete_user_func()
912 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200913 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100914 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
915 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100916
917 " g: prefix also works
918 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
919 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200920
921 " using g: prefix does not result in just "g:" matches from a lambda
922 let Fx = { a -> a }
923 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
924 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200925
926 " existence of script-local dict function does not break user function name
927 " completion
928 function s:a_dict_func() dict
929 endfunction
930 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
931 call assert_match('"call Test_cmdline_complete_user_', @:)
932 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100933endfunc
934
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200935func Test_cmdline_complete_user_names()
936 if has('unix') && executable('whoami')
937 let whoami = systemlist('whoami')[0]
938 let first_letter = whoami[0]
939 if len(first_letter) > 0
940 " Trying completion of :e ~x where x is the first letter of
941 " the user name should complete to at least the user name.
942 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
943 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
944 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200945 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200946 " Just in case: check that the system has an Administrator account.
947 let names = system('net user')
948 if names =~ 'Administrator'
949 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100950 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200951 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100952 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200953 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200954 else
955 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200956 endif
957endfunc
958
Bram Moolenaar297610b2019-12-27 17:20:55 +0100959func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200960 CheckExecutable whoami
961 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
962 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100963endfunc
964
Bram Moolenaar8b633132020-03-20 18:20:51 +0100965func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200966 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
967 call assert_equal(lang, v:lc_time)
968
969 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
970 call assert_equal(lang, v:ctype)
971
972 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
973 call assert_equal(lang, v:collate)
974
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200975 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200976 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200977
978 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200979 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200980
Bram Moolenaarec680282020-06-12 19:35:32 +0200981 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200982
Bram Moolenaarec680282020-06-12 19:35:32 +0200983 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
984 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200985
Bram Moolenaarec680282020-06-12 19:35:32 +0200986 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
987 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200988
Bram Moolenaarec680282020-06-12 19:35:32 +0200989 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
990 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200991
992 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
993 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200994endfunc
995
Bram Moolenaar297610b2019-12-27 17:20:55 +0100996func Test_cmdline_complete_env_variable()
997 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100998 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
999 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001000 unlet $X_VIM_TEST_COMPLETE_ENV
1001endfunc
1002
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001003func Test_cmdline_complete_expression()
1004 let g:SomeVar = 'blah'
1005 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1006 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1007 call assert_match('"' .. cmd .. ' SomeVar', @:)
1008 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1009 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1010 endfor
1011 unlet g:SomeVar
1012endfunc
1013
Bram Moolenaar47016f52021-08-26 16:39:58 +02001014" Unique function name for completion below
1015func s:WeirdFunc()
1016 echo 'weird'
1017endfunc
1018
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001019" Test for various command-line completion
1020func Test_cmdline_complete_various()
1021 " completion for a command starting with a comment
1022 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1023 call assert_equal("\" :|\"\<C-A>", @:)
1024
1025 " completion for a range followed by a comment
1026 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1027 call assert_equal("\"1,2\"\<C-A>", @:)
1028
1029 " completion for :k command
1030 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1031 call assert_equal("\"ka\<C-A>", @:)
1032
1033 " completion for short version of the :s command
1034 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1035 call assert_equal("\"sI \<C-A>", @:)
1036
1037 " completion for :write command
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001038 call mkdir('Xcwdir')
1039 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001040 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001041 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001042 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1043 call assert_equal("\"w >> Xfile1", @:)
1044 call chdir(save_cwd)
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001045 call delete('Xcwdir', 'rf')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001046
1047 " completion for :w ! and :r ! commands
1048 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1049 call assert_equal("\"w !invalid_xyz_cmd", @:)
1050 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1051 call assert_equal("\"r !invalid_xyz_cmd", @:)
1052
1053 " completion for :>> and :<< commands
1054 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1055 call assert_equal("\">>>\<C-A>", @:)
1056 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1057 call assert_equal("\"<<<\<C-A>", @:)
1058
1059 " completion for command with +cmd argument
1060 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1061 call assert_equal("\"buffer +/pat Xabc", @:)
1062 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1063 call assert_equal("\"buffer +/pat\<C-A>", @:)
1064
1065 " completion for a command with a trailing comment
1066 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1067 call assert_equal("\"ls \" comment\<C-A>", @:)
1068
1069 " completion for a command with a trailing command
1070 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1071 call assert_equal("\"ls | ls", @:)
1072
1073 " completion for a command with an CTRL-V escaped argument
1074 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1075 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1076
1077 " completion for a command that doesn't take additional arguments
1078 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1079 call assert_equal("\"all abc\<C-A>", @:)
1080
zeertzjqd3de1782022-09-01 12:58:52 +01001081 " completion for :wincmd with :horizontal modifier
1082 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1083 call assert_equal("\"horizontal wincmd", @:)
1084
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001085 " completion for a command with a command modifier
1086 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1087 call assert_equal("\"topleft new", @:)
1088
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001089 " completion for vim9 and legacy commands
1090 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1091 call assert_equal("\"vim9 call strlen(", @:)
1092 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"legac call strlen(", @:)
1094
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001095 " completion for the :disassemble command
1096 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\"disas debug", @:)
1098 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1099 call assert_equal("\"disas profile", @:)
1100 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1102 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1103 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001104 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001106
Bram Moolenaar47016f52021-08-26 16:39:58 +02001107 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001108 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001109
naohiro onodfe04db2021-09-12 15:45:10 +02001110 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1111 call assert_match('"disas <SNR>\d\+_', @:)
1112 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1113 call assert_match('"disas debug <SNR>\d\+_', @:)
1114
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001115 " completion for the :match command
1116 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1117 call assert_equal("\"match Search /pat/\<C-A>", @:)
1118
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001119 " completion for the :doautocmd command
1120 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1121 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1122
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001123 " completion of autocmd group after comma
1124 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1125 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1126
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001127 " completion of file name in :doautocmd
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001128 call writefile([], 'Xvarfile1')
1129 call writefile([], 'Xvarfile2')
1130 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
1132 call delete('Xvarfile1')
1133 call delete('Xvarfile2')
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001134
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001135 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001136 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001137 augroup END
1138 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001139 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001140
1141 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001142 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1143 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001144 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal("\"au XTest.test", @:)
1146
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001147 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001148
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001149 " autocmd pattern completion
1150 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1151 call assert_equal("\"au BufEnter *.py\t", @:)
1152
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001153 " completion for the :unlet command
1154 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"unlet one two", @:)
1156
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001157 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001158 " FIXME: what should happen on MS-Windows?
1159 if !has('win32')
1160 edit \{someFile}
1161 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1162 call assert_equal("\"buf {someFile}", @:)
1163 bwipe {someFile}
1164 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001165
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001166 " completion for the :bdelete command
1167 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"bdel a b c", @:)
1169
1170 " completion for the :mapclear command
1171 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"mapclear <buffer>", @:)
1173
1174 " completion for user defined commands with menu names
1175 menu Test.foo :ls<CR>
1176 com -nargs=* -complete=menu MyCmd
1177 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1178 call assert_equal('"MyCmd Test.', @:)
1179 delcom MyCmd
1180 unmenu Test
1181
1182 " completion for user defined commands with mappings
1183 mapclear
1184 map <F3> :ls<CR>
1185 com -nargs=* -complete=mapping MyCmd
1186 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001187 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001188 mapclear
1189 delcom MyCmd
1190
1191 " completion for :set path= with multiple backslashes
1192 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1193 call assert_equal('"set path=a\\\ b', @:)
1194
1195 " completion for :set dir= with a backslash
1196 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1197 call assert_equal('"set dir=a\ b', @:)
1198
1199 " completion for the :py3 commands
1200 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1201 call assert_equal('"py3 py3do py3file', @:)
1202
Bram Moolenaardf749a22021-03-28 15:29:43 +02001203 " completion for the :vim9 commands
1204 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1205 call assert_equal('"vim9cmd vim9script', @:)
1206
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001207 " redir @" is not the start of a comment. So complete after that
1208 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1209 call assert_equal('"redir @" | cwindow', @:)
1210
1211 " completion after a backtick
1212 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1213 call assert_equal('"e `a1b2c', @:)
1214
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001215 " completion for :language command with an invalid argument
1216 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1217 call assert_equal("\"language dummy \t", @:)
1218
1219 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001220 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1221 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001222
1223 " completion with ambiguous user defined commands
1224 com TCmd1 echo 'TCmd1'
1225 com TCmd2 echo 'TCmd2'
1226 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1227 call assert_equal('"TCmd ', @:)
1228 delcom TCmd1
1229 delcom TCmd2
1230
1231 " completion after a range followed by a pipe (|) character
1232 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1233 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001234
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001235 " completion after a :global command
1236 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1237 call assert_equal('"g/a/chistory', @:)
1238 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1239 call assert_equal("\"g/a\\/chist\t", @:)
1240
Bram Moolenaar9c929712020-09-07 22:05:28 +02001241 " use <Esc> as the 'wildchar' for completion
1242 set wildchar=<Esc>
1243 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1244 call assert_equal('"g/a\xb/clearjumps', @:)
1245 " pressing <esc> twice should cancel the command
1246 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1247 call assert_equal('"g/a\xb/clearjumps', @:)
1248 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001249
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001250 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001251 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001252 call writefile([], '~Xtest')
1253 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1254 call assert_equal('"e \~Xtest', @:)
1255 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001256
1257 " should be able to complete a file name that has a '*'
1258 call writefile([], 'Xx*Yy')
1259 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1260 call assert_equal('"e Xx\*Yy', @:)
1261 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001262
1263 " use a literal star
1264 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1265 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001266 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001267
1268 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1269 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001270endfunc
1271
1272" Test for 'wildignorecase'
1273func Test_cmdline_wildignorecase()
1274 CheckUnix
1275 call writefile([], 'XTEST')
1276 set wildignorecase
1277 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1278 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001279 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001280 let g:Sline = ''
1281 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1282 call assert_equal('"e xt', @:)
1283 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001284 set wildignorecase&
1285 call delete('XTEST')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001286endfunc
1287
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001288func Test_cmdline_write_alternatefile()
1289 new
1290 call setline('.', ['one', 'two'])
1291 f foo.txt
1292 new
1293 f #-A
1294 call assert_equal('foo.txt-A', expand('%'))
1295 f #<-B.txt
1296 call assert_equal('foo-B.txt', expand('%'))
1297 f %<
1298 call assert_equal('foo-B', expand('%'))
1299 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001300 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001301 bw!
1302 f foo-B.txt
1303 f %<-A
1304 call assert_equal('foo-B-A', expand('%'))
1305 bw!
1306 bw!
1307endfunc
1308
Bram Moolenaarf5724372022-09-02 19:45:15 +01001309func Test_cmdline_expand_cur_alt_file()
1310 enew
1311 file http://some.com/file.txt
1312 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1313 call assert_equal('"e http://some.com/file.txt', @:)
1314 edit another
1315 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal('"e http://some.com/file.txt', @:)
1317 bwipe
1318 bwipe http://some.com/file.txt
1319endfunc
1320
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001321" using a leading backslash here
1322set cpo+=C
1323
1324func Test_cmdline_search_range()
1325 new
1326 call setline(1, ['a', 'b', 'c', 'd'])
1327 /d
1328 1,\/s/b/B/
1329 call assert_equal('B', getline(2))
1330
1331 /a
1332 $
1333 \?,4s/c/C/
1334 call assert_equal('C', getline(3))
1335
1336 call setline(1, ['a', 'b', 'c', 'd'])
1337 %s/c/c/
1338 1,\&s/b/B/
1339 call assert_equal('B', getline(2))
1340
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001341 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001342 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001343
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001344 bwipe!
1345endfunc
1346
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001347" Test for the tick mark (') in an excmd range
1348func Test_tick_mark_in_range()
1349 " If only the tick is passed as a range and no command is specified, there
1350 " should not be an error
1351 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001352 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001353 call assert_fails("',print", 'E78:')
1354endfunc
1355
1356" Test for using a line number followed by a search pattern as range
1357func Test_lnum_and_pattern_as_range()
1358 new
1359 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1360 let @" = ''
1361 2/foo/yank
1362 call assert_equal("foo 3\n", @")
1363 call assert_equal(1, line('.'))
1364 close!
1365endfunc
1366
Bram Moolenaar65189a12017-02-06 22:22:17 +01001367" Tests for getcmdline(), getcmdpos() and getcmdtype()
1368func Check_cmdline(cmdtype)
1369 call assert_equal('MyCmd a', getcmdline())
1370 call assert_equal(8, getcmdpos())
1371 call assert_equal(a:cmdtype, getcmdtype())
1372 return ''
1373endfunc
1374
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001375set cpo&
1376
Bram Moolenaar65189a12017-02-06 22:22:17 +01001377func Test_getcmdtype()
1378 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1379
1380 let cmdtype = ''
1381 debuggreedy
1382 call feedkeys(":debug echo 'test'\<CR>", "t")
1383 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1384 call feedkeys("cont\<CR>", "xt")
1385 0debuggreedy
1386 call assert_equal('>', cmdtype)
1387
1388 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1389 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1390
1391 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001392 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001393
1394 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1395
1396 cnoremap <expr> <F6> Check_cmdline('=')
1397 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1398 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001399
1400 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001401endfunc
1402
Bram Moolenaar52604f22017-04-07 16:17:39 +02001403func Test_verbosefile()
1404 set verbosefile=Xlog
1405 echomsg 'foo'
1406 echomsg 'bar'
1407 set verbosefile=
1408 let log = readfile('Xlog')
1409 call assert_match("foo\nbar", join(log, "\n"))
1410 call delete('Xlog')
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001411 call mkdir('Xdir')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001412 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001413 call delete('Xdir', 'd')
Bram Moolenaar52604f22017-04-07 16:17:39 +02001414endfunc
1415
Bram Moolenaar4facea32019-10-12 20:17:40 +02001416func Test_verbose_option()
1417 CheckScreendump
1418
1419 let lines =<< trim [SCRIPT]
1420 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1421 call feedkeys("\r", 't') " for the hit-enter prompt
1422 set verbose=20
1423 [SCRIPT]
1424 call writefile(lines, 'XTest_verbose')
1425
1426 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001427 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001428 call term_sendkeys(buf, ":DoSomething\<CR>")
1429 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1430
1431 " clean up
1432 call StopVimInTerminal(buf)
1433 call delete('XTest_verbose')
1434endfunc
1435
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001436func Test_setcmdpos()
1437 func InsertTextAtPos(text, pos)
1438 call assert_equal(0, setcmdpos(a:pos))
1439 return a:text
1440 endfunc
1441
1442 " setcmdpos() with position in the middle of the command line.
1443 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1444 call assert_equal('"1ab2', @:)
1445
1446 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1447 call assert_equal('"1b2a', @:)
1448
1449 " setcmdpos() with position beyond the end of the command line.
1450 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1451 call assert_equal('"12ab', @:)
1452
1453 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001454 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001455endfunc
1456
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001457func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001458 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001459 let encoding_save = &encoding
1460
1461 for e in encodings
1462 exe 'set encoding=' . e
1463
1464 " Test overstrike in the middle of the command line.
1465 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001466 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001467
1468 " Test overstrike going beyond end of command line.
1469 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001470 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001471
1472 " Test toggling insert/overstrike a few times.
1473 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001474 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001475 endfor
1476
Bram Moolenaar30276f22019-01-24 17:59:39 +01001477 " Test overstrike with multi-byte characters.
1478 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001479 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001480
1481 let &encoding = encoding_save
1482endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001483
Bram Moolenaar52410572019-10-27 05:12:45 +01001484func Test_buffers_lastused()
1485 " check that buffers are sorted by time when wildmode has lastused
1486 call test_settime(1550020000) " middle
1487 edit bufa
1488 enew
1489 call test_settime(1550030000) " newest
1490 edit bufb
1491 enew
1492 call test_settime(1550010000) " oldest
1493 edit bufc
1494 enew
1495 call test_settime(0)
1496 enew
1497
1498 call assert_equal(['bufa', 'bufb', 'bufc'],
1499 \ getcompletion('', 'buffer'))
1500
1501 let save_wildmode = &wildmode
1502 set wildmode=full:lastused
1503
1504 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1505 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1506 call assert_equal('b bufb', X)
1507 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1508 call assert_equal('b bufa', X)
1509 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1510 call assert_equal('b bufc', X)
1511 enew
1512
1513 edit other
1514 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1515 call assert_equal('b bufb', X)
1516 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1517 call assert_equal('b bufa', X)
1518 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1519 call assert_equal('b bufc', X)
1520 enew
1521
1522 let &wildmode = save_wildmode
1523
1524 bwipeout bufa
1525 bwipeout bufb
1526 bwipeout bufc
1527endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001528
Bram Moolenaar479950f2020-01-19 15:45:17 +01001529func Test_cmdlineclear_tabenter()
1530 CheckScreendump
1531
1532 let lines =<< trim [SCRIPT]
1533 call setline(1, range(30))
1534 [SCRIPT]
1535
1536 call writefile(lines, 'XtestCmdlineClearTabenter')
1537 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001538 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001539 " in one tab make the command line higher with CTRL-W -
1540 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1541 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1542
1543 call StopVimInTerminal(buf)
1544 call delete('XtestCmdlineClearTabenter')
1545endfunc
1546
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001547" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001548func Test_cmdline_expand_special()
1549 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001550 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001551 call assert_fails('e <afile>', 'E495:')
1552 call assert_fails('e <abuf>', 'E496:')
1553 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001554
1555 call writefile([], 'Xfile.cpp')
1556 call writefile([], 'Xfile.java')
1557 new Xfile.cpp
1558 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1559 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1560 close
1561 call delete('Xfile.cpp')
1562 call delete('Xfile.java')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001563endfunc
1564
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001565" Test for backtick expression in the command line
1566func Test_cmd_backtick()
1567 %argd
1568 argadd `=['a', 'b', 'c']`
1569 call assert_equal(['a', 'b', 'c'], argv())
1570 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001571
1572 argadd `echo abc def`
1573 call assert_equal(['abc def'], argv())
1574 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001575endfunc
1576
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001577" Test for the :! command
1578func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001579 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001580
1581 let lines =<< trim [SCRIPT]
1582 " Test for no previous command
1583 call assert_fails('!!', 'E34:')
1584 set nomore
1585 " Test for cmdline expansion with :!
1586 call setline(1, 'foo!')
1587 silent !echo <cWORD> > Xfile.out
1588 call assert_equal(['foo!'], readfile('Xfile.out'))
1589 " Test for using previous command
1590 silent !echo \! !
1591 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1592 call writefile(v:errors, 'Xresult')
1593 call delete('Xfile.out')
1594 qall!
1595 [SCRIPT]
1596 call writefile(lines, 'Xscript')
1597 if RunVim([], [], '--clean -S Xscript')
1598 call assert_equal([], readfile('Xresult'))
1599 endif
1600 call delete('Xscript')
1601 call delete('Xresult')
1602endfunc
1603
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001604" Test error: "E135: *Filter* Autocommands must not change current buffer"
1605func Test_cmd_bang_E135()
1606 new
1607 call setline(1, ['a', 'b', 'c', 'd'])
1608 augroup test_cmd_filter_E135
1609 au!
1610 autocmd FilterReadPost * help
1611 augroup END
1612 call assert_fails('2,3!echo "x"', 'E135:')
1613
1614 augroup test_cmd_filter_E135
1615 au!
1616 augroup END
1617 %bwipe!
1618endfunc
1619
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001620" Test for using ~ for home directory in cmdline completion matches
1621func Test_cmdline_expand_home()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001622 call mkdir('Xexpdir')
1623 call writefile([], 'Xexpdir/Xfile1')
1624 call writefile([], 'Xexpdir/Xfile2')
1625 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001626 let save_HOME = $HOME
1627 let $HOME = getcwd()
1628 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1629 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1630 let $HOME = save_HOME
1631 cd ..
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001632 call delete('Xexpdir', 'rf')
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001633endfunc
1634
Bram Moolenaar578fe942020-02-27 21:32:51 +01001635" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1636" or insert mode (when 'insertmode' is set)
1637func Test_cmdline_ctrl_g()
1638 new
1639 call setline(1, 'abc')
1640 call cursor(1, 3)
1641 " If command line is entered from insert mode, using C-\ C-G should back to
1642 " insert mode
1643 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1644 call assert_equal('abxyc', getline(1))
1645 call assert_equal(4, col('.'))
1646
1647 " If command line is entered in 'insertmode', using C-\ C-G should back to
1648 " 'insertmode'
1649 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1650 call assert_equal('ab12xyc', getline(1))
1651 close!
1652endfunc
1653
Bram Moolenaar578fe942020-02-27 21:32:51 +01001654" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001655func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001656 func T(a, c, p)
1657 return "oneA\noneB\noneC"
1658 endfunc
1659 command -nargs=1 -complete=custom,T MyCmd
1660
Bram Moolenaar578fe942020-02-27 21:32:51 +01001661 set nowildmenu
1662 set wildmode=full,list
1663 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001664 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001665 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001666 call assert_equal('"MyCmd oneA', @:)
1667
1668 set wildmode=longest,full
1669 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1670 call assert_equal('"MyCmd one', @:)
1671 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1672 call assert_equal('"MyCmd oneC', @:)
1673
1674 set wildmode=longest
1675 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1676 call assert_equal('"MyCmd one', @:)
1677
1678 set wildmode=list:longest
1679 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001680 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001681 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001682 call assert_equal('"MyCmd one', @:)
1683
1684 set wildmode=""
1685 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1686 call assert_equal('"MyCmd oneA', @:)
1687
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001688 " Test for wildmode=longest with 'fileignorecase' set
1689 set wildmode=longest
1690 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001691 argadd AAA AAAA AAAAA
1692 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1693 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001694 set fileignorecase&
1695
1696 " Test for listing files with wildmode=list
1697 set wildmode=list
1698 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001699 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001700 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001701 call assert_equal('"b A', @:)
1702
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001703 " when using longest completion match, matches shorter than the argument
1704 " should be ignored (happens with :help)
1705 set wildmode=longest,full
1706 set wildmenu
1707 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1708 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001709 " non existing file
1710 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1711 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001712 set wildmenu&
1713
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001714 " Test for longest file name completion with 'fileignorecase'
1715 " On MS-Windows, file names are case insensitive.
1716 if has('unix')
1717 call writefile([], 'XTESTfoo')
1718 call writefile([], 'Xtestbar')
1719 set nofileignorecase
1720 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1721 call assert_equal('"e XTESTfoo', @:)
1722 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1723 call assert_equal('"e Xtestbar', @:)
1724 set fileignorecase
1725 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1726 call assert_equal('"e Xtest', @:)
1727 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1728 call assert_equal('"e Xtest', @:)
1729 set fileignorecase&
1730 call delete('XTESTfoo')
1731 call delete('Xtestbar')
1732 endif
1733
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001734 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001735 delcommand MyCmd
1736 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001737 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001738 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001739endfunc
1740
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001741func Test_wildmode()
1742 " Test with utf-8 encoding
1743 call Wildmode_tests()
1744
1745 " Test with latin1 encoding
1746 let save_encoding = &encoding
1747 set encoding=latin1
1748 call Wildmode_tests()
1749 let &encoding = save_encoding
1750endfunc
1751
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001752func Test_custom_complete_autoload()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001753 call mkdir('Xcustdir/autoload', 'p')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001754 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001755 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001756 let lines =<< trim END
1757 func vim8#Complete(a, c, p)
1758 return "oneA\noneB\noneC"
1759 endfunc
1760 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001761 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001762
1763 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1764 set nowildmenu
1765 set wildmode=full,list
1766 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1767 call assert_equal('"MyCmd oneA oneB oneC', @:)
1768
1769 let &rtp = save_rtp
1770 set wildmode& wildmenu&
1771 delcommand MyCmd
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001772 call delete('Xcustdir', 'rf')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001773endfunc
1774
Bram Moolenaar578fe942020-02-27 21:32:51 +01001775" Test for interrupting the command-line completion
1776func Test_interrupt_compl()
1777 func F(lead, cmdl, p)
1778 if a:lead =~ 'tw'
1779 call interrupt()
1780 return
1781 endif
1782 return "one\ntwo\nthree"
1783 endfunc
1784 command -nargs=1 -complete=custom,F Tcmd
1785
1786 set nowildmenu
1787 set wildmode=full
1788 let interrupted = 0
1789 try
1790 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1791 catch /^Vim:Interrupt$/
1792 let interrupted = 1
1793 endtry
1794 call assert_equal(1, interrupted)
1795
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001796 let interrupted = 0
1797 try
1798 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1799 catch /^Vim:Interrupt$/
1800 let interrupted = 1
1801 endtry
1802 call assert_equal(1, interrupted)
1803
Bram Moolenaar578fe942020-02-27 21:32:51 +01001804 delcommand Tcmd
1805 delfunc F
1806 set wildmode&
1807endfunc
1808
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001809" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001810func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001811 let str = ":one two\<C-U>"
1812 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001813 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001814 let str ..= "\<Left>five\<Right>"
1815 let str ..= "\<Home>two "
1816 let str ..= "\<C-Left>one "
1817 let str ..= "\<C-Right> three"
1818 let str ..= "\<End>\<S-Left>four "
1819 let str ..= "\<S-Right> six"
1820 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1821 call feedkeys(str, 'xt')
1822 call assert_equal("\"one two three four five six seven", @:)
1823endfunc
1824
1825" Test for moving the cursor on the / command line in 'rightleft' mode
1826func Test_cmdline_edit_rightleft()
1827 CheckFeature rightleft
1828 set rightleft
1829 set rightleftcmd=search
1830 let str = "/one two\<C-U>"
1831 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001832 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001833 let str ..= "\<Right>five\<Left>"
1834 let str ..= "\<Home>two "
1835 let str ..= "\<C-Right>one "
1836 let str ..= "\<C-Left> three"
1837 let str ..= "\<End>\<S-Right>four "
1838 let str ..= "\<S-Left> six"
1839 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1840 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1841 call assert_equal("\"one two three four five six seven", @/)
1842 set rightleftcmd&
1843 set rightleft&
1844endfunc
1845
1846" Test for using <C-\>e in the command line to evaluate an expression
1847func Test_cmdline_expr()
1848 " Evaluate an expression from the beginning of a command line
1849 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1850 call assert_equal('"hello', @:)
1851
1852 " Use an invalid expression for <C-\>e
1853 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1854
1855 " Insert literal <CTRL-\> in the command line
1856 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1857 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001858endfunc
1859
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001860" This was making the insert position negative
1861func Test_cmdline_expr_register()
1862 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1863endfunc
1864
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001865" Test for 'imcmdline' and 'imsearch'
1866" This test doesn't actually test the input method functionality.
1867func Test_cmdline_inputmethod()
1868 new
1869 call setline(1, ['', 'abc', ''])
1870 set imcmdline
1871
1872 call feedkeys(":\"abc\<CR>", 'xt')
1873 call assert_equal("\"abc", @:)
1874 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1875 call assert_equal("\"abc", @:)
1876 call feedkeys("/abc\<CR>", 'xt')
1877 call assert_equal([2, 1], [line('.'), col('.')])
1878 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1879 call assert_equal([2, 1], [line('.'), col('.')])
1880
1881 set imsearch=2
1882 call cursor(1, 1)
1883 call feedkeys("/abc\<CR>", 'xt')
1884 call assert_equal([2, 1], [line('.'), col('.')])
1885 call cursor(1, 1)
1886 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1887 call assert_equal([2, 1], [line('.'), col('.')])
1888 set imdisable
1889 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1890 call assert_equal([2, 1], [line('.'), col('.')])
1891 set imdisable&
1892 set imsearch&
1893
1894 set imcmdline&
1895 %bwipe!
1896endfunc
1897
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001898" Test for using CTRL-_ in the command line with 'allowrevins'
1899func Test_cmdline_revins()
1900 CheckNotMSWindows
1901 CheckFeature rightleft
1902 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1903 call assert_equal("\"abc\<c-_>", @:)
1904 set allowrevins
1905 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1906 call assert_equal('"abcñèæ', @:)
1907 set allowrevins&
1908endfunc
1909
1910" Test for typing UTF-8 composing characters in the command line
1911func Test_cmdline_composing_chars()
1912 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1913 call assert_equal('"ゔ', @:)
1914endfunc
1915
Bram Moolenaar0e717042020-04-27 19:29:01 +02001916" test that ";" works to find a match at the start of the first line
1917func Test_zero_line_search()
1918 new
1919 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1920 call cursor(1,1)
1921 0;/pattern/d
1922 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1923 q!
1924endfunc
1925
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001926func Test_read_shellcmd()
1927 CheckUnix
1928 if executable('ls')
1929 " There should be ls in the $PATH
1930 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1931 call assert_match('^"r! .*\<ls\>', @:)
1932 endif
1933
1934 if executable('rm')
1935 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1936 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1937 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001938
1939 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1940 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1941 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001942 endif
1943endfunc
1944
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001945" Test for going up and down the directory tree using 'wildmenu'
1946func Test_wildmenu_dirstack()
1947 CheckUnix
1948 %bw!
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001949 call mkdir('Xwildmenu/dir2/dir3/dir4', 'p')
1950 call writefile([], 'Xwildmenu/file1_1.txt')
1951 call writefile([], 'Xwildmenu/file1_2.txt')
1952 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
1953 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
1954 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
1955 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
1956 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
1957 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001958 set wildmenu
1959
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001960 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001961 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001962 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001963 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001964 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001965 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001966 call assert_equal('"e ../../dir3/', @:)
1967 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1968 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001969 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001970 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001971 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001972 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001973 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001974 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1975 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001976
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001977 call delete('Xwildmenu', 'rf')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001978 set wildmenu&
1979endfunc
1980
obcat71c6f7a2021-05-13 20:23:10 +02001981" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001982" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
1983" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02001984func Test_recalling_cmdline()
1985 CheckFeature cmdline_hist
1986
1987 let g:cmdlines = []
1988 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1989
1990 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001991 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
1992 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
1993 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
1994 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02001995 "\ TODO: {'name': 'debug', ...}
1996 \]
1997 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001998 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
1999 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2000 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2001 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2002 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002003 \]
2004 let prefix = 'vi'
2005 for h in histories
2006 call histadd(h.name, 'vim')
2007 call histadd(h.name, 'virtue')
2008 call histadd(h.name, 'Virgo')
2009 call histadd(h.name, 'vogue')
2010 call histadd(h.name, 'emacs')
2011 for k in keypairs
2012 let g:cmdlines = []
2013 let keyseqs = h.enter
2014 \ .. prefix
2015 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2016 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2017 \ .. h.exit
2018 call feedkeys(keyseqs, 'xt')
2019 call histdel(h.name, -1) " delete the history added by feedkeys above
2020 let expect = k.prefixmatch
2021 \ ? ['virtue', 'vim', 'virtue', prefix]
2022 \ : ['emacs', 'vogue', 'emacs', prefix]
2023 call assert_equal(expect, g:cmdlines)
2024 endfor
2025 endfor
2026
2027 unlet g:cmdlines
2028 cunmap <Plug>(save-cmdline)
2029endfunc
2030
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002031func Test_cmd_map_cmdlineChanged()
2032 let g:log = []
2033 cnoremap <F1> l<Cmd><CR>s
2034 augroup test
2035 autocmd!
2036 autocmd CmdlineChanged : let g:log += [getcmdline()]
2037 augroup END
2038
2039 call feedkeys(":\<F1>\<CR>", 'xt')
2040 call assert_equal(['l', 'ls'], g:log)
2041
Bram Moolenaar796139a2021-05-18 21:38:45 +02002042 let @b = 'b'
2043 cnoremap <F1> a<C-R>b
2044 let g:log = []
2045 call feedkeys(":\<F1>\<CR>", 'xt')
2046 call assert_equal(['a', 'ab'], g:log)
2047
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002048 unlet g:log
2049 cunmap <F1>
2050 augroup test
2051 autocmd!
2052 augroup END
2053endfunc
2054
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002055" Test for the 'suffixes' option
2056func Test_suffixes_opt()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002057 call writefile([], 'Xsuffile')
2058 call writefile([], 'Xsuffile.c')
2059 call writefile([], 'Xsuffile.o')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002060 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002061 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2062 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2063 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2064 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002065 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002066 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2067 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2068 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2069 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002070 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002071 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2072 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2073 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2074 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002075 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002076 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002077 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2078 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
2079 call delete('Xsuffile')
2080 call delete('Xsuffile.c')
2081 call delete('Xsuffile.o')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002082endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002083
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002084" Test for using a popup menu for the command line completion matches
2085" (wildoptions=pum)
2086func Test_wildmenu_pum()
2087 CheckRunVimInTerminal
2088
2089 let commands =<< trim [CODE]
2090 set wildmenu
2091 set wildoptions=pum
2092 set shm+=I
2093 set noruler
2094 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002095
2096 func CmdCompl(a, b, c)
2097 return repeat(['aaaa'], 120)
2098 endfunc
2099 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002100
2101 func MyStatusLine() abort
2102 return 'status'
2103 endfunc
2104 func SetupStatusline()
2105 set statusline=%!MyStatusLine()
2106 set laststatus=2
2107 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002108
2109 func MyTabLine()
2110 return 'my tab line'
2111 endfunc
2112 func SetupTabline()
2113 set statusline=
2114 set tabline=%!MyTabLine()
2115 set showtabline=2
2116 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002117
2118 func DoFeedKeys()
2119 let &wildcharm = char2nr("\t")
2120 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2121 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002122 [CODE]
2123 call writefile(commands, 'Xtest')
2124
2125 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2126
2127 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002128 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2129
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002130 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002131 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002132 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2133
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002134 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002135 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002136 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2137
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002138 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002139 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002140 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2141
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002142 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002143 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002144 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2145
2146 " pressing <C-E> should end completion and go back to the original match
2147 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002148 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2149
2150 " pressing <C-Y> should select the current match and end completion
2151 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002152 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2153
2154 " With 'wildmode' set to 'longest,full', completing a match should display
2155 " the longest match, the wildmenu should not be displayed.
2156 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2157 call TermWait(buf)
2158 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002159 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2160
2161 " pressing <Tab> should display the wildmenu
2162 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002163 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2164
2165 " pressing <Tab> second time should select the next entry in the menu
2166 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002167 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2168
2169 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002170 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002171 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002172 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2173
2174 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002175 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2176
2177 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002178 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2179
2180 " Directory name completion
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002181 call mkdir('Xnamedir/XdirA/XdirB', 'p')
2182 call writefile([], 'Xnamedir/XfileA')
2183 call writefile([], 'Xnamedir/XdirA/XfileB')
2184 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002185
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002186 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002187 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2188
2189 " Pressing <Right> on a directory name should go into that directory
2190 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002191 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2192
2193 " Pressing <Left> on a directory name should go to the parent directory
2194 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002195 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2196
2197 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002198 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002199 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002200 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2201
2202 " Pressing <C-D> when the popup menu is displayed should remove the popup
2203 " menu
2204 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002205 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2206
2207 " Pressing <S-Tab> should open the popup menu with the last entry selected
2208 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002209 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2210
2211 " Pressing <Esc> should close the popup menu and cancel the cmd line
2212 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002213 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2214
2215 " Typing a character when the popup is open, should close the popup
2216 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002217 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2218
2219 " When the popup is open, entering the cmdline window should close the popup
2220 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002221 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2222 call term_sendkeys(buf, ":q\<CR>")
2223
2224 " After the last popup menu item, <C-N> should show the original string
2225 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002226 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2227
2228 " Use the popup menu for the command name
2229 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002230 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2231
2232 " Pressing the left arrow should remove the popup menu
2233 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2235
2236 " Pressing <BS> should remove the popup menu and erase the last character
2237 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002238 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2239
2240 " Pressing <C-W> should remove the popup menu and erase the previous word
2241 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002242 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2243
2244 " Pressing <C-U> should remove the popup menu and erase the entire line
2245 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002246 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2247
2248 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2249 " the cmdline from history
2250 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002251 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2252
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002253 " Check "list" still works
2254 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2255 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2257 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2259
rbtnn68cc2b82022-02-09 11:55:47 +00002260 " Tests a directory name contained full-width characters.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002261 call mkdir('Xnamedir/あいう', 'p')
2262 call writefile([], 'Xnamedir/あいう/abc')
2263 call writefile([], 'Xnamedir/あいう/xyz')
2264 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002265
2266 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002267 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002268 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2269
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002270 " Pressing <C-A> when the popup menu is displayed should list all the
2271 " matches and pressing a key after that should remove the popup menu
2272 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2273 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2274 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2275
2276 " Pressing <C-A> when the popup menu is displayed should list all the
2277 " matches and pressing <Left> after that should move the cursor
2278 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2279 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2280 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2281
2282 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2283 " should be displayed correctly on the screen.
2284 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2285 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2286
2287 " After using <C-A> to expand all the filename matches, pressing <Up>
2288 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002289 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002290 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2291 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2292 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2293
2294 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2295 " crash Vim
2296 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2297 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2298
Bram Moolenaar414acd32022-02-10 21:09:45 +00002299 " After removing the pum the command line is redrawn
2300 call term_sendkeys(buf, ":edit foo\<CR>")
2301 call term_sendkeys(buf, ":edit bar\<CR>")
2302 call term_sendkeys(buf, ":ls\<CR>")
2303 call term_sendkeys(buf, ":com\<Tab> ")
2304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002305 call term_sendkeys(buf, "\<C-U>\<CR>")
2306
2307 " Esc still works to abort the command when 'statusline' is set
2308 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2309 call term_sendkeys(buf, ":si\<Tab>")
2310 call term_sendkeys(buf, "\<Esc>")
2311 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002312
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002313 " Esc still works to abort the command when 'tabline' is set
2314 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2315 call term_sendkeys(buf, ":si\<Tab>")
2316 call term_sendkeys(buf, "\<Esc>")
2317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2318
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002319 " popup is cleared also when 'lazyredraw' is set
2320 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2321 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2323 call term_sendkeys(buf, "\<Esc>")
2324
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002325 " Pressing <PageDown> should scroll the menu downward
2326 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2327 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2328 call term_sendkeys(buf, "\<PageDown>")
2329 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2330 call term_sendkeys(buf, "\<PageDown>")
2331 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2332 call term_sendkeys(buf, "\<PageDown>")
2333 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2334 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2335 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2336
2337 " Pressing <PageUp> should scroll the menu upward
2338 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2339 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2340 call term_sendkeys(buf, "\<PageUp>")
2341 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2342 call term_sendkeys(buf, "\<PageUp>")
2343 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2344 call term_sendkeys(buf, "\<PageUp>")
2345 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2346
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002347 call term_sendkeys(buf, "\<C-U>\<CR>")
2348 call StopVimInTerminal(buf)
2349 call delete('Xtest')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002350 call delete('Xnamedir', 'rf')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002351endfunc
2352
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002353" Test for wildmenumode() with the cmdline popup menu
2354func Test_wildmenumode_with_pum()
2355 set wildmenu
2356 set wildoptions=pum
2357 cnoremap <expr> <F2> wildmenumode()
2358 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2359 call assert_equal('"sign define10', @:)
2360 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2361 call assert_equal('"sign define jump list place undefine unplace0', @:)
2362 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2363 call assert_equal('"sign 0', @:)
2364 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2365 call assert_equal('"sign define0', @:)
2366 set nowildmenu wildoptions&
2367 cunmap <F2>
2368endfunc
2369
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002370func Test_wildmenu_with_pum_foldexpr()
2371 CheckRunVimInTerminal
2372
2373 let lines =<< trim END
2374 call setline(1, ['folded one', 'folded two', 'some more text'])
2375 func MyFoldText()
2376 return 'foo'
2377 endfunc
2378 set foldtext=MyFoldText() wildoptions=pum
2379 normal ggzfj
2380 END
2381 call writefile(lines, 'Xpumfold')
2382 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2383 call term_sendkeys(buf, ":set\<Tab>")
2384 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2385
2386 call term_sendkeys(buf, "\<Esc>")
2387 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2388
2389 call StopVimInTerminal(buf)
2390 call delete('Xpumfold')
2391endfunc
2392
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002393" Test for opening the cmdline completion popup menu from the terminal window.
2394" The popup menu should be positioned correctly over the status line of the
2395" bottom-most window.
2396func Test_wildmenu_pum_from_terminal()
2397 CheckRunVimInTerminal
2398 let python = PythonProg()
2399 call CheckPython(python)
2400
2401 %bw!
2402 let cmds = ['set wildmenu wildoptions=pum']
2403 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2404 call add(cmds, "call term_start('" .. pcmd .. "')")
2405 call writefile(cmds, 'Xtest')
2406 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2407 call term_sendkeys(buf, "\r\r\r")
2408 call term_wait(buf)
2409 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2410 call term_wait(buf)
2411 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2412 call term_wait(buf)
2413 call StopVimInTerminal(buf)
2414 call delete('Xtest')
2415endfunc
2416
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002417" Test for completion after a :substitute command followed by a pipe (|)
2418" character
2419func Test_cmdline_complete_substitute()
2420 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2421 call assert_equal("\"s | \t", @:)
2422 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2423 call assert_equal("\"s/ | \t", @:)
2424 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2425 call assert_equal("\"s/one | \t", @:)
2426 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2427 call assert_equal("\"s/one/ | \t", @:)
2428 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2429 call assert_equal("\"s/one/two | \t", @:)
2430 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2431 call assert_equal('"s/one/two/ | chistory', @:)
2432 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2433 call assert_equal("\"s/one/two/g \t", @:)
2434 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2435 call assert_equal("\"s/one/two/g | chistory", @:)
2436 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2437 call assert_equal("\"s/one/t\\/ | \t", @:)
2438 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2439 call assert_equal('"s/one/t"o/ | chistory', @:)
2440 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2441 call assert_equal('"s/one/t|o/ | chistory', @:)
2442 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2443 call assert_equal("\"&\t", @:)
2444endfunc
2445
2446" Test for the :dlist command completion
2447func Test_cmdline_complete_dlist()
2448 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2449 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2450 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2451 call assert_equal("\"dlist 10 /pat/ \t", @:)
2452 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2453 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2454 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2455 call assert_equal("\"dlist 10 /pat\\\t", @:)
2456 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2457 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2458endfunc
2459
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002460" argument list (only for :argdel) fuzzy completion
2461func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002462 argadd change.py count.py charge.py
2463 set wildoptions&
2464 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2465 call assert_equal('"argdel cge', @:)
2466 set wildoptions=fuzzy
2467 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2468 call assert_equal('"argdel change.py charge.py', @:)
2469 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002470 set wildoptions&
2471endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002472
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002473" autocmd group name fuzzy completion
2474func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002475 set wildoptions&
2476 augroup MyFuzzyGroup
2477 augroup END
2478 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2479 call assert_equal('"augroup mfg', @:)
2480 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2481 call assert_equal('"augroup MyFuzzyGroup', @:)
2482 set wildoptions=fuzzy
2483 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2484 call assert_equal('"augroup MyFuzzyGroup', @:)
2485 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2486 call assert_equal('"augroup My*p', @:)
2487 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002488 set wildoptions&
2489endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002490
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002491" buffer name fuzzy completion
2492func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002493 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002494 " Use a long name to reduce the risk of matching a random directory name
2495 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002496 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002497 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2498 call assert_equal('"b SRFWL', @:)
2499 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2500 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002501 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002502 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2503 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2504 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2505 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002506 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002507 set wildoptions&
2508endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002509
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002510" buffer name (full path) fuzzy completion
2511func Test_fuzzy_completion_bufname_fullpath()
2512 CheckUnix
2513 set wildoptions&
2514 call mkdir('Xcmd/Xstate/Xfile.js', 'p')
2515 edit Xcmd/Xstate/Xfile.js
2516 cd Xcmd/Xstate
2517 enew
2518 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2519 call assert_equal('"b CmdStateFile', @:)
2520 set wildoptions=fuzzy
2521 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2522 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2523 cd -
2524 call delete('Xcmd', 'rf')
2525 set wildoptions&
2526endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002527
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002528" :behave suboptions fuzzy completion
2529func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002530 set wildoptions&
2531 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2532 call assert_equal('"behave xm', @:)
2533 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2534 call assert_equal('"behave xterm', @:)
2535 set wildoptions=fuzzy
2536 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2537 call assert_equal('"behave xterm', @:)
2538 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2539 call assert_equal('"behave xt*m', @:)
2540 let g:Sline = ''
2541 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2542 call assert_equal('mswin', g:Sline)
2543 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002544 set wildoptions&
2545endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002546
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002547" " colorscheme name fuzzy completion - NOT supported
2548" func Test_fuzzy_completion_colorscheme()
2549" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002550
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002551" built-in command name fuzzy completion
2552func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002553 set wildoptions&
2554 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2555 call assert_equal('"sbwin', @:)
2556 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2557 call assert_equal('"sbrewind', @:)
2558 set wildoptions=fuzzy
2559 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2560 call assert_equal('"sbrewind', @:)
2561 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2562 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002563 set wildoptions&
2564endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002565
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002566" " compiler name fuzzy completion - NOT supported
2567" func Test_fuzzy_completion_compiler()
2568" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002569
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002570" :cscope suboptions fuzzy completion
2571func Test_fuzzy_completion_cscope()
2572 CheckFeature cscope
2573 set wildoptions&
2574 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2575 call assert_equal('"cscope ret', @:)
2576 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2577 call assert_equal('"cscope reset', @:)
2578 set wildoptions=fuzzy
2579 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2580 call assert_equal('"cscope reset', @:)
2581 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2582 call assert_equal('"cscope re*t', @:)
2583 set wildoptions&
2584endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002585
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002586" :diffget/:diffput buffer name fuzzy completion
2587func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002588 new SomeBuffer
2589 diffthis
2590 new OtherBuffer
2591 diffthis
2592 set wildoptions&
2593 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2594 call assert_equal('"diffget sbuf', @:)
2595 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2596 call assert_equal('"diffput sbuf', @:)
2597 set wildoptions=fuzzy
2598 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2599 call assert_equal('"diffget SomeBuffer', @:)
2600 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"diffput SomeBuffer', @:)
2602 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002603 set wildoptions&
2604endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002605
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002606" " directory name fuzzy completion - NOT supported
2607" func Test_fuzzy_completion_dirname()
2608" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002609
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002610" environment variable name fuzzy completion
2611func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002612 set wildoptions&
2613 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2614 call assert_equal('"echo $VUT', @:)
2615 set wildoptions=fuzzy
2616 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2617 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002618 set wildoptions&
2619endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002620
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002621" autocmd event fuzzy completion
2622func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002623 set wildoptions&
2624 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2625 call assert_equal('"autocmd BWout', @:)
2626 set wildoptions=fuzzy
2627 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2628 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002629 set wildoptions&
2630endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002631
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002632" vim expression fuzzy completion
2633func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002634 let g:PerPlaceCount = 10
2635 set wildoptions&
2636 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2637 call assert_equal('"let c = ppc', @:)
2638 set wildoptions=fuzzy
2639 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2640 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002641 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002642endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002643
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002644" " file name fuzzy completion - NOT supported
2645" func Test_fuzzy_completion_filename()
2646" endfunc
2647
2648" " files in path fuzzy completion - NOT supported
2649" func Test_fuzzy_completion_filesinpath()
2650" endfunc
2651
2652" " filetype name fuzzy completion - NOT supported
2653" func Test_fuzzy_completion_filetype()
2654" endfunc
2655
2656" user defined function name completion
2657func Test_fuzzy_completion_userdefined_func()
2658 set wildoptions&
2659 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2660 call assert_equal('"call Test_f_u_f', @:)
2661 set wildoptions=fuzzy
2662 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2663 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2664 set wildoptions&
2665endfunc
2666
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002667" <SNR> functions should be sorted to the end
2668func Test_fuzzy_completion_userdefined_snr_func()
2669 func s:Sendmail()
2670 endfunc
2671 func SendSomemail()
2672 endfunc
2673 func S1e2n3dmail()
2674 endfunc
2675 set wildoptions=fuzzy
2676 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002677 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002678 set wildoptions&
2679 delfunc s:Sendmail
2680 delfunc SendSomemail
2681 delfunc S1e2n3dmail
2682endfunc
2683
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002684" user defined command name completion
2685func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002686 set wildoptions&
2687 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2688 call assert_equal('"MsFeat', @:)
2689 set wildoptions=fuzzy
2690 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2691 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002692 set wildoptions&
2693endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002694
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002695" " :help tag fuzzy completion - NOT supported
2696" func Test_fuzzy_completion_helptag()
2697" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002698
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002699" highlight group name fuzzy completion
2700func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002701 set wildoptions&
2702 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2703 call assert_equal('"highlight SKey', @:)
2704 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2705 call assert_equal('"highlight SpecialKey', @:)
2706 set wildoptions=fuzzy
2707 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2708 call assert_equal('"highlight SpecialKey', @:)
2709 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2710 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002711 set wildoptions&
2712endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002713
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002714" :history suboptions fuzzy completion
2715func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002716 set wildoptions&
2717 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"history dg', @:)
2719 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2720 call assert_equal('"history search', @:)
2721 set wildoptions=fuzzy
2722 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal('"history debug', @:)
2724 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002726 set wildoptions&
2727endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002729" :language locale name fuzzy completion
2730func Test_fuzzy_completion_lang()
2731 CheckUnix
2732 set wildoptions&
2733 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2734 call assert_equal('"lang psx', @:)
2735 set wildoptions=fuzzy
2736 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2737 call assert_equal('"lang POSIX', @:)
2738 set wildoptions&
2739endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002740
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002741" :mapclear buffer argument fuzzy completion
2742func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002743 set wildoptions&
2744 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2745 call assert_equal('"mapclear buf', @:)
2746 set wildoptions=fuzzy
2747 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2748 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002749 set wildoptions&
2750endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002751
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002752" map name fuzzy completion
2753func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002754 " test regex completion works
2755 set wildoptions=fuzzy
2756 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2757 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002758 nmap <plug>MyLongMap :p<CR>
2759 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2760 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2761 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2762 call assert_equal("\"nmap MLM \t", @:)
2763 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2764 call assert_equal("\"nmap <F2> one two \t", @:)
2765 " duplicate entries should be removed
2766 vmap <plug>MyLongMap :<C-U>#<CR>
2767 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2768 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2769 nunmap <plug>MyLongMap
2770 vunmap <plug>MyLongMap
2771 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2772 call assert_equal("\"nmap ABC\t", @:)
2773 " results should be sorted by best match
2774 nmap <Plug>format :
2775 nmap <Plug>goformat :
2776 nmap <Plug>TestFOrmat :
2777 nmap <Plug>fendoff :
2778 nmap <Plug>state :
2779 nmap <Plug>FendingOff :
2780 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2781 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2782 nunmap <Plug>format
2783 nunmap <Plug>goformat
2784 nunmap <Plug>TestFOrmat
2785 nunmap <Plug>fendoff
2786 nunmap <Plug>state
2787 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002788 set wildoptions&
2789endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002790
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002791" abbreviation fuzzy completion
2792func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002793 set wildoptions=fuzzy
2794 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal("\"iabbr <nowait>", @:)
2796 iabbr WaitForCompletion WFC
2797 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2798 call assert_equal("\"iabbr WaitForCompletion", @:)
2799 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2800 call assert_equal("\"iabbr a1z\t", @:)
2801 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002802 set wildoptions&
2803endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002804
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002805" menu name fuzzy completion
2806func Test_fuzzy_completion_menu()
2807 CheckGui
2808 set wildoptions&
2809 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"menu pup', @:)
2811 set wildoptions=fuzzy
2812 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal('"menu PopUp.', @:)
2814 set wildoptions&
2815endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002816
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002817" :messages suboptions fuzzy completion
2818func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002819 set wildoptions&
2820 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2821 call assert_equal('"messages clr', @:)
2822 set wildoptions=fuzzy
2823 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2824 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002825 set wildoptions&
2826endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002827
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002828" :set option name fuzzy completion
2829func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002830 set wildoptions&
2831 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2832 call assert_equal('"set brkopt', @:)
2833 set wildoptions=fuzzy
2834 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2835 call assert_equal('"set breakindentopt', @:)
2836 set wildoptions&
2837 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2838 call assert_equal('"set fixendofline', @:)
2839 set wildoptions=fuzzy
2840 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002842 set wildoptions&
2843endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002844
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002845" :set <term_option>
2846func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002847 set wildoptions&
2848 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_equal('"set t_EC', @:)
2850 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2851 call assert_equal('"set <t_EC>', @:)
2852 set wildoptions=fuzzy
2853 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2854 call assert_equal('"set t_EC', @:)
2855 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002857 set wildoptions&
2858endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002859
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002860" " :packadd directory name fuzzy completion - NOT supported
2861" func Test_fuzzy_completion_packadd()
2862" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002863
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002864" " shell command name fuzzy completion - NOT supported
2865" func Test_fuzzy_completion_shellcmd()
2866" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002867
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002868" :sign suboptions fuzzy completion
2869func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002870 set wildoptions&
2871 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2872 call assert_equal('"sign ufe', @:)
2873 set wildoptions=fuzzy
2874 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002876 set wildoptions&
2877endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002878
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002879" :syntax suboptions fuzzy completion
2880func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002881 set wildoptions&
2882 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2883 call assert_equal('"syntax kwd', @:)
2884 set wildoptions=fuzzy
2885 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2886 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002887 set wildoptions&
2888endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002889
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890" syntax group name fuzzy completion
2891func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002892 set wildoptions&
2893 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2894 call assert_equal('"syntax list mpar', @:)
2895 set wildoptions=fuzzy
2896 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2897 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002898 set wildoptions&
2899endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002900
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002901" :syntime suboptions fuzzy completion
2902func Test_fuzzy_completion_syntime()
2903 CheckFeature profile
2904 set wildoptions&
2905 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal('"syntime clr', @:)
2907 set wildoptions=fuzzy
2908 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2909 call assert_equal('"syntime clear', @:)
2910 set wildoptions&
2911endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002912
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002913" " tag name fuzzy completion - NOT supported
2914" func Test_fuzzy_completion_tagname()
2915" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002916
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002917" " tag name and file fuzzy completion - NOT supported
2918" func Test_fuzzy_completion_tagfile()
2919" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002920
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002921" " user names fuzzy completion - how to test this functionality?
2922" func Test_fuzzy_completion_username()
2923" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002924
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002925" user defined variable name fuzzy completion
2926func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002927 let g:SomeVariable=10
2928 set wildoptions&
2929 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2930 call assert_equal('"let SVar', @:)
2931 set wildoptions=fuzzy
2932 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002934 set wildoptions&
2935endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002936
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002937" Test for sorting the results by the best match
2938func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002939 %bw!
2940 command T123format :
2941 command T123goformat :
2942 command T123TestFOrmat :
2943 command T123fendoff :
2944 command T123state :
2945 command T123FendingOff :
2946 set wildoptions=fuzzy
2947 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2948 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2949 delcommand T123format
2950 delcommand T123goformat
2951 delcommand T123TestFOrmat
2952 delcommand T123fendoff
2953 delcommand T123state
2954 delcommand T123FendingOff
2955 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002956 set wildoptions&
2957endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002958
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002959" Test for fuzzy completion of a command with lower case letters and a number
2960func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002961 command Foo2Bar :
2962 set wildoptions=fuzzy
2963 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2964 call assert_equal('"Foo2Bar', @:)
2965 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal('"Foo2Bar', @:)
2967 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal('"Foo2Bar', @:)
2969 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002970 set wildoptions&
2971endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002972
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002973" Test for command completion for a command starting with 'k'
2974func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002975 command KillKillKill :
2976 set wildoptions&
2977 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2978 call assert_equal("\"killkill\<Tab>", @:)
2979 set wildoptions=fuzzy
2980 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2981 call assert_equal('"KillKillKill', @:)
2982 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002983 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002984endfunc
2985
2986" Test for fuzzy completion for user defined custom completion function
2987func Test_fuzzy_completion_custom_func()
2988 func Tcompl(a, c, p)
2989 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
2990 endfunc
2991 command -nargs=* -complete=custom,Tcompl Fuzzy :
2992 set wildoptions&
2993 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal("\"Fuzzy format", @:)
2995 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal("\"Fuzzy xy", @:)
2997 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal("\"Fuzzy ttt", @:)
2999 set wildoptions=fuzzy
3000 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3001 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3002 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3003 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3004 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3005 call assert_equal("\"Fuzzy xy", @:)
3006 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal("\"Fuzzy TestFOrmat", @:)
3008 delcom Fuzzy
3009 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003010endfunc
3011
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003012" Test for :breakadd argument completion
3013func Test_cmdline_complete_breakadd()
3014 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal("\"breakadd expr file func here", @:)
3016 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3017 call assert_equal("\"breakadd expr", @:)
3018 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3019 call assert_equal("\"breakadd expr", @:)
3020 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3021 call assert_equal("\"breakadd here", @:)
3022 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3023 call assert_equal("\"breakadd here", @:)
3024 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal("\"breakadd abc", @:)
3026 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3027 let l = getcompletion('not', 'breakpoint')
3028 call assert_equal([], l)
3029
3030 " Test for :breakadd file [lnum] <file>
3031 call writefile([], 'Xscript')
3032 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal("\"breakadd file Xscript", @:)
3034 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3035 call assert_equal("\"breakadd file Xscript", @:)
3036 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3037 call assert_equal("\"breakadd file 20 Xscript", @:)
3038 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3039 call assert_equal("\"breakadd file 20 Xscript", @:)
3040 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3042 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal("\"breakadd file 20\t", @:)
3044 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal("\"breakadd file 20x\t", @:)
3046 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal("\"breakadd file Xscript ", @:)
3048 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal("\"breakadd file X1B2C3", @:)
3050 call delete('Xscript')
3051
3052 " Test for :breakadd func [lnum] <function>
3053 func Xbreak_func()
3054 endfunc
3055 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3056 call assert_equal("\"breakadd func Xbreak_func", @:)
3057 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3058 call assert_equal("\"breakadd func Xbreak_func", @:)
3059 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3061 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3062 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3063 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3065 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3066 call assert_equal("\"breakadd func 20\t", @:)
3067 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3068 call assert_equal("\"breakadd func 20x\t", @:)
3069 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal("\"breakadd func Xbreak_func ", @:)
3071 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3072 call assert_equal("\"breakadd func X1B2C3", @:)
3073 delfunc Xbreak_func
3074
3075 " Test for :breakadd expr <expression>
3076 let g:Xtest_var = 10
3077 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3078 call assert_equal("\"breakadd expr Xtest_var", @:)
3079 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3080 call assert_equal("\"breakadd expr Xtest_var", @:)
3081 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal("\"breakadd expr Xtest_var ", @:)
3083 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal("\"breakadd expr X1B2C3", @:)
3085 unlet g:Xtest_var
3086
3087 " Test for :breakadd here
3088 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3089 call assert_equal("\"breakadd here Xtest", @:)
3090 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3091 call assert_equal("\"breakadd here Xtest", @:)
3092 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3093 call assert_equal("\"breakadd here ", @:)
3094endfunc
3095
3096" Test for :breakdel argument completion
3097func Test_cmdline_complete_breakdel()
3098 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3099 call assert_equal("\"breakdel file func here", @:)
3100 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3101 call assert_equal("\"breakdel file", @:)
3102 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal("\"breakdel file", @:)
3104 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3105 call assert_equal("\"breakdel here", @:)
3106 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3107 call assert_equal("\"breakdel here", @:)
3108 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3109 call assert_equal("\"breakdel abc", @:)
3110
3111 " Test for :breakdel file [lnum] <file>
3112 call writefile([], 'Xscript')
3113 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"breakdel file Xscript", @:)
3115 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"breakdel file Xscript", @:)
3117 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakdel file 20 Xscript", @:)
3119 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakdel file 20 Xscript", @:)
3121 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3123 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"breakdel file 20\t", @:)
3125 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakdel file 20x\t", @:)
3127 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakdel file Xscript ", @:)
3129 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakdel file X1B2C3", @:)
3131 call delete('Xscript')
3132
3133 " Test for :breakdel func [lnum] <function>
3134 func Xbreak_func()
3135 endfunc
3136 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal("\"breakdel func Xbreak_func", @:)
3138 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal("\"breakdel func Xbreak_func", @:)
3140 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3142 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3143 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3144 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3146 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal("\"breakdel func 20\t", @:)
3148 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal("\"breakdel func 20x\t", @:)
3150 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal("\"breakdel func Xbreak_func ", @:)
3152 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal("\"breakdel func X1B2C3", @:)
3154 delfunc Xbreak_func
3155
3156 " Test for :breakdel here
3157 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakdel here Xtest", @:)
3159 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakdel here Xtest", @:)
3161 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003163endfunc
3164
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003165" Test for :scriptnames argument completion
3166func Test_cmdline_complete_scriptnames()
3167 set wildmenu
3168 call writefile(['let a = 1'], 'Xa1b2c3.vim')
3169 source Xa1b2c3.vim
3170 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3171 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3172 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3173 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3174 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"script b2c3", @:)
3176 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_match("\"script 2\<Tab>$", @:)
3178 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3180 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"script ", @:)
3182 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3183 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3184 new
3185 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3186 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3187 bw!
3188 call delete('Xa1b2c3.vim')
3189 set wildmenu&
3190endfunc
3191
Bram Moolenaard8893442022-05-06 20:38:47 +01003192" this was going over the end of IObuff
3193func Test_report_error_with_composing()
3194 let caught = 'no'
3195 try
3196 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3197 catch /E492:/
3198 let caught = 'yes'
3199 endtry
3200 call assert_equal('yes', caught)
3201endfunc
3202
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003203" Test for expanding 2-letter and 3-letter :substitute command arguments.
3204" These commands don't accept an argument.
3205func Test_cmdline_complete_substitute_short()
3206 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3207 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3208 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3209 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3210 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3211 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3213 endfor
3214endfunc
3215
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003216" Test for :! shell command argument completion
3217func Test_cmdline_complete_bang_cmd_argument()
3218 set wildoptions=fuzzy
3219 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3220 call assert_equal('"!vim test_cmdline.vim', @:)
3221 set wildoptions&
3222 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3223 call assert_equal('"!vim test_cmdline.vim', @:)
3224endfunc
3225
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003226func Check_completion()
3227 call assert_equal('let a', getcmdline())
3228 call assert_equal(6, getcmdpos())
3229 call assert_equal(7, getcmdscreenpos())
3230 call assert_equal('var', getcmdcompltype())
3231 return ''
3232endfunc
3233
3234func Test_screenpos_and_completion()
3235 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3236endfunc
3237
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003238func Test_recursive_register()
3239 let @= = ''
3240 silent! ?e/
3241 let caught = 'no'
3242 try
3243 normal //
3244 catch /E169:/
3245 let caught = 'yes'
3246 endtry
3247 call assert_equal('yes', caught)
3248endfunc
3249
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003250func Test_long_error_message()
3251 " the error should be truncated, not overrun IObuff
3252 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3253endfunc
3254
zeertzjq6791adc2022-07-26 20:42:25 +01003255func Test_cmdline_redraw_tabline()
3256 CheckRunVimInTerminal
3257
3258 let lines =<< trim END
3259 set showtabline=2
3260 autocmd CmdlineEnter * set tabline=foo
3261 END
3262 call writefile(lines, 'Xcmdline_redraw_tabline')
3263 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3264 call term_sendkeys(buf, ':')
3265 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3266
3267 call StopVimInTerminal(buf)
3268 call delete('Xcmdline_redraw_tabline')
3269endfunc
3270
zeertzjqb82a2ab2022-08-21 14:33:57 +01003271func Test_wildmenu_pum_disable_while_shown()
3272 set wildoptions=pum
3273 set wildmenu
3274 cnoremap <F2> <Cmd>set nowildmenu<CR>
3275 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3276 call assert_equal(0, pumvisible())
3277 cunmap <F2>
3278 set wildoptions& wildmenu&
3279endfunc
3280
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003281func Test_setcmdline()
3282 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003283 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003284 call assert_equal(0, setcmdline(a:text))
3285 call assert_equal(a:text, getcmdline())
3286 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003287 call assert_equal(getcmdtype(), g:cmdtype)
3288 unlet g:cmdtype
3289 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003290
3291 call assert_equal(0, setcmdline(a:text, a:pos))
3292 call assert_equal(a:text, getcmdline())
3293 call assert_equal(a:pos, getcmdpos())
3294
3295 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003296 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3297 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003298
3299 return ''
3300 endfunc
3301
3302 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3303 call assert_equal('set rtp?', @:)
3304
zeertzjq54acb902022-08-29 16:21:25 +01003305 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3306 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3307 call assert_equal('foo', g:str)
3308 unlet g:str
3309
3310 delfunc SetText
3311
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003312 " setcmdline() returns 1 when not editing the command line.
3313 call assert_equal(1, 'foo'->setcmdline())
3314
3315 " Called in custom function
3316 func CustomComplete(A, L, P)
3317 call assert_equal(0, setcmdline("DoCmd "))
3318 return "January\nFebruary\nMars\n"
3319 endfunc
3320
3321 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3322 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3323 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003324 delcom DoCmd
3325 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003326
3327 " Called in <expr>
3328 cnoremap <expr>a setcmdline('let foo=')
3329 call feedkeys(":a\<CR>", 'tx')
3330 call assert_equal('let foo=0', @:)
3331 cunmap a
3332endfunc
3333
Bram Moolenaar309976e2019-12-05 18:16:33 +01003334" vim: shiftwidth=2 sts=2 expandtab