blob: 7c86bcd123e562918cdb8e44e2fadd26a025e512 [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()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 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 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
Bram Moolenaar0816f472022-10-05 15:42:32 +0100273 func EchoTwo()
274 set laststatus=2
275 set cmdheight=5
276 echo 'foo'
277 echo 'bar'
278 set cmdheight=1
279 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100280 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100281 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100282
283 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
284 call term_sendkeys(buf, ":resize -3\<CR>")
285 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
286
287 " using the space available doesn't change the status line
288 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
289 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
290
291 " using more space moves the status line up
292 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
293 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
294
295 " reducing cmdheight moves status line down
296 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
297 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
298
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000299 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100300 call term_sendkeys(buf, ":resize -1\<CR>")
301 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
302 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
303
Bram Moolenaar0816f472022-10-05 15:42:32 +0100304 " setting 'cmdheight' works after outputting two messages
305 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
306 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
307
Bram Moolenaarf797e302022-08-11 13:17:30 +0100308 " clean up
309 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100310endfunc
311
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100312func Test_cmdheight_tabline()
313 CheckScreendump
314
315 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
316 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
317
318 " clean up
319 call StopVimInTerminal(buf)
320endfunc
321
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100322func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100323 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
324 call assert_equal('"map <unique> <silent>', getreg(':'))
325 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
326 call assert_equal('"map <script> <unique>', getreg(':'))
327 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
328 call assert_equal('"map <expr> <script>', getreg(':'))
329 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
330 call assert_equal('"map <buffer> <expr>', getreg(':'))
331 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
332 call assert_equal('"map <nowait> <buffer>', getreg(':'))
333 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
334 call assert_equal('"map <special> <nowait>', getreg(':'))
335 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
336 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200337
Bram Moolenaar1776a282019-05-03 16:05:41 +0200338 map <Middle>x middle
339
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200340 map ,f commaf
341 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200342 map <Left> left
343 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200344 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
345 call assert_equal('"map ,f', getreg(':'))
346 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
347 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200348 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
349 call assert_equal('"map <Left>', getreg(':'))
350 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200351 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000352 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
353 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 unmap ,f
355 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200356 unmap <Left>
357 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200358
zeertzjqc3a26c62023-02-17 16:40:20 +0000359 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200360 map <Left> left
361 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
362 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200363 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200364 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000365 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
366 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200367 unmap <Left>
368
369 set cpo+=<
370 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200371 exe "set t_k6=\<Esc>[17~"
372 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200373 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
374 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200375 if !has('gui_running')
376 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal("\"map <F6>x", getreg(':'))
378 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200379 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200380 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200381 set cpo-=<
382
383 set cpo+=B
384 map <Left> left
385 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
386 call assert_equal('"map <Left>', getreg(':'))
387 unmap <Left>
388 set cpo-=B
389
390 set cpo+=k
391 map <Left> left
392 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
393 call assert_equal('"map <Left>', getreg(':'))
394 unmap <Left>
395 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200396
Bram Moolenaar531be472020-09-23 22:38:05 +0200397 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
398
Bram Moolenaar1776a282019-05-03 16:05:41 +0200399 unmap <Middle>x
400 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100401endfunc
402
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100403func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100404 hi Aardig ctermfg=green
405 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000406 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100407 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000408 call assert_equal('"match none', @:)
409 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
410 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100411endfunc
412
413func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100414 hi Aardig ctermfg=green
415 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
416 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200417 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
418 call assert_equal('"hi default Aardig', getreg(':'))
419 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
420 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100421 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal('"hi link', getreg(':'))
423 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
424 call assert_equal('"hi default', getreg(':'))
425 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
426 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200427 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
428 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
429 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
430 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200431
432 " A cleared group does not show up in completions.
433 hi Anders ctermfg=green
434 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
435 hi clear Aardig
436 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
437 hi clear Anders
438 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100439endfunc
440
Bram Moolenaar75e15672020-06-28 13:10:22 +0200441" Test for command-line expansion of "hi Ni " (easter egg)
442func Test_highlight_easter_egg()
443 call test_override('ui_delay', 1)
444 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
445 call assert_equal("\"hi Ni \<Tab>", @:)
446 call test_override('ALL', 0)
447endfunc
448
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200449func Test_getcompletion()
450 let groupcount = len(getcompletion('', 'event'))
451 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200452 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200453 call assert_true(matchcount > 0)
454 call assert_true(groupcount > matchcount)
455
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200456 if has('menu')
457 source $VIMRUNTIME/menu.vim
458 let matchcount = len(getcompletion('', 'menu'))
459 call assert_true(matchcount > 0)
460 call assert_equal(['File.'], getcompletion('File', 'menu'))
461 call assert_true(matchcount > 0)
462 let matchcount = len(getcompletion('File.', 'menu'))
463 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000464 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200465 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200466
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467 let l = getcompletion('v:n', 'var')
468 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('v:notexists', 'var')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200472 args a.c b.c
473 let l = getcompletion('', 'arglist')
474 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000475 let l = getcompletion('a.', 'buffer')
476 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200477 %argdelete
478
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200479 let l = getcompletion('', 'augroup')
480 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200481 let l = getcompletion('blahblah', 'augroup')
482 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200483
484 let l = getcompletion('', 'behave')
485 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200486 let l = getcompletion('not', 'behave')
487 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200488
489 let l = getcompletion('', 'color')
490 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200491 let l = getcompletion('dirty', 'color')
492 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200493
494 let l = getcompletion('', 'command')
495 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200496 let l = getcompletion('awake', 'command')
497 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200498
499 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200500 call assert_true(index(l, 'samples/') >= 0)
501 let l = getcompletion('NoMatch', 'dir')
502 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100504 if glob('~/*') !=# ''
505 let l = getcompletion('~/', 'dir')
506 call assert_true(l[0][0] ==# '~')
507 endif
508
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509 let l = getcompletion('exe', 'expression')
510 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200511 let l = getcompletion('kill', 'expression')
512 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200513
514 let l = getcompletion('tag', 'function')
515 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200516 let l = getcompletion('paint', 'function')
517 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200518
Kota Kato90c23532023-01-18 15:27:38 +0000519 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000520 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000521 let l = getcompletion('ruby', 'function')
522 call assert_equal([], l)
523 endif
524
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200525 let Flambda = {-> 'hello'}
526 let l = getcompletion('', 'function')
527 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200529
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530 let l = getcompletion('run', 'file')
531 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200532 let l = getcompletion('walk', 'file')
533 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200534 set wildignore=*.vim
535 let l = getcompletion('run', 'file', 1)
536 call assert_true(index(l, 'runtest.vim') < 0)
537 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000538 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100539 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000540 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
541 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200542
543 let l = getcompletion('ha', 'filetype')
544 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200545 let l = getcompletion('horse', 'filetype')
546 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200547
Doug Kearns81642d92024-01-04 22:37:44 +0100548 if has('keymap')
549 let l = getcompletion('acc', 'keymap')
550 call assert_true(index(l, 'accents') >= 0)
551 let l = getcompletion('nullkeymap', 'keymap')
552 call assert_equal([], l)
553 endif
554
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200555 let l = getcompletion('z', 'syntax')
556 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200557 let l = getcompletion('emacs', 'syntax')
558 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200559
560 let l = getcompletion('jikes', 'compiler')
561 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200562 let l = getcompletion('break', 'compiler')
563 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200564
565 let l = getcompletion('last', 'help')
566 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200567 let l = getcompletion('giveup', 'help')
568 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200569
570 let l = getcompletion('time', 'option')
571 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200572 let l = getcompletion('space', 'option')
573 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200574
575 let l = getcompletion('er', 'highlight')
576 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200577 let l = getcompletion('dark', 'highlight')
578 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200579
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200580 let l = getcompletion('', 'messages')
581 call assert_true(index(l, 'clear') >= 0)
582 let l = getcompletion('not', 'messages')
583 call assert_equal([], l)
584
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200585 let l = getcompletion('', 'mapclear')
586 call assert_true(index(l, '<buffer>') >= 0)
587 let l = getcompletion('not', 'mapclear')
588 call assert_equal([], l)
589
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200590 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200591 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200592 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
593 let root = has('win32') ? 'C:\\' : '/'
594 let l = getcompletion(root, 'shellcmd')
595 let expected = map(filter(glob(root . '*', 0, 1),
596 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
597 call assert_equal(expected, l)
598
Bram Moolenaarb650b982016-08-05 20:35:13 +0200599 if has('cscope')
600 let l = getcompletion('', 'cscope')
601 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
602 call assert_equal(cmds, l)
603 " using cmdline completion must not change the result
604 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
605 let l = getcompletion('', 'cscope')
606 call assert_equal(cmds, l)
607 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
608 let l = getcompletion('find ', 'cscope')
609 call assert_equal(keys, l)
610 endif
611
Bram Moolenaar7522f692016-08-06 14:12:50 +0200612 if has('signs')
613 sign define Testing linehl=Comment
614 let l = getcompletion('', 'sign')
615 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
616 call assert_equal(cmds, l)
617 " using cmdline completion must not change the result
618 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
619 let l = getcompletion('', 'sign')
620 call assert_equal(cmds, l)
621 let l = getcompletion('list ', 'sign')
622 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000623 let l = getcompletion('de*', 'sign')
624 call assert_equal(['define'], l)
625 let l = getcompletion('p?', 'sign')
626 call assert_equal(['place'], l)
627 let l = getcompletion('j.', 'sign')
628 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200629 endif
630
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200631 " Command line completion tests
632 let l = getcompletion('cd ', 'cmdline')
633 call assert_true(index(l, 'samples/') >= 0)
634 let l = getcompletion('cd NoMatch', 'cmdline')
635 call assert_equal([], l)
636 let l = getcompletion('let v:n', 'cmdline')
637 call assert_true(index(l, 'v:null') >= 0)
638 let l = getcompletion('let v:notexists', 'cmdline')
639 call assert_equal([], l)
640 let l = getcompletion('call tag', 'cmdline')
641 call assert_true(index(l, 'taglist(') >= 0)
642 let l = getcompletion('call paint', 'cmdline')
643 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200644 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
645 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200646
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100647 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000648 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100649 return "oneA\noneB\noneC"
650 endfunc
651 command -nargs=1 -complete=custom,T MyCmd
652 let l = getcompletion('MyCmd ', 'cmdline')
653 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000654 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100655
656 delcommand MyCmd
657 delfunc T
ii144785fe02021-11-21 12:13:56 +0000658 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100659
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200660 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200661 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200662 if has('cmdline_hist')
663 call add(names, 'history')
664 endif
665 if has('gettext')
666 call add(names, 'locale')
667 endif
668 if has('profile')
669 call add(names, 'syntime')
670 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200671
672 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100673 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200674
675 for name in names
676 let matchcount = len(getcompletion('', name))
677 call assert_true(matchcount >= 0, 'No matches for ' . name)
678 endfor
679
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200680 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200681
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000682 edit a~b
683 enew
684 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
685 bw a~b
686
687 if has('unix')
688 edit Xtest\
689 enew
690 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
691 bw Xtest\
692 endif
693
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100694 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200695 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100696 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200697endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200698
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000699func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000700 " Get a dialog in the GUI
701 CheckNotGui
702
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000703 " This was using uninitialized memory.
704 let lines =<< trim END
705 set verbose=6
706 norm @=ٷ
707 qall!
708 END
709 call writefile(lines, 'XmultiScript', 'D')
710 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
711endfunc
712
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000713" Test for getcompletion() with "fuzzy" in 'wildoptions'
714func Test_getcompletion_wildoptions()
715 let save_wildoptions = &wildoptions
716 set wildoptions&
717 let l = getcompletion('space', 'option')
718 call assert_equal([], l)
719 let l = getcompletion('ier', 'command')
720 call assert_equal([], l)
721 set wildoptions=fuzzy
722 let l = getcompletion('space', 'option')
723 call assert_true(index(l, 'backspace') >= 0)
724 let l = getcompletion('ier', 'command')
725 call assert_true(index(l, 'compiler') >= 0)
726 let &wildoptions = save_wildoptions
727endfunc
728
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000729func Test_complete_autoload_error()
730 let save_rtp = &rtp
731 let lines =<< trim END
732 vim9script
733 export def Complete(..._): string
734 return 'match'
735 enddef
736 echo this will cause an error
737 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100738 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000739 call writefile(lines, 'Xdir/autoload/script.vim')
740 exe 'set rtp+=' .. getcwd() .. '/Xdir'
741
742 let lines =<< trim END
743 vim9script
744 import autoload 'script.vim'
745 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
746 &wildcharm = char2nr("\<Tab>")
747 feedkeys(":Cmd \<Tab>", 'xt')
748 END
749 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
750
751 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000752endfunc
753
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100754func Test_fullcommand()
755 let tests = {
756 \ '': '',
757 \ ':': '',
758 \ ':::': '',
759 \ ':::5': '',
760 \ 'not_a_cmd': '',
761 \ 'Check': '',
762 \ 'syntax': 'syntax',
763 \ ':syntax': 'syntax',
764 \ '::::syntax': 'syntax',
765 \ 'sy': 'syntax',
766 \ 'syn': 'syntax',
767 \ 'synt': 'syntax',
768 \ ':sy': 'syntax',
769 \ '::::sy': 'syntax',
770 \ 'match': 'match',
771 \ '2match': 'match',
772 \ '3match': 'match',
773 \ 'aboveleft': 'aboveleft',
774 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100775 \ 'en': 'endif',
776 \ 'end': 'endif',
777 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100778 \ 's': 'substitute',
779 \ '5s': 'substitute',
780 \ ':5s': 'substitute',
781 \ "'<,'>s": 'substitute',
782 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100783 \ 'CheckLin': 'CheckLinux',
784 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100785 \ }
786
787 for [in, want] in items(tests)
788 call assert_equal(want, fullcommand(in))
789 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200790 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100791
792 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200793
794 command -buffer BufferLocalCommand :
795 command GlobalCommand :
796 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
797 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
798 delcommand BufferLocalCommand
799 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100800endfunc
801
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200802func Test_shellcmd_completion()
803 let save_path = $PATH
804
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100805 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200806 call writefile([''], 'Xpathdir/Xfile.exe')
807 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
808
809 " Set PATH to example directory without trailing slash.
810 let $PATH = getcwd() . '/Xpathdir'
811
812 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
813 " dirs in the PATH, even though they won't be executed. We check that only
814 " subdirs of the PWD and executables from the PATH are included in the
815 " suggestions.
816 let actual = getcompletion('X', 'shellcmd')
817 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
818 call insert(expected, 'Xfile.exe')
819 call assert_equal(expected, actual)
820
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200821 let $PATH = save_path
822endfunc
823
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200824func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100825 call mkdir('a/b/c', 'pR')
826 call writefile(['asdfasdf'], 'a/b/c/fileXname')
827 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
828 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200829 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200830endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100831
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100832func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100833 let @a = "def"
834 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
835 call assert_equal('"abc def ghi', @:)
836
837 new
838 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
839
840 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
841 call assert_equal('"aaa asdf bbb', @:)
842
843 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
844 call assert_equal('"aaa /tmp/some bbb', @:)
845
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200846 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
847 call assert_equal('"aaa '.getline(1).' bbb', @:)
848
Bram Moolenaar21efc362016-12-03 14:05:49 +0100849 set incsearch
850 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
851 call assert_equal('"aaa verylongword bbb', @:)
852
853 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
854 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100855
856 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
857 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100858 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200859
860 " Error while typing a command used to cause that it was not executed
861 " in the end.
862 new
863 try
864 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
865 catch /^Vim\%((\a\+)\)\=:E32/
866 " ignore error E32
867 endtry
868 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100869
Bram Moolenaar578fe942020-02-27 21:32:51 +0100870 " Try to paste an invalid register using <C-R>
871 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
872 call assert_equal('"onetwo', @:)
873
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100874 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100875 let @a = "xy\<C-H>z"
876 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
877 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100878 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
879 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100880 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
881 call assert_equal("\"xy\<C-H>z", @:)
882
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100883 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
884 let @a = "xy\<C-V>z"
885 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
886 call assert_equal('"xyz', @:)
887 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
888 call assert_equal("\"xy\<C-V>z", @:)
889
Bram Moolenaar578fe942020-02-27 21:32:51 +0100890 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
891
Bram Moolenaar72532d32018-04-07 19:09:09 +0200892 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100893endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100894
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100895func Test_cmdline_remove_char()
896 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100897
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100898 for e in ['utf8', 'latin1']
899 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100900
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100901 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
902 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100903
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100904 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
905 call assert_equal('"abcdef', @:)
906
907 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
908 call assert_equal('"abc ghi', @:, e)
909
910 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
911 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100912
913 " This was going before the start in latin1.
914 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100915 endfor
916
917 let &encoding = encoding_save
918endfunc
919
zeertzjqff2b79d2024-02-26 20:38:36 +0100920func Test_cmdline_del_utf8()
921 let @s = '⒌'
922 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
923 call assert_equal('",,', @:)
924
925 let @s = 'a̳'
926 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
927 call assert_equal('",,', @:)
928
929 let @s = 'β̳'
930 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
931 call assert_equal('",,', @:)
932
933 if has('arabic')
934 let @s = 'لا'
935 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
936 call assert_equal('",,', @:)
937 endif
938endfunc
939
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100940func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200941 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100942
943 set keymap=esperanto
944 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
945 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
946 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100947endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100948
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100949func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100950 new
951 2;'(
952 2;')
953 quit
954endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100955
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100956func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100957 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100958 new
959 source Xtest.vim
960 " Trigger calling validate_cursor()
961 diffsp Xtest.vim
962 quit!
963 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100964endfunc
965
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100966func Test_mark_from_line_zero()
967 " this was reading past the end of the first (empty) line
968 new
969 norm oxxxx
970 call assert_fails("0;'(", 'E20:')
971 bwipe!
972endfunc
973
Bram Moolenaarba47b512017-01-24 21:18:19 +0100974func Test_cmdline_complete_wildoptions()
975 help
976 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
977 let a = join(sort(split(@:)),' ')
978 set wildoptions=tagfile
979 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
980 let b = join(sort(split(@:)),' ')
981 call assert_equal(a, b)
982 bw!
983endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100984
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200985func Test_cmdline_complete_user_cmd()
986 command! -complete=color -nargs=1 Foo :
987 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
988 call assert_equal('"Foo blue', @:)
989 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
990 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000991 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
992 call assert_equal('"Foo a blue', @:)
993 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
994 call assert_equal('"Foo b\', @:)
995 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
996 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200997 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100998
999 redraw
1000 call assert_equal('~', Screenline(&lines - 1))
1001 command! FooOne :
1002 command! FooTwo :
1003
1004 set nowildmenu
1005 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1006 call assert_equal('"FooOne', @:)
1007 call assert_equal('~', Screenline(&lines - 1))
1008
1009 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1010 call assert_equal('"FooTwo', @:)
1011 call assert_equal('~', Screenline(&lines - 1))
1012
1013 delcommand FooOne
1014 delcommand FooTwo
1015 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001016endfunc
1017
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001018func Test_complete_user_cmd()
1019 command FooBar echo 'global'
1020 command -buffer FooBar echo 'local'
1021 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1022 call assert_equal('"FooBar', @:)
1023
1024 delcommand -buffer FooBar
1025 delcommand FooBar
1026endfunc
1027
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001028func s:ScriptLocalFunction()
1029 echo 'yes'
1030endfunc
1031
1032func Test_cmdline_complete_user_func()
1033 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001034 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001035 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1036 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001037
1038 " g: prefix also works
1039 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1040 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001041
1042 " using g: prefix does not result in just "g:" matches from a lambda
1043 let Fx = { a -> a }
1044 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1045 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001046
1047 " existence of script-local dict function does not break user function name
1048 " completion
1049 function s:a_dict_func() dict
1050 endfunction
1051 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1052 call assert_match('"call Test_cmdline_complete_user_', @:)
1053 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001054endfunc
1055
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001056func Test_cmdline_complete_user_names()
1057 if has('unix') && executable('whoami')
1058 let whoami = systemlist('whoami')[0]
1059 let first_letter = whoami[0]
1060 if len(first_letter) > 0
1061 " Trying completion of :e ~x where x is the first letter of
1062 " the user name should complete to at least the user name.
1063 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1064 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1065 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001066 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001067 " Just in case: check that the system has an Administrator account.
1068 let names = system('net user')
1069 if names =~ 'Administrator'
1070 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001071 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001072 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001073 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001074 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001075 else
1076 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001077 endif
1078endfunc
1079
Bram Moolenaar297610b2019-12-27 17:20:55 +01001080func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001081 CheckExecutable whoami
1082 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1083 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001084endfunc
1085
Bram Moolenaar8b633132020-03-20 18:20:51 +01001086func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001087 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1088 call assert_equal(lang, v:lc_time)
1089
1090 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1091 call assert_equal(lang, v:ctype)
1092
1093 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1094 call assert_equal(lang, v:collate)
1095
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001096 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001097 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001098
1099 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001100 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001101
Bram Moolenaarec680282020-06-12 19:35:32 +02001102 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001103
Bram Moolenaarec680282020-06-12 19:35:32 +02001104 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1105 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001106
Bram Moolenaarec680282020-06-12 19:35:32 +02001107 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1108 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001109
Bram Moolenaarec680282020-06-12 19:35:32 +02001110 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1111 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001112
1113 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1114 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001115endfunc
1116
Bram Moolenaar297610b2019-12-27 17:20:55 +01001117func Test_cmdline_complete_env_variable()
1118 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001119 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1120 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001121 unlet $X_VIM_TEST_COMPLETE_ENV
1122endfunc
1123
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001124func Test_cmdline_complete_expression()
1125 let g:SomeVar = 'blah'
1126 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1127 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1128 call assert_match('"' .. cmd .. ' SomeVar', @:)
1129 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1130 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1131 endfor
1132 unlet g:SomeVar
1133endfunc
1134
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001135func Test_cmdline_complete_argopt()
1136 " completion for ++opt=arg for file commands
1137 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1138 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1139 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1140
1141 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001142 " Test ++ff in the middle of the cmdline
1143 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1144 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001145
1146 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1147 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1148 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1149 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1150 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1151
1152 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1153
1154 " completion should skip the ++opt and continue
1155 call writefile([], 'Xaaaaa.txt', 'D')
1156 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1158
1159 if has('terminal')
1160 " completion for terminal's [options]
1161 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1162 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1163 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1164
1165 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1166
1167 " :terminal completion should skip the ++opt when considering what is the
1168 " first option, which is a list of shell commands, unlike second option
1169 " onwards.
1170 let first_param = getcompletion('terminal ', 'cmdline')
1171 let second_param = getcompletion('terminal foo ', 'cmdline')
1172 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1173 call assert_equal(first_param, skipped_opt_param)
1174 call assert_notequal(first_param, second_param)
1175 endif
1176endfunc
1177
Bram Moolenaar47016f52021-08-26 16:39:58 +02001178" Unique function name for completion below
1179func s:WeirdFunc()
1180 echo 'weird'
1181endfunc
1182
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001183" Test for various command-line completion
1184func Test_cmdline_complete_various()
1185 " completion for a command starting with a comment
1186 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1187 call assert_equal("\" :|\"\<C-A>", @:)
1188
1189 " completion for a range followed by a comment
1190 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1191 call assert_equal("\"1,2\"\<C-A>", @:)
1192
1193 " completion for :k command
1194 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1195 call assert_equal("\"ka\<C-A>", @:)
1196
1197 " completion for short version of the :s command
1198 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1199 call assert_equal("\"sI \<C-A>", @:)
1200
1201 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001202 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001203 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001204 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001205 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001206 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1207 call assert_equal("\"w >> Xfile1", @:)
1208 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001209
1210 " completion for :w ! and :r ! commands
1211 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"w !invalid_xyz_cmd", @:)
1213 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"r !invalid_xyz_cmd", @:)
1215
1216 " completion for :>> and :<< commands
1217 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\">>>\<C-A>", @:)
1219 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1220 call assert_equal("\"<<<\<C-A>", @:)
1221
1222 " completion for command with +cmd argument
1223 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal("\"buffer +/pat Xabc", @:)
1225 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1226 call assert_equal("\"buffer +/pat\<C-A>", @:)
1227
1228 " completion for a command with a trailing comment
1229 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1230 call assert_equal("\"ls \" comment\<C-A>", @:)
1231
1232 " completion for a command with a trailing command
1233 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1234 call assert_equal("\"ls | ls", @:)
1235
1236 " completion for a command with an CTRL-V escaped argument
1237 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1238 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1239
1240 " completion for a command that doesn't take additional arguments
1241 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1242 call assert_equal("\"all abc\<C-A>", @:)
1243
zeertzjqd3de1782022-09-01 12:58:52 +01001244 " completion for :wincmd with :horizontal modifier
1245 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1246 call assert_equal("\"horizontal wincmd", @:)
1247
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001248 " completion for a command with a command modifier
1249 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1250 call assert_equal("\"topleft new", @:)
1251
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001252 " completion for vim9 and legacy commands
1253 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1254 call assert_equal("\"vim9 call strlen(", @:)
1255 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1256 call assert_equal("\"legac call strlen(", @:)
1257
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001258 " completion for the :disassemble command
1259 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1260 call assert_equal("\"disas debug", @:)
1261 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1262 call assert_equal("\"disas profile", @:)
1263 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1264 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1265 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1266 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001267 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1268 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001269
Bram Moolenaar47016f52021-08-26 16:39:58 +02001270 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001271 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001272
naohiro onodfe04db2021-09-12 15:45:10 +02001273 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1274 call assert_match('"disas <SNR>\d\+_', @:)
1275 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1276 call assert_match('"disas debug <SNR>\d\+_', @:)
1277
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001278 " completion for the :match command
1279 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1280 call assert_equal("\"match Search /pat/\<C-A>", @:)
1281
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001282 " completion for the :doautocmd command
1283 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1284 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1285
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001286 " completion of autocmd group after comma
1287 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1288 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1289
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001290 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001291 call writefile([], 'Xvarfile1', 'D')
1292 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001293 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1294 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001295
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001296 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001297 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001298 augroup END
1299 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001300 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001301
1302 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001303 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1304 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001305 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1306 call assert_equal("\"au XTest.test", @:)
1307
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001308 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001309
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001310 " autocmd pattern completion
1311 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1312 call assert_equal("\"au BufEnter *.py\t", @:)
1313
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001314 " completion for the :unlet command
1315 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal("\"unlet one two", @:)
1317
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001318 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001319 " FIXME: what should happen on MS-Windows?
1320 if !has('win32')
1321 edit \{someFile}
1322 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1323 call assert_equal("\"buf {someFile}", @:)
1324 bwipe {someFile}
1325 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001326
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001327 " completion for the :bdelete command
1328 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1329 call assert_equal("\"bdel a b c", @:)
1330
1331 " completion for the :mapclear command
1332 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1333 call assert_equal("\"mapclear <buffer>", @:)
1334
1335 " completion for user defined commands with menu names
1336 menu Test.foo :ls<CR>
1337 com -nargs=* -complete=menu MyCmd
1338 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1339 call assert_equal('"MyCmd Test.', @:)
1340 delcom MyCmd
1341 unmenu Test
1342
1343 " completion for user defined commands with mappings
1344 mapclear
1345 map <F3> :ls<CR>
1346 com -nargs=* -complete=mapping MyCmd
1347 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001348 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001349 mapclear
1350 delcom MyCmd
1351
Yee Cheng Chin54844852023-10-09 18:12:31 +02001352 " Prepare for path completion
1353 call mkdir('Xa b c', 'D')
1354 defer delete('Xcomma,foobar.txt')
1355 call writefile([], 'Xcomma,foobar.txt')
1356
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001357 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001358 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1359 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1360 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001361
1362 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001363 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1364 call assert_equal('"set dir=Xa\ b\ c/', @:)
1365 set dir&
1366
1367 " completion for :set tags= / set dictionary= with escaped commas
1368 if has('win32')
1369 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1370 " '\,'
1371 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1372 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1373
1374 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1375 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1376
1377 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1378 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1379
1380 " completion for :set dictionary= with escaped commas (same behavior, but
1381 " different internal code path from 'set tags=' for escaping the output)
1382 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1383 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1384 else
1385 " In other platforms, backslashes are rounded down (since '\,' itself will
1386 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1387 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1388 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1389
1390 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1391 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1392
1393 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1394 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1395
1396 " completion for :set dictionary= with escaped commas (same behavior, but
1397 " different internal code path from 'set tags=' for escaping the output)
1398 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1399 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1400 endif
1401 set tags&
1402 set dictionary&
1403
1404 " completion for :set makeprg= with no escaped commas
1405 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1406 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1407
1408 if !has('win32')
1409 " Cannot create file with backslash in file name in Windows, so only test
1410 " this elsewhere.
1411 defer delete('Xcomma\,fooslash.txt')
1412 call writefile([], 'Xcomma\,fooslash.txt')
1413 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1414 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1415 endif
1416 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001417
1418 " completion for the :py3 commands
1419 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1420 call assert_equal('"py3 py3do py3file', @:)
1421
Bram Moolenaardf749a22021-03-28 15:29:43 +02001422 " completion for the :vim9 commands
1423 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1424 call assert_equal('"vim9cmd vim9script', @:)
1425
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001426 " redir @" is not the start of a comment. So complete after that
1427 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1428 call assert_equal('"redir @" | cwindow', @:)
1429
1430 " completion after a backtick
1431 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1432 call assert_equal('"e `a1b2c', @:)
1433
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001434 " completion for :language command with an invalid argument
1435 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1436 call assert_equal("\"language dummy \t", @:)
1437
1438 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001439 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1440 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001441
1442 " completion with ambiguous user defined commands
1443 com TCmd1 echo 'TCmd1'
1444 com TCmd2 echo 'TCmd2'
1445 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1446 call assert_equal('"TCmd ', @:)
1447 delcom TCmd1
1448 delcom TCmd2
1449
1450 " completion after a range followed by a pipe (|) character
1451 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1452 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001453
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001454 " completion after a :global command
1455 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1456 call assert_equal('"g/a/chistory', @:)
1457 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1458 call assert_equal("\"g/a\\/chist\t", @:)
1459
Bram Moolenaar9c929712020-09-07 22:05:28 +02001460 " use <Esc> as the 'wildchar' for completion
1461 set wildchar=<Esc>
1462 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal('"g/a\xb/clearjumps', @:)
1464 " pressing <esc> twice should cancel the command
1465 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1466 call assert_equal('"g/a\xb/clearjumps', @:)
1467 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001468
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001469 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001470 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001471 call writefile([], '~Xtest')
1472 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1473 call assert_equal('"e \~Xtest', @:)
1474 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001475
1476 " should be able to complete a file name that has a '*'
1477 call writefile([], 'Xx*Yy')
1478 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1479 call assert_equal('"e Xx\*Yy', @:)
1480 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001481
1482 " use a literal star
1483 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1484 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001485 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001486
1487 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1488 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001489endfunc
1490
zeertzjq094dd152023-06-15 22:51:57 +01001491" Test that expanding a pattern doesn't interfere with cmdline completion.
1492func Test_expand_during_cmdline_completion()
1493 func ExpandStuff()
1494 badd <script>:p:h/README.*
1495 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1496 $bwipe
1497 call assert_equal('README.txt', expand('README.*'))
1498 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1499 endfunc
1500 augroup test_CmdlineChanged
1501 autocmd!
1502 autocmd CmdlineChanged * call ExpandStuff()
1503 augroup END
1504
1505 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1506 call assert_equal('"sign place', @:)
1507
1508 augroup test_CmdlineChanged
1509 au!
1510 augroup END
1511 augroup! test_CmdlineChanged
1512 delfunc ExpandStuff
1513endfunc
1514
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001515" Test for 'wildignorecase'
1516func Test_cmdline_wildignorecase()
1517 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001518 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001519 set wildignorecase
1520 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1521 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001522 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001523 let g:Sline = ''
1524 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1525 call assert_equal('"e xt', @:)
1526 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001527 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001528endfunc
1529
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001530func Test_cmdline_write_alternatefile()
1531 new
1532 call setline('.', ['one', 'two'])
1533 f foo.txt
1534 new
1535 f #-A
1536 call assert_equal('foo.txt-A', expand('%'))
1537 f #<-B.txt
1538 call assert_equal('foo-B.txt', expand('%'))
1539 f %<
1540 call assert_equal('foo-B', expand('%'))
1541 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001542 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001543 bw!
1544 f foo-B.txt
1545 f %<-A
1546 call assert_equal('foo-B-A', expand('%'))
1547 bw!
1548 bw!
1549endfunc
1550
Bram Moolenaarf5724372022-09-02 19:45:15 +01001551func Test_cmdline_expand_cur_alt_file()
1552 enew
1553 file http://some.com/file.txt
1554 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1555 call assert_equal('"e http://some.com/file.txt', @:)
1556 edit another
1557 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1558 call assert_equal('"e http://some.com/file.txt', @:)
1559 bwipe
1560 bwipe http://some.com/file.txt
1561endfunc
1562
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001563" using a leading backslash here
1564set cpo+=C
1565
1566func Test_cmdline_search_range()
1567 new
1568 call setline(1, ['a', 'b', 'c', 'd'])
1569 /d
1570 1,\/s/b/B/
1571 call assert_equal('B', getline(2))
1572
1573 /a
1574 $
1575 \?,4s/c/C/
1576 call assert_equal('C', getline(3))
1577
1578 call setline(1, ['a', 'b', 'c', 'd'])
1579 %s/c/c/
1580 1,\&s/b/B/
1581 call assert_equal('B', getline(2))
1582
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001583 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001584 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001585
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001586 bwipe!
1587endfunc
1588
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001589" Test for the tick mark (') in an excmd range
1590func Test_tick_mark_in_range()
1591 " If only the tick is passed as a range and no command is specified, there
1592 " should not be an error
1593 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001594 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001595 call assert_fails("',print", 'E78:')
1596endfunc
1597
1598" Test for using a line number followed by a search pattern as range
1599func Test_lnum_and_pattern_as_range()
1600 new
1601 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1602 let @" = ''
1603 2/foo/yank
1604 call assert_equal("foo 3\n", @")
1605 call assert_equal(1, line('.'))
1606 close!
1607endfunc
1608
Bram Moolenaar65189a12017-02-06 22:22:17 +01001609" Tests for getcmdline(), getcmdpos() and getcmdtype()
1610func Check_cmdline(cmdtype)
1611 call assert_equal('MyCmd a', getcmdline())
1612 call assert_equal(8, getcmdpos())
1613 call assert_equal(a:cmdtype, getcmdtype())
1614 return ''
1615endfunc
1616
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001617set cpo&
1618
Bram Moolenaar65189a12017-02-06 22:22:17 +01001619func Test_getcmdtype()
1620 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1621
1622 let cmdtype = ''
1623 debuggreedy
1624 call feedkeys(":debug echo 'test'\<CR>", "t")
1625 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1626 call feedkeys("cont\<CR>", "xt")
1627 0debuggreedy
1628 call assert_equal('>', cmdtype)
1629
1630 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1631 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1632
1633 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001634 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001635
1636 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1637
1638 cnoremap <expr> <F6> Check_cmdline('=')
1639 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1640 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001641
1642 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001643endfunc
1644
Bram Moolenaar52604f22017-04-07 16:17:39 +02001645func Test_verbosefile()
1646 set verbosefile=Xlog
1647 echomsg 'foo'
1648 echomsg 'bar'
1649 set verbosefile=
1650 let log = readfile('Xlog')
1651 call assert_match("foo\nbar", join(log, "\n"))
1652 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001653
1654 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001655 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001656endfunc
1657
Bram Moolenaar4facea32019-10-12 20:17:40 +02001658func Test_verbose_option()
1659 CheckScreendump
1660
1661 let lines =<< trim [SCRIPT]
1662 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1663 call feedkeys("\r", 't') " for the hit-enter prompt
1664 set verbose=20
1665 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001666 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001667
1668 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001669 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001670 call term_sendkeys(buf, ":DoSomething\<CR>")
1671 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1672
1673 " clean up
1674 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001675endfunc
1676
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001677func Test_setcmdpos()
1678 func InsertTextAtPos(text, pos)
1679 call assert_equal(0, setcmdpos(a:pos))
1680 return a:text
1681 endfunc
1682
1683 " setcmdpos() with position in the middle of the command line.
1684 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1685 call assert_equal('"1ab2', @:)
1686
1687 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1688 call assert_equal('"1b2a', @:)
1689
1690 " setcmdpos() with position beyond the end of the command line.
1691 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1692 call assert_equal('"12ab', @:)
1693
1694 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001695 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001696endfunc
1697
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001698func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001699 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001700 let encoding_save = &encoding
1701
1702 for e in encodings
1703 exe 'set encoding=' . e
1704
1705 " Test overstrike in the middle of the command line.
1706 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001707 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001708
1709 " Test overstrike going beyond end of command line.
1710 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001711 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001712
1713 " Test toggling insert/overstrike a few times.
1714 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001715 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001716 endfor
1717
Bram Moolenaar30276f22019-01-24 17:59:39 +01001718 " Test overstrike with multi-byte characters.
1719 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001720 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001721
1722 let &encoding = encoding_save
1723endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001724
Bram Moolenaar52410572019-10-27 05:12:45 +01001725func Test_buffers_lastused()
1726 " check that buffers are sorted by time when wildmode has lastused
1727 call test_settime(1550020000) " middle
1728 edit bufa
1729 enew
1730 call test_settime(1550030000) " newest
1731 edit bufb
1732 enew
1733 call test_settime(1550010000) " oldest
1734 edit bufc
1735 enew
1736 call test_settime(0)
1737 enew
1738
1739 call assert_equal(['bufa', 'bufb', 'bufc'],
1740 \ getcompletion('', 'buffer'))
1741
1742 let save_wildmode = &wildmode
1743 set wildmode=full:lastused
1744
1745 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1746 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1747 call assert_equal('b bufb', X)
1748 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1749 call assert_equal('b bufa', X)
1750 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1751 call assert_equal('b bufc', X)
1752 enew
1753
1754 edit other
1755 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1756 call assert_equal('b bufb', X)
1757 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1758 call assert_equal('b bufa', X)
1759 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1760 call assert_equal('b bufc', X)
1761 enew
1762
1763 let &wildmode = save_wildmode
1764
1765 bwipeout bufa
1766 bwipeout bufb
1767 bwipeout bufc
1768endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001769
Bram Moolenaar479950f2020-01-19 15:45:17 +01001770func Test_cmdlineclear_tabenter()
1771 CheckScreendump
1772
1773 let lines =<< trim [SCRIPT]
1774 call setline(1, range(30))
1775 [SCRIPT]
1776
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001777 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001778 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001779 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001780 " in one tab make the command line higher with CTRL-W -
1781 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1782 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1783
1784 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001785endfunc
1786
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001787" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001788func Test_cmdline_expand_special()
1789 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001790 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001791 call assert_fails('e <afile>', 'E495:')
1792 call assert_fails('e <abuf>', 'E496:')
1793 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001794
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001795 call writefile([], 'Xfile.cpp', 'D')
1796 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001797 new Xfile.cpp
1798 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1799 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1800 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001801endfunc
1802
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001803" Test for backtick expression in the command line
1804func Test_cmd_backtick()
1805 %argd
1806 argadd `=['a', 'b', 'c']`
1807 call assert_equal(['a', 'b', 'c'], argv())
1808 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001809
1810 argadd `echo abc def`
1811 call assert_equal(['abc def'], argv())
1812 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001813endfunc
1814
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001815" Test for the :! command
1816func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001817 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001818
1819 let lines =<< trim [SCRIPT]
1820 " Test for no previous command
1821 call assert_fails('!!', 'E34:')
1822 set nomore
1823 " Test for cmdline expansion with :!
1824 call setline(1, 'foo!')
1825 silent !echo <cWORD> > Xfile.out
1826 call assert_equal(['foo!'], readfile('Xfile.out'))
1827 " Test for using previous command
1828 silent !echo \! !
1829 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1830 call writefile(v:errors, 'Xresult')
1831 call delete('Xfile.out')
1832 qall!
1833 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001834 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001835 if RunVim([], [], '--clean -S Xscript')
1836 call assert_equal([], readfile('Xresult'))
1837 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001838 call delete('Xresult')
1839endfunc
1840
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001841" Test error: "E135: *Filter* Autocommands must not change current buffer"
1842func Test_cmd_bang_E135()
1843 new
1844 call setline(1, ['a', 'b', 'c', 'd'])
1845 augroup test_cmd_filter_E135
1846 au!
1847 autocmd FilterReadPost * help
1848 augroup END
1849 call assert_fails('2,3!echo "x"', 'E135:')
1850
1851 augroup test_cmd_filter_E135
1852 au!
1853 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001854 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001855 %bwipe!
1856endfunc
1857
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001858func Test_cmd_bang_args()
1859 new
1860 :.!
1861 call assert_equal(0, v:shell_error)
1862
1863 " Note that below there is one space char after the '!'. This caused a
1864 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1865 :.!
1866 call assert_equal(0, v:shell_error)
1867 bwipe!
1868
1869 CheckUnix
1870 :.!pwd
1871 call assert_equal(0, v:shell_error)
1872 :.! pwd
1873 call assert_equal(0, v:shell_error)
1874
1875 " Note there is one space after 'pwd'.
1876 :.! pwd
1877 call assert_equal(0, v:shell_error)
1878
1879 " Note there are two spaces after 'pwd'.
1880 :.! pwd
1881 call assert_equal(0, v:shell_error)
1882 :.!ls ~
1883 call assert_equal(0, v:shell_error)
1884
1885 " Note there is one space char after '~'.
1886 :.!ls ~
1887 call assert_equal(0, v:shell_error)
1888
1889 " Note there are two spaces after '~'.
1890 :.!ls ~
1891 call assert_equal(0, v:shell_error)
1892
1893 :.!echo "foo"
1894 call assert_equal(getline('.'), "foo")
1895 :.!echo "foo "
1896 call assert_equal(getline('.'), "foo ")
1897 :.!echo " foo "
1898 call assert_equal(getline('.'), " foo ")
1899 :.!echo " foo "
1900 call assert_equal(getline('.'), " foo ")
1901
1902 %bwipe!
1903endfunc
1904
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001905" Test for using ~ for home directory in cmdline completion matches
1906func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001907 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001908 call writefile([], 'Xexpdir/Xfile1')
1909 call writefile([], 'Xexpdir/Xfile2')
1910 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001911 let save_HOME = $HOME
1912 let $HOME = getcwd()
1913 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1914 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1915 let $HOME = save_HOME
1916 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001917endfunc
1918
Bram Moolenaar578fe942020-02-27 21:32:51 +01001919" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1920" or insert mode (when 'insertmode' is set)
1921func Test_cmdline_ctrl_g()
1922 new
1923 call setline(1, 'abc')
1924 call cursor(1, 3)
1925 " If command line is entered from insert mode, using C-\ C-G should back to
1926 " insert mode
1927 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1928 call assert_equal('abxyc', getline(1))
1929 call assert_equal(4, col('.'))
1930
1931 " If command line is entered in 'insertmode', using C-\ C-G should back to
1932 " 'insertmode'
1933 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1934 call assert_equal('ab12xyc', getline(1))
1935 close!
1936endfunc
1937
Bram Moolenaar578fe942020-02-27 21:32:51 +01001938" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001939func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001940 func T(a, c, p)
1941 return "oneA\noneB\noneC"
1942 endfunc
1943 command -nargs=1 -complete=custom,T MyCmd
1944
Bram Moolenaar578fe942020-02-27 21:32:51 +01001945 set nowildmenu
1946 set wildmode=full,list
1947 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001948 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001949 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001950 call assert_equal('"MyCmd oneA', @:)
1951
1952 set wildmode=longest,full
1953 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1954 call assert_equal('"MyCmd one', @:)
1955 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1956 call assert_equal('"MyCmd oneC', @:)
1957
1958 set wildmode=longest
1959 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1960 call assert_equal('"MyCmd one', @:)
1961
1962 set wildmode=list:longest
1963 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001964 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001965 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001966 call assert_equal('"MyCmd one', @:)
1967
1968 set wildmode=""
1969 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1970 call assert_equal('"MyCmd oneA', @:)
1971
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001972 " Test for wildmode=longest with 'fileignorecase' set
1973 set wildmode=longest
1974 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001975 argadd AAA AAAA AAAAA
1976 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1977 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001978 set fileignorecase&
1979
1980 " Test for listing files with wildmode=list
1981 set wildmode=list
1982 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001983 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001984 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001985 call assert_equal('"b A', @:)
1986
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001987 " when using longest completion match, matches shorter than the argument
1988 " should be ignored (happens with :help)
1989 set wildmode=longest,full
1990 set wildmenu
1991 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1992 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001993 " non existing file
1994 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1995 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001996 set wildmenu&
1997
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001998 " Test for longest file name completion with 'fileignorecase'
1999 " On MS-Windows, file names are case insensitive.
2000 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002001 call writefile([], 'XTESTfoo', 'D')
2002 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002003 set nofileignorecase
2004 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2005 call assert_equal('"e XTESTfoo', @:)
2006 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2007 call assert_equal('"e Xtestbar', @:)
2008 set fileignorecase
2009 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2010 call assert_equal('"e Xtest', @:)
2011 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2012 call assert_equal('"e Xtest', @:)
2013 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002014 endif
2015
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002016 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002017 delcommand MyCmd
2018 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002019 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002020 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002021endfunc
2022
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002023func Test_wildmode()
2024 " Test with utf-8 encoding
2025 call Wildmode_tests()
2026
2027 " Test with latin1 encoding
2028 let save_encoding = &encoding
2029 set encoding=latin1
2030 call Wildmode_tests()
2031 let &encoding = save_encoding
2032endfunc
2033
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002034func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002035 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002036 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002037 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002038 let lines =<< trim END
2039 func vim8#Complete(a, c, p)
2040 return "oneA\noneB\noneC"
2041 endfunc
2042 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002043 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002044
2045 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2046 set nowildmenu
2047 set wildmode=full,list
2048 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2049 call assert_equal('"MyCmd oneA oneB oneC', @:)
2050
2051 let &rtp = save_rtp
2052 set wildmode& wildmenu&
2053 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002054endfunc
2055
Bram Moolenaar578fe942020-02-27 21:32:51 +01002056" Test for interrupting the command-line completion
2057func Test_interrupt_compl()
2058 func F(lead, cmdl, p)
2059 if a:lead =~ 'tw'
2060 call interrupt()
2061 return
2062 endif
2063 return "one\ntwo\nthree"
2064 endfunc
2065 command -nargs=1 -complete=custom,F Tcmd
2066
2067 set nowildmenu
2068 set wildmode=full
2069 let interrupted = 0
2070 try
2071 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2072 catch /^Vim:Interrupt$/
2073 let interrupted = 1
2074 endtry
2075 call assert_equal(1, interrupted)
2076
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002077 let interrupted = 0
2078 try
2079 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2080 catch /^Vim:Interrupt$/
2081 let interrupted = 1
2082 endtry
2083 call assert_equal(1, interrupted)
2084
Bram Moolenaar578fe942020-02-27 21:32:51 +01002085 delcommand Tcmd
2086 delfunc F
2087 set wildmode&
2088endfunc
2089
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002090" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002091func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002092 let str = ":one two\<C-U>"
2093 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002094 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002095 let str ..= "\<Left>five\<Right>"
2096 let str ..= "\<Home>two "
2097 let str ..= "\<C-Left>one "
2098 let str ..= "\<C-Right> three"
2099 let str ..= "\<End>\<S-Left>four "
2100 let str ..= "\<S-Right> six"
2101 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2102 call feedkeys(str, 'xt')
2103 call assert_equal("\"one two three four five six seven", @:)
2104endfunc
2105
2106" Test for moving the cursor on the / command line in 'rightleft' mode
2107func Test_cmdline_edit_rightleft()
2108 CheckFeature rightleft
2109 set rightleft
2110 set rightleftcmd=search
2111 let str = "/one two\<C-U>"
2112 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002113 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002114 let str ..= "\<Right>five\<Left>"
2115 let str ..= "\<Home>two "
2116 let str ..= "\<C-Right>one "
2117 let str ..= "\<C-Left> three"
2118 let str ..= "\<End>\<S-Right>four "
2119 let str ..= "\<S-Left> six"
2120 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2121 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2122 call assert_equal("\"one two three four five six seven", @/)
2123 set rightleftcmd&
2124 set rightleft&
2125endfunc
2126
2127" Test for using <C-\>e in the command line to evaluate an expression
2128func Test_cmdline_expr()
2129 " Evaluate an expression from the beginning of a command line
2130 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2131 call assert_equal('"hello', @:)
2132
2133 " Use an invalid expression for <C-\>e
2134 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2135
2136 " Insert literal <CTRL-\> in the command line
2137 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2138 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002139endfunc
2140
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002141" This was making the insert position negative
2142func Test_cmdline_expr_register()
2143 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2144endfunc
2145
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002146" Test for 'imcmdline' and 'imsearch'
2147" This test doesn't actually test the input method functionality.
2148func Test_cmdline_inputmethod()
2149 new
2150 call setline(1, ['', 'abc', ''])
2151 set imcmdline
2152
2153 call feedkeys(":\"abc\<CR>", 'xt')
2154 call assert_equal("\"abc", @:)
2155 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2156 call assert_equal("\"abc", @:)
2157 call feedkeys("/abc\<CR>", 'xt')
2158 call assert_equal([2, 1], [line('.'), col('.')])
2159 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2160 call assert_equal([2, 1], [line('.'), col('.')])
2161
2162 set imsearch=2
2163 call cursor(1, 1)
2164 call feedkeys("/abc\<CR>", 'xt')
2165 call assert_equal([2, 1], [line('.'), col('.')])
2166 call cursor(1, 1)
2167 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2168 call assert_equal([2, 1], [line('.'), col('.')])
2169 set imdisable
2170 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2171 call assert_equal([2, 1], [line('.'), col('.')])
2172 set imdisable&
2173 set imsearch&
2174
2175 set imcmdline&
2176 %bwipe!
2177endfunc
2178
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002179" Test for using CTRL-_ in the command line with 'allowrevins'
2180func Test_cmdline_revins()
2181 CheckNotMSWindows
2182 CheckFeature rightleft
2183 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2184 call assert_equal("\"abc\<c-_>", @:)
2185 set allowrevins
2186 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2187 call assert_equal('"abcñèæ', @:)
2188 set allowrevins&
2189endfunc
2190
2191" Test for typing UTF-8 composing characters in the command line
2192func Test_cmdline_composing_chars()
2193 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2194 call assert_equal('"ゔ', @:)
2195endfunc
2196
Bram Moolenaar0e717042020-04-27 19:29:01 +02002197" test that ";" works to find a match at the start of the first line
2198func Test_zero_line_search()
2199 new
2200 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2201 call cursor(1,1)
2202 0;/pattern/d
2203 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2204 q!
2205endfunc
2206
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002207func Test_read_shellcmd()
2208 CheckUnix
2209 if executable('ls')
2210 " There should be ls in the $PATH
2211 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2212 call assert_match('^"r! .*\<ls\>', @:)
2213 endif
2214
2215 if executable('rm')
2216 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2217 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2218 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002219
2220 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2221 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2222 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002223 endif
2224endfunc
2225
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002226" Test for going up and down the directory tree using 'wildmenu'
2227func Test_wildmenu_dirstack()
2228 CheckUnix
2229 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002230 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002231 call writefile([], 'Xwildmenu/file1_1.txt')
2232 call writefile([], 'Xwildmenu/file1_2.txt')
2233 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2234 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2235 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2236 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2237 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2238 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002239 set wildmenu
2240
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002241 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002242 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002243 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002244 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002245 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002246 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002247 call assert_equal('"e ../../dir3/', @:)
2248 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2249 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002250 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002251 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002252 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002253 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002254 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002255 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2256 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002257
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002258 set wildmenu&
2259endfunc
2260
obcat71c6f7a2021-05-13 20:23:10 +02002261" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002262" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2263" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002264func Test_recalling_cmdline()
2265 CheckFeature cmdline_hist
2266
2267 let g:cmdlines = []
2268 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2269
2270 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002271 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2272 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2273 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2274 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002275 "\ TODO: {'name': 'debug', ...}
2276 \]
2277 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002278 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2279 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2280 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2281 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2282 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002283 \]
2284 let prefix = 'vi'
2285 for h in histories
2286 call histadd(h.name, 'vim')
2287 call histadd(h.name, 'virtue')
2288 call histadd(h.name, 'Virgo')
2289 call histadd(h.name, 'vogue')
2290 call histadd(h.name, 'emacs')
2291 for k in keypairs
2292 let g:cmdlines = []
2293 let keyseqs = h.enter
2294 \ .. prefix
2295 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2296 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2297 \ .. h.exit
2298 call feedkeys(keyseqs, 'xt')
2299 call histdel(h.name, -1) " delete the history added by feedkeys above
2300 let expect = k.prefixmatch
2301 \ ? ['virtue', 'vim', 'virtue', prefix]
2302 \ : ['emacs', 'vogue', 'emacs', prefix]
2303 call assert_equal(expect, g:cmdlines)
2304 endfor
2305 endfor
2306
2307 unlet g:cmdlines
2308 cunmap <Plug>(save-cmdline)
2309endfunc
2310
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002311func Test_cmd_map_cmdlineChanged()
2312 let g:log = []
2313 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002314 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002315 autocmd!
2316 autocmd CmdlineChanged : let g:log += [getcmdline()]
2317 augroup END
2318
2319 call feedkeys(":\<F1>\<CR>", 'xt')
2320 call assert_equal(['l', 'ls'], g:log)
2321
Bram Moolenaar796139a2021-05-18 21:38:45 +02002322 let @b = 'b'
2323 cnoremap <F1> a<C-R>b
2324 let g:log = []
2325 call feedkeys(":\<F1>\<CR>", 'xt')
2326 call assert_equal(['a', 'ab'], g:log)
2327
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002328 unlet g:log
2329 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002330 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002331 autocmd!
2332 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002333 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002334endfunc
2335
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002336" Test for the 'suffixes' option
2337func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002338 call writefile([], 'Xsuffile', 'D')
2339 call writefile([], 'Xsuffile.c', 'D')
2340 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002341 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002342 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2343 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2344 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2345 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002346 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002347 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2348 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2349 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2350 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002351 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002352 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2353 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2354 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2355 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002356 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002357 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002358 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2359 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002360endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002361
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002362" Test for using a popup menu for the command line completion matches
2363" (wildoptions=pum)
2364func Test_wildmenu_pum()
2365 CheckRunVimInTerminal
2366
2367 let commands =<< trim [CODE]
2368 set wildmenu
2369 set wildoptions=pum
2370 set shm+=I
2371 set noruler
2372 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002373
2374 func CmdCompl(a, b, c)
2375 return repeat(['aaaa'], 120)
2376 endfunc
2377 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002378
2379 func MyStatusLine() abort
2380 return 'status'
2381 endfunc
2382 func SetupStatusline()
2383 set statusline=%!MyStatusLine()
2384 set laststatus=2
2385 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002386
2387 func MyTabLine()
2388 return 'my tab line'
2389 endfunc
2390 func SetupTabline()
2391 set statusline=
2392 set tabline=%!MyTabLine()
2393 set showtabline=2
2394 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002395
2396 func DoFeedKeys()
2397 let &wildcharm = char2nr("\t")
2398 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2399 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002400 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002401 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002402
2403 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2404
2405 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2407
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002408 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002409 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002410 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2411
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002412 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002413 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002414 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2415
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002416 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002417 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002418 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2419
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002420 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002421 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002422 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2423
2424 " pressing <C-E> should end completion and go back to the original match
2425 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002426 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2427
2428 " pressing <C-Y> should select the current match and end completion
2429 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002430 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2431
2432 " With 'wildmode' set to 'longest,full', completing a match should display
2433 " the longest match, the wildmenu should not be displayed.
2434 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2435 call TermWait(buf)
2436 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002437 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2438
2439 " pressing <Tab> should display the wildmenu
2440 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002441 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2442
2443 " pressing <Tab> second time should select the next entry in the menu
2444 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002445 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2446
2447 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002448 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002449 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002450 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2451
2452 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002453 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2454
2455 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002456 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2457
2458 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002459 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002460 call writefile([], 'Xnamedir/XfileA')
2461 call writefile([], 'Xnamedir/XdirA/XfileB')
2462 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002463
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002464 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002465 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2466
2467 " Pressing <Right> on a directory name should go into that directory
2468 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002469 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2470
2471 " Pressing <Left> on a directory name should go to the parent directory
2472 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002473 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2474
2475 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002476 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002477 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002478 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2479
2480 " Pressing <C-D> when the popup menu is displayed should remove the popup
2481 " menu
2482 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002483 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2484
2485 " Pressing <S-Tab> should open the popup menu with the last entry selected
2486 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002487 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2488
2489 " Pressing <Esc> should close the popup menu and cancel the cmd line
2490 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002491 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2492
2493 " Typing a character when the popup is open, should close the popup
2494 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002495 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2496
2497 " When the popup is open, entering the cmdline window should close the popup
2498 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002499 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2500 call term_sendkeys(buf, ":q\<CR>")
2501
2502 " After the last popup menu item, <C-N> should show the original string
2503 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002504 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2505
2506 " Use the popup menu for the command name
2507 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002508 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2509
2510 " Pressing the left arrow should remove the popup menu
2511 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002512 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2513
2514 " Pressing <BS> should remove the popup menu and erase the last character
2515 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002516 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2517
2518 " Pressing <C-W> should remove the popup menu and erase the previous word
2519 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002520 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2521
2522 " Pressing <C-U> should remove the popup menu and erase the entire line
2523 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002524 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2525
2526 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2527 " the cmdline from history
2528 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002529 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2530
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002531 " Check "list" still works
2532 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2533 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002534 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2535 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002536 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2537
rbtnn68cc2b82022-02-09 11:55:47 +00002538 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002539 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002540 call writefile([], 'Xnamedir/あいう/abc')
2541 call writefile([], 'Xnamedir/あいう/xyz')
2542 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002543
2544 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002545 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002546 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2547
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002548 " Pressing <C-A> when the popup menu is displayed should list all the
2549 " matches and pressing a key after that should remove the popup menu
2550 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2551 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2552 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2553
2554 " Pressing <C-A> when the popup menu is displayed should list all the
2555 " matches and pressing <Left> after that should move the cursor
2556 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2557 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2558 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2559
2560 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2561 " should be displayed correctly on the screen.
2562 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2563 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2564
2565 " After using <C-A> to expand all the filename matches, pressing <Up>
2566 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002567 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002568 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2569 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2570 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2571
2572 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2573 " crash Vim
2574 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2575 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2576
Bram Moolenaar414acd32022-02-10 21:09:45 +00002577 " After removing the pum the command line is redrawn
2578 call term_sendkeys(buf, ":edit foo\<CR>")
2579 call term_sendkeys(buf, ":edit bar\<CR>")
2580 call term_sendkeys(buf, ":ls\<CR>")
2581 call term_sendkeys(buf, ":com\<Tab> ")
2582 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002583 call term_sendkeys(buf, "\<C-U>\<CR>")
2584
2585 " Esc still works to abort the command when 'statusline' is set
2586 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2587 call term_sendkeys(buf, ":si\<Tab>")
2588 call term_sendkeys(buf, "\<Esc>")
2589 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002590
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002591 " Esc still works to abort the command when 'tabline' is set
2592 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2593 call term_sendkeys(buf, ":si\<Tab>")
2594 call term_sendkeys(buf, "\<Esc>")
2595 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2596
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002597 " popup is cleared also when 'lazyredraw' is set
2598 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2599 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2600 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2601 call term_sendkeys(buf, "\<Esc>")
2602
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002603 " Pressing <PageDown> should scroll the menu downward
2604 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2605 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2606 call term_sendkeys(buf, "\<PageDown>")
2607 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2608 call term_sendkeys(buf, "\<PageDown>")
2609 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2610 call term_sendkeys(buf, "\<PageDown>")
2611 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2612 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2613 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2614
2615 " Pressing <PageUp> should scroll the menu upward
2616 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2617 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2618 call term_sendkeys(buf, "\<PageUp>")
2619 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2620 call term_sendkeys(buf, "\<PageUp>")
2621 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2622 call term_sendkeys(buf, "\<PageUp>")
2623 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2624
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002625 " pressing <C-E> to end completion should work in middle of the line too
2626 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2627 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2628 call term_sendkeys(buf, "\<C-E>")
2629 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2630
2631 " pressing <C-Y> should select the current match and end completion
2632 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2633 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2634
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002635 call term_sendkeys(buf, "\<C-U>\<CR>")
2636 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002637endfunc
2638
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002639" Test for wildmenumode() with the cmdline popup menu
2640func Test_wildmenumode_with_pum()
2641 set wildmenu
2642 set wildoptions=pum
2643 cnoremap <expr> <F2> wildmenumode()
2644 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2645 call assert_equal('"sign define10', @:)
2646 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2647 call assert_equal('"sign define jump list place undefine unplace0', @:)
2648 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2649 call assert_equal('"sign 0', @:)
2650 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2651 call assert_equal('"sign define0', @:)
2652 set nowildmenu wildoptions&
2653 cunmap <F2>
2654endfunc
2655
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002656func Test_wildmenu_with_pum_foldexpr()
2657 CheckRunVimInTerminal
2658
2659 let lines =<< trim END
2660 call setline(1, ['folded one', 'folded two', 'some more text'])
2661 func MyFoldText()
2662 return 'foo'
2663 endfunc
2664 set foldtext=MyFoldText() wildoptions=pum
2665 normal ggzfj
2666 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002667 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002668 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2669 call term_sendkeys(buf, ":set\<Tab>")
2670 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2671
2672 call term_sendkeys(buf, "\<Esc>")
2673 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2674
2675 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002676endfunc
2677
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002678" Test for opening the cmdline completion popup menu from the terminal window.
2679" The popup menu should be positioned correctly over the status line of the
2680" bottom-most window.
2681func Test_wildmenu_pum_from_terminal()
2682 CheckRunVimInTerminal
2683 let python = PythonProg()
2684 call CheckPython(python)
2685
2686 %bw!
2687 let cmds = ['set wildmenu wildoptions=pum']
2688 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2689 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002690 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002691 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2692 call term_sendkeys(buf, "\r\r\r")
2693 call term_wait(buf)
2694 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2695 call term_wait(buf)
2696 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2697 call term_wait(buf)
2698 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002699endfunc
2700
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002701func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002702 CheckRunVimInTerminal
2703
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002704 " Test odd wildchar interactions with pum. Make sure they behave properly
2705 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002706 let lines =<< trim END
2707 set wildoptions=pum
2708 set wildchar=<C-E>
2709 END
2710 call writefile(lines, 'XwildmenuTest', 'D')
2711 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2712
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002713 call term_sendkeys(buf, ":\<C-E>")
2714 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002715
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002716 " <C-E> being a wildchar takes priority over its original functionality
2717 call term_sendkeys(buf, "\<C-E>")
2718 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2719
2720 call term_sendkeys(buf, "\<Esc>")
2721 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2722
2723 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2724 " command-line, and we need to make sure to clean up properly.
2725 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2726 call term_sendkeys(buf, ":\<Esc>")
2727 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2728
2729 call term_sendkeys(buf, "\<Esc>")
2730 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2731
2732 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2733 " and we again need to make sure we clean up properly.
2734 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2735 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2736 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2737
2738 call term_sendkeys(buf, "\<C-N>")
2739 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2740
2741 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002742endfunc
2743
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002744" Test for completion after a :substitute command followed by a pipe (|)
2745" character
2746func Test_cmdline_complete_substitute()
2747 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2748 call assert_equal("\"s | \t", @:)
2749 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2750 call assert_equal("\"s/ | \t", @:)
2751 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2752 call assert_equal("\"s/one | \t", @:)
2753 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2754 call assert_equal("\"s/one/ | \t", @:)
2755 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2756 call assert_equal("\"s/one/two | \t", @:)
2757 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2758 call assert_equal('"s/one/two/ | chistory', @:)
2759 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2760 call assert_equal("\"s/one/two/g \t", @:)
2761 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2762 call assert_equal("\"s/one/two/g | chistory", @:)
2763 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2764 call assert_equal("\"s/one/t\\/ | \t", @:)
2765 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2766 call assert_equal('"s/one/t"o/ | chistory', @:)
2767 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2768 call assert_equal('"s/one/t|o/ | chistory', @:)
2769 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2770 call assert_equal("\"&\t", @:)
2771endfunc
2772
2773" Test for the :dlist command completion
2774func Test_cmdline_complete_dlist()
2775 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2776 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2777 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2778 call assert_equal("\"dlist 10 /pat/ \t", @:)
2779 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2780 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2781 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2782 call assert_equal("\"dlist 10 /pat\\\t", @:)
2783 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2784 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2785endfunc
2786
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002787" argument list (only for :argdel) fuzzy completion
2788func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002789 argadd change.py count.py charge.py
2790 set wildoptions&
2791 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2792 call assert_equal('"argdel cge', @:)
2793 set wildoptions=fuzzy
2794 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal('"argdel change.py charge.py', @:)
2796 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002797 set wildoptions&
2798endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002799
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002800" autocmd group name fuzzy completion
2801func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002802 set wildoptions&
2803 augroup MyFuzzyGroup
2804 augroup END
2805 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2806 call assert_equal('"augroup mfg', @:)
2807 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2808 call assert_equal('"augroup MyFuzzyGroup', @:)
2809 set wildoptions=fuzzy
2810 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2811 call assert_equal('"augroup MyFuzzyGroup', @:)
2812 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal('"augroup My*p', @:)
2814 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002815 set wildoptions&
2816endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002817
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818" buffer name fuzzy completion
2819func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002821 " Use a long name to reduce the risk of matching a random directory name
2822 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002823 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002824 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2825 call assert_equal('"b SRFWL', @:)
2826 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2827 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002828 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002829 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2830 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2831 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2832 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002833 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002834 set wildoptions&
2835endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002836
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837" buffer name (full path) fuzzy completion
2838func Test_fuzzy_completion_bufname_fullpath()
2839 CheckUnix
2840 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002841 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002842 edit Xcmd/Xstate/Xfile.js
2843 cd Xcmd/Xstate
2844 enew
2845 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2846 call assert_equal('"b CmdStateFile', @:)
2847 set wildoptions=fuzzy
2848 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2850 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002851 set wildoptions&
2852endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002853
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002854" :behave suboptions fuzzy completion
2855func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002856 set wildoptions&
2857 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal('"behave xm', @:)
2859 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2860 call assert_equal('"behave xterm', @:)
2861 set wildoptions=fuzzy
2862 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2863 call assert_equal('"behave xterm', @:)
2864 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2865 call assert_equal('"behave xt*m', @:)
2866 let g:Sline = ''
2867 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2868 call assert_equal('mswin', g:Sline)
2869 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870 set wildoptions&
2871endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002872
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002873" " colorscheme name fuzzy completion - NOT supported
2874" func Test_fuzzy_completion_colorscheme()
2875" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002876
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002877" built-in command name fuzzy completion
2878func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002879 set wildoptions&
2880 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2881 call assert_equal('"sbwin', @:)
2882 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2883 call assert_equal('"sbrewind', @:)
2884 set wildoptions=fuzzy
2885 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2886 call assert_equal('"sbrewind', @:)
2887 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002889 set wildoptions&
2890endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002891
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002892" " compiler name fuzzy completion - NOT supported
2893" func Test_fuzzy_completion_compiler()
2894" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002895
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002896" :cscope suboptions fuzzy completion
2897func Test_fuzzy_completion_cscope()
2898 CheckFeature cscope
2899 set wildoptions&
2900 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2901 call assert_equal('"cscope ret', @:)
2902 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2903 call assert_equal('"cscope reset', @:)
2904 set wildoptions=fuzzy
2905 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal('"cscope reset', @:)
2907 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2908 call assert_equal('"cscope re*t', @:)
2909 set wildoptions&
2910endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002911
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002912" :diffget/:diffput buffer name fuzzy completion
2913func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002914 new SomeBuffer
2915 diffthis
2916 new OtherBuffer
2917 diffthis
2918 set wildoptions&
2919 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"diffget sbuf', @:)
2921 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2922 call assert_equal('"diffput sbuf', @:)
2923 set wildoptions=fuzzy
2924 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2925 call assert_equal('"diffget SomeBuffer', @:)
2926 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2927 call assert_equal('"diffput SomeBuffer', @:)
2928 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002929 set wildoptions&
2930endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002931
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002932" " directory name fuzzy completion - NOT supported
2933" func Test_fuzzy_completion_dirname()
2934" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002935
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002936" environment variable name fuzzy completion
2937func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002938 set wildoptions&
2939 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2940 call assert_equal('"echo $VUT', @:)
2941 set wildoptions=fuzzy
2942 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2943 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944 set wildoptions&
2945endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002946
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947" autocmd event fuzzy completion
2948func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949 set wildoptions&
2950 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"autocmd BWout', @:)
2952 set wildoptions=fuzzy
2953 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002955 set wildoptions&
2956endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002957
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958" vim expression fuzzy completion
2959func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960 let g:PerPlaceCount = 10
2961 set wildoptions&
2962 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2963 call assert_equal('"let c = ppc', @:)
2964 set wildoptions=fuzzy
2965 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002967 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002968endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002969
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002970" " file name fuzzy completion - NOT supported
2971" func Test_fuzzy_completion_filename()
2972" endfunc
2973
2974" " files in path fuzzy completion - NOT supported
2975" func Test_fuzzy_completion_filesinpath()
2976" endfunc
2977
2978" " filetype name fuzzy completion - NOT supported
2979" func Test_fuzzy_completion_filetype()
2980" endfunc
2981
2982" user defined function name completion
2983func Test_fuzzy_completion_userdefined_func()
2984 set wildoptions&
2985 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2986 call assert_equal('"call Test_f_u_f', @:)
2987 set wildoptions=fuzzy
2988 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2989 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2990 set wildoptions&
2991endfunc
2992
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002993" <SNR> functions should be sorted to the end
2994func Test_fuzzy_completion_userdefined_snr_func()
2995 func s:Sendmail()
2996 endfunc
2997 func SendSomemail()
2998 endfunc
2999 func S1e2n3dmail()
3000 endfunc
3001 set wildoptions=fuzzy
3002 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003003 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003004 set wildoptions&
3005 delfunc s:Sendmail
3006 delfunc SendSomemail
3007 delfunc S1e2n3dmail
3008endfunc
3009
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003010" user defined command name completion
3011func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003012 set wildoptions&
3013 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3014 call assert_equal('"MsFeat', @:)
3015 set wildoptions=fuzzy
3016 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3017 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003018 set wildoptions&
3019endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003020
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003021" " :help tag fuzzy completion - NOT supported
3022" func Test_fuzzy_completion_helptag()
3023" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003024
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003025" highlight group name fuzzy completion
3026func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003027 set wildoptions&
3028 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal('"highlight SKey', @:)
3030 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal('"highlight SpecialKey', @:)
3032 set wildoptions=fuzzy
3033 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal('"highlight SpecialKey', @:)
3035 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003037 set wildoptions&
3038endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003039
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003040" :history suboptions fuzzy completion
3041func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003042 set wildoptions&
3043 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3044 call assert_equal('"history dg', @:)
3045 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal('"history search', @:)
3047 set wildoptions=fuzzy
3048 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal('"history debug', @:)
3050 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3051 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003052 set wildoptions&
3053endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003054
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003055" :language locale name fuzzy completion
3056func Test_fuzzy_completion_lang()
3057 CheckUnix
3058 set wildoptions&
3059 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal('"lang psx', @:)
3061 set wildoptions=fuzzy
3062 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3063 call assert_equal('"lang POSIX', @:)
3064 set wildoptions&
3065endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003066
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003067" :mapclear buffer argument fuzzy completion
3068func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003069 set wildoptions&
3070 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3071 call assert_equal('"mapclear buf', @:)
3072 set wildoptions=fuzzy
3073 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3074 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003075 set wildoptions&
3076endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003077
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003078" map name fuzzy completion
3079func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003080 " test regex completion works
3081 set wildoptions=fuzzy
3082 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003084 nmap <plug>MyLongMap :p<CR>
3085 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3087 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal("\"nmap MLM \t", @:)
3089 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"nmap <F2> one two \t", @:)
3091 " duplicate entries should be removed
3092 vmap <plug>MyLongMap :<C-U>#<CR>
3093 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3095 nunmap <plug>MyLongMap
3096 vunmap <plug>MyLongMap
3097 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal("\"nmap ABC\t", @:)
3099 " results should be sorted by best match
3100 nmap <Plug>format :
3101 nmap <Plug>goformat :
3102 nmap <Plug>TestFOrmat :
3103 nmap <Plug>fendoff :
3104 nmap <Plug>state :
3105 nmap <Plug>FendingOff :
3106 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3107 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3108 nunmap <Plug>format
3109 nunmap <Plug>goformat
3110 nunmap <Plug>TestFOrmat
3111 nunmap <Plug>fendoff
3112 nunmap <Plug>state
3113 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003114 set wildoptions&
3115endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003116
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003117" abbreviation fuzzy completion
3118func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003119 set wildoptions=fuzzy
3120 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"iabbr <nowait>", @:)
3122 iabbr WaitForCompletion WFC
3123 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"iabbr WaitForCompletion", @:)
3125 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003127
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003128 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003129 set wildoptions&
3130endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003131
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003132" menu name fuzzy completion
3133func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003134 CheckFeature menu
3135
3136 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003137 set wildoptions&
3138 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal('"menu pup', @:)
3140 set wildoptions=fuzzy
3141 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003143
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003144 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003145 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003146endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003147
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003148" :messages suboptions fuzzy completion
3149func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003150 set wildoptions&
3151 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal('"messages clr', @:)
3153 set wildoptions=fuzzy
3154 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003156 set wildoptions&
3157endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003158
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003159" :set option name fuzzy completion
3160func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003161 set wildoptions&
3162 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal('"set brkopt', @:)
3164 set wildoptions=fuzzy
3165 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal('"set breakindentopt', @:)
3167 set wildoptions&
3168 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal('"set fixendofline', @:)
3170 set wildoptions=fuzzy
3171 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003173 set wildoptions&
3174endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003175
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003176" :set <term_option>
3177func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003178 set wildoptions&
3179 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal('"set t_EC', @:)
3181 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal('"set <t_EC>', @:)
3183 set wildoptions=fuzzy
3184 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal('"set t_EC', @:)
3186 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003188 set wildoptions&
3189endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003190
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003191" " :packadd directory name fuzzy completion - NOT supported
3192" func Test_fuzzy_completion_packadd()
3193" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003194
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003195" " shell command name fuzzy completion - NOT supported
3196" func Test_fuzzy_completion_shellcmd()
3197" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003198
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003199" :sign suboptions fuzzy completion
3200func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003201 set wildoptions&
3202 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3203 call assert_equal('"sign ufe', @:)
3204 set wildoptions=fuzzy
3205 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003207 set wildoptions&
3208endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003209
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003210" :syntax suboptions fuzzy completion
3211func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003212 set wildoptions&
3213 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal('"syntax kwd', @:)
3215 set wildoptions=fuzzy
3216 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3217 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003218 set wildoptions&
3219endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003220
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003221" syntax group name fuzzy completion
3222func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003223 set wildoptions&
3224 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3225 call assert_equal('"syntax list mpar', @:)
3226 set wildoptions=fuzzy
3227 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003229 set wildoptions&
3230endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003231
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003232" :syntime suboptions fuzzy completion
3233func Test_fuzzy_completion_syntime()
3234 CheckFeature profile
3235 set wildoptions&
3236 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal('"syntime clr', @:)
3238 set wildoptions=fuzzy
3239 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal('"syntime clear', @:)
3241 set wildoptions&
3242endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003243
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003244" " tag name fuzzy completion - NOT supported
3245" func Test_fuzzy_completion_tagname()
3246" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003247
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003248" " tag name and file fuzzy completion - NOT supported
3249" func Test_fuzzy_completion_tagfile()
3250" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003251
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003252" " user names fuzzy completion - how to test this functionality?
3253" func Test_fuzzy_completion_username()
3254" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003255
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003256" user defined variable name fuzzy completion
3257func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003258 let g:SomeVariable=10
3259 set wildoptions&
3260 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3261 call assert_equal('"let SVar', @:)
3262 set wildoptions=fuzzy
3263 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003265 set wildoptions&
3266endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003267
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003268" Test for sorting the results by the best match
3269func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003270 %bw!
3271 command T123format :
3272 command T123goformat :
3273 command T123TestFOrmat :
3274 command T123fendoff :
3275 command T123state :
3276 command T123FendingOff :
3277 set wildoptions=fuzzy
3278 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3279 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3280 delcommand T123format
3281 delcommand T123goformat
3282 delcommand T123TestFOrmat
3283 delcommand T123fendoff
3284 delcommand T123state
3285 delcommand T123FendingOff
3286 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003287 set wildoptions&
3288endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003289
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003290" Test for fuzzy completion of a command with lower case letters and a number
3291func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003292 command Foo2Bar :
3293 set wildoptions=fuzzy
3294 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3295 call assert_equal('"Foo2Bar', @:)
3296 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3297 call assert_equal('"Foo2Bar', @:)
3298 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3299 call assert_equal('"Foo2Bar', @:)
3300 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003301 set wildoptions&
3302endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003303
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003304" Test for command completion for a command starting with 'k'
3305func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003306 command KillKillKill :
3307 set wildoptions&
3308 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal("\"killkill\<Tab>", @:)
3310 set wildoptions=fuzzy
3311 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3312 call assert_equal('"KillKillKill', @:)
3313 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003314 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003315endfunc
3316
3317" Test for fuzzy completion for user defined custom completion function
3318func Test_fuzzy_completion_custom_func()
3319 func Tcompl(a, c, p)
3320 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3321 endfunc
3322 command -nargs=* -complete=custom,Tcompl Fuzzy :
3323 set wildoptions&
3324 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal("\"Fuzzy format", @:)
3326 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3327 call assert_equal("\"Fuzzy xy", @:)
3328 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3329 call assert_equal("\"Fuzzy ttt", @:)
3330 set wildoptions=fuzzy
3331 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3333 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3334 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3335 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3336 call assert_equal("\"Fuzzy xy", @:)
3337 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3338 call assert_equal("\"Fuzzy TestFOrmat", @:)
3339 delcom Fuzzy
3340 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003341endfunc
3342
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003343" Test for fuzzy completion in the middle of a cmdline instead of at the end
3344func Test_fuzzy_completion_in_middle()
3345 set wildoptions=fuzzy
3346 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3347 call assert_equal("\"set wildchar wildcharm wrap", @:)
3348
3349 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3350 call assert_equal("\"args ++encoding= zz", @:)
3351 set wildoptions&
3352endfunc
3353
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003354" Test for :breakadd argument completion
3355func Test_cmdline_complete_breakadd()
3356 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3357 call assert_equal("\"breakadd expr file func here", @:)
3358 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal("\"breakadd expr", @:)
3360 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3361 call assert_equal("\"breakadd expr", @:)
3362 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3363 call assert_equal("\"breakadd here", @:)
3364 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3365 call assert_equal("\"breakadd here", @:)
3366 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3367 call assert_equal("\"breakadd abc", @:)
3368 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3369 let l = getcompletion('not', 'breakpoint')
3370 call assert_equal([], l)
3371
3372 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003373 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003374 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3375 call assert_equal("\"breakadd file Xscript", @:)
3376 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3377 call assert_equal("\"breakadd file Xscript", @:)
3378 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3379 call assert_equal("\"breakadd file 20 Xscript", @:)
3380 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3381 call assert_equal("\"breakadd file 20 Xscript", @:)
3382 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3383 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3384 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3385 call assert_equal("\"breakadd file 20\t", @:)
3386 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3387 call assert_equal("\"breakadd file 20x\t", @:)
3388 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3389 call assert_equal("\"breakadd file Xscript ", @:)
3390 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3391 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003392
3393 " Test for :breakadd func [lnum] <function>
3394 func Xbreak_func()
3395 endfunc
3396 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3397 call assert_equal("\"breakadd func Xbreak_func", @:)
3398 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal("\"breakadd func Xbreak_func", @:)
3400 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3402 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3403 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3404 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3405 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3406 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3407 call assert_equal("\"breakadd func 20\t", @:)
3408 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3409 call assert_equal("\"breakadd func 20x\t", @:)
3410 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3411 call assert_equal("\"breakadd func Xbreak_func ", @:)
3412 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3413 call assert_equal("\"breakadd func X1B2C3", @:)
3414 delfunc Xbreak_func
3415
3416 " Test for :breakadd expr <expression>
3417 let g:Xtest_var = 10
3418 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3419 call assert_equal("\"breakadd expr Xtest_var", @:)
3420 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3421 call assert_equal("\"breakadd expr Xtest_var", @:)
3422 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3423 call assert_equal("\"breakadd expr Xtest_var ", @:)
3424 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3425 call assert_equal("\"breakadd expr X1B2C3", @:)
3426 unlet g:Xtest_var
3427
3428 " Test for :breakadd here
3429 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3430 call assert_equal("\"breakadd here Xtest", @:)
3431 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal("\"breakadd here Xtest", @:)
3433 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal("\"breakadd here ", @:)
3435endfunc
3436
3437" Test for :breakdel argument completion
3438func Test_cmdline_complete_breakdel()
3439 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3440 call assert_equal("\"breakdel file func here", @:)
3441 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3442 call assert_equal("\"breakdel file", @:)
3443 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3444 call assert_equal("\"breakdel file", @:)
3445 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3446 call assert_equal("\"breakdel here", @:)
3447 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3448 call assert_equal("\"breakdel here", @:)
3449 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3450 call assert_equal("\"breakdel abc", @:)
3451
3452 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003453 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003454 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3455 call assert_equal("\"breakdel file Xscript", @:)
3456 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3457 call assert_equal("\"breakdel file Xscript", @:)
3458 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3459 call assert_equal("\"breakdel file 20 Xscript", @:)
3460 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3461 call assert_equal("\"breakdel file 20 Xscript", @:)
3462 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3463 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3464 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3465 call assert_equal("\"breakdel file 20\t", @:)
3466 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3467 call assert_equal("\"breakdel file 20x\t", @:)
3468 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3469 call assert_equal("\"breakdel file Xscript ", @:)
3470 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3471 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003472
3473 " Test for :breakdel func [lnum] <function>
3474 func Xbreak_func()
3475 endfunc
3476 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3477 call assert_equal("\"breakdel func Xbreak_func", @:)
3478 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3479 call assert_equal("\"breakdel func Xbreak_func", @:)
3480 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3481 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3482 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3483 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3484 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3485 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3486 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3487 call assert_equal("\"breakdel func 20\t", @:)
3488 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3489 call assert_equal("\"breakdel func 20x\t", @:)
3490 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3491 call assert_equal("\"breakdel func Xbreak_func ", @:)
3492 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3493 call assert_equal("\"breakdel func X1B2C3", @:)
3494 delfunc Xbreak_func
3495
3496 " Test for :breakdel here
3497 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3498 call assert_equal("\"breakdel here Xtest", @:)
3499 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3500 call assert_equal("\"breakdel here Xtest", @:)
3501 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3502 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003503endfunc
3504
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003505" Test for :scriptnames argument completion
3506func Test_cmdline_complete_scriptnames()
3507 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003508 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003509 source Xa1b2c3.vim
3510 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3511 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3512 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3513 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3514 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3515 call assert_equal("\"script b2c3", @:)
3516 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3517 call assert_match("\"script 2\<Tab>$", @:)
3518 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3519 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3520 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3521 call assert_equal("\"script ", @:)
3522 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3523 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3524 new
3525 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3526 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3527 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003528 set wildmenu&
3529endfunc
3530
Bram Moolenaard8893442022-05-06 20:38:47 +01003531" this was going over the end of IObuff
3532func Test_report_error_with_composing()
3533 let caught = 'no'
3534 try
3535 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3536 catch /E492:/
3537 let caught = 'yes'
3538 endtry
3539 call assert_equal('yes', caught)
3540endfunc
3541
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003542" Test for expanding 2-letter and 3-letter :substitute command arguments.
3543" These commands don't accept an argument.
3544func Test_cmdline_complete_substitute_short()
3545 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3546 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3547 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3548 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3549 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3550 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3551 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3552 endfor
3553endfunc
3554
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003555" Test for :! shell command argument completion
3556func Test_cmdline_complete_bang_cmd_argument()
3557 set wildoptions=fuzzy
3558 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3559 call assert_equal('"!vim test_cmdline.vim', @:)
3560 set wildoptions&
3561 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3562 call assert_equal('"!vim test_cmdline.vim', @:)
3563endfunc
3564
zeertzjq961b2e52023-04-17 15:53:24 +01003565func Call_cmd_funcs()
3566 return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003567endfunc
3568
3569func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003570 call assert_equal(0, getcmdpos())
3571 call assert_equal(0, getcmdscreenpos())
3572 call assert_equal('', getcmdcompltype())
3573
3574 cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
3575 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
3576 call assert_equal("\"let a[6, 7, 'var']", @:)
3577 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
3578 call assert_equal("\"quit [6, 7, '']", @:)
3579 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
3580 call assert_equal("\"nosuchcommand [15, 16, '']", @:)
3581 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003582endfunc
3583
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003584func Test_recursive_register()
3585 let @= = ''
3586 silent! ?e/
3587 let caught = 'no'
3588 try
3589 normal //
3590 catch /E169:/
3591 let caught = 'yes'
3592 endtry
3593 call assert_equal('yes', caught)
3594endfunc
3595
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003596func Test_long_error_message()
3597 " the error should be truncated, not overrun IObuff
3598 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3599endfunc
3600
zeertzjq6791adc2022-07-26 20:42:25 +01003601func Test_cmdline_redraw_tabline()
3602 CheckRunVimInTerminal
3603
3604 let lines =<< trim END
3605 set showtabline=2
3606 autocmd CmdlineEnter * set tabline=foo
3607 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003608 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003609 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3610 call term_sendkeys(buf, ':')
3611 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3612
3613 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003614endfunc
3615
zeertzjqb82a2ab2022-08-21 14:33:57 +01003616func Test_wildmenu_pum_disable_while_shown()
3617 set wildoptions=pum
3618 set wildmenu
3619 cnoremap <F2> <Cmd>set nowildmenu<CR>
3620 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3621 call assert_equal(0, pumvisible())
3622 cunmap <F2>
3623 set wildoptions& wildmenu&
3624endfunc
3625
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003626func Test_setcmdline()
3627 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003628 call assert_equal(0, setcmdline(test_null_string()))
3629 call assert_equal('', getcmdline())
3630 call assert_equal(1, getcmdpos())
3631
3632 call assert_equal(0, setcmdline(''[: -1]))
3633 call assert_equal('', getcmdline())
3634 call assert_equal(1, getcmdpos())
3635
zeertzjq54acb902022-08-29 16:21:25 +01003636 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003637 call assert_equal(0, setcmdline(a:text))
3638 call assert_equal(a:text, getcmdline())
3639 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003640 call assert_equal(getcmdtype(), g:cmdtype)
3641 unlet g:cmdtype
3642 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003643
3644 call assert_equal(0, setcmdline(a:text, a:pos))
3645 call assert_equal(a:text, getcmdline())
3646 call assert_equal(a:pos, getcmdpos())
3647
3648 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003649 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3650 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003651
3652 return ''
3653 endfunc
3654
3655 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3656 call assert_equal('set rtp?', @:)
3657
zeertzjq54acb902022-08-29 16:21:25 +01003658 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3659 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3660 call assert_equal('foo', g:str)
3661 unlet g:str
3662
3663 delfunc SetText
3664
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003665 " setcmdline() returns 1 when not editing the command line.
3666 call assert_equal(1, 'foo'->setcmdline())
3667
3668 " Called in custom function
3669 func CustomComplete(A, L, P)
3670 call assert_equal(0, setcmdline("DoCmd "))
3671 return "January\nFebruary\nMars\n"
3672 endfunc
3673
3674 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3675 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3676 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003677 delcom DoCmd
3678 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003679
3680 " Called in <expr>
3681 cnoremap <expr>a setcmdline('let foo=')
3682 call feedkeys(":a\<CR>", 'tx')
3683 call assert_equal('let foo=0', @:)
3684 cunmap a
3685endfunc
3686
Sean Dewarfc8a6012023-04-17 16:41:20 +01003687func Test_rulerformat_position()
3688 CheckScreendump
3689
3690 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3691 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3692 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3693 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3694 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3695
3696 " clean up
3697 call StopVimInTerminal(buf)
3698endfunc
3699
zeertzjqe4c79d32023-08-15 22:41:53 +02003700func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003701 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003702
zeertzjqe4c79d32023-08-15 22:41:53 +02003703 call assert_equal(getcompletion('', 'cmdline'),
3704 \ getcompletion('TestCompletion ', 'cmdline'))
3705 call assert_equal(['<buffer>'],
3706 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3707
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003708 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003709endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003710
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003711func Test_custom_completion()
3712 func CustomComplete1(lead, line, pos)
3713 return "a\nb\nc"
3714 endfunc
3715 func CustomComplete2(lead, line, pos)
3716 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3717 endfunc
3718 func Check_custom_completion()
3719 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3720 return ''
3721 endfunc
3722 func Check_customlist_completion()
3723 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3724 return ''
3725 endfunc
3726
3727 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3728 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3729
3730 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3731 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3732
3733 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3734 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3735
3736 call assert_equal(getcompletion('', 'custom,CustomComplete1'), ['a', 'b', 'c'])
3737 call assert_equal(getcompletion('', 'customlist,CustomComplete2'), ['a', 'b'])
3738 call assert_equal(getcompletion('b', 'customlist,CustomComplete2'), ['b'])
3739
3740 delcom Test1
3741 delcom Test2
3742
3743 delfunc CustomComplete1
3744 delfunc CustomComplete2
3745 delfunc Check_custom_completion
3746 delfunc Check_customlist_completion
3747endfunc
3748
zeertzjq28a23602023-09-29 19:58:35 +02003749func Test_custom_completion_with_glob()
3750 func TestGlobComplete(A, L, P)
3751 return split(glob('Xglob*'), "\n")
3752 endfunc
3753
3754 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3755 call writefile([], 'Xglob1', 'D')
3756 call writefile([], 'Xglob2', 'D')
3757
3758 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3759 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3760
3761 delcommand TestGlobComplete
3762 delfunc TestGlobComplete
3763endfunc
3764
Christian Brabandt8610f742024-01-12 17:34:40 +01003765func Test_window_size_stays_same_after_changing_cmdheight()
3766 set laststatus=2
3767 let expected = winheight(0)
3768 function! Function_name() abort
3769 call feedkeys(":"..repeat('x', &columns), 'x')
3770 let &cmdheight=2
3771 let &cmdheight=1
3772 redraw
3773 endfunction
3774 call Function_name()
3775 call assert_equal(expected, winheight(0))
3776endfunc
3777
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01003778" verify that buffer-completion finds all buffer names matching a pattern
3779func Test_buffer_completion()
3780 " should return empty list
3781 call assert_equal([], getcompletion('', 'buffer'))
3782
3783 call mkdir('Xbuf_complete', 'R')
3784 e Xbuf_complete/Foobar.c
3785 e Xbuf_complete/MyFoobar.c
3786 e AFoobar.h
3787 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
3788
3789 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
3790 call assert_equal(expected, getcompletion('Foo', 'buffer'))
3791 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
3792 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
3793endfunc
3794
Bram Moolenaar309976e2019-12-05 18:16:33 +01003795" vim: shiftwidth=2 sts=2 expandtab