blob: f9533fa02914b0159f11fda670a658c93141ab98 [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:')
883 call assert_equal(getcompletiontype(''), 'command')
884 call assert_equal(getcompletiontype('dummy '), '')
885 call assert_equal(getcompletiontype('cd '), 'dir_in_path')
886 call assert_equal(getcompletiontype('let v:n'), 'var')
887 call assert_equal(getcompletiontype('call tag'), 'function')
888 call assert_equal(getcompletiontype('help '), 'help')
889endfunc
890
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000891func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000892 " Get a dialog in the GUI
893 CheckNotGui
894
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000895 " This was using uninitialized memory.
896 let lines =<< trim END
897 set verbose=6
898 norm @=ٷ
899 qall!
900 END
901 call writefile(lines, 'XmultiScript', 'D')
902 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
903endfunc
904
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000905" Test for getcompletion() with "fuzzy" in 'wildoptions'
906func Test_getcompletion_wildoptions()
907 let save_wildoptions = &wildoptions
908 set wildoptions&
909 let l = getcompletion('space', 'option')
910 call assert_equal([], l)
911 let l = getcompletion('ier', 'command')
912 call assert_equal([], l)
913 set wildoptions=fuzzy
914 let l = getcompletion('space', 'option')
915 call assert_true(index(l, 'backspace') >= 0)
916 let l = getcompletion('ier', 'command')
917 call assert_true(index(l, 'compiler') >= 0)
918 let &wildoptions = save_wildoptions
919endfunc
920
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000921func Test_complete_autoload_error()
922 let save_rtp = &rtp
923 let lines =<< trim END
924 vim9script
925 export def Complete(..._): string
926 return 'match'
927 enddef
928 echo this will cause an error
929 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100930 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000931 call writefile(lines, 'Xdir/autoload/script.vim')
932 exe 'set rtp+=' .. getcwd() .. '/Xdir'
933
934 let lines =<< trim END
935 vim9script
936 import autoload 'script.vim'
937 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
938 &wildcharm = char2nr("\<Tab>")
939 feedkeys(":Cmd \<Tab>", 'xt')
940 END
941 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
942
943 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000944endfunc
945
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100946func Test_fullcommand()
947 let tests = {
948 \ '': '',
949 \ ':': '',
950 \ ':::': '',
951 \ ':::5': '',
952 \ 'not_a_cmd': '',
953 \ 'Check': '',
954 \ 'syntax': 'syntax',
955 \ ':syntax': 'syntax',
956 \ '::::syntax': 'syntax',
957 \ 'sy': 'syntax',
958 \ 'syn': 'syntax',
959 \ 'synt': 'syntax',
960 \ ':sy': 'syntax',
961 \ '::::sy': 'syntax',
962 \ 'match': 'match',
963 \ '2match': 'match',
964 \ '3match': 'match',
965 \ 'aboveleft': 'aboveleft',
966 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100967 \ 'en': 'endif',
968 \ 'end': 'endif',
969 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100970 \ 's': 'substitute',
971 \ '5s': 'substitute',
972 \ ':5s': 'substitute',
973 \ "'<,'>s": 'substitute',
974 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100975 \ 'CheckLin': 'CheckLinux',
976 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100977 \ }
978
979 for [in, want] in items(tests)
980 call assert_equal(want, fullcommand(in))
981 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200982 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100983
984 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200985
986 command -buffer BufferLocalCommand :
987 command GlobalCommand :
988 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
989 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
990 delcommand BufferLocalCommand
991 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100992endfunc
993
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200994func Test_shellcmd_completion()
995 let save_path = $PATH
996
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100997 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200998 call writefile([''], 'Xpathdir/Xfile.exe')
999 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
1000
1001 " Set PATH to example directory without trailing slash.
1002 let $PATH = getcwd() . '/Xpathdir'
1003
1004 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
1005 " dirs in the PATH, even though they won't be executed. We check that only
1006 " subdirs of the PWD and executables from the PATH are included in the
1007 " suggestions.
1008 let actual = getcompletion('X', 'shellcmd')
1009 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
1010 call insert(expected, 'Xfile.exe')
1011 call assert_equal(expected, actual)
1012
Bram Moolenaar6ab9e422018-07-28 19:20:13 +02001013 let $PATH = save_path
1014endfunc
1015
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001016func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +01001017 call mkdir('a/b/c', 'pR')
1018 call writefile(['asdfasdf'], 'a/b/c/fileXname')
1019 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
1020 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +02001021 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001022endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +01001023
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001024func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +01001025 let @a = "def"
1026 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
1027 call assert_equal('"abc def ghi', @:)
1028
1029 new
1030 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
1031
1032 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1033 call assert_equal('"aaa asdf bbb', @:)
1034
1035 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
1036 call assert_equal('"aaa /tmp/some bbb', @:)
1037
Bram Moolenaare2c8d832018-05-01 19:24:03 +02001038 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
1039 call assert_equal('"aaa '.getline(1).' bbb', @:)
1040
Bram Moolenaar21efc362016-12-03 14:05:49 +01001041 set incsearch
1042 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1043 call assert_equal('"aaa verylongword bbb', @:)
1044
1045 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
1046 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001047
1048 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1049 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001050 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001051
1052 " Error while typing a command used to cause that it was not executed
1053 " in the end.
1054 new
1055 try
1056 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1057 catch /^Vim\%((\a\+)\)\=:E32/
1058 " ignore error E32
1059 endtry
1060 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001061
Bram Moolenaar578fe942020-02-27 21:32:51 +01001062 " Try to paste an invalid register using <C-R>
1063 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1064 call assert_equal('"onetwo', @:)
1065
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001066 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001067 let @a = "xy\<C-H>z"
1068 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1069 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001070 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1071 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001072 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1073 call assert_equal("\"xy\<C-H>z", @:)
1074
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001075 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1076 let @a = "xy\<C-V>z"
1077 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1078 call assert_equal('"xyz', @:)
1079 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1080 call assert_equal("\"xy\<C-V>z", @:)
1081
Bram Moolenaar578fe942020-02-27 21:32:51 +01001082 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1083
Bram Moolenaar72532d32018-04-07 19:09:09 +02001084 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001085endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001086
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001087func Test_cmdline_remove_char()
1088 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001089
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001090 for e in ['utf8', 'latin1']
1091 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001092
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001093 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1094 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001095
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001096 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1097 call assert_equal('"abcdef', @:)
1098
1099 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1100 call assert_equal('"abc ghi', @:, e)
1101
1102 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1103 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001104
1105 " This was going before the start in latin1.
1106 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001107 endfor
1108
1109 let &encoding = encoding_save
1110endfunc
1111
zeertzjqff2b79d2024-02-26 20:38:36 +01001112func Test_cmdline_del_utf8()
1113 let @s = '⒌'
1114 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1115 call assert_equal('",,', @:)
1116
1117 let @s = 'a̳'
1118 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1119 call assert_equal('",,', @:)
1120
1121 let @s = 'β̳'
1122 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1123 call assert_equal('",,', @:)
1124
1125 if has('arabic')
1126 let @s = 'لا'
1127 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1128 call assert_equal('",,', @:)
1129 endif
1130endfunc
1131
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001132func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001133 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001134
1135 set keymap=esperanto
1136 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1137 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1138 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001139endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001140
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001141func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001142 new
1143 2;'(
1144 2;')
1145 quit
1146endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001147
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001148func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001149 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001150 new
1151 source Xtest.vim
1152 " Trigger calling validate_cursor()
1153 diffsp Xtest.vim
1154 quit!
1155 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001156endfunc
1157
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001158func Test_mark_from_line_zero()
1159 " this was reading past the end of the first (empty) line
1160 new
1161 norm oxxxx
1162 call assert_fails("0;'(", 'E20:')
1163 bwipe!
1164endfunc
1165
Bram Moolenaarba47b512017-01-24 21:18:19 +01001166func Test_cmdline_complete_wildoptions()
1167 help
1168 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1169 let a = join(sort(split(@:)),' ')
1170 set wildoptions=tagfile
1171 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1172 let b = join(sort(split(@:)),' ')
1173 call assert_equal(a, b)
1174 bw!
1175endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001176
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001177func Test_cmdline_complete_user_cmd()
1178 command! -complete=color -nargs=1 Foo :
1179 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1180 call assert_equal('"Foo blue', @:)
1181 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1182 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001183 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1184 call assert_equal('"Foo a blue', @:)
1185 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1186 call assert_equal('"Foo b\', @:)
1187 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1188 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001189 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001190
1191 redraw
1192 call assert_equal('~', Screenline(&lines - 1))
1193 command! FooOne :
1194 command! FooTwo :
1195
1196 set nowildmenu
1197 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1198 call assert_equal('"FooOne', @:)
1199 call assert_equal('~', Screenline(&lines - 1))
1200
1201 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1202 call assert_equal('"FooTwo', @:)
1203 call assert_equal('~', Screenline(&lines - 1))
1204
1205 delcommand FooOne
1206 delcommand FooTwo
1207 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001208endfunc
1209
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001210func Test_complete_user_cmd()
1211 command FooBar echo 'global'
1212 command -buffer FooBar echo 'local'
1213 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1214 call assert_equal('"FooBar', @:)
1215
1216 delcommand -buffer FooBar
1217 delcommand FooBar
1218endfunc
1219
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001220func s:ScriptLocalFunction()
1221 echo 'yes'
1222endfunc
1223
1224func Test_cmdline_complete_user_func()
1225 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001226 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001227 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1228 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001229
1230 " g: prefix also works
1231 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1232 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001233
1234 " using g: prefix does not result in just "g:" matches from a lambda
1235 let Fx = { a -> a }
1236 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1237 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001238
1239 " existence of script-local dict function does not break user function name
1240 " completion
1241 function s:a_dict_func() dict
1242 endfunction
1243 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1244 call assert_match('"call Test_cmdline_complete_user_', @:)
1245 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001246endfunc
1247
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001248func Test_cmdline_complete_user_names()
1249 if has('unix') && executable('whoami')
1250 let whoami = systemlist('whoami')[0]
1251 let first_letter = whoami[0]
1252 if len(first_letter) > 0
1253 " Trying completion of :e ~x where x is the first letter of
1254 " the user name should complete to at least the user name.
1255 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1256 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1257 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001258 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001259 " Just in case: check that the system has an Administrator account.
1260 let names = system('net user')
1261 if names =~ 'Administrator'
1262 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001263 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001264 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001265 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001266 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001267 else
1268 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001269 endif
1270endfunc
1271
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001272func Test_cmdline_complete_shellcmdline()
1273 CheckExecutable whoami
1274 command -nargs=1 -complete=shellcmdline MyCmd
1275
1276 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1277 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001278 let l = getcompletion('whoam', 'shellcmdline')
1279 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001280
1281 delcommand MyCmd
1282endfunc
1283
Bram Moolenaar297610b2019-12-27 17:20:55 +01001284func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001285 CheckExecutable whoami
1286 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1287 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001288endfunc
1289
Bram Moolenaar8b633132020-03-20 18:20:51 +01001290func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001291 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1292 call assert_equal(lang, v:lc_time)
1293
1294 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1295 call assert_equal(lang, v:ctype)
1296
1297 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1298 call assert_equal(lang, v:collate)
1299
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001300 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001301 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001302
1303 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001304 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001305
Bram Moolenaarec680282020-06-12 19:35:32 +02001306 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001307
Bram Moolenaarec680282020-06-12 19:35:32 +02001308 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1309 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001310
Bram Moolenaarec680282020-06-12 19:35:32 +02001311 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1312 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001313
Bram Moolenaarec680282020-06-12 19:35:32 +02001314 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1315 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001316
1317 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1318 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001319endfunc
1320
Bram Moolenaar297610b2019-12-27 17:20:55 +01001321func Test_cmdline_complete_env_variable()
1322 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001323 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1324 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001325 unlet $X_VIM_TEST_COMPLETE_ENV
1326endfunc
1327
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001328func Test_cmdline_complete_expression()
1329 let g:SomeVar = 'blah'
1330 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1331 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1332 call assert_match('"' .. cmd .. ' SomeVar', @:)
1333 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1334 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1335 endfor
1336 unlet g:SomeVar
1337endfunc
1338
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001339func Test_cmdline_complete_argopt()
1340 " completion for ++opt=arg for file commands
1341 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1342 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1343 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1344
1345 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001346 " Test ++ff in the middle of the cmdline
1347 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1348 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001349
1350 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1351 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1352 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1353 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1354 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1355
1356 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1357
1358 " completion should skip the ++opt and continue
1359 call writefile([], 'Xaaaaa.txt', 'D')
1360 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1361 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1362
1363 if has('terminal')
1364 " completion for terminal's [options]
1365 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1366 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1367 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1368
1369 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1370
1371 " :terminal completion should skip the ++opt when considering what is the
1372 " first option, which is a list of shell commands, unlike second option
1373 " onwards.
1374 let first_param = getcompletion('terminal ', 'cmdline')
1375 let second_param = getcompletion('terminal foo ', 'cmdline')
1376 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1377 call assert_equal(first_param, skipped_opt_param)
1378 call assert_notequal(first_param, second_param)
1379 endif
1380endfunc
1381
Bram Moolenaar47016f52021-08-26 16:39:58 +02001382" Unique function name for completion below
1383func s:WeirdFunc()
1384 echo 'weird'
1385endfunc
1386
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001387" Test for various command-line completion
1388func Test_cmdline_complete_various()
1389 " completion for a command starting with a comment
1390 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1391 call assert_equal("\" :|\"\<C-A>", @:)
1392
1393 " completion for a range followed by a comment
1394 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1395 call assert_equal("\"1,2\"\<C-A>", @:)
1396
1397 " completion for :k command
1398 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1399 call assert_equal("\"ka\<C-A>", @:)
1400
Doug Kearnsea842022024-09-29 17:17:41 +02001401 " completion for :keepmarks command
1402 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1403 call assert_equal("\"kee edit", @:)
1404
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001405 " completion for short version of the :s command
1406 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1407 call assert_equal("\"sI \<C-A>", @:)
1408
1409 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001410 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001411 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001412 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001413 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001414 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1415 call assert_equal("\"w >> Xfile1", @:)
1416 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001417
1418 " completion for :w ! and :r ! commands
1419 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1420 call assert_equal("\"w !invalid_xyz_cmd", @:)
1421 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1422 call assert_equal("\"r !invalid_xyz_cmd", @:)
1423
1424 " completion for :>> and :<< commands
1425 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1426 call assert_equal("\">>>\<C-A>", @:)
1427 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1428 call assert_equal("\"<<<\<C-A>", @:)
1429
1430 " completion for command with +cmd argument
1431 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1432 call assert_equal("\"buffer +/pat Xabc", @:)
1433 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1434 call assert_equal("\"buffer +/pat\<C-A>", @:)
1435
1436 " completion for a command with a trailing comment
1437 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1438 call assert_equal("\"ls \" comment\<C-A>", @:)
1439
1440 " completion for a command with a trailing command
1441 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1442 call assert_equal("\"ls | ls", @:)
1443
1444 " completion for a command with an CTRL-V escaped argument
1445 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1446 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1447
1448 " completion for a command that doesn't take additional arguments
1449 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1450 call assert_equal("\"all abc\<C-A>", @:)
1451
zeertzjqd3de1782022-09-01 12:58:52 +01001452 " completion for :wincmd with :horizontal modifier
1453 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1454 call assert_equal("\"horizontal wincmd", @:)
1455
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001456 " completion for a command with a command modifier
1457 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1458 call assert_equal("\"topleft new", @:)
1459
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001460 " completion for vim9 and legacy commands
1461 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1462 call assert_equal("\"vim9 call strlen(", @:)
1463 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1464 call assert_equal("\"legac call strlen(", @:)
1465
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001466 " completion for the :disassemble command
1467 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1468 call assert_equal("\"disas debug", @:)
1469 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1470 call assert_equal("\"disas profile", @:)
1471 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1472 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1473 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1474 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001475 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1476 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001477
Bram Moolenaar47016f52021-08-26 16:39:58 +02001478 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001479 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001480
naohiro onodfe04db2021-09-12 15:45:10 +02001481 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1482 call assert_match('"disas <SNR>\d\+_', @:)
1483 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1484 call assert_match('"disas debug <SNR>\d\+_', @:)
1485
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001486 " completion for the :match command
1487 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1488 call assert_equal("\"match Search /pat/\<C-A>", @:)
1489
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001490 " completion for the :doautocmd command
1491 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1492 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1493
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001494 " completion of autocmd group after comma
1495 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1496 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1497
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001498 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001499 call writefile([], 'Xvarfile1', 'D')
1500 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001501 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1502 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001503
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001504 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001505 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001506 augroup END
1507 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001508 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001509
1510 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001511 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1512 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001513 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1514 call assert_equal("\"au XTest.test", @:)
1515
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001516 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001517
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001518 " autocmd pattern completion
1519 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1520 call assert_equal("\"au BufEnter *.py\t", @:)
1521
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001522 " completion for the :unlet command
1523 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1524 call assert_equal("\"unlet one two", @:)
1525
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001526 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001527 " FIXME: what should happen on MS-Windows?
1528 if !has('win32')
1529 edit \{someFile}
1530 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1531 call assert_equal("\"buf {someFile}", @:)
1532 bwipe {someFile}
1533 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001534
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001535 " completion for the :bdelete command
1536 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1537 call assert_equal("\"bdel a b c", @:)
1538
1539 " completion for the :mapclear command
1540 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1541 call assert_equal("\"mapclear <buffer>", @:)
1542
1543 " completion for user defined commands with menu names
1544 menu Test.foo :ls<CR>
1545 com -nargs=* -complete=menu MyCmd
1546 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1547 call assert_equal('"MyCmd Test.', @:)
1548 delcom MyCmd
1549 unmenu Test
1550
1551 " completion for user defined commands with mappings
1552 mapclear
1553 map <F3> :ls<CR>
1554 com -nargs=* -complete=mapping MyCmd
1555 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001556 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001557 mapclear
1558 delcom MyCmd
1559
Yee Cheng Chin54844852023-10-09 18:12:31 +02001560 " Prepare for path completion
1561 call mkdir('Xa b c', 'D')
1562 defer delete('Xcomma,foobar.txt')
1563 call writefile([], 'Xcomma,foobar.txt')
1564
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001565 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001566 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1567 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1568 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001569
1570 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001571 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1572 call assert_equal('"set dir=Xa\ b\ c/', @:)
1573 set dir&
1574
1575 " completion for :set tags= / set dictionary= with escaped commas
1576 if has('win32')
1577 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1578 " '\,'
1579 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1580 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1581
1582 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1583 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1584
1585 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1586 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1587
1588 " completion for :set dictionary= with escaped commas (same behavior, but
1589 " different internal code path from 'set tags=' for escaping the output)
1590 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1591 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1592 else
1593 " In other platforms, backslashes are rounded down (since '\,' itself will
1594 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1595 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1596 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1597
1598 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1599 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1600
1601 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1602 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1603
1604 " completion for :set dictionary= with escaped commas (same behavior, but
1605 " different internal code path from 'set tags=' for escaping the output)
1606 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1607 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1608 endif
1609 set tags&
1610 set dictionary&
1611
1612 " completion for :set makeprg= with no escaped commas
1613 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1614 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1615
1616 if !has('win32')
1617 " Cannot create file with backslash in file name in Windows, so only test
1618 " this elsewhere.
1619 defer delete('Xcomma\,fooslash.txt')
1620 call writefile([], 'Xcomma\,fooslash.txt')
1621 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1622 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1623 endif
1624 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001625
1626 " completion for the :py3 commands
1627 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1628 call assert_equal('"py3 py3do py3file', @:)
1629
Bram Moolenaardf749a22021-03-28 15:29:43 +02001630 " completion for the :vim9 commands
1631 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1632 call assert_equal('"vim9cmd vim9script', @:)
1633
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001634 " redir @" is not the start of a comment. So complete after that
1635 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1636 call assert_equal('"redir @" | cwindow', @:)
1637
1638 " completion after a backtick
1639 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1640 call assert_equal('"e `a1b2c', @:)
1641
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001642 " completion for :language command with an invalid argument
1643 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1644 call assert_equal("\"language dummy \t", @:)
1645
1646 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001647 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1648 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001649
1650 " completion with ambiguous user defined commands
1651 com TCmd1 echo 'TCmd1'
1652 com TCmd2 echo 'TCmd2'
1653 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1654 call assert_equal('"TCmd ', @:)
1655 delcom TCmd1
1656 delcom TCmd2
1657
1658 " completion after a range followed by a pipe (|) character
1659 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1660 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001661
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001662 " completion after a :global command
1663 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1664 call assert_equal('"g/a/chistory', @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001665 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001666 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1667 call assert_equal("\"g/a\\/chist\t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001668 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001669
Bram Moolenaar9c929712020-09-07 22:05:28 +02001670 " use <Esc> as the 'wildchar' for completion
1671 set wildchar=<Esc>
1672 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1673 call assert_equal('"g/a\xb/clearjumps', @:)
1674 " pressing <esc> twice should cancel the command
1675 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1676 call assert_equal('"g/a\xb/clearjumps', @:)
1677 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001678
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001679 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001680 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001681 call writefile([], '~Xtest')
1682 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1683 call assert_equal('"e \~Xtest', @:)
1684 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001685
1686 " should be able to complete a file name that has a '*'
1687 call writefile([], 'Xx*Yy')
1688 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1689 call assert_equal('"e Xx\*Yy', @:)
1690 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001691
1692 " use a literal star
1693 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1694 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001695 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001696
1697 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1698 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001699endfunc
1700
zeertzjq094dd152023-06-15 22:51:57 +01001701" Test that expanding a pattern doesn't interfere with cmdline completion.
1702func Test_expand_during_cmdline_completion()
1703 func ExpandStuff()
1704 badd <script>:p:h/README.*
1705 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1706 $bwipe
1707 call assert_equal('README.txt', expand('README.*'))
1708 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1709 endfunc
1710 augroup test_CmdlineChanged
1711 autocmd!
1712 autocmd CmdlineChanged * call ExpandStuff()
1713 augroup END
1714
1715 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1716 call assert_equal('"sign place', @:)
1717
1718 augroup test_CmdlineChanged
1719 au!
1720 augroup END
1721 augroup! test_CmdlineChanged
1722 delfunc ExpandStuff
1723endfunc
1724
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001725" Test for 'wildignorecase'
1726func Test_cmdline_wildignorecase()
1727 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001728 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001729 set wildignorecase
1730 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1731 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001732 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001733 let g:Sline = ''
1734 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1735 call assert_equal('"e xt', @:)
1736 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001737 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001738endfunc
1739
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001740func Test_cmdline_write_alternatefile()
1741 new
1742 call setline('.', ['one', 'two'])
1743 f foo.txt
1744 new
1745 f #-A
1746 call assert_equal('foo.txt-A', expand('%'))
1747 f #<-B.txt
1748 call assert_equal('foo-B.txt', expand('%'))
1749 f %<
1750 call assert_equal('foo-B', expand('%'))
1751 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001752 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001753 bw!
1754 f foo-B.txt
1755 f %<-A
1756 call assert_equal('foo-B-A', expand('%'))
1757 bw!
1758 bw!
1759endfunc
1760
Bram Moolenaarf5724372022-09-02 19:45:15 +01001761func Test_cmdline_expand_cur_alt_file()
1762 enew
1763 file http://some.com/file.txt
1764 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1765 call assert_equal('"e http://some.com/file.txt', @:)
1766 edit another
1767 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1768 call assert_equal('"e http://some.com/file.txt', @:)
1769 bwipe
1770 bwipe http://some.com/file.txt
1771endfunc
1772
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001773" using a leading backslash here
1774set cpo+=C
1775
1776func Test_cmdline_search_range()
1777 new
1778 call setline(1, ['a', 'b', 'c', 'd'])
1779 /d
1780 1,\/s/b/B/
1781 call assert_equal('B', getline(2))
1782
1783 /a
1784 $
1785 \?,4s/c/C/
1786 call assert_equal('C', getline(3))
1787
1788 call setline(1, ['a', 'b', 'c', 'd'])
1789 %s/c/c/
1790 1,\&s/b/B/
1791 call assert_equal('B', getline(2))
1792
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001793 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001794 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001795
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001796 bwipe!
1797endfunc
1798
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001799" Test for the tick mark (') in an excmd range
1800func Test_tick_mark_in_range()
1801 " If only the tick is passed as a range and no command is specified, there
1802 " should not be an error
1803 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001804 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001805 call assert_fails("',print", 'E78:')
1806endfunc
1807
1808" Test for using a line number followed by a search pattern as range
1809func Test_lnum_and_pattern_as_range()
1810 new
1811 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1812 let @" = ''
1813 2/foo/yank
1814 call assert_equal("foo 3\n", @")
1815 call assert_equal(1, line('.'))
1816 close!
1817endfunc
1818
Bram Moolenaar65189a12017-02-06 22:22:17 +01001819" Tests for getcmdline(), getcmdpos() and getcmdtype()
1820func Check_cmdline(cmdtype)
1821 call assert_equal('MyCmd a', getcmdline())
1822 call assert_equal(8, getcmdpos())
1823 call assert_equal(a:cmdtype, getcmdtype())
1824 return ''
1825endfunc
1826
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001827set cpo&
1828
Shougo Matsushita69084282024-09-23 20:34:47 +02001829func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001830 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1831
1832 let cmdtype = ''
1833 debuggreedy
1834 call feedkeys(":debug echo 'test'\<CR>", "t")
1835 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1836 call feedkeys("cont\<CR>", "xt")
1837 0debuggreedy
1838 call assert_equal('>', cmdtype)
1839
1840 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1841 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1842
1843 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001844 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001845
1846 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1847
1848 cnoremap <expr> <F6> Check_cmdline('=')
1849 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1850 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001851
1852 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001853
1854 call assert_equal('', getcmdprompt())
1855 augroup test_CmdlineEnter
1856 autocmd!
1857 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1858 augroup END
1859 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1860 call assert_equal('Answer?', g:cmdprompt)
1861 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001862 call feedkeys(":\<CR>\<ESC>", "xt")
1863 call assert_equal('', g:cmdprompt)
1864 call assert_equal('', getcmdprompt())
1865
1866 let str = "C" .. repeat("c", 1023) .. "xyz"
1867 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1868 call assert_equal(str, g:cmdprompt)
1869
1870 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1871 call assert_equal('Ans?', g:cmdprompt)
1872 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001873
1874 augroup test_CmdlineEnter
1875 au!
1876 augroup END
1877 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001878endfunc
1879
Bram Moolenaar52604f22017-04-07 16:17:39 +02001880func Test_verbosefile()
1881 set verbosefile=Xlog
1882 echomsg 'foo'
1883 echomsg 'bar'
1884 set verbosefile=
1885 let log = readfile('Xlog')
1886 call assert_match("foo\nbar", join(log, "\n"))
1887 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001888
1889 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001890 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001891endfunc
1892
Bram Moolenaar4facea32019-10-12 20:17:40 +02001893func Test_verbose_option()
1894 CheckScreendump
1895
1896 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001897 " clear the TermResponse autocommand from defaults.vim
1898 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001899 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1900 call feedkeys("\r", 't') " for the hit-enter prompt
1901 set verbose=20
1902 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001903 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001904
1905 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001906 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001907 call term_sendkeys(buf, ":DoSomething\<CR>")
1908 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1909
1910 " clean up
1911 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001912endfunc
1913
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001914func Test_setcmdpos()
1915 func InsertTextAtPos(text, pos)
1916 call assert_equal(0, setcmdpos(a:pos))
1917 return a:text
1918 endfunc
1919
1920 " setcmdpos() with position in the middle of the command line.
1921 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1922 call assert_equal('"1ab2', @:)
1923
1924 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1925 call assert_equal('"1b2a', @:)
1926
1927 " setcmdpos() with position beyond the end of the command line.
1928 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1929 call assert_equal('"12ab', @:)
1930
1931 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001932 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001933endfunc
1934
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001935func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001936 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001937 let encoding_save = &encoding
1938
1939 for e in encodings
1940 exe 'set encoding=' . e
1941
1942 " Test overstrike in the middle of the command line.
1943 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001944 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001945
1946 " Test overstrike going beyond end of command line.
1947 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001948 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001949
1950 " Test toggling insert/overstrike a few times.
1951 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001952 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001953 endfor
1954
Bram Moolenaar30276f22019-01-24 17:59:39 +01001955 " Test overstrike with multi-byte characters.
1956 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001957 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001958
1959 let &encoding = encoding_save
1960endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001961
Bram Moolenaar52410572019-10-27 05:12:45 +01001962func Test_buffers_lastused()
1963 " check that buffers are sorted by time when wildmode has lastused
1964 call test_settime(1550020000) " middle
1965 edit bufa
1966 enew
1967 call test_settime(1550030000) " newest
1968 edit bufb
1969 enew
1970 call test_settime(1550010000) " oldest
1971 edit bufc
1972 enew
1973 call test_settime(0)
1974 enew
1975
1976 call assert_equal(['bufa', 'bufb', 'bufc'],
1977 \ getcompletion('', 'buffer'))
1978
1979 let save_wildmode = &wildmode
1980 set wildmode=full:lastused
1981
1982 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1983 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1984 call assert_equal('b bufb', X)
1985 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1986 call assert_equal('b bufa', X)
1987 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1988 call assert_equal('b bufc', X)
1989 enew
1990
1991 edit other
1992 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1993 call assert_equal('b bufb', X)
1994 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1995 call assert_equal('b bufa', X)
1996 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1997 call assert_equal('b bufc', X)
1998 enew
1999
2000 let &wildmode = save_wildmode
2001
2002 bwipeout bufa
2003 bwipeout bufb
2004 bwipeout bufc
2005endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01002006
Bram Moolenaar479950f2020-01-19 15:45:17 +01002007func Test_cmdlineclear_tabenter()
2008 CheckScreendump
2009
2010 let lines =<< trim [SCRIPT]
2011 call setline(1, range(30))
2012 [SCRIPT]
2013
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002014 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01002015 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02002016 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002017 " in one tab make the command line higher with CTRL-W -
2018 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
2019 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2020
2021 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002022endfunc
2023
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002024" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002025func Test_cmdline_expand_special()
2026 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02002027 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002028 call assert_fails('e <afile>', 'E495:')
2029 call assert_fails('e <abuf>', 'E496:')
2030 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002031
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002032 call writefile([], 'Xfile.cpp', 'D')
2033 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002034 new Xfile.cpp
2035 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2036 call assert_equal('"e Xfile.cpp Xfile.java', @:)
2037 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002038endfunc
2039
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002040" Test for backtick expression in the command line
2041func Test_cmd_backtick()
2042 %argd
2043 argadd `=['a', 'b', 'c']`
2044 call assert_equal(['a', 'b', 'c'], argv())
2045 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02002046
2047 argadd `echo abc def`
2048 call assert_equal(['abc def'], argv())
2049 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002050endfunc
2051
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002052" Test for the :! command
2053func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002054 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002055
2056 let lines =<< trim [SCRIPT]
2057 " Test for no previous command
2058 call assert_fails('!!', 'E34:')
2059 set nomore
2060 " Test for cmdline expansion with :!
2061 call setline(1, 'foo!')
2062 silent !echo <cWORD> > Xfile.out
2063 call assert_equal(['foo!'], readfile('Xfile.out'))
2064 " Test for using previous command
2065 silent !echo \! !
2066 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2067 call writefile(v:errors, 'Xresult')
2068 call delete('Xfile.out')
2069 qall!
2070 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002071 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002072 if RunVim([], [], '--clean -S Xscript')
2073 call assert_equal([], readfile('Xresult'))
2074 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002075 call delete('Xresult')
2076endfunc
2077
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002078" Test error: "E135: *Filter* Autocommands must not change current buffer"
2079func Test_cmd_bang_E135()
2080 new
2081 call setline(1, ['a', 'b', 'c', 'd'])
2082 augroup test_cmd_filter_E135
2083 au!
2084 autocmd FilterReadPost * help
2085 augroup END
2086 call assert_fails('2,3!echo "x"', 'E135:')
2087
2088 augroup test_cmd_filter_E135
2089 au!
2090 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002091 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002092 %bwipe!
2093endfunc
2094
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002095func Test_cmd_bang_args()
2096 new
2097 :.!
2098 call assert_equal(0, v:shell_error)
2099
2100 " Note that below there is one space char after the '!'. This caused a
2101 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2102 :.!
2103 call assert_equal(0, v:shell_error)
2104 bwipe!
2105
2106 CheckUnix
2107 :.!pwd
2108 call assert_equal(0, v:shell_error)
2109 :.! pwd
2110 call assert_equal(0, v:shell_error)
2111
2112 " Note there is one space after 'pwd'.
2113 :.! pwd
2114 call assert_equal(0, v:shell_error)
2115
2116 " Note there are two spaces after 'pwd'.
2117 :.! pwd
2118 call assert_equal(0, v:shell_error)
2119 :.!ls ~
2120 call assert_equal(0, v:shell_error)
2121
2122 " Note there is one space char after '~'.
2123 :.!ls ~
2124 call assert_equal(0, v:shell_error)
2125
2126 " Note there are two spaces after '~'.
2127 :.!ls ~
2128 call assert_equal(0, v:shell_error)
2129
2130 :.!echo "foo"
2131 call assert_equal(getline('.'), "foo")
2132 :.!echo "foo "
2133 call assert_equal(getline('.'), "foo ")
2134 :.!echo " foo "
2135 call assert_equal(getline('.'), " foo ")
2136 :.!echo " foo "
2137 call assert_equal(getline('.'), " foo ")
2138
2139 %bwipe!
2140endfunc
2141
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002142" Test for using ~ for home directory in cmdline completion matches
2143func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002144 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002145 call writefile([], 'Xexpdir/Xfile1')
2146 call writefile([], 'Xexpdir/Xfile2')
2147 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002148 let save_HOME = $HOME
2149 let $HOME = getcwd()
2150 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2151 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2152 let $HOME = save_HOME
2153 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002154endfunc
2155
Bram Moolenaar578fe942020-02-27 21:32:51 +01002156" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2157" or insert mode (when 'insertmode' is set)
2158func Test_cmdline_ctrl_g()
2159 new
2160 call setline(1, 'abc')
2161 call cursor(1, 3)
2162 " If command line is entered from insert mode, using C-\ C-G should back to
2163 " insert mode
2164 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2165 call assert_equal('abxyc', getline(1))
2166 call assert_equal(4, col('.'))
2167
2168 " If command line is entered in 'insertmode', using C-\ C-G should back to
2169 " 'insertmode'
2170 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2171 call assert_equal('ab12xyc', getline(1))
2172 close!
2173endfunc
2174
Bram Moolenaar578fe942020-02-27 21:32:51 +01002175" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002176func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002177 func T(a, c, p)
2178 return "oneA\noneB\noneC"
2179 endfunc
2180 command -nargs=1 -complete=custom,T MyCmd
2181
Bram Moolenaar578fe942020-02-27 21:32:51 +01002182 set nowildmenu
2183 set wildmode=full,list
2184 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002185 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002186 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002187 call assert_equal('"MyCmd oneA', @:)
2188
2189 set wildmode=longest,full
2190 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"MyCmd one', @:)
2192 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2193 call assert_equal('"MyCmd oneC', @:)
2194
2195 set wildmode=longest
2196 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2197 call assert_equal('"MyCmd one', @:)
2198
2199 set wildmode=list:longest
2200 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002201 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002202 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002203 call assert_equal('"MyCmd one', @:)
2204
2205 set wildmode=""
2206 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2207 call assert_equal('"MyCmd oneA', @:)
2208
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002209 " Test for wildmode=longest with 'fileignorecase' set
2210 set wildmode=longest
2211 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002212 argadd AAA AAAA AAAAA
2213 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2214 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002215 set fileignorecase&
2216
2217 " Test for listing files with wildmode=list
2218 set wildmode=list
2219 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002220 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002221 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002222 call assert_equal('"b A', @:)
2223
Girish Palya2bacc3e2025-03-02 22:55:57 +01002224 " When 'wildmenu' is not set, 'noselect' completes first item
2225 set wildmode=noselect
2226 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2227 call assert_equal('"MyCmd oneA', @:)
2228
2229 " When 'noselect' is present, do not complete first <tab>.
2230 set wildmenu
2231 set wildmode=noselect
2232 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2233 call assert_equal('"MyCmd o', @:)
2234 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2235 call assert_equal('"MyCmd o', @:)
2236 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2237 call assert_equal('"MyCmd o', @:)
2238
2239 " When 'full' is present, complete after first <tab>.
2240 set wildmode=noselect,full
2241 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2242 call assert_equal('"MyCmd o', @:)
2243 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2244 call assert_equal('"MyCmd oneA', @:)
2245 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2246 call assert_equal('"MyCmd oneB', @:)
2247 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2248 call assert_equal('"MyCmd oneB', @:)
2249
2250 " 'noselect' has no effect when 'longest' is present.
2251 set wildmode=noselect:longest
2252 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2253 call assert_equal('"MyCmd one', @:)
2254
2255 " Complete 'noselect' value in 'wildmode' option
2256 set wildmode&
2257 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2258 call assert_equal('"set wildmode=noselect', @:)
2259 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2260 call assert_equal('"set wildmode=noselect', @:)
2261
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002262 " when using longest completion match, matches shorter than the argument
2263 " should be ignored (happens with :help)
2264 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002265 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2266 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002267 " non existing file
2268 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2269 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002270
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002271 " Test for longest file name completion with 'fileignorecase'
2272 " On MS-Windows, file names are case insensitive.
2273 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002274 call writefile([], 'XTESTfoo', 'D')
2275 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002276 set nofileignorecase
2277 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2278 call assert_equal('"e XTESTfoo', @:)
2279 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2280 call assert_equal('"e Xtestbar', @:)
2281 set fileignorecase
2282 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2283 call assert_equal('"e Xtest', @:)
2284 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2285 call assert_equal('"e Xtest', @:)
2286 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002287 endif
2288
Girish Palya2bacc3e2025-03-02 22:55:57 +01002289 " If 'noselect' is present, single item menu should not insert item
2290 func! T(a, c, p)
2291 return "oneA"
2292 endfunc
2293 command! -nargs=1 -complete=custom,T MyCmd
2294 set wildmode=noselect,full
2295 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2296 call assert_equal('"MyCmd o', @:)
2297 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2298 call assert_equal('"MyCmd oneA', @:)
2299 " 'nowildmenu' should make 'noselect' ineffective
2300 set nowildmenu
2301 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2302 call assert_equal('"MyCmd oneA', @:)
2303
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002304 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002305 delcommand MyCmd
2306 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002307 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002308 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002309endfunc
2310
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002311func Test_wildmode()
2312 " Test with utf-8 encoding
2313 call Wildmode_tests()
2314
2315 " Test with latin1 encoding
2316 let save_encoding = &encoding
2317 set encoding=latin1
2318 call Wildmode_tests()
2319 let &encoding = save_encoding
2320endfunc
2321
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002322func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002323 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002324 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002325 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002326 let lines =<< trim END
2327 func vim8#Complete(a, c, p)
2328 return "oneA\noneB\noneC"
2329 endfunc
2330 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002331 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002332
2333 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2334 set nowildmenu
2335 set wildmode=full,list
2336 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2337 call assert_equal('"MyCmd oneA oneB oneC', @:)
2338
2339 let &rtp = save_rtp
2340 set wildmode& wildmenu&
2341 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002342endfunc
2343
Bram Moolenaar578fe942020-02-27 21:32:51 +01002344" Test for interrupting the command-line completion
2345func Test_interrupt_compl()
2346 func F(lead, cmdl, p)
2347 if a:lead =~ 'tw'
2348 call interrupt()
2349 return
2350 endif
2351 return "one\ntwo\nthree"
2352 endfunc
2353 command -nargs=1 -complete=custom,F Tcmd
2354
2355 set nowildmenu
2356 set wildmode=full
2357 let interrupted = 0
2358 try
2359 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2360 catch /^Vim:Interrupt$/
2361 let interrupted = 1
2362 endtry
2363 call assert_equal(1, interrupted)
2364
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002365 let interrupted = 0
2366 try
2367 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2368 catch /^Vim:Interrupt$/
2369 let interrupted = 1
2370 endtry
2371 call assert_equal(1, interrupted)
2372
Bram Moolenaar578fe942020-02-27 21:32:51 +01002373 delcommand Tcmd
2374 delfunc F
2375 set wildmode&
2376endfunc
2377
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002378" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002379func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002380 let str = ":one two\<C-U>"
2381 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002382 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002383 let str ..= "\<Left>five\<Right>"
2384 let str ..= "\<Home>two "
2385 let str ..= "\<C-Left>one "
2386 let str ..= "\<C-Right> three"
2387 let str ..= "\<End>\<S-Left>four "
2388 let str ..= "\<S-Right> six"
2389 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2390 call feedkeys(str, 'xt')
2391 call assert_equal("\"one two three four five six seven", @:)
2392endfunc
2393
2394" Test for moving the cursor on the / command line in 'rightleft' mode
2395func Test_cmdline_edit_rightleft()
2396 CheckFeature rightleft
2397 set rightleft
2398 set rightleftcmd=search
2399 let str = "/one two\<C-U>"
2400 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002401 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002402 let str ..= "\<Right>five\<Left>"
2403 let str ..= "\<Home>two "
2404 let str ..= "\<C-Right>one "
2405 let str ..= "\<C-Left> three"
2406 let str ..= "\<End>\<S-Right>four "
2407 let str ..= "\<S-Left> six"
2408 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2409 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2410 call assert_equal("\"one two three four five six seven", @/)
2411 set rightleftcmd&
2412 set rightleft&
2413endfunc
2414
2415" Test for using <C-\>e in the command line to evaluate an expression
2416func Test_cmdline_expr()
2417 " Evaluate an expression from the beginning of a command line
2418 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2419 call assert_equal('"hello', @:)
2420
2421 " Use an invalid expression for <C-\>e
2422 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2423
2424 " Insert literal <CTRL-\> in the command line
2425 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2426 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002427endfunc
2428
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002429" This was making the insert position negative
2430func Test_cmdline_expr_register()
2431 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2432endfunc
2433
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002434" Test for 'imcmdline' and 'imsearch'
2435" This test doesn't actually test the input method functionality.
2436func Test_cmdline_inputmethod()
2437 new
2438 call setline(1, ['', 'abc', ''])
2439 set imcmdline
2440
2441 call feedkeys(":\"abc\<CR>", 'xt')
2442 call assert_equal("\"abc", @:)
2443 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2444 call assert_equal("\"abc", @:)
2445 call feedkeys("/abc\<CR>", 'xt')
2446 call assert_equal([2, 1], [line('.'), col('.')])
2447 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2448 call assert_equal([2, 1], [line('.'), col('.')])
2449
2450 set imsearch=2
2451 call cursor(1, 1)
2452 call feedkeys("/abc\<CR>", 'xt')
2453 call assert_equal([2, 1], [line('.'), col('.')])
2454 call cursor(1, 1)
2455 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2456 call assert_equal([2, 1], [line('.'), col('.')])
2457 set imdisable
2458 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2459 call assert_equal([2, 1], [line('.'), col('.')])
2460 set imdisable&
2461 set imsearch&
2462
2463 set imcmdline&
2464 %bwipe!
2465endfunc
2466
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002467" Test for using CTRL-_ in the command line with 'allowrevins'
2468func Test_cmdline_revins()
2469 CheckNotMSWindows
2470 CheckFeature rightleft
2471 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2472 call assert_equal("\"abc\<c-_>", @:)
2473 set allowrevins
2474 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2475 call assert_equal('"abcñèæ', @:)
2476 set allowrevins&
2477endfunc
2478
2479" Test for typing UTF-8 composing characters in the command line
2480func Test_cmdline_composing_chars()
2481 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2482 call assert_equal('"ゔ', @:)
2483endfunc
2484
Bram Moolenaar0e717042020-04-27 19:29:01 +02002485" test that ";" works to find a match at the start of the first line
2486func Test_zero_line_search()
2487 new
2488 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2489 call cursor(1,1)
2490 0;/pattern/d
2491 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2492 q!
2493endfunc
2494
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002495func Test_read_shellcmd()
2496 CheckUnix
2497 if executable('ls')
2498 " There should be ls in the $PATH
2499 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2500 call assert_match('^"r! .*\<ls\>', @:)
2501 endif
2502
2503 if executable('rm')
2504 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2505 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2506 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002507
2508 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2509 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2510 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002511 endif
2512endfunc
2513
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002514" Test for going up and down the directory tree using 'wildmenu'
2515func Test_wildmenu_dirstack()
2516 CheckUnix
2517 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002518 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002519 call writefile([], 'Xwildmenu/file1_1.txt')
2520 call writefile([], 'Xwildmenu/file1_2.txt')
2521 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2522 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2523 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2524 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2525 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2526 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002527 set wildmenu
2528
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002529 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002530 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002531 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002532 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002533 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002534 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002535 call assert_equal('"e ../../dir3/', @:)
2536 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2537 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002538 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002539 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002540 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002541 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002542 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002543 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2544 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002545
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002546 set wildmenu&
2547endfunc
2548
obcat71c6f7a2021-05-13 20:23:10 +02002549" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002550" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2551" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002552func Test_recalling_cmdline()
2553 CheckFeature cmdline_hist
2554
2555 let g:cmdlines = []
2556 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2557
2558 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002559 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2560 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2561 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2562 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002563 "\ TODO: {'name': 'debug', ...}
2564 \]
2565 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002566 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2567 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2568 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2569 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2570 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002571 \]
2572 let prefix = 'vi'
2573 for h in histories
2574 call histadd(h.name, 'vim')
2575 call histadd(h.name, 'virtue')
2576 call histadd(h.name, 'Virgo')
2577 call histadd(h.name, 'vogue')
2578 call histadd(h.name, 'emacs')
2579 for k in keypairs
2580 let g:cmdlines = []
2581 let keyseqs = h.enter
2582 \ .. prefix
2583 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2584 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2585 \ .. h.exit
2586 call feedkeys(keyseqs, 'xt')
2587 call histdel(h.name, -1) " delete the history added by feedkeys above
2588 let expect = k.prefixmatch
2589 \ ? ['virtue', 'vim', 'virtue', prefix]
2590 \ : ['emacs', 'vogue', 'emacs', prefix]
2591 call assert_equal(expect, g:cmdlines)
2592 endfor
2593 endfor
2594
2595 unlet g:cmdlines
2596 cunmap <Plug>(save-cmdline)
2597endfunc
2598
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002599func Test_cmd_map_cmdlineChanged()
2600 let g:log = []
2601 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002602 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002603 autocmd!
2604 autocmd CmdlineChanged : let g:log += [getcmdline()]
2605 augroup END
2606
2607 call feedkeys(":\<F1>\<CR>", 'xt')
2608 call assert_equal(['l', 'ls'], g:log)
2609
Bram Moolenaar796139a2021-05-18 21:38:45 +02002610 let @b = 'b'
2611 cnoremap <F1> a<C-R>b
2612 let g:log = []
2613 call feedkeys(":\<F1>\<CR>", 'xt')
2614 call assert_equal(['a', 'ab'], g:log)
2615
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002616 unlet g:log
2617 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002618 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002619 autocmd!
2620 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002621 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002622endfunc
2623
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002624" Test for the 'suffixes' option
2625func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002626 call writefile([], 'Xsuffile', 'D')
2627 call writefile([], 'Xsuffile.c', 'D')
2628 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002629 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002630 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2631 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2632 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2633 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002634 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002635 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2636 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2637 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2638 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002639 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002640 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2641 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2642 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2643 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002644 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002645 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002646 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2647 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002648endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002649
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002650" Test for using a popup menu for the command line completion matches
2651" (wildoptions=pum)
2652func Test_wildmenu_pum()
Drew Vogelea67ba72025-05-07 22:05:17 +02002653 CheckScreendump
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002654 CheckRunVimInTerminal
2655
2656 let commands =<< trim [CODE]
2657 set wildmenu
2658 set wildoptions=pum
2659 set shm+=I
2660 set noruler
2661 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002662
2663 func CmdCompl(a, b, c)
2664 return repeat(['aaaa'], 120)
2665 endfunc
2666 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002667
2668 func MyStatusLine() abort
2669 return 'status'
2670 endfunc
2671 func SetupStatusline()
2672 set statusline=%!MyStatusLine()
2673 set laststatus=2
2674 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002675
2676 func MyTabLine()
2677 return 'my tab line'
2678 endfunc
2679 func SetupTabline()
2680 set statusline=
2681 set tabline=%!MyTabLine()
2682 set showtabline=2
2683 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002684
2685 func DoFeedKeys()
2686 let &wildcharm = char2nr("\t")
2687 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2688 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002690 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002691
2692 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2693
2694 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002695 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2696
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002697 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002698 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002699 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2700
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002701 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002702 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002703 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2704
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002705 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002706 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002707 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2708
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002709 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002710 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002711 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2712
2713 " pressing <C-E> should end completion and go back to the original match
2714 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002715 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2716
2717 " pressing <C-Y> should select the current match and end completion
2718 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002719 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2720
2721 " With 'wildmode' set to 'longest,full', completing a match should display
2722 " the longest match, the wildmenu should not be displayed.
2723 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2724 call TermWait(buf)
2725 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002726 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2727
2728 " pressing <Tab> should display the wildmenu
2729 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002730 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2731
2732 " pressing <Tab> second time should select the next entry in the menu
2733 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002734 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2735
2736 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002737 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002738 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002739 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2740
2741 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002742 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2743
2744 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002745 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2746
2747 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002748 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002749 call writefile([], 'Xnamedir/XfileA')
2750 call writefile([], 'Xnamedir/XdirA/XfileB')
2751 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002752
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002753 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002754 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2755
2756 " Pressing <Right> on a directory name should go into that directory
2757 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002758 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2759
2760 " Pressing <Left> on a directory name should go to the parent directory
2761 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002762 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2763
2764 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002765 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002766 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002767 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2768
2769 " Pressing <C-D> when the popup menu is displayed should remove the popup
2770 " menu
2771 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002772 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2773
2774 " Pressing <S-Tab> should open the popup menu with the last entry selected
2775 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002776 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2777
2778 " Pressing <Esc> should close the popup menu and cancel the cmd line
2779 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002780 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2781
2782 " Typing a character when the popup is open, should close the popup
2783 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002784 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2785
2786 " When the popup is open, entering the cmdline window should close the popup
2787 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002788 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2789 call term_sendkeys(buf, ":q\<CR>")
2790
2791 " After the last popup menu item, <C-N> should show the original string
2792 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002793 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2794
2795 " Use the popup menu for the command name
2796 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002797 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2798
2799 " Pressing the left arrow should remove the popup menu
2800 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002801 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2802
2803 " Pressing <BS> should remove the popup menu and erase the last character
2804 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002805 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2806
2807 " Pressing <C-W> should remove the popup menu and erase the previous word
2808 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002809 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2810
2811 " Pressing <C-U> should remove the popup menu and erase the entire line
2812 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002813 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2814
2815 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2816 " the cmdline from history
2817 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002818 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2819
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002820 " Check "list" still works
2821 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2822 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002823 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2824 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002825 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2826
rbtnn68cc2b82022-02-09 11:55:47 +00002827 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002828 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002829 call writefile([], 'Xnamedir/あいう/abc')
2830 call writefile([], 'Xnamedir/あいう/xyz')
2831 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002832
2833 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002834 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002835 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2836
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002837 " Pressing <C-A> when the popup menu is displayed should list all the
2838 " matches and pressing a key after that should remove the popup menu
2839 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2840 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2841 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2842
2843 " Pressing <C-A> when the popup menu is displayed should list all the
2844 " matches and pressing <Left> after that should move the cursor
2845 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2846 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2847 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2848
2849 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2850 " should be displayed correctly on the screen.
2851 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2852 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2853
2854 " After using <C-A> to expand all the filename matches, pressing <Up>
2855 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002856 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002857 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2858 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2859 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2860
2861 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2862 " crash Vim
2863 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2864 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2865
Bram Moolenaar414acd32022-02-10 21:09:45 +00002866 " After removing the pum the command line is redrawn
2867 call term_sendkeys(buf, ":edit foo\<CR>")
2868 call term_sendkeys(buf, ":edit bar\<CR>")
2869 call term_sendkeys(buf, ":ls\<CR>")
2870 call term_sendkeys(buf, ":com\<Tab> ")
2871 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002872 call term_sendkeys(buf, "\<C-U>\<CR>")
2873
2874 " Esc still works to abort the command when 'statusline' is set
2875 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2876 call term_sendkeys(buf, ":si\<Tab>")
2877 call term_sendkeys(buf, "\<Esc>")
2878 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002879
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002880 " Esc still works to abort the command when 'tabline' is set
2881 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2882 call term_sendkeys(buf, ":si\<Tab>")
2883 call term_sendkeys(buf, "\<Esc>")
2884 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2885
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002886 " popup is cleared also when 'lazyredraw' is set
2887 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2888 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2889 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2890 call term_sendkeys(buf, "\<Esc>")
2891
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002892 " Pressing <PageDown> should scroll the menu downward
2893 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2894 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2895 call term_sendkeys(buf, "\<PageDown>")
2896 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2897 call term_sendkeys(buf, "\<PageDown>")
2898 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2899 call term_sendkeys(buf, "\<PageDown>")
2900 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2901 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2902 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2903
2904 " Pressing <PageUp> should scroll the menu upward
2905 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2906 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2907 call term_sendkeys(buf, "\<PageUp>")
2908 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2909 call term_sendkeys(buf, "\<PageUp>")
2910 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2911 call term_sendkeys(buf, "\<PageUp>")
2912 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2913
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002914 " pressing <C-E> to end completion should work in middle of the line too
2915 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2916 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2917 call term_sendkeys(buf, "\<C-E>")
2918 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2919
2920 " pressing <C-Y> should select the current match and end completion
2921 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2922 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2923
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002924 call term_sendkeys(buf, "\<C-U>\<CR>")
2925 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002926endfunc
2927
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002928" Test for wildmenumode() with the cmdline popup menu
2929func Test_wildmenumode_with_pum()
2930 set wildmenu
2931 set wildoptions=pum
2932 cnoremap <expr> <F2> wildmenumode()
2933 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2934 call assert_equal('"sign define10', @:)
2935 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2936 call assert_equal('"sign define jump list place undefine unplace0', @:)
2937 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2938 call assert_equal('"sign 0', @:)
2939 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2940 call assert_equal('"sign define0', @:)
2941 set nowildmenu wildoptions&
2942 cunmap <F2>
2943endfunc
2944
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002945func Test_wildmenu_with_pum_foldexpr()
Drew Vogelea67ba72025-05-07 22:05:17 +02002946 CheckScreendump
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002947 CheckRunVimInTerminal
2948
2949 let lines =<< trim END
2950 call setline(1, ['folded one', 'folded two', 'some more text'])
2951 func MyFoldText()
2952 return 'foo'
2953 endfunc
2954 set foldtext=MyFoldText() wildoptions=pum
2955 normal ggzfj
2956 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002957 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002958 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2959 call term_sendkeys(buf, ":set\<Tab>")
2960 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2961
2962 call term_sendkeys(buf, "\<Esc>")
2963 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2964
2965 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002966endfunc
2967
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002968" Test for opening the cmdline completion popup menu from the terminal window.
2969" The popup menu should be positioned correctly over the status line of the
2970" bottom-most window.
2971func Test_wildmenu_pum_from_terminal()
Drew Vogelea67ba72025-05-07 22:05:17 +02002972 CheckScreendump
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002973 CheckRunVimInTerminal
2974 let python = PythonProg()
2975 call CheckPython(python)
2976
2977 %bw!
2978 let cmds = ['set wildmenu wildoptions=pum']
2979 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2980 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002981 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002982 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2983 call term_sendkeys(buf, "\r\r\r")
2984 call term_wait(buf)
2985 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2986 call term_wait(buf)
2987 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2988 call term_wait(buf)
2989 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002990endfunc
2991
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002992func Test_wildmenu_pum_odd_wildchar()
Drew Vogelea67ba72025-05-07 22:05:17 +02002993 CheckScreendump
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002994 CheckRunVimInTerminal
2995
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002996 " Test odd wildchar interactions with pum. Make sure they behave properly
2997 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002998 let lines =<< trim END
2999 set wildoptions=pum
3000 set wildchar=<C-E>
3001 END
3002 call writefile(lines, 'XwildmenuTest', 'D')
3003 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
3004
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003005 call term_sendkeys(buf, ":\<C-E>")
3006 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003007
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003008 " <C-E> being a wildchar takes priority over its original functionality
3009 call term_sendkeys(buf, "\<C-E>")
3010 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
3011
3012 call term_sendkeys(buf, "\<Esc>")
3013 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3014
3015 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
3016 " command-line, and we need to make sure to clean up properly.
3017 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3018 call term_sendkeys(buf, ":\<Esc>")
3019 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3020
3021 call term_sendkeys(buf, "\<Esc>")
3022 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3023
3024 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3025 " and we again need to make sure we clean up properly.
3026 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3027 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3028 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3029
3030 call term_sendkeys(buf, "\<C-N>")
3031 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3032
3033 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003034endfunc
3035
zeertzjq883018f2024-06-15 15:37:11 +02003036" Test that 'rightleft' should not affect cmdline completion popup menu.
3037func Test_wildmenu_pum_rightleft()
3038 CheckFeature rightleft
3039 CheckScreendump
3040
3041 let lines =<< trim END
3042 set wildoptions=pum
3043 set rightleft
3044 END
3045 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3046 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3047
3048 call term_sendkeys(buf, ":sign \<Tab>")
3049 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3050
3051 call StopVimInTerminal(buf)
3052endfunc
3053
Girish Palya4ec46f32025-03-04 20:56:30 +01003054" Test highlighting when pattern matches non-first character of item
3055func Test_wildmenu_pum_hl_nonfirst()
3056 CheckScreendump
3057 let lines =<< trim END
3058 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3059 hi PmenuMatchSel ctermfg=6 ctermbg=7
3060 hi PmenuMatch ctermfg=4 ctermbg=225
3061 func T(a, c, p)
3062 return ["oneA", "o neBneB", "aoneC"]
3063 endfunc
3064 command -nargs=1 -complete=customlist,T MyCmd
3065 END
3066
3067 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3068 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3069
3070 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3071 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3072 call term_sendkeys(buf, "\<Esc>")
3073 call StopVimInTerminal(buf)
3074endfunc
3075
zeertzjqd8c93402024-06-17 18:25:32 +02003076" Test highlighting matched text in cmdline completion popup menu.
3077func Test_wildmenu_pum_hl_match()
3078 CheckScreendump
3079
3080 let lines =<< trim END
3081 set wildoptions=pum,fuzzy
3082 hi PmenuMatchSel ctermfg=6 ctermbg=7
3083 hi PmenuMatch ctermfg=4 ctermbg=225
3084 END
3085 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3086 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3087
3088 call term_sendkeys(buf, ":sign plc\<Tab>")
3089 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3090 call term_sendkeys(buf, "\<Tab>")
3091 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3092 call term_sendkeys(buf, "\<Tab>")
3093 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3094 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3095 call TermWait(buf)
3096 call term_sendkeys(buf, ":sign un\<Tab>")
3097 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3098 call term_sendkeys(buf, "\<Tab>")
3099 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3100 call term_sendkeys(buf, "\<Tab>")
3101 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3102 call term_sendkeys(buf, "\<Esc>")
3103
3104 call StopVimInTerminal(buf)
3105endfunc
3106
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003107" Test for completion after a :substitute command followed by a pipe (|)
3108" character
3109func Test_cmdline_complete_substitute()
Girish Palya6b49fba2025-06-28 19:47:34 +02003110 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003111 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3112 call assert_equal("\"s | \t", @:)
3113 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3114 call assert_equal("\"s/ | \t", @:)
3115 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3116 call assert_equal("\"s/one | \t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02003117 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003118 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3119 call assert_equal("\"s/one/ | \t", @:)
3120 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3121 call assert_equal("\"s/one/two | \t", @:)
3122 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3123 call assert_equal('"s/one/two/ | chistory', @:)
3124 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3125 call assert_equal("\"s/one/two/g \t", @:)
3126 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3127 call assert_equal("\"s/one/two/g | chistory", @:)
3128 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3129 call assert_equal("\"s/one/t\\/ | \t", @:)
3130 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3131 call assert_equal('"s/one/t"o/ | chistory', @:)
3132 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3133 call assert_equal('"s/one/t|o/ | chistory', @:)
3134 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3135 call assert_equal("\"&\t", @:)
3136endfunc
3137
3138" Test for the :dlist command completion
3139func Test_cmdline_complete_dlist()
3140 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3141 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3142 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3143 call assert_equal("\"dlist 10 /pat/ \t", @:)
3144 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3145 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3146 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3147 call assert_equal("\"dlist 10 /pat\\\t", @:)
3148 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3149 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3150endfunc
3151
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003152" argument list (only for :argdel) fuzzy completion
3153func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003154 argadd change.py count.py charge.py
3155 set wildoptions&
3156 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal('"argdel cge', @:)
3158 set wildoptions=fuzzy
3159 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal('"argdel change.py charge.py', @:)
3161 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003162 set wildoptions&
3163endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003164
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003165" autocmd group name fuzzy completion
3166func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003167 set wildoptions&
3168 augroup MyFuzzyGroup
3169 augroup END
3170 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"augroup mfg', @:)
3172 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal('"augroup MyFuzzyGroup', @:)
3174 set wildoptions=fuzzy
3175 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal('"augroup MyFuzzyGroup', @:)
3177 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"augroup My*p', @:)
3179 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003180 set wildoptions&
3181endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003182
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003183" buffer name fuzzy completion
3184func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003185 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003186 " Use a long name to reduce the risk of matching a random directory name
3187 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003188 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003189 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal('"b SRFWL', @:)
3191 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003193 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003194 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3196 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003198 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003199 set wildoptions&
3200endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003201
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003202" buffer name (full path) fuzzy completion
3203func Test_fuzzy_completion_bufname_fullpath()
3204 CheckUnix
3205 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003206 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003207 edit Xcmd/Xstate/Xfile.js
3208 cd Xcmd/Xstate
3209 enew
3210 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal('"b CmdStateFile', @:)
3212 set wildoptions=fuzzy
3213 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3215 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003216 set wildoptions&
3217endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003218
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003219" :behave suboptions fuzzy completion
3220func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003221 set wildoptions&
3222 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3223 call assert_equal('"behave xm', @:)
3224 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3225 call assert_equal('"behave xterm', @:)
3226 set wildoptions=fuzzy
3227 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal('"behave xterm', @:)
3229 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal('"behave xt*m', @:)
3231 let g:Sline = ''
3232 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal('mswin', g:Sline)
3234 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003235 set wildoptions&
3236endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003237
Christian Brabandta3422aa2025-04-23 21:04:24 +02003238" :filetype suboptions completion
3239func Test_completion_filetypecmd()
3240 set wildoptions&
3241 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal('"filetype indent off on plugin', @:)
3243 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal('"filetype plugin indent off on', @:)
3245 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal('"filetype indent off on plugin', @:)
3247 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal('"filetype indent', @:)
3249 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal('"filetype plugin', @:)
3251 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal('"filetype off on', @:)
3253 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3254 call assert_equal('"filetype indent off', @:)
3255 set wildoptions&
3256endfunc
3257
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003258" " colorscheme name fuzzy completion - NOT supported
3259" func Test_fuzzy_completion_colorscheme()
3260" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003261
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003262" built-in command name fuzzy completion
3263func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003264 set wildoptions&
3265 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"sbwin', @:)
3267 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3268 call assert_equal('"sbrewind', @:)
3269 set wildoptions=fuzzy
3270 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"sbrewind', @:)
3272 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003274 set wildoptions&
3275endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003276
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003277" " compiler name fuzzy completion - NOT supported
3278" func Test_fuzzy_completion_compiler()
3279" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003280
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003281" :cscope suboptions fuzzy completion
3282func Test_fuzzy_completion_cscope()
3283 CheckFeature cscope
3284 set wildoptions&
3285 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal('"cscope ret', @:)
3287 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal('"cscope reset', @:)
3289 set wildoptions=fuzzy
3290 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal('"cscope reset', @:)
3292 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3293 call assert_equal('"cscope re*t', @:)
3294 set wildoptions&
3295endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003296
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003297" :diffget/:diffput buffer name fuzzy completion
3298func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003299 new SomeBuffer
3300 diffthis
3301 new OtherBuffer
3302 diffthis
3303 set wildoptions&
3304 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3305 call assert_equal('"diffget sbuf', @:)
3306 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3307 call assert_equal('"diffput sbuf', @:)
3308 set wildoptions=fuzzy
3309 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"diffget SomeBuffer', @:)
3311 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3312 call assert_equal('"diffput SomeBuffer', @:)
3313 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003314 set wildoptions&
3315endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003316
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003317" " directory name fuzzy completion - NOT supported
3318" func Test_fuzzy_completion_dirname()
3319" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003320
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003321" environment variable name fuzzy completion
3322func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003323 set wildoptions&
3324 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal('"echo $VUT', @:)
3326 set wildoptions=fuzzy
3327 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3328 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003329 set wildoptions&
3330endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003331
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003332" autocmd event fuzzy completion
3333func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003334 set wildoptions&
3335 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3336 call assert_equal('"autocmd BWout', @:)
3337 set wildoptions=fuzzy
3338 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3339 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003340 set wildoptions&
3341endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003342
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003343" vim expression fuzzy completion
3344func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003345 let g:PerPlaceCount = 10
3346 set wildoptions&
3347 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3348 call assert_equal('"let c = ppc', @:)
3349 set wildoptions=fuzzy
3350 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3351 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003352 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003353endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003354
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003355" " file name fuzzy completion - NOT supported
3356" func Test_fuzzy_completion_filename()
3357" endfunc
3358
3359" " files in path fuzzy completion - NOT supported
3360" func Test_fuzzy_completion_filesinpath()
3361" endfunc
3362
3363" " filetype name fuzzy completion - NOT supported
3364" func Test_fuzzy_completion_filetype()
3365" endfunc
3366
3367" user defined function name completion
3368func Test_fuzzy_completion_userdefined_func()
3369 set wildoptions&
3370 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3371 call assert_equal('"call Test_f_u_f', @:)
3372 set wildoptions=fuzzy
3373 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3374 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3375 set wildoptions&
3376endfunc
3377
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003378" <SNR> functions should be sorted to the end
3379func Test_fuzzy_completion_userdefined_snr_func()
3380 func s:Sendmail()
3381 endfunc
3382 func SendSomemail()
3383 endfunc
3384 func S1e2n3dmail()
3385 endfunc
3386 set wildoptions=fuzzy
3387 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003388 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003389 set wildoptions&
3390 delfunc s:Sendmail
3391 delfunc SendSomemail
3392 delfunc S1e2n3dmail
3393endfunc
3394
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003395" user defined command name completion
3396func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003397 set wildoptions&
3398 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal('"MsFeat', @:)
3400 set wildoptions=fuzzy
3401 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003403 set wildoptions&
3404endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003405
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003406" " :help tag fuzzy completion - NOT supported
3407" func Test_fuzzy_completion_helptag()
3408" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003409
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003410" highlight group name fuzzy completion
3411func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003412 set wildoptions&
3413 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3414 call assert_equal('"highlight SKey', @:)
3415 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3416 call assert_equal('"highlight SpecialKey', @:)
3417 set wildoptions=fuzzy
3418 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3419 call assert_equal('"highlight SpecialKey', @:)
3420 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3421 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003422 set wildoptions&
3423endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003424
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003425" :history suboptions fuzzy completion
3426func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003427 set wildoptions&
3428 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal('"history dg', @:)
3430 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3431 call assert_equal('"history search', @:)
3432 set wildoptions=fuzzy
3433 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal('"history debug', @:)
3435 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3436 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003437 set wildoptions&
3438endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003439
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003440" :language locale name fuzzy completion
3441func Test_fuzzy_completion_lang()
3442 CheckUnix
3443 set wildoptions&
3444 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3445 call assert_equal('"lang psx', @:)
3446 set wildoptions=fuzzy
3447 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3448 call assert_equal('"lang POSIX', @:)
3449 set wildoptions&
3450endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003451
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003452" :mapclear buffer argument fuzzy completion
3453func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003454 set wildoptions&
3455 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3456 call assert_equal('"mapclear buf', @:)
3457 set wildoptions=fuzzy
3458 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3459 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003460 set wildoptions&
3461endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003462
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003463" map name fuzzy completion
3464func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003465 " test regex completion works
3466 set wildoptions=fuzzy
3467 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3468 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003469 nmap <plug>MyLongMap :p<CR>
3470 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3471 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3472 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3473 call assert_equal("\"nmap MLM \t", @:)
3474 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3475 call assert_equal("\"nmap <F2> one two \t", @:)
3476 " duplicate entries should be removed
3477 vmap <plug>MyLongMap :<C-U>#<CR>
3478 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3479 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3480 nunmap <plug>MyLongMap
3481 vunmap <plug>MyLongMap
3482 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3483 call assert_equal("\"nmap ABC\t", @:)
3484 " results should be sorted by best match
3485 nmap <Plug>format :
3486 nmap <Plug>goformat :
3487 nmap <Plug>TestFOrmat :
3488 nmap <Plug>fendoff :
3489 nmap <Plug>state :
3490 nmap <Plug>FendingOff :
3491 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3492 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3493 nunmap <Plug>format
3494 nunmap <Plug>goformat
3495 nunmap <Plug>TestFOrmat
3496 nunmap <Plug>fendoff
3497 nunmap <Plug>state
3498 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003499 set wildoptions&
3500endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003501
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003502" abbreviation fuzzy completion
3503func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003504 set wildoptions=fuzzy
3505 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3506 call assert_equal("\"iabbr <nowait>", @:)
3507 iabbr WaitForCompletion WFC
3508 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3509 call assert_equal("\"iabbr WaitForCompletion", @:)
3510 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3511 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003512
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003513 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003514 set wildoptions&
3515endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003516
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003517" menu name fuzzy completion
3518func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003519 CheckFeature menu
3520
3521 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003522 set wildoptions&
3523 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3524 call assert_equal('"menu pup', @:)
3525 set wildoptions=fuzzy
3526 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3527 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003528
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003529 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003530 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003531endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003532
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003533" :messages suboptions fuzzy completion
3534func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003535 set wildoptions&
3536 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3537 call assert_equal('"messages clr', @:)
3538 set wildoptions=fuzzy
3539 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3540 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003541 set wildoptions&
3542endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003543
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003544" :set option name fuzzy completion
3545func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003546 set wildoptions&
3547 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3548 call assert_equal('"set brkopt', @:)
3549 set wildoptions=fuzzy
3550 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3551 call assert_equal('"set breakindentopt', @:)
3552 set wildoptions&
3553 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3554 call assert_equal('"set fixendofline', @:)
3555 set wildoptions=fuzzy
3556 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3557 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003558 set wildoptions&
3559endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003560
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003561" :set <term_option>
3562func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003563 set wildoptions&
3564 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3565 call assert_equal('"set t_EC', @:)
3566 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3567 call assert_equal('"set <t_EC>', @:)
3568 set wildoptions=fuzzy
3569 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal('"set t_EC', @:)
3571 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003573 set wildoptions&
3574endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003575
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003576" " :packadd directory name fuzzy completion - NOT supported
3577" func Test_fuzzy_completion_packadd()
3578" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003579
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003580" " shell command name fuzzy completion - NOT supported
3581" func Test_fuzzy_completion_shellcmd()
3582" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003583
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003584" :sign suboptions fuzzy completion
3585func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003586 set wildoptions&
3587 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3588 call assert_equal('"sign ufe', @:)
3589 set wildoptions=fuzzy
3590 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3591 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003592 set wildoptions&
3593endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003594
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003595" :syntax suboptions fuzzy completion
3596func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003597 set wildoptions&
3598 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3599 call assert_equal('"syntax kwd', @:)
3600 set wildoptions=fuzzy
3601 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3602 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003603 set wildoptions&
3604endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003605
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003606" syntax group name fuzzy completion
3607func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003608 set wildoptions&
3609 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3610 call assert_equal('"syntax list mpar', @:)
3611 set wildoptions=fuzzy
3612 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3613 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003614 set wildoptions&
3615endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003616
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003617" :syntime suboptions fuzzy completion
3618func Test_fuzzy_completion_syntime()
3619 CheckFeature profile
3620 set wildoptions&
3621 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3622 call assert_equal('"syntime clr', @:)
3623 set wildoptions=fuzzy
3624 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3625 call assert_equal('"syntime clear', @:)
3626 set wildoptions&
3627endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003628
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003629" " tag name fuzzy completion - NOT supported
3630" func Test_fuzzy_completion_tagname()
3631" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003632
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003633" " tag name and file fuzzy completion - NOT supported
3634" func Test_fuzzy_completion_tagfile()
3635" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003636
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003637" " user names fuzzy completion - how to test this functionality?
3638" func Test_fuzzy_completion_username()
3639" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003640
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003641" user defined variable name fuzzy completion
3642func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003643 let g:SomeVariable=10
3644 set wildoptions&
3645 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3646 call assert_equal('"let SVar', @:)
3647 set wildoptions=fuzzy
3648 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3649 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003650 set wildoptions&
3651endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003652
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003653" Test for sorting the results by the best match
3654func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003655 %bw!
3656 command T123format :
3657 command T123goformat :
3658 command T123TestFOrmat :
3659 command T123fendoff :
3660 command T123state :
3661 command T123FendingOff :
3662 set wildoptions=fuzzy
3663 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3664 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3665 delcommand T123format
3666 delcommand T123goformat
3667 delcommand T123TestFOrmat
3668 delcommand T123fendoff
3669 delcommand T123state
3670 delcommand T123FendingOff
3671 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003672 set wildoptions&
3673endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003674
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003675" Test for fuzzy completion of a command with lower case letters and a number
3676func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003677 command Foo2Bar :
3678 set wildoptions=fuzzy
3679 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3680 call assert_equal('"Foo2Bar', @:)
3681 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3682 call assert_equal('"Foo2Bar', @:)
3683 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3684 call assert_equal('"Foo2Bar', @:)
3685 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003686 set wildoptions&
3687endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003688
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003689" Test for command completion for a command starting with 'k'
3690func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003691 command KillKillKill :
3692 set wildoptions&
3693 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3694 call assert_equal("\"killkill\<Tab>", @:)
3695 set wildoptions=fuzzy
3696 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3697 call assert_equal('"KillKillKill', @:)
3698 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003699 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003700endfunc
3701
3702" Test for fuzzy completion for user defined custom completion function
3703func Test_fuzzy_completion_custom_func()
3704 func Tcompl(a, c, p)
3705 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3706 endfunc
3707 command -nargs=* -complete=custom,Tcompl Fuzzy :
3708 set wildoptions&
3709 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3710 call assert_equal("\"Fuzzy format", @:)
3711 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3712 call assert_equal("\"Fuzzy xy", @:)
3713 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3714 call assert_equal("\"Fuzzy ttt", @:)
3715 set wildoptions=fuzzy
3716 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3717 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3718 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3719 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3720 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3721 call assert_equal("\"Fuzzy xy", @:)
3722 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3723 call assert_equal("\"Fuzzy TestFOrmat", @:)
3724 delcom Fuzzy
3725 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003726endfunc
3727
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003728" Test for fuzzy completion in the middle of a cmdline instead of at the end
3729func Test_fuzzy_completion_in_middle()
3730 set wildoptions=fuzzy
3731 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3732 call assert_equal("\"set wildchar wildcharm wrap", @:)
3733
3734 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3735 call assert_equal("\"args ++encoding= zz", @:)
3736 set wildoptions&
3737endfunc
3738
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003739" Test for :breakadd argument completion
3740func Test_cmdline_complete_breakadd()
3741 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3742 call assert_equal("\"breakadd expr file func here", @:)
3743 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3744 call assert_equal("\"breakadd expr", @:)
3745 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3746 call assert_equal("\"breakadd expr", @:)
3747 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3748 call assert_equal("\"breakadd here", @:)
3749 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3750 call assert_equal("\"breakadd here", @:)
3751 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3752 call assert_equal("\"breakadd abc", @:)
3753 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3754 let l = getcompletion('not', 'breakpoint')
3755 call assert_equal([], l)
3756
3757 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003758 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003759 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3760 call assert_equal("\"breakadd file Xscript", @:)
3761 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3762 call assert_equal("\"breakadd file Xscript", @:)
3763 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3764 call assert_equal("\"breakadd file 20 Xscript", @:)
3765 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3766 call assert_equal("\"breakadd file 20 Xscript", @:)
3767 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3768 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3769 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3770 call assert_equal("\"breakadd file 20\t", @:)
3771 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3772 call assert_equal("\"breakadd file 20x\t", @:)
3773 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3774 call assert_equal("\"breakadd file Xscript ", @:)
3775 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3776 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003777
3778 " Test for :breakadd func [lnum] <function>
3779 func Xbreak_func()
3780 endfunc
3781 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3782 call assert_equal("\"breakadd func Xbreak_func", @:)
3783 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3784 call assert_equal("\"breakadd func Xbreak_func", @:)
3785 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3786 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3787 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3788 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3789 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3790 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3791 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3792 call assert_equal("\"breakadd func 20\t", @:)
3793 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3794 call assert_equal("\"breakadd func 20x\t", @:)
3795 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3796 call assert_equal("\"breakadd func Xbreak_func ", @:)
3797 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3798 call assert_equal("\"breakadd func X1B2C3", @:)
3799 delfunc Xbreak_func
3800
3801 " Test for :breakadd expr <expression>
3802 let g:Xtest_var = 10
3803 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3804 call assert_equal("\"breakadd expr Xtest_var", @:)
3805 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3806 call assert_equal("\"breakadd expr Xtest_var", @:)
3807 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3808 call assert_equal("\"breakadd expr Xtest_var ", @:)
3809 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3810 call assert_equal("\"breakadd expr X1B2C3", @:)
3811 unlet g:Xtest_var
3812
3813 " Test for :breakadd here
3814 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3815 call assert_equal("\"breakadd here Xtest", @:)
3816 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3817 call assert_equal("\"breakadd here Xtest", @:)
3818 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3819 call assert_equal("\"breakadd here ", @:)
3820endfunc
3821
3822" Test for :breakdel argument completion
3823func Test_cmdline_complete_breakdel()
3824 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3825 call assert_equal("\"breakdel file func here", @:)
3826 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3827 call assert_equal("\"breakdel file", @:)
3828 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3829 call assert_equal("\"breakdel file", @:)
3830 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3831 call assert_equal("\"breakdel here", @:)
3832 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3833 call assert_equal("\"breakdel here", @:)
3834 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3835 call assert_equal("\"breakdel abc", @:)
3836
3837 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003838 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003839 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3840 call assert_equal("\"breakdel file Xscript", @:)
3841 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3842 call assert_equal("\"breakdel file Xscript", @:)
3843 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3844 call assert_equal("\"breakdel file 20 Xscript", @:)
3845 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3846 call assert_equal("\"breakdel file 20 Xscript", @:)
3847 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3848 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3849 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3850 call assert_equal("\"breakdel file 20\t", @:)
3851 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3852 call assert_equal("\"breakdel file 20x\t", @:)
3853 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3854 call assert_equal("\"breakdel file Xscript ", @:)
3855 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3856 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003857
3858 " Test for :breakdel func [lnum] <function>
3859 func Xbreak_func()
3860 endfunc
3861 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3862 call assert_equal("\"breakdel func Xbreak_func", @:)
3863 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3864 call assert_equal("\"breakdel func Xbreak_func", @:)
3865 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3866 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3867 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3868 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3869 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3870 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3871 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3872 call assert_equal("\"breakdel func 20\t", @:)
3873 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3874 call assert_equal("\"breakdel func 20x\t", @:)
3875 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3876 call assert_equal("\"breakdel func Xbreak_func ", @:)
3877 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3878 call assert_equal("\"breakdel func X1B2C3", @:)
3879 delfunc Xbreak_func
3880
3881 " Test for :breakdel here
3882 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3883 call assert_equal("\"breakdel here Xtest", @:)
3884 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3885 call assert_equal("\"breakdel here Xtest", @:)
3886 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3887 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003888endfunc
3889
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003890" Test for :scriptnames argument completion
3891func Test_cmdline_complete_scriptnames()
3892 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003893 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003894 source Xa1b2c3.vim
3895 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3896 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3897 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3898 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3899 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3900 call assert_equal("\"script b2c3", @:)
3901 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3902 call assert_match("\"script 2\<Tab>$", @:)
3903 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3904 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3905 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3906 call assert_equal("\"script ", @:)
3907 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3908 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3909 new
3910 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3911 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3912 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003913 set wildmenu&
3914endfunc
3915
Bram Moolenaard8893442022-05-06 20:38:47 +01003916" this was going over the end of IObuff
3917func Test_report_error_with_composing()
3918 let caught = 'no'
3919 try
3920 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3921 catch /E492:/
3922 let caught = 'yes'
3923 endtry
3924 call assert_equal('yes', caught)
3925endfunc
3926
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003927" Test for expanding 2-letter and 3-letter :substitute command arguments.
3928" These commands don't accept an argument.
3929func Test_cmdline_complete_substitute_short()
3930 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3931 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3932 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3933 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3934 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3935 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3936 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3937 endfor
3938endfunc
3939
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003940" Test for shellcmdline command argument completion
3941func Test_cmdline_complete_shellcmdline_argument()
3942 command -nargs=+ -complete=shellcmdline MyCmd
3943
3944 set wildoptions=fuzzy
3945
3946 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3947 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003948 call assert_equal(['test_cmdline.vim'],
3949 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003950
3951 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3952 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003953 call assert_equal([],
3954 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003955
3956 let compl1 = getcompletion('', 'file')[0]
3957 let compl2 = getcompletion('', 'file')[1]
3958 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3959 call assert_equal('"MyCmd vim ' .. compl1, @:)
3960
3961 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3962 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3963
3964 let compl = getcompletion('', 'file')[1]
3965 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3966 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3967
3968 set wildoptions&
3969 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3970 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003971 call assert_equal(['test_cmdline.vim'],
3972 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003973
3974 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3975 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003976 call assert_equal([],
3977 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003978
3979 let compl1 = getcompletion('', 'file')[0]
3980 let compl2 = getcompletion('', 'file')[1]
3981 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3982 call assert_equal('"MyCmd vim ' .. compl1, @:)
3983
3984 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3985 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3986
3987 let compl = getcompletion('', 'file')[1]
3988 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3989 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3990
3991 delcommand MyCmd
3992endfunc
3993
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003994" Test for :! shell command argument completion
3995func Test_cmdline_complete_bang_cmd_argument()
3996 set wildoptions=fuzzy
3997 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3998 call assert_equal('"!vim test_cmdline.vim', @:)
3999 set wildoptions&
4000 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
4001 call assert_equal('"!vim test_cmdline.vim', @:)
4002endfunc
4003
zeertzjq961b2e52023-04-17 15:53:24 +01004004func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004005 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004006endfunc
4007
4008func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01004009 call assert_equal(0, getcmdpos())
4010 call assert_equal(0, getcmdscreenpos())
4011 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004012 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01004013
zeertzjqa821b602024-06-18 20:31:08 +02004014 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01004015 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004016 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004017 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004018 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004019 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004020 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02004021
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004022 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4023 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02004024 let g:results = []
4025 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4026 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4027 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004028 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4029 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4030 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02004031
4032 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01004033 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004034endfunc
4035
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01004036func Test_recursive_register()
4037 let @= = ''
4038 silent! ?e/
4039 let caught = 'no'
4040 try
4041 normal //
4042 catch /E169:/
4043 let caught = 'yes'
4044 endtry
4045 call assert_equal('yes', caught)
4046endfunc
4047
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004048func Test_long_error_message()
4049 " the error should be truncated, not overrun IObuff
4050 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4051endfunc
4052
zeertzjq6791adc2022-07-26 20:42:25 +01004053func Test_cmdline_redraw_tabline()
4054 CheckRunVimInTerminal
4055
4056 let lines =<< trim END
4057 set showtabline=2
4058 autocmd CmdlineEnter * set tabline=foo
4059 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004060 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004061 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4062 call term_sendkeys(buf, ':')
4063 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4064
4065 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004066endfunc
4067
zeertzjqb82a2ab2022-08-21 14:33:57 +01004068func Test_wildmenu_pum_disable_while_shown()
4069 set wildoptions=pum
4070 set wildmenu
4071 cnoremap <F2> <Cmd>set nowildmenu<CR>
4072 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4073 call assert_equal(0, pumvisible())
4074 cunmap <F2>
4075 set wildoptions& wildmenu&
4076endfunc
4077
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004078func Test_setcmdline()
4079 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004080 call assert_equal(0, setcmdline(test_null_string()))
4081 call assert_equal('', getcmdline())
4082 call assert_equal(1, getcmdpos())
4083
4084 call assert_equal(0, setcmdline(''[: -1]))
4085 call assert_equal('', getcmdline())
4086 call assert_equal(1, getcmdpos())
4087
zeertzjq54acb902022-08-29 16:21:25 +01004088 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004089 call assert_equal(0, setcmdline(a:text))
4090 call assert_equal(a:text, getcmdline())
4091 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004092 call assert_equal(getcmdtype(), g:cmdtype)
4093 unlet g:cmdtype
4094 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004095
4096 call assert_equal(0, setcmdline(a:text, a:pos))
4097 call assert_equal(a:text, getcmdline())
4098 call assert_equal(a:pos, getcmdpos())
4099
4100 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004101 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4102 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004103
4104 return ''
4105 endfunc
4106
4107 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4108 call assert_equal('set rtp?', @:)
4109
zeertzjq54acb902022-08-29 16:21:25 +01004110 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4111 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4112 call assert_equal('foo', g:str)
4113 unlet g:str
4114
4115 delfunc SetText
4116
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004117 " setcmdline() returns 1 when not editing the command line.
4118 call assert_equal(1, 'foo'->setcmdline())
4119
4120 " Called in custom function
4121 func CustomComplete(A, L, P)
4122 call assert_equal(0, setcmdline("DoCmd "))
4123 return "January\nFebruary\nMars\n"
4124 endfunc
4125
4126 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4127 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4128 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004129 delcom DoCmd
4130 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004131
4132 " Called in <expr>
4133 cnoremap <expr>a setcmdline('let foo=')
4134 call feedkeys(":a\<CR>", 'tx')
4135 call assert_equal('let foo=0', @:)
4136 cunmap a
4137endfunc
4138
Sean Dewarfc8a6012023-04-17 16:41:20 +01004139func Test_rulerformat_position()
4140 CheckScreendump
4141
4142 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4143 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4144 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4145 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4146 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4147
4148 " clean up
4149 call StopVimInTerminal(buf)
4150endfunc
4151
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004152" Test for using "%!" in 'rulerformat' to use a function
4153func Test_rulerformat_function()
4154 CheckScreendump
4155
4156 let lines =<< trim END
4157 func TestRulerFn()
4158 return '10,20%=30%%'
4159 endfunc
4160 END
4161 call writefile(lines, 'Xrulerformat_function', 'D')
4162
4163 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4164 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4165 call term_sendkeys(buf, ":redraw!\<CR>")
4166 call term_wait(buf)
4167 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4168
4169 " clean up
4170 call StopVimInTerminal(buf)
4171endfunc
4172
zeertzjqe4c79d32023-08-15 22:41:53 +02004173func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004174 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004175
zeertzjqe4c79d32023-08-15 22:41:53 +02004176 call assert_equal(getcompletion('', 'cmdline'),
4177 \ getcompletion('TestCompletion ', 'cmdline'))
4178 call assert_equal(['<buffer>'],
4179 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4180
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004181 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004182endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004183
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004184func Test_custom_completion()
4185 func CustomComplete1(lead, line, pos)
4186 return "a\nb\nc"
4187 endfunc
4188 func CustomComplete2(lead, line, pos)
4189 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4190 endfunc
4191 func Check_custom_completion()
4192 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4193 return ''
4194 endfunc
4195 func Check_customlist_completion()
4196 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4197 return ''
4198 endfunc
4199
4200 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4201 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4202
4203 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4204 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4205
4206 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4207 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4208
zeertzjq757f3212024-04-15 19:01:04 +02004209 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4210 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4211 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004212
4213 delcom Test1
4214 delcom Test2
4215
4216 delfunc CustomComplete1
4217 delfunc CustomComplete2
4218 delfunc Check_custom_completion
4219 delfunc Check_customlist_completion
4220endfunc
4221
zeertzjq28a23602023-09-29 19:58:35 +02004222func Test_custom_completion_with_glob()
4223 func TestGlobComplete(A, L, P)
4224 return split(glob('Xglob*'), "\n")
4225 endfunc
4226
4227 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4228 call writefile([], 'Xglob1', 'D')
4229 call writefile([], 'Xglob2', 'D')
4230
4231 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4232 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4233
4234 delcommand TestGlobComplete
4235 delfunc TestGlobComplete
4236endfunc
4237
Christian Brabandt8610f742024-01-12 17:34:40 +01004238func Test_window_size_stays_same_after_changing_cmdheight()
4239 set laststatus=2
4240 let expected = winheight(0)
4241 function! Function_name() abort
4242 call feedkeys(":"..repeat('x', &columns), 'x')
4243 let &cmdheight=2
4244 let &cmdheight=1
4245 redraw
4246 endfunction
4247 call Function_name()
4248 call assert_equal(expected, winheight(0))
4249endfunc
4250
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004251" verify that buffer-completion finds all buffer names matching a pattern
4252func Test_buffer_completion()
4253 " should return empty list
4254 call assert_equal([], getcompletion('', 'buffer'))
4255
4256 call mkdir('Xbuf_complete', 'R')
4257 e Xbuf_complete/Foobar.c
4258 e Xbuf_complete/MyFoobar.c
4259 e AFoobar.h
4260 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4261
4262 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4263 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4264 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4265 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4266endfunc
4267
Anton Sharonov49528da2024-04-14 20:02:24 +02004268" :set t_??
4269func Test_term_option()
4270 set wildoptions&
4271 let _cpo = &cpo
4272 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004273 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004274 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'
4275 \ .. ' 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'
4276 \ .. ' 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'
4277 \ .. ' 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'
4278 \ .. ' 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 +02004279 \ .. ' 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 +02004280 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004281 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004282 let &cpo = _cpo
4283endfunc
4284
Christian Brabandt70a11a62024-07-26 19:13:55 +02004285func Test_ex_command_completion()
4286 " required for :*
4287 set cpo+=*
4288 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
Hirohito Higashifbe4a8f2025-04-27 15:28:30 +02004289 " :++ and :-- are only valid in Vim9 script context, so they can be ignored
Christian Brabandt70a11a62024-07-26 19:13:55 +02004290 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004291 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004292 call assert_equal(0, exists(':ke'))
4293 call assert_equal(1, exists(':kee'))
4294 call assert_equal(1, exists(':keep'))
4295 call assert_equal(1, exists(':keepm'))
4296 call assert_equal(1, exists(':keepma'))
4297 call assert_equal(1, exists(':keepmar'))
4298 call assert_equal(1, exists(':keepmark'))
4299 call assert_equal(2, exists(':keepmarks'))
4300 call assert_equal(2, exists(':keepalt'))
4301 call assert_equal(2, exists(':keepjumps'))
4302 call assert_equal(2, exists(':keeppatterns'))
4303 set cpo-=*
4304endfunc
4305
zeertzjq5df3cb22024-10-07 21:05:06 +02004306func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004307 CheckMSWindows
4308 let save_shellslash = &shellslash
4309 set noshellslash
4310 call system('mkdir XXXa\_b')
4311 defer delete('XXXa', 'rf')
4312 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4313 call assert_equal('"cd XXXa\_b\', @:)
4314 let &shellslash = save_shellslash
4315endfunc
4316
zeertzjqec270a52025-04-23 20:50:23 +02004317" Test cmdcomplete_info() with CmdlineLeavePre autocmd
Girish Palya92f68e22025-04-21 11:12:41 +02004318func Test_cmdcomplete_info()
4319 augroup test_CmdlineLeavePre
4320 autocmd!
zeertzjqec270a52025-04-23 20:50:23 +02004321 " Calling expand() should not interfere with cmdcomplete_info().
4322 autocmd CmdlineLeavePre * call expand('test_cmdline.*')
Girish Palya92f68e22025-04-21 11:12:41 +02004323 autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
4324 augroup END
4325 new
4326 call assert_equal({}, cmdcomplete_info())
4327 call feedkeys(":h echom\<cr>", "tx") " No expansion
4328 call assert_equal('{}', g:cmdcomplete_info)
4329 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4330 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4331 call feedkeys(":h echom\<tab>\<cr>", "tx")
4332 call assert_equal(
4333 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4334 \ g:cmdcomplete_info)
4335 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4336 call assert_equal(
4337 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4338 \ g:cmdcomplete_info)
4339 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4340 call assert_equal(
4341 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4342 \ g:cmdcomplete_info)
4343
4344 set wildoptions=pum
4345 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4346 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4347 call feedkeys(":h echom\<tab>\<cr>", "tx")
4348 call assert_equal(
4349 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4350 \ g:cmdcomplete_info)
4351 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4352 call assert_equal(
4353 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4354 \ g:cmdcomplete_info)
4355 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4356 call assert_equal(
4357 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4358 \ g:cmdcomplete_info)
4359 bw!
4360 set wildoptions&
4361endfunc
4362
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02004363func Test_redrawtabpanel_error()
4364 CheckNotFeature tabpanel
4365 call assert_fails(':redrawtabpanel', 'E1547:')
4366endfunc
4367
Girish Palya6b49fba2025-06-28 19:47:34 +02004368" Test wildcharm completion for '/' and '?' search
4369func Test_search_complete()
4370 CheckOption incsearch
4371 set wildcharm=<c-z>
4372
4373 " Disable char_avail so that expansion of commandline works
4374 call test_override("char_avail", 1)
4375
4376 func GetComplInfo()
4377 let g:compl_info = cmdcomplete_info()
4378 return ''
4379 endfunc
4380
4381 new
4382 cnoremap <buffer><expr> <F9> GetComplInfo()
4383
4384 " Pressing <Tab> inserts tab character
4385 set wildchar=0
4386 call setline(1, "x\t")
4387 call feedkeys("/x\t\r", "tx")
4388 call assert_equal("x\t", @/)
4389 set wildchar&
4390
4391 call setline(1, ['the', 'these', 'thethe', 'thethere', 'foobar'])
4392
4393 for trig in ["\<tab>", "\<c-z>"]
4394 " Test menu first item and order
4395 call feedkeys($"gg2j/t{trig}\<f9>", 'tx')
4396 call assert_equal(['the', 'thethere', 'there', 'these', 'thethe'], g:compl_info.matches)
4397 call feedkeys($"gg2j?t{trig}\<f9>", 'tx')
4398 call assert_equal(['these', 'the', 'there', 'thethere', 'thethe'], g:compl_info.matches)
4399
4400 " <c-n> and <c-p> cycle through menu items
4401 call feedkeys($"gg/the{trig}\<cr>", 'tx')
4402 call assert_equal('these', getline('.'))
4403 call feedkeys($"gg/the{trig}\<c-n>\<cr>", 'tx')
4404 call assert_equal('thethe', getline('.'))
4405 call feedkeys($"gg/the{trig}".repeat("\<c-n>", 5)."\<cr>", 'tx')
4406 call assert_equal('these', getline('.'))
4407 call feedkeys($"G?the{trig}\<cr>", 'tx')
4408 call assert_equal('thethere', getline('.'))
4409 call feedkeys($"G?the{trig}".repeat("\<c-p>", 5)."\<cr>", 'tx')
4410 call assert_equal('thethere', getline('.'))
4411
4412 " Beginning of word pattern (<) retains '<'
4413 call feedkeys($"gg2j/\\<t{trig}\<f9>", 'tx')
4414 call assert_equal(['\<thethere', '\<the', '\<these', '\<thethe'], g:compl_info.matches)
4415 call feedkeys($"gg2j?\\<t{trig}\<f9>", 'tx')
4416 call assert_equal(['\<these', '\<the', '\<thethere', '\<thethe'], g:compl_info.matches)
4417 call feedkeys($"gg2j/\\v<t{trig}\<f9>", 'tx')
4418 call assert_equal(['\v<thethere', '\v<the', '\v<these', '\v<thethe'], g:compl_info.matches)
4419 call feedkeys($"gg2j?\\v<th{trig}\<f9>", 'tx')
4420 call assert_equal(['\v<these', '\v<the', '\v<thethere', '\v<thethe'], g:compl_info.matches)
4421 endfor
4422
4423 " Ctrl-G goes from one match to the next, after menu is opened
4424 set incsearch
4425 " first match
4426 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<cr>", 'tx')
4427 call assert_equal('thethe', getline('.'))
4428 " second match
4429 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<c-g>\<cr>", 'tx')
4430 call assert_equal('thethere', getline('.'))
4431 call assert_equal([0, 0, 0, 0], getpos('"'))
4432
4433 " CTRL-T goes to the previous match
4434 " first match
4435 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2)."\<c-t>\<cr>", 'tx')
4436 call assert_equal('thethere', getline('.'))
4437 " second match
4438 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2).repeat("\<c-t>", 2)."\<cr>", 'tx')
4439 call assert_equal('thethe', getline('.'))
4440
4441 " wild menu is cleared properly
4442 call feedkeys("/the\<c-z>\<esc>/\<f9>", 'tx')
4443 call assert_equal({}, g:compl_info)
4444 call feedkeys("/the\<c-z>\<c-e>\<f9>", 'tx')
4445 call assert_equal([], g:compl_info.matches)
4446
4447 " Do not expand if offset is present (/pattern/offset and ?pattern?offset)
4448 for pat in ["/", "/2", "/-3", "\\/"]
4449 call feedkeys("/the" . pat . "\<c-z>\<f9>", 'tx')
4450 call assert_equal({}, g:compl_info)
4451 endfor
4452 for pat in ["?", "?2", "?-3", "\\\\?"]
4453 call feedkeys("?the" . pat . "\<c-z>\<f9>", 'tx')
4454 call assert_equal({}, g:compl_info)
4455 endfor
4456
4457 " Last letter of match is multibyte
4458 call setline('$', ['theΩ'])
4459 call feedkeys("gg/th\<c-z>\<f9>", 'tx')
4460 call assert_equal(['these', 'thethe', 'the', 'thethere', 'there', 'theΩ'],
4461 \ g:compl_info.matches)
4462
4463 " Identical words
4464 call setline(1, ["foo", "foo", "foo", "foobar"])
4465 call feedkeys("gg/f\<c-z>\<f9>", 'tx')
4466 call assert_equal(['foo', 'foobar'], g:compl_info.matches)
4467
4468 " Exact match
4469 call feedkeys("/foo\<c-z>\<f9>", 'tx')
4470 call assert_equal(['foo', 'foobar'], g:compl_info.matches)
4471
4472 " Match case correctly
4473 %d
4474 call setline(1, ["foobar", "Foobar", "fooBAr", "FooBARR"])
4475 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4476 call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches)
4477 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4478 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4479 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4480 call assert_equal({}, g:compl_info)
4481 set ignorecase
4482 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4483 call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches)
4484 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4485 call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches)
4486 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4487 call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches)
4488 set smartcase
4489 call feedkeys("gg/f\<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', 'FooBARR'], g:compl_info.matches)
4493 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4494 call assert_equal({}, g:compl_info)
4495
4496 bw!
4497 call test_override("char_avail", 0)
4498 delfunc GetComplInfo
4499 unlet! g:compl_info
4500 set wildcharm=0 incsearch& ignorecase& smartcase&
4501endfunc
4502
4503func Test_search_wildmenu_screendump()
4504 CheckScreendump
4505
4506 let lines =<< trim [SCRIPT]
zeertzjq5e34eec2025-07-05 15:37:17 +02004507 call test_override('alloc_lines', 1)
Girish Palya6b49fba2025-06-28 19:47:34 +02004508 set wildmenu wildcharm=<f5>
4509 call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
4510 [SCRIPT]
4511 call writefile(lines, 'XTest_search_wildmenu', 'D')
4512 let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10})
4513
4514 " Pattern has newline at EOF
4515 call term_sendkeys(buf, "gg2j/e\\n\<f5>")
4516 call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {})
4517
4518 " longest:full
4519 call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>")
4520 call term_sendkeys(buf, "gg/t\<f5>")
4521 call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {})
4522
4523 " list:full
4524 call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>")
4525 call term_sendkeys(buf, "gg/t\<f5>")
4526 call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {})
4527
4528 " noselect:full
4529 call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>")
4530 call term_sendkeys(buf, "gg/t\<f5>")
4531 call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {})
4532
4533 " Multiline
4534 call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>")
4535 call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {})
4536
4537 call term_sendkeys(buf, "\<esc>")
4538 call StopVimInTerminal(buf)
4539endfunc
4540
4541" Test wildcharm completion for :s and :g with range
4542func Test_range_complete()
4543 set wildcharm=<c-z>
4544
4545 " Disable char_avail so that expansion of commandline works
4546 call test_override("char_avail", 1)
4547
4548 func GetComplInfo()
4549 let g:compl_info = cmdcomplete_info()
4550 return ''
4551 endfunc
4552 new
4553 cnoremap <buffer><expr> <F9> GetComplInfo()
4554
4555 call setline(1, ['ab', 'ba', 'ca', 'af'])
4556
4557 for trig in ["\<tab>", "\<c-z>"]
4558 call feedkeys($":%s/a{trig}\<f9>", 'xt')
4559 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
4560 call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt')
4561 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
4562 endfor
4563
4564 call feedkeys(":%s/\<c-z>\<f9>", 'xt')
4565 call assert_equal({}, g:compl_info)
4566
4567 for cmd in ['s', 'g']
4568 call feedkeys(":1,2" . cmd . "/a\<c-z>\<f9>", 'xt')
4569 call assert_equal(['ab', 'a'], g:compl_info.matches)
4570 endfor
4571
4572 1
4573 call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt')
4574 call assert_equal(['ab', 'a'], g:compl_info.matches)
4575
4576 /f
4577 call feedkeys(":1,s/b\<c-z>\<f9>", 'xt')
4578 call assert_equal(['b', 'ba'], g:compl_info.matches)
4579
4580 /c
4581 call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt')
4582 call assert_equal(['a', 'af'], g:compl_info.matches)
4583
4584 %s/c/c/
4585 call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt')
4586 call assert_equal(['ab', 'a'], g:compl_info.matches)
4587
4588 3
4589 normal! ma
4590 call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt')
4591 call assert_equal(['a', 'af'], g:compl_info.matches)
4592
4593 " Line number followed by a search pattern ([start]/pattern/[command])
4594 call feedkeys("3/a\<c-z>\<f9>", 'xt')
4595 call assert_equal(['a', 'af', 'ab'], g:compl_info.matches)
4596
4597 bw!
4598 call test_override("char_avail", 0)
4599 delfunc GetComplInfo
4600 unlet! g:compl_info
4601 set wildcharm=0
4602endfunc
4603
Bram Moolenaar309976e2019-12-05 18:16:33 +01004604" vim: shiftwidth=2 sts=2 expandtab