blob: c5a7d85c76e200c18028ec588dd362949ed47973 [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
zeertzjq1830e782025-03-13 20:29:13 +0100214func Test_wildmenu_with_input_func()
215 CheckScreendump
216
217 let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8})
218
219 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
220 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {})
221 call term_sendkeys(buf, "ech\<Tab>")
222 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {})
223 call term_sendkeys(buf, "\<Space>")
224 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {})
225 call term_sendkeys(buf, "bufn\<Tab>")
226 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {})
227 call term_sendkeys(buf, "\<CR>")
228
229 call term_sendkeys(buf, ":set wildoptions+=pum\<CR>")
230
231 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
232 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {})
233 call term_sendkeys(buf, "ech\<Tab>")
234 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {})
235 call term_sendkeys(buf, "\<Space>")
236 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {})
237 call term_sendkeys(buf, "bufn\<Tab>")
238 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {})
239 call term_sendkeys(buf, "\<CR>")
240
241 " clean up
242 call StopVimInTerminal(buf)
243endfunc
244
Bram Moolenaara653e532022-04-19 11:38:24 +0100245func Test_redraw_in_autocmd()
246 CheckScreendump
247
248 let lines =<< trim END
249 set cmdheight=2
250 autocmd CmdlineChanged * redraw
251 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100252 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100253
254 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
255 call term_sendkeys(buf, ":for i in range(3)\<CR>")
256 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
257
258 call term_sendkeys(buf, "let i =")
259 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
260
261 " clean up
262 call term_sendkeys(buf, "\<CR>")
263 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100264endfunc
265
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100266func Test_redrawstatus_in_autocmd()
267 CheckScreendump
268
269 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100270 set laststatus=2
271 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100272 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100273 END
274 call writefile(lines, 'XTest_redrawstatus', 'D')
275
276 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100277 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100278 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
279 call term_sendkeys(buf, ":foobar")
280 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100281 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100282 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100283 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100284 " with cmdheight=1 messages have scrolled when typing :endfor
285 call term_sendkeys(buf, "\<CR>:endfor")
286 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
287 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
288 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
289 call term_sendkeys(buf, ":for in in range(3)")
290 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
291 call term_sendkeys(buf, "\<CR>:endfor")
292 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100293
294 " clean up
295 call term_sendkeys(buf, "\<CR>")
296 call StopVimInTerminal(buf)
297endfunc
298
Bram Moolenaarf797e302022-08-11 13:17:30 +0100299func Test_changing_cmdheight()
300 CheckScreendump
301
302 let lines =<< trim END
303 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100304 func EchoOne()
305 set laststatus=2 cmdheight=1
306 echo 'foo'
307 echo 'bar'
308 set cmdheight=2
309 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 func EchoTwo()
311 set laststatus=2
312 set cmdheight=5
313 echo 'foo'
314 echo 'bar'
315 set cmdheight=1
316 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100317 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100318 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100319
320 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
321 call term_sendkeys(buf, ":resize -3\<CR>")
322 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
323
Luuk van Baale15cbc12025-01-04 17:18:08 +0100324 " :resize now also changes 'cmdheight' accordingly
325 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100326 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
327
328 " using more space moves the status line up
329 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
330 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
331
332 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100333 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100334 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
335
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000336 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100337 call term_sendkeys(buf, ":resize -1\<CR>")
338 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
339 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
340
Bram Moolenaar0816f472022-10-05 15:42:32 +0100341 " setting 'cmdheight' works after outputting two messages
342 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
343 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
344
Luuk van Baalc97e8692025-01-06 18:58:21 +0100345 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100346 call term_sendkeys(buf, ":call EchoOne()\<CR>")
347 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
348
Luuk van Baalc97e8692025-01-06 18:58:21 +0100349 " window commands do not reduce 'cmdheight' to value lower than :set by user
350 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
351 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
352
Bram Moolenaarf797e302022-08-11 13:17:30 +0100353 " clean up
354 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100355endfunc
356
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100357func Test_cmdheight_tabline()
358 CheckScreendump
359
360 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
361 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
362
363 " clean up
364 call StopVimInTerminal(buf)
365endfunc
366
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100367func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100368 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
369 call assert_equal('"map <unique> <silent>', getreg(':'))
370 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
371 call assert_equal('"map <script> <unique>', getreg(':'))
372 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
373 call assert_equal('"map <expr> <script>', getreg(':'))
374 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
375 call assert_equal('"map <buffer> <expr>', getreg(':'))
376 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal('"map <nowait> <buffer>', getreg(':'))
378 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
379 call assert_equal('"map <special> <nowait>', getreg(':'))
380 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
381 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200382
Bram Moolenaar1776a282019-05-03 16:05:41 +0200383 map <Middle>x middle
384
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200385 map ,f commaf
386 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200387 map <Left> left
388 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200389 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"map ,f', getreg(':'))
391 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200393 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"map <Left>', getreg(':'))
395 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200396 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000397 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200399 unmap ,f
400 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200401 unmap <Left>
402 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200403
zeertzjqc3a26c62023-02-17 16:40:20 +0000404 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200405 map <Left> left
406 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
407 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200408 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200409 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000410 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
411 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200412 unmap <Left>
413
414 set cpo+=<
415 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200416 exe "set t_k6=\<Esc>[17~"
417 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200418 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
419 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200420 if !has('gui_running')
421 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal("\"map <F6>x", getreg(':'))
423 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200424 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200425 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200426 set cpo-=<
427
428 set cpo+=B
429 map <Left> left
430 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
431 call assert_equal('"map <Left>', getreg(':'))
432 unmap <Left>
433 set cpo-=B
434
435 set cpo+=k
436 map <Left> left
437 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"map <Left>', getreg(':'))
439 unmap <Left>
440 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200441
Bram Moolenaar531be472020-09-23 22:38:05 +0200442 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
443
Bram Moolenaar1776a282019-05-03 16:05:41 +0200444 unmap <Middle>x
445 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100446endfunc
447
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100448func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100449 hi Aardig ctermfg=green
450 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000451 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100452 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
453 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000454 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
455 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100456endfunc
457
458func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100459 hi Aardig ctermfg=green
460 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
461 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100462
463 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200464 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
465 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100466 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
467 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100468 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
469 call assert_equal('"hi default link Aardig', getreg(':'))
470
471 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100472 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
473 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100474 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
475 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200476 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100477 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
478 " hi link accepts up to two parameters
479 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
480 call assert_equal('"hi link', getreg(':'))
481 call assert_equal('"hi link', getreg(':'))
482 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
483 call assert_equal('"hi link Aardig', getreg(':'))
484 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
485 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
486 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
487 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
488 " hi link will complete to "NONE" for second parameter
489 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
490 call assert_equal("\"hi link NonText", getreg(':'))
491 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
492 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200493
494 " A cleared group does not show up in completions.
495 hi Anders ctermfg=green
496 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
497 hi clear Aardig
498 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
499 hi clear Anders
500 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100501endfunc
502
Bram Moolenaar75e15672020-06-28 13:10:22 +0200503" Test for command-line expansion of "hi Ni " (easter egg)
504func Test_highlight_easter_egg()
505 call test_override('ui_delay', 1)
506 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
507 call assert_equal("\"hi Ni \<Tab>", @:)
508 call test_override('ALL', 0)
509endfunc
510
Yee Cheng China7b81202025-02-23 09:32:47 +0100511func Test_highlight_group_completion()
512 " Test completing keys
513 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
514 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
515 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
516 set wildoptions+=fuzzy
517 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
518 set wildoptions-=fuzzy
519
520 " Test completing the current value
521 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100522 hi AlmostEmpty term=bold
Yee Cheng China7b81202025-02-23 09:32:47 +0100523 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
524 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
525 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
526 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
527 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
528
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100529 " highlight group exists, but no value was set. Should not complete to
530 " existing value
531 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
532 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
533 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
534 call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
535
536 " "bold,underline" is unique and creates an extra item. "undercurl" isn't
537 " and should be de-duplicated.
Yee Cheng China7b81202025-02-23 09:32:47 +0100538 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
539 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
540
541 " don't complete original value if we have user input already, similar to
542 " behavior in :set <option>=<pattern>
543 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
544 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
545
546 " start/stop do not fill their current value now as they are more
547 " complicated
548 hi FooBar start=123 stop=234
549 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
550 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
551
552 if has("gui") || has("termguicolors")
553 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
554 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
555 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
556 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
557 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
558
559 " Check that existing value is de-duplicated and doesn't show up later
560 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100561
562 " highlight group exists, but no value was set. Should not complete to
563 " existing value
564 call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
565 call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
566 call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
567 call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
Yee Cheng China7b81202025-02-23 09:32:47 +0100568 endif
569
570 " Test completing attributes
571 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
572 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
573 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
574 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
575 if has("gui") || has("termguicolors")
576 set wildoptions+=fuzzy
577 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
578 set wildoptions-=fuzzy
579 endif
580
581 " Test completing cterm colors
582 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
583 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
584 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
585 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
586 set wildoptions+=fuzzy
587 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
588 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
589 set wildoptions-=fuzzy
590
591 " Test completing gui colors
592 if has("gui") || has("termguicolors")
593 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
594 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
595 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
596 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
597 set wildoptions=fuzzy
598 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
599 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
600 set wildoptions-=fuzzy
601
602 " Test pruning bad color names with space. Vim doesn't support them.
603 let v:colornames['foobar with space'] = '#123456'
604 let v:colornames['foobarwithoutspace'] = '#234567'
605 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
606
607 " Test specialized sorting. First few items are special values that
608 " go first, after that it's a sorted list of color names.
609 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
610 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
611 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
612 call assert_equal(len(gui_colors_no_space), len(completed_colors))
613 call assert_equal(sort(copy(completed_colors)), completed_colors)
614
615 " Test that the specialized sorting still works if we have some pattern matches
616 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
617 call assert_equal(sort(copy(completed_colors)), completed_colors)
618 call assert_equal('aliceblue', completed_colors[0])
619 endif
620endfunc
621
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200622func Test_getcompletion()
623 let groupcount = len(getcompletion('', 'event'))
624 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200625 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200626 call assert_true(matchcount > 0)
627 call assert_true(groupcount > matchcount)
628
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200629 if has('menu')
630 source $VIMRUNTIME/menu.vim
631 let matchcount = len(getcompletion('', 'menu'))
632 call assert_true(matchcount > 0)
633 call assert_equal(['File.'], getcompletion('File', 'menu'))
634 call assert_true(matchcount > 0)
635 let matchcount = len(getcompletion('File.', 'menu'))
636 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000637 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200638 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200639
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640 let l = getcompletion('v:n', 'var')
641 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200642 let l = getcompletion('v:notexists', 'var')
643 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200644
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200645 args a.c b.c
646 let l = getcompletion('', 'arglist')
647 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000648 let l = getcompletion('a.', 'buffer')
649 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200650 %argdelete
651
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200652 let l = getcompletion('', 'augroup')
653 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200654 let l = getcompletion('blahblah', 'augroup')
655 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200656
657 let l = getcompletion('', 'behave')
658 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200659 let l = getcompletion('not', 'behave')
660 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200661
662 let l = getcompletion('', 'color')
663 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200664 let l = getcompletion('dirty', 'color')
665 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200666
667 let l = getcompletion('', 'command')
668 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200669 let l = getcompletion('awake', 'command')
670 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200671
672 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200673 call assert_true(index(l, 'samples/') >= 0)
674 let l = getcompletion('NoMatch', 'dir')
675 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200676
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100677 if glob('~/*') !=# ''
678 let l = getcompletion('~/', 'dir')
679 call assert_true(l[0][0] ==# '~')
680 endif
681
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200682 let l = getcompletion('exe', 'expression')
683 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200684 let l = getcompletion('kill', 'expression')
685 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200686
Christian Brabandta3422aa2025-04-23 21:04:24 +0200687 let l = getcompletion('', 'filetypecmd')
688 call assert_equal(["indent", "off", "on", "plugin"], l)
689 let l = getcompletion('not', 'filetypecmd')
690 call assert_equal([], l)
691 let l = getcompletion('o', 'filetypecmd')
692 call assert_equal(['off', 'on'], l)
693
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200694 let l = getcompletion('tag', 'function')
695 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200696 let l = getcompletion('paint', 'function')
697 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200698
Kota Kato90c23532023-01-18 15:27:38 +0000699 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000700 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000701 let l = getcompletion('ruby', 'function')
702 call assert_equal([], l)
703 endif
704
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200705 let Flambda = {-> 'hello'}
706 let l = getcompletion('', 'function')
707 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200708 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200709
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200710 let l = getcompletion('run', 'file')
711 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200712 let l = getcompletion('walk', 'file')
713 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200714 set wildignore=*.vim
715 let l = getcompletion('run', 'file', 1)
716 call assert_true(index(l, 'runtest.vim') < 0)
717 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000718 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100719 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000720 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
721 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200722
723 let l = getcompletion('ha', 'filetype')
724 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200725 let l = getcompletion('horse', 'filetype')
726 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200727
Doug Kearns81642d92024-01-04 22:37:44 +0100728 if has('keymap')
729 let l = getcompletion('acc', 'keymap')
730 call assert_true(index(l, 'accents') >= 0)
731 let l = getcompletion('nullkeymap', 'keymap')
732 call assert_equal([], l)
733 endif
734
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200735 let l = getcompletion('z', 'syntax')
736 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200737 let l = getcompletion('emacs', 'syntax')
738 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200739
740 let l = getcompletion('jikes', 'compiler')
741 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200742 let l = getcompletion('break', 'compiler')
743 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200744
745 let l = getcompletion('last', 'help')
746 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200747 let l = getcompletion('giveup', 'help')
748 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200749
750 let l = getcompletion('time', 'option')
751 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200752 let l = getcompletion('space', 'option')
753 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200754
755 let l = getcompletion('er', 'highlight')
756 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200757 let l = getcompletion('dark', 'highlight')
758 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200759
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200760 let l = getcompletion('', 'messages')
761 call assert_true(index(l, 'clear') >= 0)
762 let l = getcompletion('not', 'messages')
763 call assert_equal([], l)
764
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200765 let l = getcompletion('', 'mapclear')
766 call assert_true(index(l, '<buffer>') >= 0)
767 let l = getcompletion('not', 'mapclear')
768 call assert_equal([], l)
769
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200770 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200771 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200772 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
773 let root = has('win32') ? 'C:\\' : '/'
774 let l = getcompletion(root, 'shellcmd')
775 let expected = map(filter(glob(root . '*', 0, 1),
776 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
777 call assert_equal(expected, l)
778
Bram Moolenaarb650b982016-08-05 20:35:13 +0200779 if has('cscope')
780 let l = getcompletion('', 'cscope')
781 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
782 call assert_equal(cmds, l)
783 " using cmdline completion must not change the result
784 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
785 let l = getcompletion('', 'cscope')
786 call assert_equal(cmds, l)
787 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
788 let l = getcompletion('find ', 'cscope')
789 call assert_equal(keys, l)
790 endif
791
Bram Moolenaar7522f692016-08-06 14:12:50 +0200792 if has('signs')
793 sign define Testing linehl=Comment
794 let l = getcompletion('', 'sign')
795 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
796 call assert_equal(cmds, l)
797 " using cmdline completion must not change the result
798 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
799 let l = getcompletion('', 'sign')
800 call assert_equal(cmds, l)
801 let l = getcompletion('list ', 'sign')
802 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000803 let l = getcompletion('de*', 'sign')
804 call assert_equal(['define'], l)
805 let l = getcompletion('p?', 'sign')
806 call assert_equal(['place'], l)
807 let l = getcompletion('j.', 'sign')
808 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200809 endif
810
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200811 " Command line completion tests
812 let l = getcompletion('cd ', 'cmdline')
813 call assert_true(index(l, 'samples/') >= 0)
814 let l = getcompletion('cd NoMatch', 'cmdline')
815 call assert_equal([], l)
816 let l = getcompletion('let v:n', 'cmdline')
817 call assert_true(index(l, 'v:null') >= 0)
818 let l = getcompletion('let v:notexists', 'cmdline')
819 call assert_equal([], l)
820 let l = getcompletion('call tag', 'cmdline')
821 call assert_true(index(l, 'taglist(') >= 0)
822 let l = getcompletion('call paint', 'cmdline')
823 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200824 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
825 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200826
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100827 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000828 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100829 return "oneA\noneB\noneC"
830 endfunc
831 command -nargs=1 -complete=custom,T MyCmd
832 let l = getcompletion('MyCmd ', 'cmdline')
833 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000834 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100835
836 delcommand MyCmd
837 delfunc T
ii144785fe02021-11-21 12:13:56 +0000838 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100839
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200840 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200841 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
842 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200843 if has('cmdline_hist')
844 call add(names, 'history')
845 endif
846 if has('gettext')
847 call add(names, 'locale')
848 endif
849 if has('profile')
850 call add(names, 'syntime')
851 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200852
853 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100854 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200855
856 for name in names
857 let matchcount = len(getcompletion('', name))
858 call assert_true(matchcount >= 0, 'No matches for ' . name)
859 endfor
860
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200861 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200862
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000863 edit a~b
864 enew
865 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
866 bw a~b
867
868 if has('unix')
869 edit Xtest\
870 enew
871 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
872 bw Xtest\
873 endif
874
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100875 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200876 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100877 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200878endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200879
Hirohito Higashi96b3ef22025-07-05 15:31:23 +0200880func Test_getcompletiontype()
881 call assert_fails('call getcompletiontype()', 'E119:')
882 call assert_fails('call getcompletiontype({})', 'E1174:')
zeertzjqe2c0f812025-07-06 20:26:56 +0200883 call assert_equal('command', getcompletiontype(''))
884 call assert_equal('', getcompletiontype('dummy '))
885 call assert_equal('', getcompletiontype('ls '))
886 call assert_equal('dir_in_path', getcompletiontype('cd '))
887 call assert_equal('var', getcompletiontype('let v:n'))
888 call assert_equal('function', getcompletiontype('call tag'))
889 call assert_equal('help', getcompletiontype('help '))
Hirohito Higashi96b3ef22025-07-05 15:31:23 +0200890endfunc
891
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000892func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000893 " Get a dialog in the GUI
894 CheckNotGui
895
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000896 " This was using uninitialized memory.
897 let lines =<< trim END
898 set verbose=6
899 norm @=ٷ
900 qall!
901 END
902 call writefile(lines, 'XmultiScript', 'D')
903 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
904endfunc
905
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000906" Test for getcompletion() with "fuzzy" in 'wildoptions'
907func Test_getcompletion_wildoptions()
908 let save_wildoptions = &wildoptions
909 set wildoptions&
910 let l = getcompletion('space', 'option')
911 call assert_equal([], l)
912 let l = getcompletion('ier', 'command')
913 call assert_equal([], l)
914 set wildoptions=fuzzy
915 let l = getcompletion('space', 'option')
916 call assert_true(index(l, 'backspace') >= 0)
917 let l = getcompletion('ier', 'command')
918 call assert_true(index(l, 'compiler') >= 0)
919 let &wildoptions = save_wildoptions
920endfunc
921
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000922func Test_complete_autoload_error()
923 let save_rtp = &rtp
924 let lines =<< trim END
925 vim9script
926 export def Complete(..._): string
927 return 'match'
928 enddef
929 echo this will cause an error
930 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100931 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000932 call writefile(lines, 'Xdir/autoload/script.vim')
933 exe 'set rtp+=' .. getcwd() .. '/Xdir'
934
935 let lines =<< trim END
936 vim9script
937 import autoload 'script.vim'
938 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
939 &wildcharm = char2nr("\<Tab>")
940 feedkeys(":Cmd \<Tab>", 'xt')
941 END
942 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
943
944 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000945endfunc
946
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100947func Test_fullcommand()
948 let tests = {
949 \ '': '',
950 \ ':': '',
951 \ ':::': '',
952 \ ':::5': '',
953 \ 'not_a_cmd': '',
954 \ 'Check': '',
955 \ 'syntax': 'syntax',
956 \ ':syntax': 'syntax',
957 \ '::::syntax': 'syntax',
958 \ 'sy': 'syntax',
959 \ 'syn': 'syntax',
960 \ 'synt': 'syntax',
961 \ ':sy': 'syntax',
962 \ '::::sy': 'syntax',
963 \ 'match': 'match',
964 \ '2match': 'match',
965 \ '3match': 'match',
966 \ 'aboveleft': 'aboveleft',
967 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100968 \ 'en': 'endif',
969 \ 'end': 'endif',
970 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100971 \ 's': 'substitute',
972 \ '5s': 'substitute',
973 \ ':5s': 'substitute',
974 \ "'<,'>s": 'substitute',
975 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100976 \ 'CheckLin': 'CheckLinux',
977 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100978 \ }
979
980 for [in, want] in items(tests)
981 call assert_equal(want, fullcommand(in))
982 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200983 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100984
985 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200986
987 command -buffer BufferLocalCommand :
988 command GlobalCommand :
989 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
990 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
991 delcommand BufferLocalCommand
992 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100993endfunc
994
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200995func Test_shellcmd_completion()
996 let save_path = $PATH
997
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100998 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200999 call writefile([''], 'Xpathdir/Xfile.exe')
1000 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
1001
1002 " Set PATH to example directory without trailing slash.
1003 let $PATH = getcwd() . '/Xpathdir'
1004
1005 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
1006 " dirs in the PATH, even though they won't be executed. We check that only
1007 " subdirs of the PWD and executables from the PATH are included in the
1008 " suggestions.
1009 let actual = getcompletion('X', 'shellcmd')
1010 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
1011 call insert(expected, 'Xfile.exe')
1012 call assert_equal(expected, actual)
1013
Bram Moolenaar6ab9e422018-07-28 19:20:13 +02001014 let $PATH = save_path
1015endfunc
1016
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001017func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +01001018 call mkdir('a/b/c', 'pR')
1019 call writefile(['asdfasdf'], 'a/b/c/fileXname')
1020 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
1021 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +02001022 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001023endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +01001024
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001025func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +01001026 let @a = "def"
1027 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
1028 call assert_equal('"abc def ghi', @:)
1029
1030 new
1031 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
1032
1033 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1034 call assert_equal('"aaa asdf bbb', @:)
1035
1036 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
1037 call assert_equal('"aaa /tmp/some bbb', @:)
1038
Bram Moolenaare2c8d832018-05-01 19:24:03 +02001039 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
1040 call assert_equal('"aaa '.getline(1).' bbb', @:)
1041
Bram Moolenaar21efc362016-12-03 14:05:49 +01001042 set incsearch
1043 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1044 call assert_equal('"aaa verylongword bbb', @:)
1045
1046 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
1047 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001048
1049 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1050 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001051 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001052
1053 " Error while typing a command used to cause that it was not executed
1054 " in the end.
1055 new
1056 try
1057 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1058 catch /^Vim\%((\a\+)\)\=:E32/
1059 " ignore error E32
1060 endtry
1061 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001062
Bram Moolenaar578fe942020-02-27 21:32:51 +01001063 " Try to paste an invalid register using <C-R>
1064 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1065 call assert_equal('"onetwo', @:)
1066
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001067 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001068 let @a = "xy\<C-H>z"
1069 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1070 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001071 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1072 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001073 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1074 call assert_equal("\"xy\<C-H>z", @:)
1075
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001076 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1077 let @a = "xy\<C-V>z"
1078 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1079 call assert_equal('"xyz', @:)
1080 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1081 call assert_equal("\"xy\<C-V>z", @:)
1082
Bram Moolenaar578fe942020-02-27 21:32:51 +01001083 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1084
Bram Moolenaar72532d32018-04-07 19:09:09 +02001085 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001086endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001087
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001088func Test_cmdline_remove_char()
1089 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001090
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001091 for e in ['utf8', 'latin1']
1092 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001093
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001094 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1095 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001096
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001097 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1098 call assert_equal('"abcdef', @:)
1099
1100 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1101 call assert_equal('"abc ghi', @:, e)
1102
1103 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1104 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001105
1106 " This was going before the start in latin1.
1107 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001108 endfor
1109
1110 let &encoding = encoding_save
1111endfunc
1112
zeertzjqff2b79d2024-02-26 20:38:36 +01001113func Test_cmdline_del_utf8()
1114 let @s = '⒌'
1115 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1116 call assert_equal('",,', @:)
1117
1118 let @s = 'a̳'
1119 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1120 call assert_equal('",,', @:)
1121
1122 let @s = 'β̳'
1123 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1124 call assert_equal('",,', @:)
1125
1126 if has('arabic')
1127 let @s = 'لا'
1128 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1129 call assert_equal('",,', @:)
1130 endif
1131endfunc
1132
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001133func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001134 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001135
1136 set keymap=esperanto
1137 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1138 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1139 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001140endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001141
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001142func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001143 new
1144 2;'(
1145 2;')
1146 quit
1147endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001148
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001149func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001150 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001151 new
1152 source Xtest.vim
1153 " Trigger calling validate_cursor()
1154 diffsp Xtest.vim
1155 quit!
1156 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001157endfunc
1158
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001159func Test_mark_from_line_zero()
1160 " this was reading past the end of the first (empty) line
1161 new
1162 norm oxxxx
1163 call assert_fails("0;'(", 'E20:')
1164 bwipe!
1165endfunc
1166
Bram Moolenaarba47b512017-01-24 21:18:19 +01001167func Test_cmdline_complete_wildoptions()
1168 help
1169 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1170 let a = join(sort(split(@:)),' ')
1171 set wildoptions=tagfile
1172 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1173 let b = join(sort(split(@:)),' ')
1174 call assert_equal(a, b)
1175 bw!
1176endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001177
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001178func Test_cmdline_complete_user_cmd()
1179 command! -complete=color -nargs=1 Foo :
1180 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1181 call assert_equal('"Foo blue', @:)
1182 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1183 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001184 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1185 call assert_equal('"Foo a blue', @:)
1186 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1187 call assert_equal('"Foo b\', @:)
1188 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1189 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001190 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001191
1192 redraw
1193 call assert_equal('~', Screenline(&lines - 1))
1194 command! FooOne :
1195 command! FooTwo :
1196
1197 set nowildmenu
1198 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1199 call assert_equal('"FooOne', @:)
1200 call assert_equal('~', Screenline(&lines - 1))
1201
1202 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1203 call assert_equal('"FooTwo', @:)
1204 call assert_equal('~', Screenline(&lines - 1))
1205
1206 delcommand FooOne
1207 delcommand FooTwo
1208 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001209endfunc
1210
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001211func Test_complete_user_cmd()
1212 command FooBar echo 'global'
1213 command -buffer FooBar echo 'local'
1214 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1215 call assert_equal('"FooBar', @:)
1216
1217 delcommand -buffer FooBar
1218 delcommand FooBar
1219endfunc
1220
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001221func s:ScriptLocalFunction()
1222 echo 'yes'
1223endfunc
1224
1225func Test_cmdline_complete_user_func()
1226 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001227 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001228 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1229 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001230
1231 " g: prefix also works
1232 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1233 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001234
1235 " using g: prefix does not result in just "g:" matches from a lambda
1236 let Fx = { a -> a }
1237 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1238 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001239
1240 " existence of script-local dict function does not break user function name
1241 " completion
1242 function s:a_dict_func() dict
1243 endfunction
1244 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1245 call assert_match('"call Test_cmdline_complete_user_', @:)
1246 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001247endfunc
1248
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001249func Test_cmdline_complete_user_names()
1250 if has('unix') && executable('whoami')
1251 let whoami = systemlist('whoami')[0]
1252 let first_letter = whoami[0]
1253 if len(first_letter) > 0
1254 " Trying completion of :e ~x where x is the first letter of
1255 " the user name should complete to at least the user name.
1256 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1257 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1258 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001259 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001260 " Just in case: check that the system has an Administrator account.
1261 let names = system('net user')
1262 if names =~ 'Administrator'
1263 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001264 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001265 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001266 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001267 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001268 else
1269 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001270 endif
1271endfunc
1272
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001273func Test_cmdline_complete_shellcmdline()
1274 CheckExecutable whoami
1275 command -nargs=1 -complete=shellcmdline MyCmd
1276
1277 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1278 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001279 let l = getcompletion('whoam', 'shellcmdline')
1280 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001281
1282 delcommand MyCmd
1283endfunc
1284
Bram Moolenaar297610b2019-12-27 17:20:55 +01001285func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001286 CheckExecutable whoami
1287 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1288 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001289endfunc
1290
Bram Moolenaar8b633132020-03-20 18:20:51 +01001291func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001292 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1293 call assert_equal(lang, v:lc_time)
1294
1295 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1296 call assert_equal(lang, v:ctype)
1297
1298 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1299 call assert_equal(lang, v:collate)
1300
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001301 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001302 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001303
1304 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001305 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001306
Bram Moolenaarec680282020-06-12 19:35:32 +02001307 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001308
Bram Moolenaarec680282020-06-12 19:35:32 +02001309 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1310 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001311
Bram Moolenaarec680282020-06-12 19:35:32 +02001312 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1313 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001314
Bram Moolenaarec680282020-06-12 19:35:32 +02001315 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1316 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001317
1318 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1319 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001320endfunc
1321
Bram Moolenaar297610b2019-12-27 17:20:55 +01001322func Test_cmdline_complete_env_variable()
1323 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001324 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1325 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001326 unlet $X_VIM_TEST_COMPLETE_ENV
1327endfunc
1328
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001329func Test_cmdline_complete_expression()
1330 let g:SomeVar = 'blah'
1331 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1332 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1333 call assert_match('"' .. cmd .. ' SomeVar', @:)
1334 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1335 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1336 endfor
1337 unlet g:SomeVar
1338endfunc
1339
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001340func Test_cmdline_complete_argopt()
1341 " completion for ++opt=arg for file commands
1342 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1343 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1344 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1345
1346 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001347 " Test ++ff in the middle of the cmdline
1348 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1349 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001350
1351 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1352 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1353 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1354 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1355 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1356
1357 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1358
1359 " completion should skip the ++opt and continue
1360 call writefile([], 'Xaaaaa.txt', 'D')
1361 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1362 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1363
1364 if has('terminal')
1365 " completion for terminal's [options]
1366 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1367 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1368 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1369
1370 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1371
1372 " :terminal completion should skip the ++opt when considering what is the
1373 " first option, which is a list of shell commands, unlike second option
1374 " onwards.
1375 let first_param = getcompletion('terminal ', 'cmdline')
1376 let second_param = getcompletion('terminal foo ', 'cmdline')
1377 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1378 call assert_equal(first_param, skipped_opt_param)
1379 call assert_notequal(first_param, second_param)
1380 endif
1381endfunc
1382
Bram Moolenaar47016f52021-08-26 16:39:58 +02001383" Unique function name for completion below
1384func s:WeirdFunc()
1385 echo 'weird'
1386endfunc
1387
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001388" Test for various command-line completion
1389func Test_cmdline_complete_various()
1390 " completion for a command starting with a comment
1391 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1392 call assert_equal("\" :|\"\<C-A>", @:)
1393
1394 " completion for a range followed by a comment
1395 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1396 call assert_equal("\"1,2\"\<C-A>", @:)
1397
1398 " completion for :k command
1399 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1400 call assert_equal("\"ka\<C-A>", @:)
1401
Doug Kearnsea842022024-09-29 17:17:41 +02001402 " completion for :keepmarks command
1403 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1404 call assert_equal("\"kee edit", @:)
1405
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001406 " completion for short version of the :s command
1407 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1408 call assert_equal("\"sI \<C-A>", @:)
1409
1410 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001411 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001412 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001413 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001414 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001415 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1416 call assert_equal("\"w >> Xfile1", @:)
1417 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001418
1419 " completion for :w ! and :r ! commands
1420 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal("\"w !invalid_xyz_cmd", @:)
1422 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1423 call assert_equal("\"r !invalid_xyz_cmd", @:)
1424
1425 " completion for :>> and :<< commands
1426 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal("\">>>\<C-A>", @:)
1428 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1429 call assert_equal("\"<<<\<C-A>", @:)
1430
1431 " completion for command with +cmd argument
1432 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1433 call assert_equal("\"buffer +/pat Xabc", @:)
1434 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1435 call assert_equal("\"buffer +/pat\<C-A>", @:)
1436
1437 " completion for a command with a trailing comment
1438 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1439 call assert_equal("\"ls \" comment\<C-A>", @:)
1440
1441 " completion for a command with a trailing command
1442 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1443 call assert_equal("\"ls | ls", @:)
1444
1445 " completion for a command with an CTRL-V escaped argument
1446 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1447 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1448
1449 " completion for a command that doesn't take additional arguments
1450 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1451 call assert_equal("\"all abc\<C-A>", @:)
1452
zeertzjqd3de1782022-09-01 12:58:52 +01001453 " completion for :wincmd with :horizontal modifier
1454 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1455 call assert_equal("\"horizontal wincmd", @:)
1456
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001457 " completion for a command with a command modifier
1458 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1459 call assert_equal("\"topleft new", @:)
1460
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001461 " completion for vim9 and legacy commands
1462 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal("\"vim9 call strlen(", @:)
1464 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1465 call assert_equal("\"legac call strlen(", @:)
1466
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001467 " completion for the :disassemble command
1468 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1469 call assert_equal("\"disas debug", @:)
1470 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1471 call assert_equal("\"disas profile", @:)
1472 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1473 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1474 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1475 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001476 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1477 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001478
Bram Moolenaar47016f52021-08-26 16:39:58 +02001479 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001480 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001481
naohiro onodfe04db2021-09-12 15:45:10 +02001482 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1483 call assert_match('"disas <SNR>\d\+_', @:)
1484 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1485 call assert_match('"disas debug <SNR>\d\+_', @:)
1486
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001487 " completion for the :match command
1488 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1489 call assert_equal("\"match Search /pat/\<C-A>", @:)
1490
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001491 " completion for the :doautocmd command
1492 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1493 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1494
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001495 " completion of autocmd group after comma
1496 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1497 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1498
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001499 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001500 call writefile([], 'Xvarfile1', 'D')
1501 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001502 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1503 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001504
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001505 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001506 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001507 augroup END
1508 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001509 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001510
1511 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001512 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1513 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001514 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1515 call assert_equal("\"au XTest.test", @:)
1516
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001517 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001518
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001519 " autocmd pattern completion
1520 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1521 call assert_equal("\"au BufEnter *.py\t", @:)
1522
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001523 " completion for the :unlet command
1524 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1525 call assert_equal("\"unlet one two", @:)
1526
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001527 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001528 " FIXME: what should happen on MS-Windows?
1529 if !has('win32')
1530 edit \{someFile}
1531 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1532 call assert_equal("\"buf {someFile}", @:)
1533 bwipe {someFile}
1534 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001535
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001536 " completion for the :bdelete command
1537 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1538 call assert_equal("\"bdel a b c", @:)
1539
1540 " completion for the :mapclear command
1541 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1542 call assert_equal("\"mapclear <buffer>", @:)
1543
1544 " completion for user defined commands with menu names
1545 menu Test.foo :ls<CR>
1546 com -nargs=* -complete=menu MyCmd
1547 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1548 call assert_equal('"MyCmd Test.', @:)
1549 delcom MyCmd
1550 unmenu Test
1551
1552 " completion for user defined commands with mappings
1553 mapclear
1554 map <F3> :ls<CR>
1555 com -nargs=* -complete=mapping MyCmd
1556 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001557 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001558 mapclear
1559 delcom MyCmd
1560
Yee Cheng Chin54844852023-10-09 18:12:31 +02001561 " Prepare for path completion
1562 call mkdir('Xa b c', 'D')
1563 defer delete('Xcomma,foobar.txt')
1564 call writefile([], 'Xcomma,foobar.txt')
1565
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001566 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001567 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1568 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1569 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001570
1571 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001572 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1573 call assert_equal('"set dir=Xa\ b\ c/', @:)
1574 set dir&
1575
1576 " completion for :set tags= / set dictionary= with escaped commas
1577 if has('win32')
1578 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1579 " '\,'
1580 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1581 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1582
1583 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1584 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1585
1586 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1587 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1588
1589 " completion for :set dictionary= with escaped commas (same behavior, but
1590 " different internal code path from 'set tags=' for escaping the output)
1591 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1592 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1593 else
1594 " In other platforms, backslashes are rounded down (since '\,' itself will
1595 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1596 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1597 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1598
1599 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1600 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1601
1602 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1603 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1604
1605 " completion for :set dictionary= with escaped commas (same behavior, but
1606 " different internal code path from 'set tags=' for escaping the output)
1607 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1608 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1609 endif
1610 set tags&
1611 set dictionary&
1612
1613 " completion for :set makeprg= with no escaped commas
1614 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1615 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1616
1617 if !has('win32')
1618 " Cannot create file with backslash in file name in Windows, so only test
1619 " this elsewhere.
1620 defer delete('Xcomma\,fooslash.txt')
1621 call writefile([], 'Xcomma\,fooslash.txt')
1622 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1623 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1624 endif
1625 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001626
1627 " completion for the :py3 commands
1628 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1629 call assert_equal('"py3 py3do py3file', @:)
1630
Bram Moolenaardf749a22021-03-28 15:29:43 +02001631 " completion for the :vim9 commands
1632 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1633 call assert_equal('"vim9cmd vim9script', @:)
1634
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001635 " redir @" is not the start of a comment. So complete after that
1636 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1637 call assert_equal('"redir @" | cwindow', @:)
1638
1639 " completion after a backtick
1640 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1641 call assert_equal('"e `a1b2c', @:)
1642
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001643 " completion for :language command with an invalid argument
1644 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1645 call assert_equal("\"language dummy \t", @:)
1646
1647 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001648 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1649 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001650
1651 " completion with ambiguous user defined commands
1652 com TCmd1 echo 'TCmd1'
1653 com TCmd2 echo 'TCmd2'
1654 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1655 call assert_equal('"TCmd ', @:)
1656 delcom TCmd1
1657 delcom TCmd2
1658
1659 " completion after a range followed by a pipe (|) character
1660 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1661 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001662
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001663 " completion after a :global command
1664 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1665 call assert_equal('"g/a/chistory', @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001666 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001667 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1668 call assert_equal("\"g/a\\/chist\t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001669 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001670
Bram Moolenaar9c929712020-09-07 22:05:28 +02001671 " use <Esc> as the 'wildchar' for completion
1672 set wildchar=<Esc>
1673 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1674 call assert_equal('"g/a\xb/clearjumps', @:)
1675 " pressing <esc> twice should cancel the command
1676 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1677 call assert_equal('"g/a\xb/clearjumps', @:)
1678 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001679
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001680 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001681 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001682 call writefile([], '~Xtest')
1683 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1684 call assert_equal('"e \~Xtest', @:)
1685 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001686
1687 " should be able to complete a file name that has a '*'
1688 call writefile([], 'Xx*Yy')
1689 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1690 call assert_equal('"e Xx\*Yy', @:)
1691 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001692
1693 " use a literal star
1694 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1695 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001696 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001697
1698 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1699 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001700endfunc
1701
zeertzjq094dd152023-06-15 22:51:57 +01001702" Test that expanding a pattern doesn't interfere with cmdline completion.
1703func Test_expand_during_cmdline_completion()
1704 func ExpandStuff()
1705 badd <script>:p:h/README.*
1706 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1707 $bwipe
1708 call assert_equal('README.txt', expand('README.*'))
1709 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1710 endfunc
1711 augroup test_CmdlineChanged
1712 autocmd!
1713 autocmd CmdlineChanged * call ExpandStuff()
1714 augroup END
1715
1716 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1717 call assert_equal('"sign place', @:)
1718
1719 augroup test_CmdlineChanged
1720 au!
1721 augroup END
1722 augroup! test_CmdlineChanged
1723 delfunc ExpandStuff
1724endfunc
1725
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001726" Test for 'wildignorecase'
1727func Test_cmdline_wildignorecase()
1728 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001729 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001730 set wildignorecase
1731 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1732 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001733 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001734 let g:Sline = ''
1735 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1736 call assert_equal('"e xt', @:)
1737 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001738 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001739endfunc
1740
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001741func Test_cmdline_write_alternatefile()
1742 new
1743 call setline('.', ['one', 'two'])
1744 f foo.txt
1745 new
1746 f #-A
1747 call assert_equal('foo.txt-A', expand('%'))
1748 f #<-B.txt
1749 call assert_equal('foo-B.txt', expand('%'))
1750 f %<
1751 call assert_equal('foo-B', expand('%'))
1752 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001753 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001754 bw!
1755 f foo-B.txt
1756 f %<-A
1757 call assert_equal('foo-B-A', expand('%'))
1758 bw!
1759 bw!
1760endfunc
1761
Bram Moolenaarf5724372022-09-02 19:45:15 +01001762func Test_cmdline_expand_cur_alt_file()
1763 enew
1764 file http://some.com/file.txt
1765 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"e http://some.com/file.txt', @:)
1767 edit another
1768 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1769 call assert_equal('"e http://some.com/file.txt', @:)
1770 bwipe
1771 bwipe http://some.com/file.txt
1772endfunc
1773
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001774" using a leading backslash here
1775set cpo+=C
1776
1777func Test_cmdline_search_range()
1778 new
1779 call setline(1, ['a', 'b', 'c', 'd'])
1780 /d
1781 1,\/s/b/B/
1782 call assert_equal('B', getline(2))
1783
1784 /a
1785 $
1786 \?,4s/c/C/
1787 call assert_equal('C', getline(3))
1788
1789 call setline(1, ['a', 'b', 'c', 'd'])
1790 %s/c/c/
1791 1,\&s/b/B/
1792 call assert_equal('B', getline(2))
1793
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001794 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001795 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001796
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001797 bwipe!
1798endfunc
1799
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001800" Test for the tick mark (') in an excmd range
1801func Test_tick_mark_in_range()
1802 " If only the tick is passed as a range and no command is specified, there
1803 " should not be an error
1804 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001805 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001806 call assert_fails("',print", 'E78:')
1807endfunc
1808
1809" Test for using a line number followed by a search pattern as range
1810func Test_lnum_and_pattern_as_range()
1811 new
1812 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1813 let @" = ''
1814 2/foo/yank
1815 call assert_equal("foo 3\n", @")
1816 call assert_equal(1, line('.'))
1817 close!
1818endfunc
1819
Bram Moolenaar65189a12017-02-06 22:22:17 +01001820" Tests for getcmdline(), getcmdpos() and getcmdtype()
1821func Check_cmdline(cmdtype)
1822 call assert_equal('MyCmd a', getcmdline())
1823 call assert_equal(8, getcmdpos())
1824 call assert_equal(a:cmdtype, getcmdtype())
1825 return ''
1826endfunc
1827
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001828set cpo&
1829
Shougo Matsushita69084282024-09-23 20:34:47 +02001830func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001831 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1832
1833 let cmdtype = ''
1834 debuggreedy
1835 call feedkeys(":debug echo 'test'\<CR>", "t")
1836 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1837 call feedkeys("cont\<CR>", "xt")
1838 0debuggreedy
1839 call assert_equal('>', cmdtype)
1840
1841 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1842 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1843
1844 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001845 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001846
1847 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1848
1849 cnoremap <expr> <F6> Check_cmdline('=')
1850 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1851 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001852
1853 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001854
1855 call assert_equal('', getcmdprompt())
1856 augroup test_CmdlineEnter
1857 autocmd!
1858 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1859 augroup END
1860 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1861 call assert_equal('Answer?', g:cmdprompt)
1862 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001863 call feedkeys(":\<CR>\<ESC>", "xt")
1864 call assert_equal('', g:cmdprompt)
1865 call assert_equal('', getcmdprompt())
1866
1867 let str = "C" .. repeat("c", 1023) .. "xyz"
1868 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1869 call assert_equal(str, g:cmdprompt)
1870
1871 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1872 call assert_equal('Ans?', g:cmdprompt)
1873 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001874
1875 augroup test_CmdlineEnter
1876 au!
1877 augroup END
1878 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001879endfunc
1880
Bram Moolenaar52604f22017-04-07 16:17:39 +02001881func Test_verbosefile()
1882 set verbosefile=Xlog
1883 echomsg 'foo'
1884 echomsg 'bar'
1885 set verbosefile=
1886 let log = readfile('Xlog')
1887 call assert_match("foo\nbar", join(log, "\n"))
1888 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001889
1890 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001891 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001892endfunc
1893
Bram Moolenaar4facea32019-10-12 20:17:40 +02001894func Test_verbose_option()
1895 CheckScreendump
1896
1897 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001898 " clear the TermResponse autocommand from defaults.vim
1899 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001900 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1901 call feedkeys("\r", 't') " for the hit-enter prompt
1902 set verbose=20
1903 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001904 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001905
1906 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001907 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001908 call term_sendkeys(buf, ":DoSomething\<CR>")
1909 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1910
1911 " clean up
1912 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001913endfunc
1914
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001915func Test_setcmdpos()
1916 func InsertTextAtPos(text, pos)
1917 call assert_equal(0, setcmdpos(a:pos))
1918 return a:text
1919 endfunc
1920
1921 " setcmdpos() with position in the middle of the command line.
1922 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1923 call assert_equal('"1ab2', @:)
1924
1925 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1926 call assert_equal('"1b2a', @:)
1927
1928 " setcmdpos() with position beyond the end of the command line.
1929 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1930 call assert_equal('"12ab', @:)
1931
1932 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001933 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001934endfunc
1935
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001936func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001937 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001938 let encoding_save = &encoding
1939
1940 for e in encodings
1941 exe 'set encoding=' . e
1942
1943 " Test overstrike in the middle of the command line.
1944 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001945 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001946
1947 " Test overstrike going beyond end of command line.
1948 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001949 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001950
1951 " Test toggling insert/overstrike a few times.
1952 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001953 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001954 endfor
1955
Bram Moolenaar30276f22019-01-24 17:59:39 +01001956 " Test overstrike with multi-byte characters.
1957 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001958 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001959
1960 let &encoding = encoding_save
1961endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001962
Bram Moolenaar52410572019-10-27 05:12:45 +01001963func Test_buffers_lastused()
1964 " check that buffers are sorted by time when wildmode has lastused
1965 call test_settime(1550020000) " middle
1966 edit bufa
1967 enew
1968 call test_settime(1550030000) " newest
1969 edit bufb
1970 enew
1971 call test_settime(1550010000) " oldest
1972 edit bufc
1973 enew
1974 call test_settime(0)
1975 enew
1976
1977 call assert_equal(['bufa', 'bufb', 'bufc'],
1978 \ getcompletion('', 'buffer'))
1979
1980 let save_wildmode = &wildmode
1981 set wildmode=full:lastused
1982
1983 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1984 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1985 call assert_equal('b bufb', X)
1986 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1987 call assert_equal('b bufa', X)
1988 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1989 call assert_equal('b bufc', X)
1990 enew
1991
1992 edit other
1993 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1994 call assert_equal('b bufb', X)
1995 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1996 call assert_equal('b bufa', X)
1997 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1998 call assert_equal('b bufc', X)
1999 enew
2000
2001 let &wildmode = save_wildmode
2002
2003 bwipeout bufa
2004 bwipeout bufb
2005 bwipeout bufc
2006endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01002007
Bram Moolenaar479950f2020-01-19 15:45:17 +01002008func Test_cmdlineclear_tabenter()
2009 CheckScreendump
2010
2011 let lines =<< trim [SCRIPT]
2012 call setline(1, range(30))
2013 [SCRIPT]
2014
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002015 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01002016 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02002017 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002018 " in one tab make the command line higher with CTRL-W -
2019 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
2020 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2021
2022 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002023endfunc
2024
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002025" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002026func Test_cmdline_expand_special()
2027 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02002028 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002029 call assert_fails('e <afile>', 'E495:')
2030 call assert_fails('e <abuf>', 'E496:')
2031 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002032
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002033 call writefile([], 'Xfile.cpp', 'D')
2034 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002035 new Xfile.cpp
2036 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2037 call assert_equal('"e Xfile.cpp Xfile.java', @:)
2038 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002039endfunc
2040
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002041" Test for backtick expression in the command line
2042func Test_cmd_backtick()
2043 %argd
2044 argadd `=['a', 'b', 'c']`
2045 call assert_equal(['a', 'b', 'c'], argv())
2046 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02002047
2048 argadd `echo abc def`
2049 call assert_equal(['abc def'], argv())
2050 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002051endfunc
2052
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002053" Test for the :! command
2054func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002055 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002056
2057 let lines =<< trim [SCRIPT]
2058 " Test for no previous command
2059 call assert_fails('!!', 'E34:')
2060 set nomore
2061 " Test for cmdline expansion with :!
2062 call setline(1, 'foo!')
2063 silent !echo <cWORD> > Xfile.out
2064 call assert_equal(['foo!'], readfile('Xfile.out'))
2065 " Test for using previous command
2066 silent !echo \! !
2067 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2068 call writefile(v:errors, 'Xresult')
2069 call delete('Xfile.out')
2070 qall!
2071 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002072 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002073 if RunVim([], [], '--clean -S Xscript')
2074 call assert_equal([], readfile('Xresult'))
2075 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002076 call delete('Xresult')
2077endfunc
2078
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002079" Test error: "E135: *Filter* Autocommands must not change current buffer"
2080func Test_cmd_bang_E135()
2081 new
2082 call setline(1, ['a', 'b', 'c', 'd'])
2083 augroup test_cmd_filter_E135
2084 au!
2085 autocmd FilterReadPost * help
2086 augroup END
2087 call assert_fails('2,3!echo "x"', 'E135:')
2088
2089 augroup test_cmd_filter_E135
2090 au!
2091 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002092 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002093 %bwipe!
2094endfunc
2095
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002096func Test_cmd_bang_args()
2097 new
2098 :.!
2099 call assert_equal(0, v:shell_error)
2100
2101 " Note that below there is one space char after the '!'. This caused a
2102 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2103 :.!
2104 call assert_equal(0, v:shell_error)
2105 bwipe!
2106
2107 CheckUnix
2108 :.!pwd
2109 call assert_equal(0, v:shell_error)
2110 :.! pwd
2111 call assert_equal(0, v:shell_error)
2112
2113 " Note there is one space after 'pwd'.
2114 :.! pwd
2115 call assert_equal(0, v:shell_error)
2116
2117 " Note there are two spaces after 'pwd'.
2118 :.! pwd
2119 call assert_equal(0, v:shell_error)
2120 :.!ls ~
2121 call assert_equal(0, v:shell_error)
2122
2123 " Note there is one space char after '~'.
2124 :.!ls ~
2125 call assert_equal(0, v:shell_error)
2126
2127 " Note there are two spaces after '~'.
2128 :.!ls ~
2129 call assert_equal(0, v:shell_error)
2130
2131 :.!echo "foo"
2132 call assert_equal(getline('.'), "foo")
2133 :.!echo "foo "
2134 call assert_equal(getline('.'), "foo ")
2135 :.!echo " foo "
2136 call assert_equal(getline('.'), " foo ")
2137 :.!echo " foo "
2138 call assert_equal(getline('.'), " foo ")
2139
2140 %bwipe!
2141endfunc
2142
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002143" Test for using ~ for home directory in cmdline completion matches
2144func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002145 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002146 call writefile([], 'Xexpdir/Xfile1')
2147 call writefile([], 'Xexpdir/Xfile2')
2148 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002149 let save_HOME = $HOME
2150 let $HOME = getcwd()
2151 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2152 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2153 let $HOME = save_HOME
2154 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002155endfunc
2156
Bram Moolenaar578fe942020-02-27 21:32:51 +01002157" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2158" or insert mode (when 'insertmode' is set)
2159func Test_cmdline_ctrl_g()
2160 new
2161 call setline(1, 'abc')
2162 call cursor(1, 3)
2163 " If command line is entered from insert mode, using C-\ C-G should back to
2164 " insert mode
2165 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2166 call assert_equal('abxyc', getline(1))
2167 call assert_equal(4, col('.'))
2168
2169 " If command line is entered in 'insertmode', using C-\ C-G should back to
2170 " 'insertmode'
2171 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2172 call assert_equal('ab12xyc', getline(1))
2173 close!
2174endfunc
2175
Bram Moolenaar578fe942020-02-27 21:32:51 +01002176" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002177func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002178 func T(a, c, p)
2179 return "oneA\noneB\noneC"
2180 endfunc
2181 command -nargs=1 -complete=custom,T MyCmd
2182
Bram Moolenaar578fe942020-02-27 21:32:51 +01002183 set nowildmenu
2184 set wildmode=full,list
2185 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002186 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002187 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002188 call assert_equal('"MyCmd oneA', @:)
2189
2190 set wildmode=longest,full
2191 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2192 call assert_equal('"MyCmd one', @:)
2193 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2194 call assert_equal('"MyCmd oneC', @:)
2195
2196 set wildmode=longest
2197 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2198 call assert_equal('"MyCmd one', @:)
2199
2200 set wildmode=list:longest
2201 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002202 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002203 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002204 call assert_equal('"MyCmd one', @:)
2205
2206 set wildmode=""
2207 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2208 call assert_equal('"MyCmd oneA', @:)
2209
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002210 " Test for wildmode=longest with 'fileignorecase' set
2211 set wildmode=longest
2212 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002213 argadd AAA AAAA AAAAA
2214 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2215 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002216 set fileignorecase&
2217
2218 " Test for listing files with wildmode=list
2219 set wildmode=list
2220 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002221 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002222 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002223 call assert_equal('"b A', @:)
2224
Girish Palya2bacc3e2025-03-02 22:55:57 +01002225 " When 'wildmenu' is not set, 'noselect' completes first item
2226 set wildmode=noselect
2227 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2228 call assert_equal('"MyCmd oneA', @:)
2229
2230 " When 'noselect' is present, do not complete first <tab>.
2231 set wildmenu
2232 set wildmode=noselect
2233 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2234 call assert_equal('"MyCmd o', @:)
2235 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2236 call assert_equal('"MyCmd o', @:)
2237 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2238 call assert_equal('"MyCmd o', @:)
2239
2240 " When 'full' is present, complete after first <tab>.
2241 set wildmode=noselect,full
2242 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2243 call assert_equal('"MyCmd o', @:)
2244 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2245 call assert_equal('"MyCmd oneA', @:)
2246 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2247 call assert_equal('"MyCmd oneB', @:)
2248 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2249 call assert_equal('"MyCmd oneB', @:)
2250
2251 " 'noselect' has no effect when 'longest' is present.
2252 set wildmode=noselect:longest
2253 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2254 call assert_equal('"MyCmd one', @:)
2255
2256 " Complete 'noselect' value in 'wildmode' option
2257 set wildmode&
2258 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2259 call assert_equal('"set wildmode=noselect', @:)
2260 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2261 call assert_equal('"set wildmode=noselect', @:)
2262
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002263 " when using longest completion match, matches shorter than the argument
2264 " should be ignored (happens with :help)
2265 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002266 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2267 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002268 " non existing file
2269 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2270 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002271
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002272 " Test for longest file name completion with 'fileignorecase'
2273 " On MS-Windows, file names are case insensitive.
2274 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002275 call writefile([], 'XTESTfoo', 'D')
2276 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002277 set nofileignorecase
2278 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2279 call assert_equal('"e XTESTfoo', @:)
2280 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2281 call assert_equal('"e Xtestbar', @:)
2282 set fileignorecase
2283 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2284 call assert_equal('"e Xtest', @:)
2285 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2286 call assert_equal('"e Xtest', @:)
2287 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002288 endif
2289
Girish Palya2bacc3e2025-03-02 22:55:57 +01002290 " If 'noselect' is present, single item menu should not insert item
2291 func! T(a, c, p)
2292 return "oneA"
2293 endfunc
2294 command! -nargs=1 -complete=custom,T MyCmd
2295 set wildmode=noselect,full
2296 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2297 call assert_equal('"MyCmd o', @:)
2298 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2299 call assert_equal('"MyCmd oneA', @:)
2300 " 'nowildmenu' should make 'noselect' ineffective
2301 set nowildmenu
2302 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2303 call assert_equal('"MyCmd oneA', @:)
2304
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002305 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002306 delcommand MyCmd
2307 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002308 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002309 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002310endfunc
2311
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002312func Test_wildmode()
2313 " Test with utf-8 encoding
2314 call Wildmode_tests()
2315
2316 " Test with latin1 encoding
2317 let save_encoding = &encoding
2318 set encoding=latin1
2319 call Wildmode_tests()
2320 let &encoding = save_encoding
2321endfunc
2322
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002323func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002324 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002325 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002326 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002327 let lines =<< trim END
2328 func vim8#Complete(a, c, p)
2329 return "oneA\noneB\noneC"
2330 endfunc
2331 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002332 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002333
2334 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2335 set nowildmenu
2336 set wildmode=full,list
2337 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2338 call assert_equal('"MyCmd oneA oneB oneC', @:)
2339
2340 let &rtp = save_rtp
2341 set wildmode& wildmenu&
2342 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002343endfunc
2344
Bram Moolenaar578fe942020-02-27 21:32:51 +01002345" Test for interrupting the command-line completion
2346func Test_interrupt_compl()
2347 func F(lead, cmdl, p)
2348 if a:lead =~ 'tw'
2349 call interrupt()
2350 return
2351 endif
2352 return "one\ntwo\nthree"
2353 endfunc
2354 command -nargs=1 -complete=custom,F Tcmd
2355
2356 set nowildmenu
2357 set wildmode=full
2358 let interrupted = 0
2359 try
2360 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2361 catch /^Vim:Interrupt$/
2362 let interrupted = 1
2363 endtry
2364 call assert_equal(1, interrupted)
2365
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002366 let interrupted = 0
2367 try
2368 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2369 catch /^Vim:Interrupt$/
2370 let interrupted = 1
2371 endtry
2372 call assert_equal(1, interrupted)
2373
Bram Moolenaar578fe942020-02-27 21:32:51 +01002374 delcommand Tcmd
2375 delfunc F
2376 set wildmode&
2377endfunc
2378
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002379" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002380func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002381 let str = ":one two\<C-U>"
2382 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002383 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002384 let str ..= "\<Left>five\<Right>"
2385 let str ..= "\<Home>two "
2386 let str ..= "\<C-Left>one "
2387 let str ..= "\<C-Right> three"
2388 let str ..= "\<End>\<S-Left>four "
2389 let str ..= "\<S-Right> six"
2390 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2391 call feedkeys(str, 'xt')
2392 call assert_equal("\"one two three four five six seven", @:)
2393endfunc
2394
2395" Test for moving the cursor on the / command line in 'rightleft' mode
2396func Test_cmdline_edit_rightleft()
2397 CheckFeature rightleft
2398 set rightleft
2399 set rightleftcmd=search
2400 let str = "/one two\<C-U>"
2401 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002402 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002403 let str ..= "\<Right>five\<Left>"
2404 let str ..= "\<Home>two "
2405 let str ..= "\<C-Right>one "
2406 let str ..= "\<C-Left> three"
2407 let str ..= "\<End>\<S-Right>four "
2408 let str ..= "\<S-Left> six"
2409 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2410 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2411 call assert_equal("\"one two three four five six seven", @/)
2412 set rightleftcmd&
2413 set rightleft&
2414endfunc
2415
2416" Test for using <C-\>e in the command line to evaluate an expression
2417func Test_cmdline_expr()
2418 " Evaluate an expression from the beginning of a command line
2419 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2420 call assert_equal('"hello', @:)
2421
2422 " Use an invalid expression for <C-\>e
2423 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2424
2425 " Insert literal <CTRL-\> in the command line
2426 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2427 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002428endfunc
2429
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002430" This was making the insert position negative
2431func Test_cmdline_expr_register()
2432 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2433endfunc
2434
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002435" Test for 'imcmdline' and 'imsearch'
2436" This test doesn't actually test the input method functionality.
2437func Test_cmdline_inputmethod()
2438 new
2439 call setline(1, ['', 'abc', ''])
2440 set imcmdline
2441
2442 call feedkeys(":\"abc\<CR>", 'xt')
2443 call assert_equal("\"abc", @:)
2444 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2445 call assert_equal("\"abc", @:)
2446 call feedkeys("/abc\<CR>", 'xt')
2447 call assert_equal([2, 1], [line('.'), col('.')])
2448 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2449 call assert_equal([2, 1], [line('.'), col('.')])
2450
2451 set imsearch=2
2452 call cursor(1, 1)
2453 call feedkeys("/abc\<CR>", 'xt')
2454 call assert_equal([2, 1], [line('.'), col('.')])
2455 call cursor(1, 1)
2456 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2457 call assert_equal([2, 1], [line('.'), col('.')])
2458 set imdisable
2459 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2460 call assert_equal([2, 1], [line('.'), col('.')])
2461 set imdisable&
2462 set imsearch&
2463
2464 set imcmdline&
2465 %bwipe!
2466endfunc
2467
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002468" Test for using CTRL-_ in the command line with 'allowrevins'
2469func Test_cmdline_revins()
2470 CheckNotMSWindows
2471 CheckFeature rightleft
2472 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2473 call assert_equal("\"abc\<c-_>", @:)
2474 set allowrevins
2475 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2476 call assert_equal('"abcñèæ', @:)
2477 set allowrevins&
2478endfunc
2479
2480" Test for typing UTF-8 composing characters in the command line
2481func Test_cmdline_composing_chars()
2482 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2483 call assert_equal('"ゔ', @:)
2484endfunc
2485
Bram Moolenaar0e717042020-04-27 19:29:01 +02002486" test that ";" works to find a match at the start of the first line
2487func Test_zero_line_search()
2488 new
2489 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2490 call cursor(1,1)
2491 0;/pattern/d
2492 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2493 q!
2494endfunc
2495
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002496func Test_read_shellcmd()
2497 CheckUnix
2498 if executable('ls')
2499 " There should be ls in the $PATH
2500 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2501 call assert_match('^"r! .*\<ls\>', @:)
2502 endif
2503
2504 if executable('rm')
2505 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2506 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2507 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002508
2509 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2510 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2511 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002512 endif
2513endfunc
2514
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002515" Test for going up and down the directory tree using 'wildmenu'
2516func Test_wildmenu_dirstack()
2517 CheckUnix
2518 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002519 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002520 call writefile([], 'Xwildmenu/file1_1.txt')
2521 call writefile([], 'Xwildmenu/file1_2.txt')
2522 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2523 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2524 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2525 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2526 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2527 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002528 set wildmenu
2529
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002530 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002531 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002532 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002533 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002534 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002535 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002536 call assert_equal('"e ../../dir3/', @:)
2537 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2538 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002539 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002540 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002541 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002542 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002543 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002544 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2545 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002546
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002547 set wildmenu&
2548endfunc
2549
obcat71c6f7a2021-05-13 20:23:10 +02002550" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002551" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2552" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002553func Test_recalling_cmdline()
2554 CheckFeature cmdline_hist
2555
2556 let g:cmdlines = []
2557 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2558
2559 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002560 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2561 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2562 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2563 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002564 "\ TODO: {'name': 'debug', ...}
2565 \]
2566 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002567 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2568 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2569 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2570 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2571 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002572 \]
2573 let prefix = 'vi'
2574 for h in histories
2575 call histadd(h.name, 'vim')
2576 call histadd(h.name, 'virtue')
2577 call histadd(h.name, 'Virgo')
2578 call histadd(h.name, 'vogue')
2579 call histadd(h.name, 'emacs')
2580 for k in keypairs
2581 let g:cmdlines = []
2582 let keyseqs = h.enter
2583 \ .. prefix
2584 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2585 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2586 \ .. h.exit
2587 call feedkeys(keyseqs, 'xt')
2588 call histdel(h.name, -1) " delete the history added by feedkeys above
2589 let expect = k.prefixmatch
2590 \ ? ['virtue', 'vim', 'virtue', prefix]
2591 \ : ['emacs', 'vogue', 'emacs', prefix]
2592 call assert_equal(expect, g:cmdlines)
2593 endfor
2594 endfor
2595
2596 unlet g:cmdlines
2597 cunmap <Plug>(save-cmdline)
2598endfunc
2599
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002600func Test_cmd_map_cmdlineChanged()
2601 let g:log = []
2602 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002603 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002604 autocmd!
2605 autocmd CmdlineChanged : let g:log += [getcmdline()]
2606 augroup END
2607
2608 call feedkeys(":\<F1>\<CR>", 'xt')
2609 call assert_equal(['l', 'ls'], g:log)
2610
Bram Moolenaar796139a2021-05-18 21:38:45 +02002611 let @b = 'b'
2612 cnoremap <F1> a<C-R>b
2613 let g:log = []
2614 call feedkeys(":\<F1>\<CR>", 'xt')
2615 call assert_equal(['a', 'ab'], g:log)
2616
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002617 unlet g:log
2618 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002619 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002620 autocmd!
2621 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002622 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002623endfunc
2624
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002625" Test for the 'suffixes' option
2626func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002627 call writefile([], 'Xsuffile', 'D')
2628 call writefile([], 'Xsuffile.c', 'D')
2629 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002630 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002631 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2632 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2633 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2634 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002635 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002636 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2637 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2638 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2639 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002640 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002641 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2642 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2643 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2644 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002645 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002646 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002647 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2648 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002649endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002650
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002651" Test for using a popup menu for the command line completion matches
2652" (wildoptions=pum)
2653func Test_wildmenu_pum()
Drew Vogelea67ba72025-05-07 22:05:17 +02002654 CheckScreendump
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002655 CheckRunVimInTerminal
2656
2657 let commands =<< trim [CODE]
2658 set wildmenu
2659 set wildoptions=pum
2660 set shm+=I
2661 set noruler
2662 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002663
2664 func CmdCompl(a, b, c)
2665 return repeat(['aaaa'], 120)
2666 endfunc
2667 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002668
2669 func MyStatusLine() abort
2670 return 'status'
2671 endfunc
2672 func SetupStatusline()
2673 set statusline=%!MyStatusLine()
2674 set laststatus=2
2675 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002676
2677 func MyTabLine()
2678 return 'my tab line'
2679 endfunc
2680 func SetupTabline()
2681 set statusline=
2682 set tabline=%!MyTabLine()
2683 set showtabline=2
2684 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002685
2686 func DoFeedKeys()
2687 let &wildcharm = char2nr("\t")
2688 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2689 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002691 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002692
2693 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2694
2695 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002696 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2697
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002698 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002699 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002700 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2701
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002702 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002703 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002704 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2705
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002706 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002707 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002708 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2709
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002710 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002711 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002712 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2713
2714 " pressing <C-E> should end completion and go back to the original match
2715 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002716 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2717
2718 " pressing <C-Y> should select the current match and end completion
2719 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002720 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2721
2722 " With 'wildmode' set to 'longest,full', completing a match should display
2723 " the longest match, the wildmenu should not be displayed.
2724 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2725 call TermWait(buf)
2726 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002727 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2728
2729 " pressing <Tab> should display the wildmenu
2730 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002731 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2732
2733 " pressing <Tab> second time should select the next entry in the menu
2734 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002735 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2736
2737 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002738 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002739 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002740 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2741
2742 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002743 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2744
2745 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002746 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2747
2748 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002749 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002750 call writefile([], 'Xnamedir/XfileA')
2751 call writefile([], 'Xnamedir/XdirA/XfileB')
2752 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002753
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002754 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002755 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2756
2757 " Pressing <Right> on a directory name should go into that directory
2758 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002759 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2760
2761 " Pressing <Left> on a directory name should go to the parent directory
2762 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002763 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2764
2765 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002766 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002767 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002768 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2769
2770 " Pressing <C-D> when the popup menu is displayed should remove the popup
2771 " menu
2772 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002773 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2774
2775 " Pressing <S-Tab> should open the popup menu with the last entry selected
2776 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002777 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2778
2779 " Pressing <Esc> should close the popup menu and cancel the cmd line
2780 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002781 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2782
2783 " Typing a character when the popup is open, should close the popup
2784 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002785 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2786
2787 " When the popup is open, entering the cmdline window should close the popup
2788 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002789 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2790 call term_sendkeys(buf, ":q\<CR>")
2791
2792 " After the last popup menu item, <C-N> should show the original string
2793 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002794 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2795
2796 " Use the popup menu for the command name
2797 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002798 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2799
2800 " Pressing the left arrow should remove the popup menu
2801 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002802 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2803
2804 " Pressing <BS> should remove the popup menu and erase the last character
2805 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002806 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2807
2808 " Pressing <C-W> should remove the popup menu and erase the previous word
2809 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002810 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2811
2812 " Pressing <C-U> should remove the popup menu and erase the entire line
2813 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002814 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2815
2816 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2817 " the cmdline from history
2818 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002819 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2820
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002821 " Check "list" still works
2822 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2823 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002824 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2825 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002826 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2827
rbtnn68cc2b82022-02-09 11:55:47 +00002828 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002829 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002830 call writefile([], 'Xnamedir/あいう/abc')
2831 call writefile([], 'Xnamedir/あいう/xyz')
2832 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002833
2834 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002835 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002836 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2837
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002838 " Pressing <C-A> when the popup menu is displayed should list all the
2839 " matches and pressing a key after that should remove the popup menu
2840 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2841 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2842 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2843
2844 " Pressing <C-A> when the popup menu is displayed should list all the
2845 " matches and pressing <Left> after that should move the cursor
2846 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2847 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2848 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2849
2850 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2851 " should be displayed correctly on the screen.
2852 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2853 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2854
2855 " After using <C-A> to expand all the filename matches, pressing <Up>
2856 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002857 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002858 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2859 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2860 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2861
2862 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2863 " crash Vim
2864 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2865 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2866
Bram Moolenaar414acd32022-02-10 21:09:45 +00002867 " After removing the pum the command line is redrawn
2868 call term_sendkeys(buf, ":edit foo\<CR>")
2869 call term_sendkeys(buf, ":edit bar\<CR>")
2870 call term_sendkeys(buf, ":ls\<CR>")
2871 call term_sendkeys(buf, ":com\<Tab> ")
2872 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002873 call term_sendkeys(buf, "\<C-U>\<CR>")
2874
2875 " Esc still works to abort the command when 'statusline' is set
2876 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2877 call term_sendkeys(buf, ":si\<Tab>")
2878 call term_sendkeys(buf, "\<Esc>")
2879 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002880
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002881 " Esc still works to abort the command when 'tabline' is set
2882 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2883 call term_sendkeys(buf, ":si\<Tab>")
2884 call term_sendkeys(buf, "\<Esc>")
2885 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2886
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002887 " popup is cleared also when 'lazyredraw' is set
2888 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2889 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2890 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2891 call term_sendkeys(buf, "\<Esc>")
2892
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002893 " Pressing <PageDown> should scroll the menu downward
2894 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2895 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2896 call term_sendkeys(buf, "\<PageDown>")
2897 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2898 call term_sendkeys(buf, "\<PageDown>")
2899 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2900 call term_sendkeys(buf, "\<PageDown>")
2901 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2902 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2903 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2904
2905 " Pressing <PageUp> should scroll the menu upward
2906 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2907 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2908 call term_sendkeys(buf, "\<PageUp>")
2909 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2910 call term_sendkeys(buf, "\<PageUp>")
2911 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2912 call term_sendkeys(buf, "\<PageUp>")
2913 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2914
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002915 " pressing <C-E> to end completion should work in middle of the line too
2916 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2917 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2918 call term_sendkeys(buf, "\<C-E>")
2919 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2920
2921 " pressing <C-Y> should select the current match and end completion
2922 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2923 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2924
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002925 call term_sendkeys(buf, "\<C-U>\<CR>")
2926 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002927endfunc
2928
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002929" Test for wildmenumode() with the cmdline popup menu
2930func Test_wildmenumode_with_pum()
2931 set wildmenu
2932 set wildoptions=pum
2933 cnoremap <expr> <F2> wildmenumode()
2934 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2935 call assert_equal('"sign define10', @:)
2936 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2937 call assert_equal('"sign define jump list place undefine unplace0', @:)
2938 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2939 call assert_equal('"sign 0', @:)
2940 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2941 call assert_equal('"sign define0', @:)
2942 set nowildmenu wildoptions&
2943 cunmap <F2>
2944endfunc
2945
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002946func Test_wildmenu_with_pum_foldexpr()
Drew Vogelea67ba72025-05-07 22:05:17 +02002947 CheckScreendump
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002948 CheckRunVimInTerminal
2949
2950 let lines =<< trim END
2951 call setline(1, ['folded one', 'folded two', 'some more text'])
2952 func MyFoldText()
2953 return 'foo'
2954 endfunc
2955 set foldtext=MyFoldText() wildoptions=pum
2956 normal ggzfj
2957 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002958 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002959 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2960 call term_sendkeys(buf, ":set\<Tab>")
2961 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2962
2963 call term_sendkeys(buf, "\<Esc>")
2964 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2965
2966 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002967endfunc
2968
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002969" Test for opening the cmdline completion popup menu from the terminal window.
2970" The popup menu should be positioned correctly over the status line of the
2971" bottom-most window.
2972func Test_wildmenu_pum_from_terminal()
Drew Vogelea67ba72025-05-07 22:05:17 +02002973 CheckScreendump
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002974 CheckRunVimInTerminal
2975 let python = PythonProg()
2976 call CheckPython(python)
2977
2978 %bw!
2979 let cmds = ['set wildmenu wildoptions=pum']
2980 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2981 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002982 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002983 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2984 call term_sendkeys(buf, "\r\r\r")
2985 call term_wait(buf)
2986 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2987 call term_wait(buf)
2988 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2989 call term_wait(buf)
2990 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002991endfunc
2992
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002993func Test_wildmenu_pum_odd_wildchar()
Drew Vogelea67ba72025-05-07 22:05:17 +02002994 CheckScreendump
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002995 CheckRunVimInTerminal
2996
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002997 " Test odd wildchar interactions with pum. Make sure they behave properly
2998 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002999 let lines =<< trim END
3000 set wildoptions=pum
3001 set wildchar=<C-E>
3002 END
3003 call writefile(lines, 'XwildmenuTest', 'D')
3004 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
3005
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003006 call term_sendkeys(buf, ":\<C-E>")
3007 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003008
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003009 " <C-E> being a wildchar takes priority over its original functionality
3010 call term_sendkeys(buf, "\<C-E>")
3011 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
3012
3013 call term_sendkeys(buf, "\<Esc>")
3014 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3015
3016 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
3017 " command-line, and we need to make sure to clean up properly.
3018 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3019 call term_sendkeys(buf, ":\<Esc>")
3020 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3021
3022 call term_sendkeys(buf, "\<Esc>")
3023 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3024
3025 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3026 " and we again need to make sure we clean up properly.
3027 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3028 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3029 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3030
3031 call term_sendkeys(buf, "\<C-N>")
3032 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3033
3034 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003035endfunc
3036
zeertzjq883018f2024-06-15 15:37:11 +02003037" Test that 'rightleft' should not affect cmdline completion popup menu.
3038func Test_wildmenu_pum_rightleft()
3039 CheckFeature rightleft
3040 CheckScreendump
3041
3042 let lines =<< trim END
3043 set wildoptions=pum
3044 set rightleft
3045 END
3046 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3047 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3048
3049 call term_sendkeys(buf, ":sign \<Tab>")
3050 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3051
3052 call StopVimInTerminal(buf)
3053endfunc
3054
Girish Palya4ec46f32025-03-04 20:56:30 +01003055" Test highlighting when pattern matches non-first character of item
3056func Test_wildmenu_pum_hl_nonfirst()
3057 CheckScreendump
3058 let lines =<< trim END
3059 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3060 hi PmenuMatchSel ctermfg=6 ctermbg=7
3061 hi PmenuMatch ctermfg=4 ctermbg=225
3062 func T(a, c, p)
3063 return ["oneA", "o neBneB", "aoneC"]
3064 endfunc
3065 command -nargs=1 -complete=customlist,T MyCmd
3066 END
3067
3068 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3069 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3070
3071 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3072 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3073 call term_sendkeys(buf, "\<Esc>")
3074 call StopVimInTerminal(buf)
3075endfunc
3076
zeertzjqd8c93402024-06-17 18:25:32 +02003077" Test highlighting matched text in cmdline completion popup menu.
3078func Test_wildmenu_pum_hl_match()
3079 CheckScreendump
3080
3081 let lines =<< trim END
3082 set wildoptions=pum,fuzzy
3083 hi PmenuMatchSel ctermfg=6 ctermbg=7
3084 hi PmenuMatch ctermfg=4 ctermbg=225
3085 END
3086 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3087 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3088
3089 call term_sendkeys(buf, ":sign plc\<Tab>")
3090 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3091 call term_sendkeys(buf, "\<Tab>")
3092 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3093 call term_sendkeys(buf, "\<Tab>")
3094 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3095 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3096 call TermWait(buf)
3097 call term_sendkeys(buf, ":sign un\<Tab>")
3098 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3099 call term_sendkeys(buf, "\<Tab>")
3100 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3101 call term_sendkeys(buf, "\<Tab>")
3102 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3103 call term_sendkeys(buf, "\<Esc>")
3104
3105 call StopVimInTerminal(buf)
3106endfunc
3107
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003108" Test for completion after a :substitute command followed by a pipe (|)
3109" character
3110func Test_cmdline_complete_substitute()
Girish Palya6b49fba2025-06-28 19:47:34 +02003111 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003112 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3113 call assert_equal("\"s | \t", @:)
3114 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3115 call assert_equal("\"s/ | \t", @:)
3116 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3117 call assert_equal("\"s/one | \t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02003118 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003119 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3120 call assert_equal("\"s/one/ | \t", @:)
3121 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3122 call assert_equal("\"s/one/two | \t", @:)
3123 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3124 call assert_equal('"s/one/two/ | chistory', @:)
3125 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3126 call assert_equal("\"s/one/two/g \t", @:)
3127 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3128 call assert_equal("\"s/one/two/g | chistory", @:)
3129 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3130 call assert_equal("\"s/one/t\\/ | \t", @:)
3131 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3132 call assert_equal('"s/one/t"o/ | chistory', @:)
3133 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3134 call assert_equal('"s/one/t|o/ | chistory', @:)
3135 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3136 call assert_equal("\"&\t", @:)
3137endfunc
3138
3139" Test for the :dlist command completion
3140func Test_cmdline_complete_dlist()
3141 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3142 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3143 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3144 call assert_equal("\"dlist 10 /pat/ \t", @:)
3145 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3146 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3147 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3148 call assert_equal("\"dlist 10 /pat\\\t", @:)
3149 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3150 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3151endfunc
3152
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003153" argument list (only for :argdel) fuzzy completion
3154func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003155 argadd change.py count.py charge.py
3156 set wildoptions&
3157 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal('"argdel cge', @:)
3159 set wildoptions=fuzzy
3160 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3161 call assert_equal('"argdel change.py charge.py', @:)
3162 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003163 set wildoptions&
3164endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003165
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003166" autocmd group name fuzzy completion
3167func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003168 set wildoptions&
3169 augroup MyFuzzyGroup
3170 augroup END
3171 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal('"augroup mfg', @:)
3173 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal('"augroup MyFuzzyGroup', @:)
3175 set wildoptions=fuzzy
3176 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal('"augroup MyFuzzyGroup', @:)
3178 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_equal('"augroup My*p', @:)
3180 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003181 set wildoptions&
3182endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003183
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003184" buffer name fuzzy completion
3185func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003186 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003187 " Use a long name to reduce the risk of matching a random directory name
3188 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003189 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003190 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal('"b SRFWL', @:)
3192 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003194 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003195 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3196 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3197 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3198 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003199 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003200 set wildoptions&
3201endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003202
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003203" buffer name (full path) fuzzy completion
3204func Test_fuzzy_completion_bufname_fullpath()
3205 CheckUnix
3206 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003207 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003208 edit Xcmd/Xstate/Xfile.js
3209 cd Xcmd/Xstate
3210 enew
3211 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_equal('"b CmdStateFile', @:)
3213 set wildoptions=fuzzy
3214 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3215 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3216 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003217 set wildoptions&
3218endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003219
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003220" :behave suboptions fuzzy completion
3221func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003222 set wildoptions&
3223 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal('"behave xm', @:)
3225 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal('"behave xterm', @:)
3227 set wildoptions=fuzzy
3228 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3229 call assert_equal('"behave xterm', @:)
3230 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal('"behave xt*m', @:)
3232 let g:Sline = ''
3233 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal('mswin', g:Sline)
3235 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003236 set wildoptions&
3237endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003238
Christian Brabandta3422aa2025-04-23 21:04:24 +02003239" :filetype suboptions completion
3240func Test_completion_filetypecmd()
3241 set wildoptions&
3242 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal('"filetype indent off on plugin', @:)
3244 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal('"filetype plugin indent off on', @:)
3246 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal('"filetype indent off on plugin', @:)
3248 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal('"filetype indent', @:)
3250 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal('"filetype plugin', @:)
3252 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3253 call assert_equal('"filetype off on', @:)
3254 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3255 call assert_equal('"filetype indent off', @:)
3256 set wildoptions&
3257endfunc
3258
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003259" " colorscheme name fuzzy completion - NOT supported
3260" func Test_fuzzy_completion_colorscheme()
3261" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003262
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003263" built-in command name fuzzy completion
3264func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003265 set wildoptions&
3266 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal('"sbwin', @:)
3268 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"sbrewind', @:)
3270 set wildoptions=fuzzy
3271 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal('"sbrewind', @:)
3273 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003275 set wildoptions&
3276endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003277
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003278" " compiler name fuzzy completion - NOT supported
3279" func Test_fuzzy_completion_compiler()
3280" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003281
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003282" :cscope suboptions fuzzy completion
3283func Test_fuzzy_completion_cscope()
3284 CheckFeature cscope
3285 set wildoptions&
3286 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3287 call assert_equal('"cscope ret', @:)
3288 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3289 call assert_equal('"cscope reset', @:)
3290 set wildoptions=fuzzy
3291 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal('"cscope reset', @:)
3293 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3294 call assert_equal('"cscope re*t', @:)
3295 set wildoptions&
3296endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003297
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003298" :diffget/:diffput buffer name fuzzy completion
3299func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003300 new SomeBuffer
3301 diffthis
3302 new OtherBuffer
3303 diffthis
3304 set wildoptions&
3305 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal('"diffget sbuf', @:)
3307 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3308 call assert_equal('"diffput sbuf', @:)
3309 set wildoptions=fuzzy
3310 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3311 call assert_equal('"diffget SomeBuffer', @:)
3312 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3313 call assert_equal('"diffput SomeBuffer', @:)
3314 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003315 set wildoptions&
3316endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003317
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003318" " directory name fuzzy completion - NOT supported
3319" func Test_fuzzy_completion_dirname()
3320" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003321
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003322" environment variable name fuzzy completion
3323func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003324 set wildoptions&
3325 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3326 call assert_equal('"echo $VUT', @:)
3327 set wildoptions=fuzzy
3328 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3329 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003330 set wildoptions&
3331endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003332
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003333" autocmd event fuzzy completion
3334func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003335 set wildoptions&
3336 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3337 call assert_equal('"autocmd BWout', @:)
3338 set wildoptions=fuzzy
3339 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3340 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003341 set wildoptions&
3342endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003343
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003344" vim expression fuzzy completion
3345func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003346 let g:PerPlaceCount = 10
3347 set wildoptions&
3348 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3349 call assert_equal('"let c = ppc', @:)
3350 set wildoptions=fuzzy
3351 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3352 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003353 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003354endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003355
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003356" " file name fuzzy completion - NOT supported
3357" func Test_fuzzy_completion_filename()
3358" endfunc
3359
3360" " files in path fuzzy completion - NOT supported
3361" func Test_fuzzy_completion_filesinpath()
3362" endfunc
3363
3364" " filetype name fuzzy completion - NOT supported
3365" func Test_fuzzy_completion_filetype()
3366" endfunc
3367
3368" user defined function name completion
3369func Test_fuzzy_completion_userdefined_func()
3370 set wildoptions&
3371 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3372 call assert_equal('"call Test_f_u_f', @:)
3373 set wildoptions=fuzzy
3374 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3375 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3376 set wildoptions&
3377endfunc
3378
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003379" <SNR> functions should be sorted to the end
3380func Test_fuzzy_completion_userdefined_snr_func()
3381 func s:Sendmail()
3382 endfunc
3383 func SendSomemail()
3384 endfunc
3385 func S1e2n3dmail()
3386 endfunc
3387 set wildoptions=fuzzy
3388 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003389 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003390 set wildoptions&
3391 delfunc s:Sendmail
3392 delfunc SendSomemail
3393 delfunc S1e2n3dmail
3394endfunc
3395
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003396" user defined command name completion
3397func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003398 set wildoptions&
3399 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3400 call assert_equal('"MsFeat', @:)
3401 set wildoptions=fuzzy
3402 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3403 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003404 set wildoptions&
3405endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003406
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003407" " :help tag fuzzy completion - NOT supported
3408" func Test_fuzzy_completion_helptag()
3409" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003410
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003411" highlight group name fuzzy completion
3412func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003413 set wildoptions&
3414 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3415 call assert_equal('"highlight SKey', @:)
3416 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3417 call assert_equal('"highlight SpecialKey', @:)
3418 set wildoptions=fuzzy
3419 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3420 call assert_equal('"highlight SpecialKey', @:)
3421 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3422 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003423 set wildoptions&
3424endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003425
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003426" :history suboptions fuzzy completion
3427func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003428 set wildoptions&
3429 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3430 call assert_equal('"history dg', @:)
3431 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal('"history search', @:)
3433 set wildoptions=fuzzy
3434 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3435 call assert_equal('"history debug', @:)
3436 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3437 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003438 set wildoptions&
3439endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003440
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003441" :language locale name fuzzy completion
3442func Test_fuzzy_completion_lang()
3443 CheckUnix
3444 set wildoptions&
3445 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3446 call assert_equal('"lang psx', @:)
3447 set wildoptions=fuzzy
3448 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3449 call assert_equal('"lang POSIX', @:)
3450 set wildoptions&
3451endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003452
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003453" :mapclear buffer argument fuzzy completion
3454func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003455 set wildoptions&
3456 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3457 call assert_equal('"mapclear buf', @:)
3458 set wildoptions=fuzzy
3459 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003461 set wildoptions&
3462endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003463
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003464" map name fuzzy completion
3465func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003466 " test regex completion works
3467 set wildoptions=fuzzy
3468 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3469 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003470 nmap <plug>MyLongMap :p<CR>
3471 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3472 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3473 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3474 call assert_equal("\"nmap MLM \t", @:)
3475 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3476 call assert_equal("\"nmap <F2> one two \t", @:)
3477 " duplicate entries should be removed
3478 vmap <plug>MyLongMap :<C-U>#<CR>
3479 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3480 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3481 nunmap <plug>MyLongMap
3482 vunmap <plug>MyLongMap
3483 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3484 call assert_equal("\"nmap ABC\t", @:)
3485 " results should be sorted by best match
3486 nmap <Plug>format :
3487 nmap <Plug>goformat :
3488 nmap <Plug>TestFOrmat :
3489 nmap <Plug>fendoff :
3490 nmap <Plug>state :
3491 nmap <Plug>FendingOff :
3492 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3493 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3494 nunmap <Plug>format
3495 nunmap <Plug>goformat
3496 nunmap <Plug>TestFOrmat
3497 nunmap <Plug>fendoff
3498 nunmap <Plug>state
3499 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003500 set wildoptions&
3501endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003502
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003503" abbreviation fuzzy completion
3504func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003505 set wildoptions=fuzzy
3506 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3507 call assert_equal("\"iabbr <nowait>", @:)
3508 iabbr WaitForCompletion WFC
3509 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3510 call assert_equal("\"iabbr WaitForCompletion", @:)
3511 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3512 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003513
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003514 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003515 set wildoptions&
3516endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003517
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003518" menu name fuzzy completion
3519func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003520 CheckFeature menu
3521
3522 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003523 set wildoptions&
3524 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal('"menu pup', @:)
3526 set wildoptions=fuzzy
3527 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3528 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003529
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003530 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003531 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003532endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003533
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003534" :messages suboptions fuzzy completion
3535func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003536 set wildoptions&
3537 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3538 call assert_equal('"messages clr', @:)
3539 set wildoptions=fuzzy
3540 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3541 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003542 set wildoptions&
3543endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003544
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003545" :set option name fuzzy completion
3546func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003547 set wildoptions&
3548 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3549 call assert_equal('"set brkopt', @:)
3550 set wildoptions=fuzzy
3551 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal('"set breakindentopt', @:)
3553 set wildoptions&
3554 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3555 call assert_equal('"set fixendofline', @:)
3556 set wildoptions=fuzzy
3557 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3558 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003559 set wildoptions&
3560endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003561
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003562" :set <term_option>
3563func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003564 set wildoptions&
3565 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3566 call assert_equal('"set t_EC', @:)
3567 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3568 call assert_equal('"set <t_EC>', @:)
3569 set wildoptions=fuzzy
3570 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3571 call assert_equal('"set t_EC', @:)
3572 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3573 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003574 set wildoptions&
3575endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003576
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003577" " :packadd directory name fuzzy completion - NOT supported
3578" func Test_fuzzy_completion_packadd()
3579" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003580
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003581" " shell command name fuzzy completion - NOT supported
3582" func Test_fuzzy_completion_shellcmd()
3583" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003584
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003585" :sign suboptions fuzzy completion
3586func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003587 set wildoptions&
3588 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3589 call assert_equal('"sign ufe', @:)
3590 set wildoptions=fuzzy
3591 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3592 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003593 set wildoptions&
3594endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003595
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003596" :syntax suboptions fuzzy completion
3597func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003598 set wildoptions&
3599 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3600 call assert_equal('"syntax kwd', @:)
3601 set wildoptions=fuzzy
3602 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003604 set wildoptions&
3605endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003606
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003607" syntax group name fuzzy completion
3608func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003609 set wildoptions&
3610 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3611 call assert_equal('"syntax list mpar', @:)
3612 set wildoptions=fuzzy
3613 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3614 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003615 set wildoptions&
3616endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003617
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003618" :syntime suboptions fuzzy completion
3619func Test_fuzzy_completion_syntime()
3620 CheckFeature profile
3621 set wildoptions&
3622 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3623 call assert_equal('"syntime clr', @:)
3624 set wildoptions=fuzzy
3625 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3626 call assert_equal('"syntime clear', @:)
3627 set wildoptions&
3628endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003629
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003630" " tag name fuzzy completion - NOT supported
3631" func Test_fuzzy_completion_tagname()
3632" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003633
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003634" " tag name and file fuzzy completion - NOT supported
3635" func Test_fuzzy_completion_tagfile()
3636" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003637
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003638" " user names fuzzy completion - how to test this functionality?
3639" func Test_fuzzy_completion_username()
3640" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003641
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003642" user defined variable name fuzzy completion
3643func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003644 let g:SomeVariable=10
3645 set wildoptions&
3646 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3647 call assert_equal('"let SVar', @:)
3648 set wildoptions=fuzzy
3649 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3650 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003651 set wildoptions&
3652endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003653
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003654" Test for sorting the results by the best match
3655func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003656 %bw!
3657 command T123format :
3658 command T123goformat :
3659 command T123TestFOrmat :
3660 command T123fendoff :
3661 command T123state :
3662 command T123FendingOff :
3663 set wildoptions=fuzzy
3664 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3665 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3666 delcommand T123format
3667 delcommand T123goformat
3668 delcommand T123TestFOrmat
3669 delcommand T123fendoff
3670 delcommand T123state
3671 delcommand T123FendingOff
3672 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003673 set wildoptions&
3674endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003675
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003676" Test for fuzzy completion of a command with lower case letters and a number
3677func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003678 command Foo2Bar :
3679 set wildoptions=fuzzy
3680 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3681 call assert_equal('"Foo2Bar', @:)
3682 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3683 call assert_equal('"Foo2Bar', @:)
3684 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3685 call assert_equal('"Foo2Bar', @:)
3686 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003687 set wildoptions&
3688endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003689
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003690" Test for command completion for a command starting with 'k'
3691func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003692 command KillKillKill :
3693 set wildoptions&
3694 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3695 call assert_equal("\"killkill\<Tab>", @:)
3696 set wildoptions=fuzzy
3697 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3698 call assert_equal('"KillKillKill', @:)
3699 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003700 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003701endfunc
3702
3703" Test for fuzzy completion for user defined custom completion function
3704func Test_fuzzy_completion_custom_func()
3705 func Tcompl(a, c, p)
3706 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3707 endfunc
3708 command -nargs=* -complete=custom,Tcompl Fuzzy :
3709 set wildoptions&
3710 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3711 call assert_equal("\"Fuzzy format", @:)
3712 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3713 call assert_equal("\"Fuzzy xy", @:)
3714 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3715 call assert_equal("\"Fuzzy ttt", @:)
3716 set wildoptions=fuzzy
3717 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3718 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3719 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3720 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3721 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3722 call assert_equal("\"Fuzzy xy", @:)
3723 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3724 call assert_equal("\"Fuzzy TestFOrmat", @:)
3725 delcom Fuzzy
3726 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003727endfunc
3728
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003729" Test for fuzzy completion in the middle of a cmdline instead of at the end
3730func Test_fuzzy_completion_in_middle()
3731 set wildoptions=fuzzy
3732 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"set wildchar wildcharm wrap", @:)
3734
3735 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3736 call assert_equal("\"args ++encoding= zz", @:)
3737 set wildoptions&
3738endfunc
3739
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003740" Test for :breakadd argument completion
3741func Test_cmdline_complete_breakadd()
3742 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3743 call assert_equal("\"breakadd expr file func here", @:)
3744 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3745 call assert_equal("\"breakadd expr", @:)
3746 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3747 call assert_equal("\"breakadd expr", @:)
3748 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3749 call assert_equal("\"breakadd here", @:)
3750 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3751 call assert_equal("\"breakadd here", @:)
3752 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3753 call assert_equal("\"breakadd abc", @:)
3754 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3755 let l = getcompletion('not', 'breakpoint')
3756 call assert_equal([], l)
3757
3758 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003759 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003760 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3761 call assert_equal("\"breakadd file Xscript", @:)
3762 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3763 call assert_equal("\"breakadd file Xscript", @:)
3764 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3765 call assert_equal("\"breakadd file 20 Xscript", @:)
3766 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3767 call assert_equal("\"breakadd file 20 Xscript", @:)
3768 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3769 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3770 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal("\"breakadd file 20\t", @:)
3772 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3773 call assert_equal("\"breakadd file 20x\t", @:)
3774 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3775 call assert_equal("\"breakadd file Xscript ", @:)
3776 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3777 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003778
3779 " Test for :breakadd func [lnum] <function>
3780 func Xbreak_func()
3781 endfunc
3782 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3783 call assert_equal("\"breakadd func Xbreak_func", @:)
3784 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3785 call assert_equal("\"breakadd func Xbreak_func", @:)
3786 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3787 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3788 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3789 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3790 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3791 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3792 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3793 call assert_equal("\"breakadd func 20\t", @:)
3794 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3795 call assert_equal("\"breakadd func 20x\t", @:)
3796 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3797 call assert_equal("\"breakadd func Xbreak_func ", @:)
3798 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3799 call assert_equal("\"breakadd func X1B2C3", @:)
3800 delfunc Xbreak_func
3801
3802 " Test for :breakadd expr <expression>
3803 let g:Xtest_var = 10
3804 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3805 call assert_equal("\"breakadd expr Xtest_var", @:)
3806 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3807 call assert_equal("\"breakadd expr Xtest_var", @:)
3808 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3809 call assert_equal("\"breakadd expr Xtest_var ", @:)
3810 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3811 call assert_equal("\"breakadd expr X1B2C3", @:)
3812 unlet g:Xtest_var
3813
3814 " Test for :breakadd here
3815 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3816 call assert_equal("\"breakadd here Xtest", @:)
3817 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3818 call assert_equal("\"breakadd here Xtest", @:)
3819 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3820 call assert_equal("\"breakadd here ", @:)
3821endfunc
3822
3823" Test for :breakdel argument completion
3824func Test_cmdline_complete_breakdel()
3825 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3826 call assert_equal("\"breakdel file func here", @:)
3827 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3828 call assert_equal("\"breakdel file", @:)
3829 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3830 call assert_equal("\"breakdel file", @:)
3831 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3832 call assert_equal("\"breakdel here", @:)
3833 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3834 call assert_equal("\"breakdel here", @:)
3835 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3836 call assert_equal("\"breakdel abc", @:)
3837
3838 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003839 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003840 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3841 call assert_equal("\"breakdel file Xscript", @:)
3842 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3843 call assert_equal("\"breakdel file Xscript", @:)
3844 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3845 call assert_equal("\"breakdel file 20 Xscript", @:)
3846 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3847 call assert_equal("\"breakdel file 20 Xscript", @:)
3848 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3849 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3850 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3851 call assert_equal("\"breakdel file 20\t", @:)
3852 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3853 call assert_equal("\"breakdel file 20x\t", @:)
3854 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3855 call assert_equal("\"breakdel file Xscript ", @:)
3856 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3857 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003858
3859 " Test for :breakdel func [lnum] <function>
3860 func Xbreak_func()
3861 endfunc
3862 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3863 call assert_equal("\"breakdel func Xbreak_func", @:)
3864 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3865 call assert_equal("\"breakdel func Xbreak_func", @:)
3866 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3867 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3868 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3869 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3870 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3871 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3872 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3873 call assert_equal("\"breakdel func 20\t", @:)
3874 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3875 call assert_equal("\"breakdel func 20x\t", @:)
3876 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3877 call assert_equal("\"breakdel func Xbreak_func ", @:)
3878 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3879 call assert_equal("\"breakdel func X1B2C3", @:)
3880 delfunc Xbreak_func
3881
3882 " Test for :breakdel here
3883 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3884 call assert_equal("\"breakdel here Xtest", @:)
3885 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3886 call assert_equal("\"breakdel here Xtest", @:)
3887 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3888 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003889endfunc
3890
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003891" Test for :scriptnames argument completion
3892func Test_cmdline_complete_scriptnames()
3893 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003894 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003895 source Xa1b2c3.vim
3896 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3897 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3898 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3899 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3900 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3901 call assert_equal("\"script b2c3", @:)
3902 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3903 call assert_match("\"script 2\<Tab>$", @:)
3904 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3905 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3906 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3907 call assert_equal("\"script ", @:)
3908 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3909 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3910 new
3911 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3912 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3913 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003914 set wildmenu&
3915endfunc
3916
Bram Moolenaard8893442022-05-06 20:38:47 +01003917" this was going over the end of IObuff
3918func Test_report_error_with_composing()
3919 let caught = 'no'
3920 try
3921 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3922 catch /E492:/
3923 let caught = 'yes'
3924 endtry
3925 call assert_equal('yes', caught)
3926endfunc
3927
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003928" Test for expanding 2-letter and 3-letter :substitute command arguments.
3929" These commands don't accept an argument.
3930func Test_cmdline_complete_substitute_short()
3931 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3932 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3933 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3934 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3935 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3936 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3937 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3938 endfor
3939endfunc
3940
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003941" Test for shellcmdline command argument completion
3942func Test_cmdline_complete_shellcmdline_argument()
3943 command -nargs=+ -complete=shellcmdline MyCmd
3944
3945 set wildoptions=fuzzy
3946
3947 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3948 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003949 call assert_equal(['test_cmdline.vim'],
3950 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003951
3952 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3953 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003954 call assert_equal([],
3955 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003956
3957 let compl1 = getcompletion('', 'file')[0]
3958 let compl2 = getcompletion('', 'file')[1]
3959 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3960 call assert_equal('"MyCmd vim ' .. compl1, @:)
3961
3962 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3963 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3964
3965 let compl = getcompletion('', 'file')[1]
3966 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3967 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3968
3969 set wildoptions&
3970 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3971 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003972 call assert_equal(['test_cmdline.vim'],
3973 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003974
3975 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3976 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003977 call assert_equal([],
3978 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003979
3980 let compl1 = getcompletion('', 'file')[0]
3981 let compl2 = getcompletion('', 'file')[1]
3982 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3983 call assert_equal('"MyCmd vim ' .. compl1, @:)
3984
3985 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3986 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3987
3988 let compl = getcompletion('', 'file')[1]
3989 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3990 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3991
3992 delcommand MyCmd
3993endfunc
3994
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003995" Test for :! shell command argument completion
3996func Test_cmdline_complete_bang_cmd_argument()
3997 set wildoptions=fuzzy
3998 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3999 call assert_equal('"!vim test_cmdline.vim', @:)
4000 set wildoptions&
4001 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4002 call assert_equal('"!vim test_cmdline.vim', @:)
4003endfunc
4004
zeertzjq961b2e52023-04-17 15:53:24 +01004005func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004006 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004007endfunc
4008
4009func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01004010 call assert_equal(0, getcmdpos())
4011 call assert_equal(0, getcmdscreenpos())
4012 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004013 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01004014
zeertzjqa821b602024-06-18 20:31:08 +02004015 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01004016 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004017 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004018 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004019 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004020 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004021 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02004022
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004023 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4024 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02004025 let g:results = []
4026 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4027 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4028 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004029 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4030 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4031 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02004032
4033 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01004034 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004035endfunc
4036
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01004037func Test_recursive_register()
4038 let @= = ''
4039 silent! ?e/
4040 let caught = 'no'
4041 try
4042 normal //
4043 catch /E169:/
4044 let caught = 'yes'
4045 endtry
4046 call assert_equal('yes', caught)
4047endfunc
4048
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004049func Test_long_error_message()
4050 " the error should be truncated, not overrun IObuff
4051 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4052endfunc
4053
zeertzjq6791adc2022-07-26 20:42:25 +01004054func Test_cmdline_redraw_tabline()
4055 CheckRunVimInTerminal
4056
4057 let lines =<< trim END
4058 set showtabline=2
4059 autocmd CmdlineEnter * set tabline=foo
4060 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004061 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004062 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4063 call term_sendkeys(buf, ':')
4064 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4065
4066 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004067endfunc
4068
zeertzjqb82a2ab2022-08-21 14:33:57 +01004069func Test_wildmenu_pum_disable_while_shown()
4070 set wildoptions=pum
4071 set wildmenu
4072 cnoremap <F2> <Cmd>set nowildmenu<CR>
4073 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4074 call assert_equal(0, pumvisible())
4075 cunmap <F2>
4076 set wildoptions& wildmenu&
4077endfunc
4078
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004079func Test_setcmdline()
4080 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004081 call assert_equal(0, setcmdline(test_null_string()))
4082 call assert_equal('', getcmdline())
4083 call assert_equal(1, getcmdpos())
4084
4085 call assert_equal(0, setcmdline(''[: -1]))
4086 call assert_equal('', getcmdline())
4087 call assert_equal(1, getcmdpos())
4088
zeertzjq54acb902022-08-29 16:21:25 +01004089 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004090 call assert_equal(0, setcmdline(a:text))
4091 call assert_equal(a:text, getcmdline())
4092 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004093 call assert_equal(getcmdtype(), g:cmdtype)
4094 unlet g:cmdtype
4095 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004096
4097 call assert_equal(0, setcmdline(a:text, a:pos))
4098 call assert_equal(a:text, getcmdline())
4099 call assert_equal(a:pos, getcmdpos())
4100
4101 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004102 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4103 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004104
4105 return ''
4106 endfunc
4107
4108 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4109 call assert_equal('set rtp?', @:)
4110
zeertzjq54acb902022-08-29 16:21:25 +01004111 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4112 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4113 call assert_equal('foo', g:str)
4114 unlet g:str
4115
4116 delfunc SetText
4117
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004118 " setcmdline() returns 1 when not editing the command line.
4119 call assert_equal(1, 'foo'->setcmdline())
4120
4121 " Called in custom function
4122 func CustomComplete(A, L, P)
4123 call assert_equal(0, setcmdline("DoCmd "))
4124 return "January\nFebruary\nMars\n"
4125 endfunc
4126
4127 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4128 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4129 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004130 delcom DoCmd
4131 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004132
4133 " Called in <expr>
4134 cnoremap <expr>a setcmdline('let foo=')
4135 call feedkeys(":a\<CR>", 'tx')
4136 call assert_equal('let foo=0', @:)
4137 cunmap a
4138endfunc
4139
Sean Dewarfc8a6012023-04-17 16:41:20 +01004140func Test_rulerformat_position()
4141 CheckScreendump
4142
4143 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4144 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4145 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4146 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4147 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4148
4149 " clean up
4150 call StopVimInTerminal(buf)
4151endfunc
4152
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004153" Test for using "%!" in 'rulerformat' to use a function
4154func Test_rulerformat_function()
4155 CheckScreendump
4156
4157 let lines =<< trim END
4158 func TestRulerFn()
4159 return '10,20%=30%%'
4160 endfunc
4161 END
4162 call writefile(lines, 'Xrulerformat_function', 'D')
4163
4164 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4165 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4166 call term_sendkeys(buf, ":redraw!\<CR>")
4167 call term_wait(buf)
4168 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4169
4170 " clean up
4171 call StopVimInTerminal(buf)
4172endfunc
4173
zeertzjqe4c79d32023-08-15 22:41:53 +02004174func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004175 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004176
zeertzjqe4c79d32023-08-15 22:41:53 +02004177 call assert_equal(getcompletion('', 'cmdline'),
4178 \ getcompletion('TestCompletion ', 'cmdline'))
4179 call assert_equal(['<buffer>'],
4180 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4181
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004182 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004183endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004184
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004185func Test_custom_completion()
4186 func CustomComplete1(lead, line, pos)
4187 return "a\nb\nc"
4188 endfunc
4189 func CustomComplete2(lead, line, pos)
4190 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4191 endfunc
4192 func Check_custom_completion()
4193 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4194 return ''
4195 endfunc
4196 func Check_customlist_completion()
4197 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4198 return ''
4199 endfunc
4200
4201 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4202 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4203
4204 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4205 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
zeertzjqe2c0f812025-07-06 20:26:56 +02004206 call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 '))
4207 call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 '))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004208
4209 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4210 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4211
zeertzjq757f3212024-04-15 19:01:04 +02004212 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4213 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4214 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004215
4216 delcom Test1
4217 delcom Test2
4218
4219 delfunc CustomComplete1
4220 delfunc CustomComplete2
4221 delfunc Check_custom_completion
4222 delfunc Check_customlist_completion
4223endfunc
4224
zeertzjq28a23602023-09-29 19:58:35 +02004225func Test_custom_completion_with_glob()
4226 func TestGlobComplete(A, L, P)
4227 return split(glob('Xglob*'), "\n")
4228 endfunc
4229
4230 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4231 call writefile([], 'Xglob1', 'D')
4232 call writefile([], 'Xglob2', 'D')
4233
4234 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4235 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4236
4237 delcommand TestGlobComplete
4238 delfunc TestGlobComplete
4239endfunc
4240
Christian Brabandt8610f742024-01-12 17:34:40 +01004241func Test_window_size_stays_same_after_changing_cmdheight()
4242 set laststatus=2
4243 let expected = winheight(0)
4244 function! Function_name() abort
4245 call feedkeys(":"..repeat('x', &columns), 'x')
4246 let &cmdheight=2
4247 let &cmdheight=1
4248 redraw
4249 endfunction
4250 call Function_name()
4251 call assert_equal(expected, winheight(0))
4252endfunc
4253
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004254" verify that buffer-completion finds all buffer names matching a pattern
4255func Test_buffer_completion()
4256 " should return empty list
4257 call assert_equal([], getcompletion('', 'buffer'))
4258
4259 call mkdir('Xbuf_complete', 'R')
4260 e Xbuf_complete/Foobar.c
4261 e Xbuf_complete/MyFoobar.c
4262 e AFoobar.h
4263 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4264
4265 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4266 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4267 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4268 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4269endfunc
4270
Anton Sharonov49528da2024-04-14 20:02:24 +02004271" :set t_??
4272func Test_term_option()
4273 set wildoptions&
4274 let _cpo = &cpo
4275 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004276 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004277 let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm'
4278 \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe'
4279 \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC'
4280 \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr'
4281 \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi'
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004282 \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*'
Anton Sharonov49528da2024-04-14 20:02:24 +02004283 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004284 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004285 let &cpo = _cpo
4286endfunc
4287
Christian Brabandt70a11a62024-07-26 19:13:55 +02004288func Test_ex_command_completion()
4289 " required for :*
4290 set cpo+=*
4291 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
Hirohito Higashifbe4a8f2025-04-27 15:28:30 +02004292 " :++ and :-- are only valid in Vim9 script context, so they can be ignored
Christian Brabandt70a11a62024-07-26 19:13:55 +02004293 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004294 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004295 call assert_equal(0, exists(':ke'))
4296 call assert_equal(1, exists(':kee'))
4297 call assert_equal(1, exists(':keep'))
4298 call assert_equal(1, exists(':keepm'))
4299 call assert_equal(1, exists(':keepma'))
4300 call assert_equal(1, exists(':keepmar'))
4301 call assert_equal(1, exists(':keepmark'))
4302 call assert_equal(2, exists(':keepmarks'))
4303 call assert_equal(2, exists(':keepalt'))
4304 call assert_equal(2, exists(':keepjumps'))
4305 call assert_equal(2, exists(':keeppatterns'))
4306 set cpo-=*
4307endfunc
4308
zeertzjq5df3cb22024-10-07 21:05:06 +02004309func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004310 CheckMSWindows
4311 let save_shellslash = &shellslash
4312 set noshellslash
4313 call system('mkdir XXXa\_b')
4314 defer delete('XXXa', 'rf')
4315 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4316 call assert_equal('"cd XXXa\_b\', @:)
4317 let &shellslash = save_shellslash
4318endfunc
4319
zeertzjqec270a52025-04-23 20:50:23 +02004320" Test cmdcomplete_info() with CmdlineLeavePre autocmd
Girish Palya92f68e22025-04-21 11:12:41 +02004321func Test_cmdcomplete_info()
4322 augroup test_CmdlineLeavePre
4323 autocmd!
zeertzjqec270a52025-04-23 20:50:23 +02004324 " Calling expand() should not interfere with cmdcomplete_info().
4325 autocmd CmdlineLeavePre * call expand('test_cmdline.*')
Girish Palya92f68e22025-04-21 11:12:41 +02004326 autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
4327 augroup END
4328 new
4329 call assert_equal({}, cmdcomplete_info())
4330 call feedkeys(":h echom\<cr>", "tx") " No expansion
4331 call assert_equal('{}', g:cmdcomplete_info)
4332 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4333 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4334 call feedkeys(":h echom\<tab>\<cr>", "tx")
4335 call assert_equal(
4336 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4337 \ g:cmdcomplete_info)
4338 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4339 call assert_equal(
4340 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4341 \ g:cmdcomplete_info)
4342 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4343 call assert_equal(
4344 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4345 \ g:cmdcomplete_info)
4346
4347 set wildoptions=pum
4348 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4349 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4350 call feedkeys(":h echom\<tab>\<cr>", "tx")
4351 call assert_equal(
4352 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4353 \ g:cmdcomplete_info)
4354 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4355 call assert_equal(
4356 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4357 \ g:cmdcomplete_info)
4358 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4359 call assert_equal(
4360 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4361 \ g:cmdcomplete_info)
4362 bw!
4363 set wildoptions&
4364endfunc
4365
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02004366func Test_redrawtabpanel_error()
4367 CheckNotFeature tabpanel
4368 call assert_fails(':redrawtabpanel', 'E1547:')
4369endfunc
4370
Girish Palya6b49fba2025-06-28 19:47:34 +02004371" Test wildcharm completion for '/' and '?' search
4372func Test_search_complete()
4373 CheckOption incsearch
4374 set wildcharm=<c-z>
4375
4376 " Disable char_avail so that expansion of commandline works
4377 call test_override("char_avail", 1)
4378
4379 func GetComplInfo()
4380 let g:compl_info = cmdcomplete_info()
4381 return ''
4382 endfunc
4383
4384 new
4385 cnoremap <buffer><expr> <F9> GetComplInfo()
4386
4387 " Pressing <Tab> inserts tab character
4388 set wildchar=0
4389 call setline(1, "x\t")
4390 call feedkeys("/x\t\r", "tx")
4391 call assert_equal("x\t", @/)
4392 set wildchar&
4393
4394 call setline(1, ['the', 'these', 'thethe', 'thethere', 'foobar'])
4395
4396 for trig in ["\<tab>", "\<c-z>"]
4397 " Test menu first item and order
4398 call feedkeys($"gg2j/t{trig}\<f9>", 'tx')
4399 call assert_equal(['the', 'thethere', 'there', 'these', 'thethe'], g:compl_info.matches)
4400 call feedkeys($"gg2j?t{trig}\<f9>", 'tx')
4401 call assert_equal(['these', 'the', 'there', 'thethere', 'thethe'], g:compl_info.matches)
4402
4403 " <c-n> and <c-p> cycle through menu items
4404 call feedkeys($"gg/the{trig}\<cr>", 'tx')
4405 call assert_equal('these', getline('.'))
4406 call feedkeys($"gg/the{trig}\<c-n>\<cr>", 'tx')
4407 call assert_equal('thethe', getline('.'))
4408 call feedkeys($"gg/the{trig}".repeat("\<c-n>", 5)."\<cr>", 'tx')
4409 call assert_equal('these', getline('.'))
4410 call feedkeys($"G?the{trig}\<cr>", 'tx')
4411 call assert_equal('thethere', getline('.'))
4412 call feedkeys($"G?the{trig}".repeat("\<c-p>", 5)."\<cr>", 'tx')
4413 call assert_equal('thethere', getline('.'))
4414
4415 " Beginning of word pattern (<) retains '<'
4416 call feedkeys($"gg2j/\\<t{trig}\<f9>", 'tx')
4417 call assert_equal(['\<thethere', '\<the', '\<these', '\<thethe'], g:compl_info.matches)
4418 call feedkeys($"gg2j?\\<t{trig}\<f9>", 'tx')
4419 call assert_equal(['\<these', '\<the', '\<thethere', '\<thethe'], g:compl_info.matches)
4420 call feedkeys($"gg2j/\\v<t{trig}\<f9>", 'tx')
4421 call assert_equal(['\v<thethere', '\v<the', '\v<these', '\v<thethe'], g:compl_info.matches)
4422 call feedkeys($"gg2j?\\v<th{trig}\<f9>", 'tx')
4423 call assert_equal(['\v<these', '\v<the', '\v<thethere', '\v<thethe'], g:compl_info.matches)
4424 endfor
4425
4426 " Ctrl-G goes from one match to the next, after menu is opened
4427 set incsearch
4428 " first match
4429 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<cr>", 'tx')
4430 call assert_equal('thethe', getline('.'))
4431 " second match
4432 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<c-g>\<cr>", 'tx')
4433 call assert_equal('thethere', getline('.'))
4434 call assert_equal([0, 0, 0, 0], getpos('"'))
4435
4436 " CTRL-T goes to the previous match
4437 " first match
4438 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2)."\<c-t>\<cr>", 'tx')
4439 call assert_equal('thethere', getline('.'))
4440 " second match
4441 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2).repeat("\<c-t>", 2)."\<cr>", 'tx')
4442 call assert_equal('thethe', getline('.'))
4443
4444 " wild menu is cleared properly
4445 call feedkeys("/the\<c-z>\<esc>/\<f9>", 'tx')
4446 call assert_equal({}, g:compl_info)
4447 call feedkeys("/the\<c-z>\<c-e>\<f9>", 'tx')
4448 call assert_equal([], g:compl_info.matches)
4449
4450 " Do not expand if offset is present (/pattern/offset and ?pattern?offset)
4451 for pat in ["/", "/2", "/-3", "\\/"]
4452 call feedkeys("/the" . pat . "\<c-z>\<f9>", 'tx')
4453 call assert_equal({}, g:compl_info)
4454 endfor
4455 for pat in ["?", "?2", "?-3", "\\\\?"]
4456 call feedkeys("?the" . pat . "\<c-z>\<f9>", 'tx')
4457 call assert_equal({}, g:compl_info)
4458 endfor
4459
4460 " Last letter of match is multibyte
4461 call setline('$', ['theΩ'])
4462 call feedkeys("gg/th\<c-z>\<f9>", 'tx')
4463 call assert_equal(['these', 'thethe', 'the', 'thethere', 'there', 'theΩ'],
4464 \ g:compl_info.matches)
4465
4466 " Identical words
4467 call setline(1, ["foo", "foo", "foo", "foobar"])
4468 call feedkeys("gg/f\<c-z>\<f9>", 'tx')
4469 call assert_equal(['foo', 'foobar'], g:compl_info.matches)
4470
4471 " Exact match
4472 call feedkeys("/foo\<c-z>\<f9>", 'tx')
4473 call assert_equal(['foo', 'foobar'], g:compl_info.matches)
4474
4475 " Match case correctly
4476 %d
4477 call setline(1, ["foobar", "Foobar", "fooBAr", "FooBARR"])
4478 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4479 call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches)
4480 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4481 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4482 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4483 call assert_equal({}, g:compl_info)
Girish Palyaaf220072025-07-07 19:42:10 +02004484 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
4485 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004486 set ignorecase
4487 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4488 call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches)
4489 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4490 call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches)
4491 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4492 call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches)
Girish Palyaaf220072025-07-07 19:42:10 +02004493 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
4494 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004495 set smartcase
4496 call feedkeys("gg/f\<tab>\<f9>", 'tx')
Girish Palyaaf220072025-07-07 19:42:10 +02004497 call assert_equal(['foobar', 'fooBAr', 'foobarr'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004498 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4499 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4500 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4501 call assert_equal({}, g:compl_info)
Girish Palyaaf220072025-07-07 19:42:10 +02004502 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
4503 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
4504 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
4505 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004506
4507 bw!
4508 call test_override("char_avail", 0)
4509 delfunc GetComplInfo
4510 unlet! g:compl_info
4511 set wildcharm=0 incsearch& ignorecase& smartcase&
4512endfunc
4513
4514func Test_search_wildmenu_screendump()
4515 CheckScreendump
4516
4517 let lines =<< trim [SCRIPT]
zeertzjq5e34eec2025-07-05 15:37:17 +02004518 call test_override('alloc_lines', 1)
Girish Palya6b49fba2025-06-28 19:47:34 +02004519 set wildmenu wildcharm=<f5>
4520 call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
4521 [SCRIPT]
4522 call writefile(lines, 'XTest_search_wildmenu', 'D')
4523 let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10})
4524
4525 " Pattern has newline at EOF
4526 call term_sendkeys(buf, "gg2j/e\\n\<f5>")
4527 call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {})
4528
4529 " longest:full
4530 call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>")
4531 call term_sendkeys(buf, "gg/t\<f5>")
4532 call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {})
4533
4534 " list:full
4535 call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>")
4536 call term_sendkeys(buf, "gg/t\<f5>")
4537 call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {})
4538
4539 " noselect:full
4540 call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>")
4541 call term_sendkeys(buf, "gg/t\<f5>")
4542 call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {})
4543
4544 " Multiline
4545 call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>")
4546 call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {})
4547
zeertzjq08e5b122025-07-06 11:06:44 +02004548 " 'incsearch' is redrawn after accepting completion
4549 call term_sendkeys(buf, "\<esc>:set wim=full\<cr>")
4550 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
4551 call term_sendkeys(buf, "/th")
4552 call VerifyScreenDump(buf, 'Test_search_wildmenu_6', {})
4553 call term_sendkeys(buf, "\<f5>")
4554 call VerifyScreenDump(buf, 'Test_search_wildmenu_7', {})
4555 call term_sendkeys(buf, "\<c-n>\<c-y>")
4556 call VerifyScreenDump(buf, 'Test_search_wildmenu_8', {})
4557
Girish Palya6b49fba2025-06-28 19:47:34 +02004558 call term_sendkeys(buf, "\<esc>")
4559 call StopVimInTerminal(buf)
4560endfunc
4561
4562" Test wildcharm completion for :s and :g with range
4563func Test_range_complete()
4564 set wildcharm=<c-z>
4565
4566 " Disable char_avail so that expansion of commandline works
4567 call test_override("char_avail", 1)
4568
4569 func GetComplInfo()
4570 let g:compl_info = cmdcomplete_info()
4571 return ''
4572 endfunc
4573 new
4574 cnoremap <buffer><expr> <F9> GetComplInfo()
4575
4576 call setline(1, ['ab', 'ba', 'ca', 'af'])
4577
4578 for trig in ["\<tab>", "\<c-z>"]
4579 call feedkeys($":%s/a{trig}\<f9>", 'xt')
4580 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
4581 call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt')
4582 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
4583 endfor
4584
4585 call feedkeys(":%s/\<c-z>\<f9>", 'xt')
4586 call assert_equal({}, g:compl_info)
4587
4588 for cmd in ['s', 'g']
4589 call feedkeys(":1,2" . cmd . "/a\<c-z>\<f9>", 'xt')
4590 call assert_equal(['ab', 'a'], g:compl_info.matches)
4591 endfor
4592
4593 1
4594 call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt')
4595 call assert_equal(['ab', 'a'], g:compl_info.matches)
4596
4597 /f
4598 call feedkeys(":1,s/b\<c-z>\<f9>", 'xt')
4599 call assert_equal(['b', 'ba'], g:compl_info.matches)
4600
4601 /c
4602 call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt')
4603 call assert_equal(['a', 'af'], g:compl_info.matches)
4604
4605 %s/c/c/
4606 call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt')
4607 call assert_equal(['ab', 'a'], g:compl_info.matches)
4608
4609 3
4610 normal! ma
4611 call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt')
4612 call assert_equal(['a', 'af'], g:compl_info.matches)
4613
4614 " Line number followed by a search pattern ([start]/pattern/[command])
4615 call feedkeys("3/a\<c-z>\<f9>", 'xt')
4616 call assert_equal(['a', 'af', 'ab'], g:compl_info.matches)
4617
4618 bw!
4619 call test_override("char_avail", 0)
4620 delfunc GetComplInfo
4621 unlet! g:compl_info
4622 set wildcharm=0
4623endfunc
4624
Bram Moolenaar309976e2019-12-05 18:16:33 +01004625" vim: shiftwidth=2 sts=2 expandtab