blob: 46ace6616187093a71fd2b8e10d588259574f2e3 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
4import './util/vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02005
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00006func SetUp()
7 func SaveLastScreenLine()
8 let g:Sline = Screenline(&lines - 1)
9 return ''
10 endfunc
11 cnoremap <expr> <F4> SaveLastScreenLine()
12endfunc
13
14func TearDown()
15 delfunc SaveLastScreenLine
16 cunmap <F4>
17endfunc
18
Bram Moolenaarae3150e2016-06-11 23:22:36 +020019func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010020 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020021 call feedkeys(":e Xtest\t\r", "tx")
22 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020023
24 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
25 call feedkeys(":e %\t\r", "tx")
26 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020027endfunc
28
29func Test_complete_list()
30 " We can't see the output, but at least we check the code runs properly.
31 call feedkeys(":e test\<C-D>\r", "tx")
32 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010033
34 " If a command doesn't support completion, then CTRL-D should be literally
35 " used.
36 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
37 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000038
39 " Test for displaying the tail of the completion matches
40 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010041 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000042 call writefile([], 'Xtest/a.c')
43 call writefile([], 'Xtest/a.h')
44 let g:Sline = ''
45 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
46 call assert_equal('a.c a.h', g:Sline)
47 call assert_equal('"e Xtest/', @:)
48 if has('win32')
49 " Test for 'completeslash'
50 set completeslash=backslash
51 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
52 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000053 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
54 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000055 set completeslash=slash
56 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000058 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
59 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000060 set completeslash&
61 endif
62
63 " Test for displaying the tail with wildcards
64 let g:Sline = ''
65 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
66 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
67 call assert_equal('"e Xtes?/', @:)
68 let g:Sline = ''
69 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
70 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
71 call assert_equal('"e Xtes*/', @:)
72 let g:Sline = ''
73 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
74 call assert_equal(':e Xtes[/', g:Sline)
75 call assert_equal('"e Xtes[/', @:)
76
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000077 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020078endfunc
79
80func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010081 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010082 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
83 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
84 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
85 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020086 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010087
88 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010089 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010090 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010091 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020092 call assert_equal('testfile2', getline(1))
93
Bram Moolenaar37db6422019-03-28 21:26:23 +010094 " <S-Tab> is like <Tab> but begin with the last match and then go to
95 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010096 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010098 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010099 call assert_equal('testfile1', getline(1))
100
101 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100102 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100103 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100104 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100105 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100106 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100107 call assert_equal('testfile1', getline(1))
108
109 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100110 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100111 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100112 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100113 call assert_equal('testfile1', getline(1))
114
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100115 " this fails in some Unix GUIs, not sure why
116 if !has('unix') || !has('gui_running')
117 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
118 " different than 'wildchar'.
119 set wildcharm=<C-Z>
120 cnoremap <C-J> <Down><C-Z>
121 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100122 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100123 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100124 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100125 call assert_equal('testfile1', getline(1))
126 set wildcharm=0
127 cunmap <C-J>
128 cunmap <C-K>
129 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100130
Bram Moolenaar578fe942020-02-27 21:32:51 +0100131 " Test for canceling the wild menu by adding a character
132 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100133 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
134 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100135
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100136 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100137 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100138 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
139 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
140 cd -
141
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000142 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100143 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100144 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
145 call assert_equal('"cd Xwilddir1/0', @:)
146 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
147 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100148 cunmap <F2>
149
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000150 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
151 " After this pressing <Left> or <Right> should not change the selection.
152 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
153 call assert_equal('"sign define', @:)
154 call histadd('cmd', 'TestWildMenu')
155 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"TestWildMenu', @:)
157
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200158 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
159 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
160 call assert_equal('"sign un yy zz', @:)
161
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign unplace yy zz', @:)
164
Bram Moolenaar37db6422019-03-28 21:26:23 +0100165 " cleanup
166 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200167 set nowildmenu
168endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100169
Bram Moolenaara60053b2020-09-03 16:50:13 +0200170func Test_wildmenu_screendump()
171 CheckScreendump
172
173 let lines =<< trim [SCRIPT]
174 set wildmenu hlsearch
175 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100176 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200177
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200178 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200179 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
180 call term_sendkeys(buf, ":vim\<Tab>")
181 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
182
183 call term_sendkeys(buf, "\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
188
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200189 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100190 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200191 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192
193 " Test that the wild menu is cleared properly
194 call term_sendkeys(buf, " ")
195 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
196
197 " Test that a different wildchar still works
198 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
199 call term_sendkeys(buf, ":vim\<Esc>")
200 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
201
202 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
203 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200204 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200205 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200206
207 " clean up
208 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209endfunc
210
zeertzjq1830e782025-03-13 20:29:13 +0100211func Test_wildmenu_with_input_func()
212 CheckScreendump
213
214 let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8})
215
216 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
217 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {})
218 call term_sendkeys(buf, "ech\<Tab>")
219 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {})
220 call term_sendkeys(buf, "\<Space>")
221 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {})
222 call term_sendkeys(buf, "bufn\<Tab>")
223 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {})
224 call term_sendkeys(buf, "\<CR>")
225
226 call term_sendkeys(buf, ":set wildoptions+=pum\<CR>")
227
228 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
229 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {})
230 call term_sendkeys(buf, "ech\<Tab>")
231 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {})
232 call term_sendkeys(buf, "\<Space>")
233 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {})
234 call term_sendkeys(buf, "bufn\<Tab>")
235 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {})
236 call term_sendkeys(buf, "\<CR>")
237
238 " clean up
239 call StopVimInTerminal(buf)
240endfunc
241
Bram Moolenaara653e532022-04-19 11:38:24 +0100242func Test_redraw_in_autocmd()
243 CheckScreendump
244
245 let lines =<< trim END
246 set cmdheight=2
247 autocmd CmdlineChanged * redraw
248 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100249 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100250
251 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
252 call term_sendkeys(buf, ":for i in range(3)\<CR>")
253 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
254
255 call term_sendkeys(buf, "let i =")
256 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
257
258 " clean up
259 call term_sendkeys(buf, "\<CR>")
260 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100261endfunc
262
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100263func Test_redrawstatus_in_autocmd()
264 CheckScreendump
265
266 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100267 set laststatus=2
268 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100269 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100270 END
271 call writefile(lines, 'XTest_redrawstatus', 'D')
272
273 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100274 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100275 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
276 call term_sendkeys(buf, ":foobar")
277 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100278 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100279 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100280 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100281 " with cmdheight=1 messages have scrolled when typing :endfor
282 call term_sendkeys(buf, "\<CR>:endfor")
283 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
284 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
285 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
286 call term_sendkeys(buf, ":for in in range(3)")
287 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
288 call term_sendkeys(buf, "\<CR>:endfor")
289 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100290
291 " clean up
292 call term_sendkeys(buf, "\<CR>")
293 call StopVimInTerminal(buf)
294endfunc
295
Bram Moolenaarf797e302022-08-11 13:17:30 +0100296func Test_changing_cmdheight()
297 CheckScreendump
298
299 let lines =<< trim END
300 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100301 func EchoOne()
302 set laststatus=2 cmdheight=1
303 echo 'foo'
304 echo 'bar'
305 set cmdheight=2
306 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100307 func EchoTwo()
308 set laststatus=2
309 set cmdheight=5
310 echo 'foo'
311 echo 'bar'
312 set cmdheight=1
313 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100314 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100315 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100316
317 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
318 call term_sendkeys(buf, ":resize -3\<CR>")
319 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
320
Luuk van Baale15cbc12025-01-04 17:18:08 +0100321 " :resize now also changes 'cmdheight' accordingly
322 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100323 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
324
325 " using more space moves the status line up
326 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
327 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
328
329 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100330 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100331 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
332
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000333 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100334 call term_sendkeys(buf, ":resize -1\<CR>")
335 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
336 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
337
Bram Moolenaar0816f472022-10-05 15:42:32 +0100338 " setting 'cmdheight' works after outputting two messages
339 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
340 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
341
Luuk van Baalc97e8692025-01-06 18:58:21 +0100342 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100343 call term_sendkeys(buf, ":call EchoOne()\<CR>")
344 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
345
Luuk van Baalc97e8692025-01-06 18:58:21 +0100346 " window commands do not reduce 'cmdheight' to value lower than :set by user
347 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
348 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
349
Bram Moolenaarf797e302022-08-11 13:17:30 +0100350 " clean up
351 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100352endfunc
353
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100354func Test_cmdheight_tabline()
355 CheckScreendump
356
357 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
358 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
359
360 " clean up
361 call StopVimInTerminal(buf)
362endfunc
363
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100364func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100365 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
366 call assert_equal('"map <unique> <silent>', getreg(':'))
367 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
368 call assert_equal('"map <script> <unique>', getreg(':'))
369 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
370 call assert_equal('"map <expr> <script>', getreg(':'))
371 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
372 call assert_equal('"map <buffer> <expr>', getreg(':'))
373 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
374 call assert_equal('"map <nowait> <buffer>', getreg(':'))
375 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
376 call assert_equal('"map <special> <nowait>', getreg(':'))
377 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
378 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200379
Bram Moolenaar1776a282019-05-03 16:05:41 +0200380 map <Middle>x middle
381
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200382 map ,f commaf
383 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200384 map <Left> left
385 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200386 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
387 call assert_equal('"map ,f', getreg(':'))
388 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
389 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200390 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
391 call assert_equal('"map <Left>', getreg(':'))
392 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200393 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000394 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
395 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200396 unmap ,f
397 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200398 unmap <Left>
399 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200400
zeertzjqc3a26c62023-02-17 16:40:20 +0000401 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200402 map <Left> left
403 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
404 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200405 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200406 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000407 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
408 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200409 unmap <Left>
410
411 set cpo+=<
412 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200413 exe "set t_k6=\<Esc>[17~"
414 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200415 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
416 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200417 if !has('gui_running')
418 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
419 call assert_equal("\"map <F6>x", getreg(':'))
420 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200421 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200422 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200423 set cpo-=<
424
425 set cpo+=B
426 map <Left> left
427 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
428 call assert_equal('"map <Left>', getreg(':'))
429 unmap <Left>
430 set cpo-=B
431
432 set cpo+=k
433 map <Left> left
434 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
435 call assert_equal('"map <Left>', getreg(':'))
436 unmap <Left>
437 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200438
Bram Moolenaar531be472020-09-23 22:38:05 +0200439 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
440
Bram Moolenaar1776a282019-05-03 16:05:41 +0200441 unmap <Middle>x
442 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100443endfunc
444
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100445func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100446 hi Aardig ctermfg=green
447 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000448 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100449 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
450 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000451 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
452 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100453endfunc
454
455func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100456 hi Aardig ctermfg=green
457 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
458 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100459
460 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200461 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
462 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100463 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
464 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100465 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
466 call assert_equal('"hi default link Aardig', getreg(':'))
467
468 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100469 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
470 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100471 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
472 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200473 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100474 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
475 " hi link accepts up to two parameters
476 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
477 call assert_equal('"hi link', getreg(':'))
478 call assert_equal('"hi link', getreg(':'))
479 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
480 call assert_equal('"hi link Aardig', getreg(':'))
481 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
482 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
483 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
484 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
485 " hi link will complete to "NONE" for second parameter
486 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
487 call assert_equal("\"hi link NonText", getreg(':'))
488 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
489 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200490
491 " A cleared group does not show up in completions.
492 hi Anders ctermfg=green
493 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
494 hi clear Aardig
495 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
496 hi clear Anders
497 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100498endfunc
499
Bram Moolenaar75e15672020-06-28 13:10:22 +0200500" Test for command-line expansion of "hi Ni " (easter egg)
501func Test_highlight_easter_egg()
502 call test_override('ui_delay', 1)
503 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
504 call assert_equal("\"hi Ni \<Tab>", @:)
505 call test_override('ALL', 0)
506endfunc
507
Yee Cheng China7b81202025-02-23 09:32:47 +0100508func Test_highlight_group_completion()
509 " Test completing keys
510 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
511 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
512 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
513 set wildoptions+=fuzzy
514 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
515 set wildoptions-=fuzzy
516
517 " Test completing the current value
518 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100519 hi AlmostEmpty term=bold
Yee Cheng China7b81202025-02-23 09:32:47 +0100520 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
521 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
522 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
523 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
524 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
525
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100526 " highlight group exists, but no value was set. Should not complete to
527 " existing value
528 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
529 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
530 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
531 call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
532
533 " "bold,underline" is unique and creates an extra item. "undercurl" isn't
534 " and should be de-duplicated.
Yee Cheng China7b81202025-02-23 09:32:47 +0100535 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
536 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
537
538 " don't complete original value if we have user input already, similar to
539 " behavior in :set <option>=<pattern>
540 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
541 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
542
543 " start/stop do not fill their current value now as they are more
544 " complicated
545 hi FooBar start=123 stop=234
546 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
547 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
548
549 if has("gui") || has("termguicolors")
550 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
551 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
552 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
553 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
554 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
555
556 " Check that existing value is de-duplicated and doesn't show up later
557 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100558
559 " highlight group exists, but no value was set. Should not complete to
560 " existing value
561 call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
562 call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
563 call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
564 call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
Yee Cheng China7b81202025-02-23 09:32:47 +0100565 endif
566
567 " Test completing attributes
568 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
569 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
570 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
571 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
572 if has("gui") || has("termguicolors")
573 set wildoptions+=fuzzy
574 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
575 set wildoptions-=fuzzy
576 endif
577
578 " Test completing cterm colors
579 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
580 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
581 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
582 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
583 set wildoptions+=fuzzy
584 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
585 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
586 set wildoptions-=fuzzy
587
588 " Test completing gui colors
589 if has("gui") || has("termguicolors")
590 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
591 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
592 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
593 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
594 set wildoptions=fuzzy
595 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
596 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
597 set wildoptions-=fuzzy
598
599 " Test pruning bad color names with space. Vim doesn't support them.
600 let v:colornames['foobar with space'] = '#123456'
601 let v:colornames['foobarwithoutspace'] = '#234567'
602 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
603
604 " Test specialized sorting. First few items are special values that
605 " go first, after that it's a sorted list of color names.
606 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
607 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
608 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
609 call assert_equal(len(gui_colors_no_space), len(completed_colors))
610 call assert_equal(sort(copy(completed_colors)), completed_colors)
611
612 " Test that the specialized sorting still works if we have some pattern matches
613 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
614 call assert_equal(sort(copy(completed_colors)), completed_colors)
615 call assert_equal('aliceblue', completed_colors[0])
616 endif
617endfunc
618
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200619func Test_getcompletion()
620 let groupcount = len(getcompletion('', 'event'))
621 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200622 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200623 call assert_true(matchcount > 0)
624 call assert_true(groupcount > matchcount)
625
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200626 if has('menu')
627 source $VIMRUNTIME/menu.vim
628 let matchcount = len(getcompletion('', 'menu'))
629 call assert_true(matchcount > 0)
630 call assert_equal(['File.'], getcompletion('File', 'menu'))
631 call assert_true(matchcount > 0)
632 let matchcount = len(getcompletion('File.', 'menu'))
633 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000634 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200635 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200636
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200637 let l = getcompletion('v:n', 'var')
638 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200639 let l = getcompletion('v:notexists', 'var')
640 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200641
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200642 args a.c b.c
643 let l = getcompletion('', 'arglist')
644 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000645 let l = getcompletion('a.', 'buffer')
646 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200647 %argdelete
648
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200649 let l = getcompletion('', 'augroup')
650 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200651 let l = getcompletion('blahblah', 'augroup')
652 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200653
654 let l = getcompletion('', 'behave')
655 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200656 let l = getcompletion('not', 'behave')
657 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200658
659 let l = getcompletion('', 'color')
660 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200661 let l = getcompletion('dirty', 'color')
662 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200663
664 let l = getcompletion('', 'command')
665 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200666 let l = getcompletion('awake', 'command')
667 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200668
669 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200670 call assert_true(index(l, 'samples/') >= 0)
671 let l = getcompletion('NoMatch', 'dir')
672 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200673
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100674 if glob('~/*') !=# ''
675 let l = getcompletion('~/', 'dir')
676 call assert_true(l[0][0] ==# '~')
677 endif
678
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200679 let l = getcompletion('exe', 'expression')
680 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200681 let l = getcompletion('kill', 'expression')
682 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200683
Christian Brabandta3422aa2025-04-23 21:04:24 +0200684 let l = getcompletion('', 'filetypecmd')
685 call assert_equal(["indent", "off", "on", "plugin"], l)
686 let l = getcompletion('not', 'filetypecmd')
687 call assert_equal([], l)
688 let l = getcompletion('o', 'filetypecmd')
689 call assert_equal(['off', 'on'], l)
690
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200691 let l = getcompletion('tag', 'function')
692 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200693 let l = getcompletion('paint', 'function')
694 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200695
Kota Kato90c23532023-01-18 15:27:38 +0000696 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000697 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000698 let l = getcompletion('ruby', 'function')
699 call assert_equal([], l)
700 endif
701
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200702 let Flambda = {-> 'hello'}
703 let l = getcompletion('', 'function')
704 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200705 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200706
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200707 let l = getcompletion('run', 'file')
708 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200709 let l = getcompletion('walk', 'file')
710 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200711 set wildignore=*.vim
712 let l = getcompletion('run', 'file', 1)
713 call assert_true(index(l, 'runtest.vim') < 0)
714 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000715 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100716 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000717 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
718 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200719
720 let l = getcompletion('ha', 'filetype')
721 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200722 let l = getcompletion('horse', 'filetype')
723 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200724
Doug Kearns81642d92024-01-04 22:37:44 +0100725 if has('keymap')
726 let l = getcompletion('acc', 'keymap')
727 call assert_true(index(l, 'accents') >= 0)
728 let l = getcompletion('nullkeymap', 'keymap')
729 call assert_equal([], l)
730 endif
731
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200732 let l = getcompletion('z', 'syntax')
733 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200734 let l = getcompletion('emacs', 'syntax')
735 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200736
737 let l = getcompletion('jikes', 'compiler')
738 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200739 let l = getcompletion('break', 'compiler')
740 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200741
742 let l = getcompletion('last', 'help')
743 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200744 let l = getcompletion('giveup', 'help')
745 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200746
747 let l = getcompletion('time', 'option')
748 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200749 let l = getcompletion('space', 'option')
750 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200751
752 let l = getcompletion('er', 'highlight')
753 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200754 let l = getcompletion('dark', 'highlight')
755 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200756
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200757 let l = getcompletion('', 'messages')
758 call assert_true(index(l, 'clear') >= 0)
759 let l = getcompletion('not', 'messages')
760 call assert_equal([], l)
761
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200762 let l = getcompletion('', 'mapclear')
763 call assert_true(index(l, '<buffer>') >= 0)
764 let l = getcompletion('not', 'mapclear')
765 call assert_equal([], l)
766
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200767 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200768 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200769 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
770 let root = has('win32') ? 'C:\\' : '/'
771 let l = getcompletion(root, 'shellcmd')
772 let expected = map(filter(glob(root . '*', 0, 1),
773 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
774 call assert_equal(expected, l)
775
Bram Moolenaarb650b982016-08-05 20:35:13 +0200776 if has('cscope')
777 let l = getcompletion('', 'cscope')
778 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
779 call assert_equal(cmds, l)
780 " using cmdline completion must not change the result
781 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
782 let l = getcompletion('', 'cscope')
783 call assert_equal(cmds, l)
784 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
785 let l = getcompletion('find ', 'cscope')
786 call assert_equal(keys, l)
787 endif
788
Bram Moolenaar7522f692016-08-06 14:12:50 +0200789 if has('signs')
790 sign define Testing linehl=Comment
791 let l = getcompletion('', 'sign')
792 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
793 call assert_equal(cmds, l)
794 " using cmdline completion must not change the result
795 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
796 let l = getcompletion('', 'sign')
797 call assert_equal(cmds, l)
798 let l = getcompletion('list ', 'sign')
799 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000800 let l = getcompletion('de*', 'sign')
801 call assert_equal(['define'], l)
802 let l = getcompletion('p?', 'sign')
803 call assert_equal(['place'], l)
804 let l = getcompletion('j.', 'sign')
805 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200806 endif
807
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200808 " Command line completion tests
809 let l = getcompletion('cd ', 'cmdline')
810 call assert_true(index(l, 'samples/') >= 0)
811 let l = getcompletion('cd NoMatch', 'cmdline')
812 call assert_equal([], l)
813 let l = getcompletion('let v:n', 'cmdline')
814 call assert_true(index(l, 'v:null') >= 0)
815 let l = getcompletion('let v:notexists', 'cmdline')
816 call assert_equal([], l)
817 let l = getcompletion('call tag', 'cmdline')
818 call assert_true(index(l, 'taglist(') >= 0)
819 let l = getcompletion('call paint', 'cmdline')
820 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200821 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
822 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200823
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100824 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000825 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100826 return "oneA\noneB\noneC"
827 endfunc
828 command -nargs=1 -complete=custom,T MyCmd
829 let l = getcompletion('MyCmd ', 'cmdline')
830 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000831 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100832
833 delcommand MyCmd
834 delfunc T
ii144785fe02021-11-21 12:13:56 +0000835 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100836
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200837 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200838 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
839 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200840 if has('cmdline_hist')
841 call add(names, 'history')
842 endif
843 if has('gettext')
844 call add(names, 'locale')
845 endif
846 if has('profile')
847 call add(names, 'syntime')
848 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200849
850 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100851 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200852
853 for name in names
854 let matchcount = len(getcompletion('', name))
855 call assert_true(matchcount >= 0, 'No matches for ' . name)
856 endfor
857
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200858 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200859
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000860 edit a~b
861 enew
862 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
863 bw a~b
864
865 if has('unix')
866 edit Xtest\
867 enew
868 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
869 bw Xtest\
870 endif
871
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100872 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200873 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100874 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200875endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200876
Hirohito Higashi96b3ef22025-07-05 15:31:23 +0200877func Test_getcompletiontype()
878 call assert_fails('call getcompletiontype()', 'E119:')
879 call assert_fails('call getcompletiontype({})', 'E1174:')
zeertzjqe2c0f812025-07-06 20:26:56 +0200880 call assert_equal('command', getcompletiontype(''))
881 call assert_equal('', getcompletiontype('dummy '))
882 call assert_equal('', getcompletiontype('ls '))
883 call assert_equal('dir_in_path', getcompletiontype('cd '))
884 call assert_equal('var', getcompletiontype('let v:n'))
885 call assert_equal('function', getcompletiontype('call tag'))
886 call assert_equal('help', getcompletiontype('help '))
Hirohito Higashi96b3ef22025-07-05 15:31:23 +0200887endfunc
888
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000889func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000890 " Get a dialog in the GUI
891 CheckNotGui
892
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000893 " This was using uninitialized memory.
894 let lines =<< trim END
895 set verbose=6
896 norm @=ٷ
897 qall!
898 END
899 call writefile(lines, 'XmultiScript', 'D')
900 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
901endfunc
902
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000903" Test for getcompletion() with "fuzzy" in 'wildoptions'
904func Test_getcompletion_wildoptions()
905 let save_wildoptions = &wildoptions
906 set wildoptions&
907 let l = getcompletion('space', 'option')
908 call assert_equal([], l)
909 let l = getcompletion('ier', 'command')
910 call assert_equal([], l)
911 set wildoptions=fuzzy
912 let l = getcompletion('space', 'option')
913 call assert_true(index(l, 'backspace') >= 0)
914 let l = getcompletion('ier', 'command')
915 call assert_true(index(l, 'compiler') >= 0)
916 let &wildoptions = save_wildoptions
917endfunc
918
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000919func Test_complete_autoload_error()
920 let save_rtp = &rtp
921 let lines =<< trim END
922 vim9script
923 export def Complete(..._): string
924 return 'match'
925 enddef
926 echo this will cause an error
927 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100928 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000929 call writefile(lines, 'Xdir/autoload/script.vim')
930 exe 'set rtp+=' .. getcwd() .. '/Xdir'
931
932 let lines =<< trim END
933 vim9script
934 import autoload 'script.vim'
935 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
936 &wildcharm = char2nr("\<Tab>")
937 feedkeys(":Cmd \<Tab>", 'xt')
938 END
939 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
940
941 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000942endfunc
943
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100944func Test_fullcommand()
945 let tests = {
946 \ '': '',
947 \ ':': '',
948 \ ':::': '',
949 \ ':::5': '',
950 \ 'not_a_cmd': '',
951 \ 'Check': '',
952 \ 'syntax': 'syntax',
953 \ ':syntax': 'syntax',
954 \ '::::syntax': 'syntax',
955 \ 'sy': 'syntax',
956 \ 'syn': 'syntax',
957 \ 'synt': 'syntax',
958 \ ':sy': 'syntax',
959 \ '::::sy': 'syntax',
960 \ 'match': 'match',
961 \ '2match': 'match',
962 \ '3match': 'match',
963 \ 'aboveleft': 'aboveleft',
964 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100965 \ 'en': 'endif',
966 \ 'end': 'endif',
967 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100968 \ 's': 'substitute',
969 \ '5s': 'substitute',
970 \ ':5s': 'substitute',
971 \ "'<,'>s": 'substitute',
972 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100973 \ 'CheckLin': 'CheckLinux',
974 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100975 \ }
976
977 for [in, want] in items(tests)
978 call assert_equal(want, fullcommand(in))
979 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200980 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100981
982 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200983
984 command -buffer BufferLocalCommand :
985 command GlobalCommand :
986 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
987 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
988 delcommand BufferLocalCommand
989 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100990endfunc
991
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200992func Test_shellcmd_completion()
993 let save_path = $PATH
994
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100995 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200996 call writefile([''], 'Xpathdir/Xfile.exe')
997 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
998
999 " Set PATH to example directory without trailing slash.
1000 let $PATH = getcwd() . '/Xpathdir'
1001
1002 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
1003 " dirs in the PATH, even though they won't be executed. We check that only
1004 " subdirs of the PWD and executables from the PATH are included in the
1005 " suggestions.
1006 let actual = getcompletion('X', 'shellcmd')
1007 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
1008 call insert(expected, 'Xfile.exe')
1009 call assert_equal(expected, actual)
1010
Bram Moolenaar6ab9e422018-07-28 19:20:13 +02001011 let $PATH = save_path
1012endfunc
1013
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001014func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +01001015 call mkdir('a/b/c', 'pR')
1016 call writefile(['asdfasdf'], 'a/b/c/fileXname')
1017 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
1018 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +02001019 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001020endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +01001021
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001022func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +01001023 let @a = "def"
1024 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
1025 call assert_equal('"abc def ghi', @:)
1026
1027 new
1028 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
1029
1030 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1031 call assert_equal('"aaa asdf bbb', @:)
1032
1033 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
1034 call assert_equal('"aaa /tmp/some bbb', @:)
1035
Bram Moolenaare2c8d832018-05-01 19:24:03 +02001036 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
1037 call assert_equal('"aaa '.getline(1).' bbb', @:)
1038
Bram Moolenaar21efc362016-12-03 14:05:49 +01001039 set incsearch
1040 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1041 call assert_equal('"aaa verylongword bbb', @:)
1042
1043 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
1044 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001045
1046 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1047 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001048 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001049
1050 " Error while typing a command used to cause that it was not executed
1051 " in the end.
1052 new
1053 try
1054 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1055 catch /^Vim\%((\a\+)\)\=:E32/
1056 " ignore error E32
1057 endtry
1058 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001059
Bram Moolenaar578fe942020-02-27 21:32:51 +01001060 " Try to paste an invalid register using <C-R>
1061 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1062 call assert_equal('"onetwo', @:)
1063
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001064 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001065 let @a = "xy\<C-H>z"
1066 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1067 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001068 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1069 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001070 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1071 call assert_equal("\"xy\<C-H>z", @:)
1072
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001073 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1074 let @a = "xy\<C-V>z"
1075 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1076 call assert_equal('"xyz', @:)
1077 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1078 call assert_equal("\"xy\<C-V>z", @:)
1079
Bram Moolenaar578fe942020-02-27 21:32:51 +01001080 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1081
Bram Moolenaar72532d32018-04-07 19:09:09 +02001082 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001083endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001084
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001085func Test_cmdline_remove_char()
1086 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001087
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001088 for e in ['utf8', 'latin1']
1089 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001090
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001091 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1092 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001093
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001094 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1095 call assert_equal('"abcdef', @:)
1096
1097 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1098 call assert_equal('"abc ghi', @:, e)
1099
1100 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1101 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001102
1103 " This was going before the start in latin1.
1104 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001105 endfor
1106
1107 let &encoding = encoding_save
1108endfunc
1109
zeertzjqff2b79d2024-02-26 20:38:36 +01001110func Test_cmdline_del_utf8()
1111 let @s = '⒌'
1112 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1113 call assert_equal('",,', @:)
1114
1115 let @s = 'a̳'
1116 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1117 call assert_equal('",,', @:)
1118
1119 let @s = 'β̳'
1120 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1121 call assert_equal('",,', @:)
1122
1123 if has('arabic')
1124 let @s = 'لا'
1125 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1126 call assert_equal('",,', @:)
1127 endif
1128endfunc
1129
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001130func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001131 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001132
1133 set keymap=esperanto
1134 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1135 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1136 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001137endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001138
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001139func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001140 new
1141 2;'(
1142 2;')
1143 quit
1144endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001145
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001146func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001147 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001148 new
1149 source Xtest.vim
1150 " Trigger calling validate_cursor()
1151 diffsp Xtest.vim
1152 quit!
1153 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001154endfunc
1155
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001156func Test_mark_from_line_zero()
1157 " this was reading past the end of the first (empty) line
1158 new
1159 norm oxxxx
1160 call assert_fails("0;'(", 'E20:')
1161 bwipe!
1162endfunc
1163
Bram Moolenaarba47b512017-01-24 21:18:19 +01001164func Test_cmdline_complete_wildoptions()
1165 help
1166 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1167 let a = join(sort(split(@:)),' ')
1168 set wildoptions=tagfile
1169 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1170 let b = join(sort(split(@:)),' ')
1171 call assert_equal(a, b)
1172 bw!
1173endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001174
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001175func Test_cmdline_complete_user_cmd()
1176 command! -complete=color -nargs=1 Foo :
1177 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1178 call assert_equal('"Foo blue', @:)
1179 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1180 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001181 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1182 call assert_equal('"Foo a blue', @:)
1183 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1184 call assert_equal('"Foo b\', @:)
1185 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1186 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001187 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001188
1189 redraw
1190 call assert_equal('~', Screenline(&lines - 1))
1191 command! FooOne :
1192 command! FooTwo :
1193
1194 set nowildmenu
1195 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1196 call assert_equal('"FooOne', @:)
1197 call assert_equal('~', Screenline(&lines - 1))
1198
1199 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1200 call assert_equal('"FooTwo', @:)
1201 call assert_equal('~', Screenline(&lines - 1))
1202
1203 delcommand FooOne
1204 delcommand FooTwo
1205 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001206endfunc
1207
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001208func Test_complete_user_cmd()
1209 command FooBar echo 'global'
1210 command -buffer FooBar echo 'local'
1211 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1212 call assert_equal('"FooBar', @:)
1213
1214 delcommand -buffer FooBar
1215 delcommand FooBar
1216endfunc
1217
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001218func s:ScriptLocalFunction()
1219 echo 'yes'
1220endfunc
1221
1222func Test_cmdline_complete_user_func()
1223 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001224 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001225 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1226 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001227
1228 " g: prefix also works
1229 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1230 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001231
1232 " using g: prefix does not result in just "g:" matches from a lambda
1233 let Fx = { a -> a }
1234 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1235 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001236
1237 " existence of script-local dict function does not break user function name
1238 " completion
1239 function s:a_dict_func() dict
1240 endfunction
1241 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1242 call assert_match('"call Test_cmdline_complete_user_', @:)
1243 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001244endfunc
1245
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001246func Test_cmdline_complete_user_names()
1247 if has('unix') && executable('whoami')
1248 let whoami = systemlist('whoami')[0]
1249 let first_letter = whoami[0]
1250 if len(first_letter) > 0
1251 " Trying completion of :e ~x where x is the first letter of
1252 " the user name should complete to at least the user name.
1253 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1254 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1255 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001256 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001257 " Just in case: check that the system has an Administrator account.
1258 let names = system('net user')
1259 if names =~ 'Administrator'
1260 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001261 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001262 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001263 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001264 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001265 else
1266 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001267 endif
1268endfunc
1269
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001270func Test_cmdline_complete_shellcmdline()
1271 CheckExecutable whoami
1272 command -nargs=1 -complete=shellcmdline MyCmd
1273
1274 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1275 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001276 let l = getcompletion('whoam', 'shellcmdline')
1277 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001278
1279 delcommand MyCmd
1280endfunc
1281
Bram Moolenaar297610b2019-12-27 17:20:55 +01001282func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001283 CheckExecutable whoami
1284 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1285 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001286endfunc
1287
Bram Moolenaar8b633132020-03-20 18:20:51 +01001288func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001289 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1290 call assert_equal(lang, v:lc_time)
1291
1292 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1293 call assert_equal(lang, v:ctype)
1294
1295 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1296 call assert_equal(lang, v:collate)
1297
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001298 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001299 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001300
1301 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001302 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001303
Bram Moolenaarec680282020-06-12 19:35:32 +02001304 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001305
Bram Moolenaarec680282020-06-12 19:35:32 +02001306 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1307 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001308
Bram Moolenaarec680282020-06-12 19:35:32 +02001309 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1310 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001311
Bram Moolenaarec680282020-06-12 19:35:32 +02001312 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1313 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001314
1315 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1316 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001317endfunc
1318
Bram Moolenaar297610b2019-12-27 17:20:55 +01001319func Test_cmdline_complete_env_variable()
1320 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001321 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1322 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001323 unlet $X_VIM_TEST_COMPLETE_ENV
1324endfunc
1325
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001326func Test_cmdline_complete_expression()
1327 let g:SomeVar = 'blah'
1328 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1329 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1330 call assert_match('"' .. cmd .. ' SomeVar', @:)
1331 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1332 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1333 endfor
1334 unlet g:SomeVar
1335endfunc
1336
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001337func Test_cmdline_complete_argopt()
1338 " completion for ++opt=arg for file commands
1339 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1340 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1341 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1342
1343 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001344 " Test ++ff in the middle of the cmdline
1345 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1346 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001347
1348 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1349 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1350 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1351 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1352 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1353
1354 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1355
1356 " completion should skip the ++opt and continue
1357 call writefile([], 'Xaaaaa.txt', 'D')
1358 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1359 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1360
1361 if has('terminal')
1362 " completion for terminal's [options]
1363 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1364 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1365 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1366
1367 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1368
1369 " :terminal completion should skip the ++opt when considering what is the
1370 " first option, which is a list of shell commands, unlike second option
1371 " onwards.
1372 let first_param = getcompletion('terminal ', 'cmdline')
1373 let second_param = getcompletion('terminal foo ', 'cmdline')
1374 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1375 call assert_equal(first_param, skipped_opt_param)
1376 call assert_notequal(first_param, second_param)
1377 endif
1378endfunc
1379
Bram Moolenaar47016f52021-08-26 16:39:58 +02001380" Unique function name for completion below
1381func s:WeirdFunc()
1382 echo 'weird'
1383endfunc
1384
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001385" Test for various command-line completion
1386func Test_cmdline_complete_various()
1387 " completion for a command starting with a comment
1388 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1389 call assert_equal("\" :|\"\<C-A>", @:)
1390
1391 " completion for a range followed by a comment
1392 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1393 call assert_equal("\"1,2\"\<C-A>", @:)
1394
1395 " completion for :k command
1396 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1397 call assert_equal("\"ka\<C-A>", @:)
1398
Doug Kearnsea842022024-09-29 17:17:41 +02001399 " completion for :keepmarks command
1400 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1401 call assert_equal("\"kee edit", @:)
1402
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001403 " completion for short version of the :s command
1404 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1405 call assert_equal("\"sI \<C-A>", @:)
1406
1407 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001408 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001409 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001410 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001411 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001412 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1413 call assert_equal("\"w >> Xfile1", @:)
1414 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001415
1416 " completion for :w ! and :r ! commands
1417 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1418 call assert_equal("\"w !invalid_xyz_cmd", @:)
1419 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1420 call assert_equal("\"r !invalid_xyz_cmd", @:)
1421
1422 " completion for :>> and :<< commands
1423 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1424 call assert_equal("\">>>\<C-A>", @:)
1425 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1426 call assert_equal("\"<<<\<C-A>", @:)
1427
1428 " completion for command with +cmd argument
1429 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1430 call assert_equal("\"buffer +/pat Xabc", @:)
1431 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1432 call assert_equal("\"buffer +/pat\<C-A>", @:)
1433
1434 " completion for a command with a trailing comment
1435 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1436 call assert_equal("\"ls \" comment\<C-A>", @:)
1437
1438 " completion for a command with a trailing command
1439 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1440 call assert_equal("\"ls | ls", @:)
1441
1442 " completion for a command with an CTRL-V escaped argument
1443 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1444 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1445
1446 " completion for a command that doesn't take additional arguments
1447 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1448 call assert_equal("\"all abc\<C-A>", @:)
1449
zeertzjqd3de1782022-09-01 12:58:52 +01001450 " completion for :wincmd with :horizontal modifier
1451 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1452 call assert_equal("\"horizontal wincmd", @:)
1453
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001454 " completion for a command with a command modifier
1455 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1456 call assert_equal("\"topleft new", @:)
1457
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001458 " completion for vim9 and legacy commands
1459 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1460 call assert_equal("\"vim9 call strlen(", @:)
1461 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1462 call assert_equal("\"legac call strlen(", @:)
1463
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001464 " completion for the :disassemble command
1465 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1466 call assert_equal("\"disas debug", @:)
1467 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1468 call assert_equal("\"disas profile", @:)
1469 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1470 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1471 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1472 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001473 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1474 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001475
Bram Moolenaar47016f52021-08-26 16:39:58 +02001476 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001477 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001478
naohiro onodfe04db2021-09-12 15:45:10 +02001479 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1480 call assert_match('"disas <SNR>\d\+_', @:)
1481 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1482 call assert_match('"disas debug <SNR>\d\+_', @:)
1483
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001484 " completion for the :match command
1485 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1486 call assert_equal("\"match Search /pat/\<C-A>", @:)
1487
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001488 " completion for the :doautocmd command
1489 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1490 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1491
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001492 " completion of autocmd group after comma
1493 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1494 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1495
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001496 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001497 call writefile([], 'Xvarfile1', 'D')
1498 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001499 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1500 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001501
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001502 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001503 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001504 augroup END
1505 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001506 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001507
1508 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001509 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1510 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001511 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1512 call assert_equal("\"au XTest.test", @:)
1513
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001514 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001515
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001516 " autocmd pattern completion
1517 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1518 call assert_equal("\"au BufEnter *.py\t", @:)
1519
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001520 " completion for the :unlet command
1521 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1522 call assert_equal("\"unlet one two", @:)
1523
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001524 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001525 " FIXME: what should happen on MS-Windows?
1526 if !has('win32')
1527 edit \{someFile}
1528 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1529 call assert_equal("\"buf {someFile}", @:)
1530 bwipe {someFile}
1531 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001532
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001533 " completion for the :bdelete command
1534 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1535 call assert_equal("\"bdel a b c", @:)
1536
1537 " completion for the :mapclear command
1538 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1539 call assert_equal("\"mapclear <buffer>", @:)
1540
1541 " completion for user defined commands with menu names
1542 menu Test.foo :ls<CR>
1543 com -nargs=* -complete=menu MyCmd
1544 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1545 call assert_equal('"MyCmd Test.', @:)
1546 delcom MyCmd
1547 unmenu Test
1548
1549 " completion for user defined commands with mappings
1550 mapclear
1551 map <F3> :ls<CR>
1552 com -nargs=* -complete=mapping MyCmd
1553 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001554 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001555 mapclear
1556 delcom MyCmd
1557
Yee Cheng Chin54844852023-10-09 18:12:31 +02001558 " Prepare for path completion
1559 call mkdir('Xa b c', 'D')
1560 defer delete('Xcomma,foobar.txt')
1561 call writefile([], 'Xcomma,foobar.txt')
1562
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001563 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001564 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1565 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1566 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001567
1568 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001569 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1570 call assert_equal('"set dir=Xa\ b\ c/', @:)
1571 set dir&
1572
1573 " completion for :set tags= / set dictionary= with escaped commas
1574 if has('win32')
1575 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1576 " '\,'
1577 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1578 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1579
1580 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1581 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1582
1583 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1584 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1585
1586 " completion for :set dictionary= with escaped commas (same behavior, but
1587 " different internal code path from 'set tags=' for escaping the output)
1588 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1589 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1590 else
1591 " In other platforms, backslashes are rounded down (since '\,' itself will
1592 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1593 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1594 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1595
1596 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1597 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1598
1599 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1600 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1601
1602 " completion for :set dictionary= with escaped commas (same behavior, but
1603 " different internal code path from 'set tags=' for escaping the output)
1604 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1605 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1606 endif
1607 set tags&
1608 set dictionary&
1609
1610 " completion for :set makeprg= with no escaped commas
1611 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1612 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1613
1614 if !has('win32')
1615 " Cannot create file with backslash in file name in Windows, so only test
1616 " this elsewhere.
1617 defer delete('Xcomma\,fooslash.txt')
1618 call writefile([], 'Xcomma\,fooslash.txt')
1619 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1620 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1621 endif
1622 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001623
1624 " completion for the :py3 commands
1625 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1626 call assert_equal('"py3 py3do py3file', @:)
1627
Bram Moolenaardf749a22021-03-28 15:29:43 +02001628 " completion for the :vim9 commands
1629 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1630 call assert_equal('"vim9cmd vim9script', @:)
1631
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001632 " redir @" is not the start of a comment. So complete after that
1633 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1634 call assert_equal('"redir @" | cwindow', @:)
1635
1636 " completion after a backtick
1637 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1638 call assert_equal('"e `a1b2c', @:)
1639
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001640 " completion for :language command with an invalid argument
1641 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1642 call assert_equal("\"language dummy \t", @:)
1643
1644 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001645 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1646 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001647
1648 " completion with ambiguous user defined commands
1649 com TCmd1 echo 'TCmd1'
1650 com TCmd2 echo 'TCmd2'
1651 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1652 call assert_equal('"TCmd ', @:)
1653 delcom TCmd1
1654 delcom TCmd2
1655
1656 " completion after a range followed by a pipe (|) character
1657 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1658 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001659
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001660 " completion after a :global command
1661 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1662 call assert_equal('"g/a/chistory', @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001663 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001664 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1665 call assert_equal("\"g/a\\/chist\t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02001666 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001667
Bram Moolenaar9c929712020-09-07 22:05:28 +02001668 " use <Esc> as the 'wildchar' for completion
1669 set wildchar=<Esc>
1670 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1671 call assert_equal('"g/a\xb/clearjumps', @:)
1672 " pressing <esc> twice should cancel the command
1673 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1674 call assert_equal('"g/a\xb/clearjumps', @:)
1675 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001676
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001677 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001678 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001679 call writefile([], '~Xtest')
1680 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1681 call assert_equal('"e \~Xtest', @:)
1682 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001683
1684 " should be able to complete a file name that has a '*'
1685 call writefile([], 'Xx*Yy')
1686 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1687 call assert_equal('"e Xx\*Yy', @:)
1688 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001689
1690 " use a literal star
1691 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1692 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001693 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001694
1695 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1696 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001697endfunc
1698
zeertzjq094dd152023-06-15 22:51:57 +01001699" Test that expanding a pattern doesn't interfere with cmdline completion.
1700func Test_expand_during_cmdline_completion()
1701 func ExpandStuff()
1702 badd <script>:p:h/README.*
1703 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1704 $bwipe
1705 call assert_equal('README.txt', expand('README.*'))
1706 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1707 endfunc
1708 augroup test_CmdlineChanged
1709 autocmd!
1710 autocmd CmdlineChanged * call ExpandStuff()
1711 augroup END
1712
1713 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1714 call assert_equal('"sign place', @:)
1715
1716 augroup test_CmdlineChanged
1717 au!
1718 augroup END
1719 augroup! test_CmdlineChanged
1720 delfunc ExpandStuff
1721endfunc
1722
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001723" Test for 'wildignorecase'
1724func Test_cmdline_wildignorecase()
1725 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001726 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001727 set wildignorecase
1728 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1729 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001730 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001731 let g:Sline = ''
1732 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1733 call assert_equal('"e xt', @:)
1734 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001735 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001736endfunc
1737
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001738func Test_cmdline_write_alternatefile()
1739 new
1740 call setline('.', ['one', 'two'])
1741 f foo.txt
1742 new
1743 f #-A
1744 call assert_equal('foo.txt-A', expand('%'))
1745 f #<-B.txt
1746 call assert_equal('foo-B.txt', expand('%'))
1747 f %<
1748 call assert_equal('foo-B', expand('%'))
1749 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001750 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001751 bw!
1752 f foo-B.txt
1753 f %<-A
1754 call assert_equal('foo-B-A', expand('%'))
1755 bw!
1756 bw!
1757endfunc
1758
Bram Moolenaarf5724372022-09-02 19:45:15 +01001759func Test_cmdline_expand_cur_alt_file()
1760 enew
1761 file http://some.com/file.txt
1762 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1763 call assert_equal('"e http://some.com/file.txt', @:)
1764 edit another
1765 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1766 call assert_equal('"e http://some.com/file.txt', @:)
1767 bwipe
1768 bwipe http://some.com/file.txt
1769endfunc
1770
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001771" using a leading backslash here
1772set cpo+=C
1773
1774func Test_cmdline_search_range()
1775 new
1776 call setline(1, ['a', 'b', 'c', 'd'])
1777 /d
1778 1,\/s/b/B/
1779 call assert_equal('B', getline(2))
1780
1781 /a
1782 $
1783 \?,4s/c/C/
1784 call assert_equal('C', getline(3))
1785
1786 call setline(1, ['a', 'b', 'c', 'd'])
1787 %s/c/c/
1788 1,\&s/b/B/
1789 call assert_equal('B', getline(2))
1790
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001791 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001792 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001793
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001794 bwipe!
1795endfunc
1796
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001797" Test for the tick mark (') in an excmd range
1798func Test_tick_mark_in_range()
1799 " If only the tick is passed as a range and no command is specified, there
1800 " should not be an error
1801 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001802 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001803 call assert_fails("',print", 'E78:')
1804endfunc
1805
1806" Test for using a line number followed by a search pattern as range
1807func Test_lnum_and_pattern_as_range()
1808 new
1809 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1810 let @" = ''
1811 2/foo/yank
1812 call assert_equal("foo 3\n", @")
1813 call assert_equal(1, line('.'))
1814 close!
1815endfunc
1816
Bram Moolenaar65189a12017-02-06 22:22:17 +01001817" Tests for getcmdline(), getcmdpos() and getcmdtype()
1818func Check_cmdline(cmdtype)
1819 call assert_equal('MyCmd a', getcmdline())
1820 call assert_equal(8, getcmdpos())
1821 call assert_equal(a:cmdtype, getcmdtype())
1822 return ''
1823endfunc
1824
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001825set cpo&
1826
Shougo Matsushita69084282024-09-23 20:34:47 +02001827func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001828 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1829
1830 let cmdtype = ''
1831 debuggreedy
1832 call feedkeys(":debug echo 'test'\<CR>", "t")
1833 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1834 call feedkeys("cont\<CR>", "xt")
1835 0debuggreedy
1836 call assert_equal('>', cmdtype)
1837
1838 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1839 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1840
1841 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001842 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001843
1844 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1845
1846 cnoremap <expr> <F6> Check_cmdline('=')
1847 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1848 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001849
1850 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001851
1852 call assert_equal('', getcmdprompt())
1853 augroup test_CmdlineEnter
1854 autocmd!
1855 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1856 augroup END
1857 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1858 call assert_equal('Answer?', g:cmdprompt)
1859 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001860 call feedkeys(":\<CR>\<ESC>", "xt")
1861 call assert_equal('', g:cmdprompt)
1862 call assert_equal('', getcmdprompt())
1863
1864 let str = "C" .. repeat("c", 1023) .. "xyz"
1865 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1866 call assert_equal(str, g:cmdprompt)
1867
1868 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1869 call assert_equal('Ans?', g:cmdprompt)
1870 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001871
1872 augroup test_CmdlineEnter
1873 au!
1874 augroup END
1875 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001876endfunc
1877
Bram Moolenaar52604f22017-04-07 16:17:39 +02001878func Test_verbosefile()
1879 set verbosefile=Xlog
1880 echomsg 'foo'
1881 echomsg 'bar'
1882 set verbosefile=
1883 let log = readfile('Xlog')
1884 call assert_match("foo\nbar", join(log, "\n"))
1885 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001886
1887 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001888 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001889endfunc
1890
Bram Moolenaar4facea32019-10-12 20:17:40 +02001891func Test_verbose_option()
1892 CheckScreendump
1893
1894 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001895 " clear the TermResponse autocommand from defaults.vim
1896 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001897 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1898 call feedkeys("\r", 't') " for the hit-enter prompt
1899 set verbose=20
1900 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001901 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001902
1903 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001904 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001905 call term_sendkeys(buf, ":DoSomething\<CR>")
1906 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1907
1908 " clean up
1909 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001910endfunc
1911
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001912func Test_setcmdpos()
1913 func InsertTextAtPos(text, pos)
1914 call assert_equal(0, setcmdpos(a:pos))
1915 return a:text
1916 endfunc
1917
1918 " setcmdpos() with position in the middle of the command line.
1919 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1920 call assert_equal('"1ab2', @:)
1921
1922 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1923 call assert_equal('"1b2a', @:)
1924
1925 " setcmdpos() with position beyond the end of the command line.
1926 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1927 call assert_equal('"12ab', @:)
1928
1929 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001930 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001931endfunc
1932
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001933func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001934 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001935 let encoding_save = &encoding
1936
1937 for e in encodings
1938 exe 'set encoding=' . e
1939
1940 " Test overstrike in the middle of the command line.
1941 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001942 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001943
1944 " Test overstrike going beyond end of command line.
1945 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001946 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001947
1948 " Test toggling insert/overstrike a few times.
1949 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001950 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001951 endfor
1952
Bram Moolenaar30276f22019-01-24 17:59:39 +01001953 " Test overstrike with multi-byte characters.
1954 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001955 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001956
1957 let &encoding = encoding_save
1958endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001959
Bram Moolenaar52410572019-10-27 05:12:45 +01001960func Test_buffers_lastused()
1961 " check that buffers are sorted by time when wildmode has lastused
1962 call test_settime(1550020000) " middle
1963 edit bufa
1964 enew
1965 call test_settime(1550030000) " newest
1966 edit bufb
1967 enew
1968 call test_settime(1550010000) " oldest
1969 edit bufc
1970 enew
1971 call test_settime(0)
1972 enew
1973
1974 call assert_equal(['bufa', 'bufb', 'bufc'],
1975 \ getcompletion('', 'buffer'))
1976
1977 let save_wildmode = &wildmode
1978 set wildmode=full:lastused
1979
1980 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1981 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1982 call assert_equal('b bufb', X)
1983 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1984 call assert_equal('b bufa', X)
1985 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1986 call assert_equal('b bufc', X)
1987 enew
1988
1989 edit other
1990 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1991 call assert_equal('b bufb', X)
1992 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1993 call assert_equal('b bufa', X)
1994 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1995 call assert_equal('b bufc', X)
1996 enew
1997
1998 let &wildmode = save_wildmode
1999
2000 bwipeout bufa
2001 bwipeout bufb
2002 bwipeout bufc
2003endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01002004
Bram Moolenaar479950f2020-01-19 15:45:17 +01002005func Test_cmdlineclear_tabenter()
2006 CheckScreendump
2007
2008 let lines =<< trim [SCRIPT]
2009 call setline(1, range(30))
2010 [SCRIPT]
2011
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002012 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01002013 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02002014 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002015 " in one tab make the command line higher with CTRL-W -
2016 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
2017 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2018
2019 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002020endfunc
2021
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002022" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002023func Test_cmdline_expand_special()
2024 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02002025 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002026 call assert_fails('e <afile>', 'E495:')
2027 call assert_fails('e <abuf>', 'E496:')
2028 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002029
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002030 call writefile([], 'Xfile.cpp', 'D')
2031 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002032 new Xfile.cpp
2033 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2034 call assert_equal('"e Xfile.cpp Xfile.java', @:)
2035 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002036endfunc
2037
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002038" Test for backtick expression in the command line
2039func Test_cmd_backtick()
2040 %argd
2041 argadd `=['a', 'b', 'c']`
2042 call assert_equal(['a', 'b', 'c'], argv())
2043 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02002044
2045 argadd `echo abc def`
2046 call assert_equal(['abc def'], argv())
2047 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002048endfunc
2049
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002050" Test for the :! command
2051func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002052 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002053
2054 let lines =<< trim [SCRIPT]
2055 " Test for no previous command
2056 call assert_fails('!!', 'E34:')
2057 set nomore
2058 " Test for cmdline expansion with :!
2059 call setline(1, 'foo!')
2060 silent !echo <cWORD> > Xfile.out
2061 call assert_equal(['foo!'], readfile('Xfile.out'))
2062 " Test for using previous command
2063 silent !echo \! !
2064 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2065 call writefile(v:errors, 'Xresult')
2066 call delete('Xfile.out')
2067 qall!
2068 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002069 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002070 if RunVim([], [], '--clean -S Xscript')
2071 call assert_equal([], readfile('Xresult'))
2072 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002073 call delete('Xresult')
2074endfunc
2075
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002076" Test error: "E135: *Filter* Autocommands must not change current buffer"
2077func Test_cmd_bang_E135()
2078 new
2079 call setline(1, ['a', 'b', 'c', 'd'])
2080 augroup test_cmd_filter_E135
2081 au!
2082 autocmd FilterReadPost * help
2083 augroup END
2084 call assert_fails('2,3!echo "x"', 'E135:')
2085
2086 augroup test_cmd_filter_E135
2087 au!
2088 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002089 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002090 %bwipe!
2091endfunc
2092
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002093func Test_cmd_bang_args()
2094 new
2095 :.!
2096 call assert_equal(0, v:shell_error)
2097
2098 " Note that below there is one space char after the '!'. This caused a
2099 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2100 :.!
2101 call assert_equal(0, v:shell_error)
2102 bwipe!
2103
2104 CheckUnix
2105 :.!pwd
2106 call assert_equal(0, v:shell_error)
2107 :.! pwd
2108 call assert_equal(0, v:shell_error)
2109
2110 " Note there is one space after 'pwd'.
2111 :.! pwd
2112 call assert_equal(0, v:shell_error)
2113
2114 " Note there are two spaces after 'pwd'.
2115 :.! pwd
2116 call assert_equal(0, v:shell_error)
2117 :.!ls ~
2118 call assert_equal(0, v:shell_error)
2119
2120 " Note there is one space char after '~'.
2121 :.!ls ~
2122 call assert_equal(0, v:shell_error)
2123
2124 " Note there are two spaces after '~'.
2125 :.!ls ~
2126 call assert_equal(0, v:shell_error)
2127
2128 :.!echo "foo"
2129 call assert_equal(getline('.'), "foo")
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
2137 %bwipe!
2138endfunc
2139
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002140" Test for using ~ for home directory in cmdline completion matches
2141func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002142 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002143 call writefile([], 'Xexpdir/Xfile1')
2144 call writefile([], 'Xexpdir/Xfile2')
2145 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002146 let save_HOME = $HOME
2147 let $HOME = getcwd()
2148 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2149 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2150 let $HOME = save_HOME
2151 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002152endfunc
2153
Bram Moolenaar578fe942020-02-27 21:32:51 +01002154" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2155" or insert mode (when 'insertmode' is set)
2156func Test_cmdline_ctrl_g()
2157 new
2158 call setline(1, 'abc')
2159 call cursor(1, 3)
2160 " If command line is entered from insert mode, using C-\ C-G should back to
2161 " insert mode
2162 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2163 call assert_equal('abxyc', getline(1))
2164 call assert_equal(4, col('.'))
2165
2166 " If command line is entered in 'insertmode', using C-\ C-G should back to
2167 " 'insertmode'
2168 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2169 call assert_equal('ab12xyc', getline(1))
2170 close!
2171endfunc
2172
Bram Moolenaar578fe942020-02-27 21:32:51 +01002173" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002174func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002175 func T(a, c, p)
2176 return "oneA\noneB\noneC"
2177 endfunc
2178 command -nargs=1 -complete=custom,T MyCmd
2179
Bram Moolenaar578fe942020-02-27 21:32:51 +01002180 set nowildmenu
2181 set wildmode=full,list
2182 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002183 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002184 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002185 call assert_equal('"MyCmd oneA', @:)
2186
2187 set wildmode=longest,full
2188 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2189 call assert_equal('"MyCmd one', @:)
2190 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2191 call assert_equal('"MyCmd oneC', @:)
2192
2193 set wildmode=longest
2194 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2195 call assert_equal('"MyCmd one', @:)
2196
2197 set wildmode=list:longest
2198 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002199 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002200 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002201 call assert_equal('"MyCmd one', @:)
2202
2203 set wildmode=""
2204 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2205 call assert_equal('"MyCmd oneA', @:)
2206
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002207 " Test for wildmode=longest with 'fileignorecase' set
2208 set wildmode=longest
2209 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002210 argadd AAA AAAA AAAAA
2211 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2212 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002213 set fileignorecase&
2214
2215 " Test for listing files with wildmode=list
2216 set wildmode=list
2217 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002218 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002219 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002220 call assert_equal('"b A', @:)
2221
Girish Palya2bacc3e2025-03-02 22:55:57 +01002222 " When 'wildmenu' is not set, 'noselect' completes first item
2223 set wildmode=noselect
2224 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2225 call assert_equal('"MyCmd oneA', @:)
2226
2227 " When 'noselect' is present, do not complete first <tab>.
2228 set wildmenu
2229 set wildmode=noselect
2230 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2231 call assert_equal('"MyCmd o', @:)
2232 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2233 call assert_equal('"MyCmd o', @:)
2234 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2235 call assert_equal('"MyCmd o', @:)
2236
2237 " When 'full' is present, complete after first <tab>.
2238 set wildmode=noselect,full
2239 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2240 call assert_equal('"MyCmd o', @:)
2241 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2242 call assert_equal('"MyCmd oneA', @:)
2243 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2244 call assert_equal('"MyCmd oneB', @:)
2245 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2246 call assert_equal('"MyCmd oneB', @:)
2247
2248 " 'noselect' has no effect when 'longest' is present.
2249 set wildmode=noselect:longest
2250 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2251 call assert_equal('"MyCmd one', @:)
2252
2253 " Complete 'noselect' value in 'wildmode' option
2254 set wildmode&
2255 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2256 call assert_equal('"set wildmode=noselect', @:)
2257 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2258 call assert_equal('"set wildmode=noselect', @:)
2259
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002260 " when using longest completion match, matches shorter than the argument
2261 " should be ignored (happens with :help)
2262 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002263 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2264 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002265 " non existing file
2266 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2267 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002268
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002269 " Test for longest file name completion with 'fileignorecase'
2270 " On MS-Windows, file names are case insensitive.
2271 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002272 call writefile([], 'XTESTfoo', 'D')
2273 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002274 set nofileignorecase
2275 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2276 call assert_equal('"e XTESTfoo', @:)
2277 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2278 call assert_equal('"e Xtestbar', @:)
2279 set fileignorecase
2280 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2281 call assert_equal('"e Xtest', @:)
2282 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2283 call assert_equal('"e Xtest', @:)
2284 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002285 endif
2286
Girish Palya2bacc3e2025-03-02 22:55:57 +01002287 " If 'noselect' is present, single item menu should not insert item
2288 func! T(a, c, p)
2289 return "oneA"
2290 endfunc
2291 command! -nargs=1 -complete=custom,T MyCmd
2292 set wildmode=noselect,full
2293 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2294 call assert_equal('"MyCmd o', @:)
2295 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2296 call assert_equal('"MyCmd oneA', @:)
2297 " 'nowildmenu' should make 'noselect' ineffective
2298 set nowildmenu
2299 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2300 call assert_equal('"MyCmd oneA', @:)
2301
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002302 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002303 delcommand MyCmd
2304 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002305 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002306 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002307endfunc
2308
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002309func Test_wildmode()
2310 " Test with utf-8 encoding
2311 call Wildmode_tests()
2312
2313 " Test with latin1 encoding
2314 let save_encoding = &encoding
2315 set encoding=latin1
2316 call Wildmode_tests()
2317 let &encoding = save_encoding
2318endfunc
2319
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002320func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002321 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002322 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002323 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002324 let lines =<< trim END
2325 func vim8#Complete(a, c, p)
2326 return "oneA\noneB\noneC"
2327 endfunc
2328 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002329 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002330
2331 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2332 set nowildmenu
2333 set wildmode=full,list
2334 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2335 call assert_equal('"MyCmd oneA oneB oneC', @:)
2336
2337 let &rtp = save_rtp
2338 set wildmode& wildmenu&
2339 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002340endfunc
2341
Bram Moolenaar578fe942020-02-27 21:32:51 +01002342" Test for interrupting the command-line completion
2343func Test_interrupt_compl()
2344 func F(lead, cmdl, p)
2345 if a:lead =~ 'tw'
2346 call interrupt()
2347 return
2348 endif
2349 return "one\ntwo\nthree"
2350 endfunc
2351 command -nargs=1 -complete=custom,F Tcmd
2352
2353 set nowildmenu
2354 set wildmode=full
2355 let interrupted = 0
2356 try
2357 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2358 catch /^Vim:Interrupt$/
2359 let interrupted = 1
2360 endtry
2361 call assert_equal(1, interrupted)
2362
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002363 let interrupted = 0
2364 try
2365 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2366 catch /^Vim:Interrupt$/
2367 let interrupted = 1
2368 endtry
2369 call assert_equal(1, interrupted)
2370
Bram Moolenaar578fe942020-02-27 21:32:51 +01002371 delcommand Tcmd
2372 delfunc F
2373 set wildmode&
2374endfunc
2375
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002376" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002377func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002378 let str = ":one two\<C-U>"
2379 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002380 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002381 let str ..= "\<Left>five\<Right>"
2382 let str ..= "\<Home>two "
2383 let str ..= "\<C-Left>one "
2384 let str ..= "\<C-Right> three"
2385 let str ..= "\<End>\<S-Left>four "
2386 let str ..= "\<S-Right> six"
2387 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2388 call feedkeys(str, 'xt')
2389 call assert_equal("\"one two three four five six seven", @:)
2390endfunc
2391
2392" Test for moving the cursor on the / command line in 'rightleft' mode
2393func Test_cmdline_edit_rightleft()
2394 CheckFeature rightleft
2395 set rightleft
2396 set rightleftcmd=search
2397 let str = "/one two\<C-U>"
2398 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002399 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002400 let str ..= "\<Right>five\<Left>"
2401 let str ..= "\<Home>two "
2402 let str ..= "\<C-Right>one "
2403 let str ..= "\<C-Left> three"
2404 let str ..= "\<End>\<S-Right>four "
2405 let str ..= "\<S-Left> six"
2406 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2407 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2408 call assert_equal("\"one two three four five six seven", @/)
2409 set rightleftcmd&
2410 set rightleft&
2411endfunc
2412
2413" Test for using <C-\>e in the command line to evaluate an expression
2414func Test_cmdline_expr()
2415 " Evaluate an expression from the beginning of a command line
2416 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2417 call assert_equal('"hello', @:)
2418
2419 " Use an invalid expression for <C-\>e
2420 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2421
2422 " Insert literal <CTRL-\> in the command line
2423 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2424 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002425endfunc
2426
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002427" This was making the insert position negative
2428func Test_cmdline_expr_register()
2429 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2430endfunc
2431
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002432" Test for 'imcmdline' and 'imsearch'
2433" This test doesn't actually test the input method functionality.
2434func Test_cmdline_inputmethod()
2435 new
2436 call setline(1, ['', 'abc', ''])
2437 set imcmdline
2438
2439 call feedkeys(":\"abc\<CR>", 'xt')
2440 call assert_equal("\"abc", @:)
2441 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2442 call assert_equal("\"abc", @:)
2443 call feedkeys("/abc\<CR>", 'xt')
2444 call assert_equal([2, 1], [line('.'), col('.')])
2445 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2446 call assert_equal([2, 1], [line('.'), col('.')])
2447
2448 set imsearch=2
2449 call cursor(1, 1)
2450 call feedkeys("/abc\<CR>", 'xt')
2451 call assert_equal([2, 1], [line('.'), col('.')])
2452 call cursor(1, 1)
2453 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2454 call assert_equal([2, 1], [line('.'), col('.')])
2455 set imdisable
2456 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2457 call assert_equal([2, 1], [line('.'), col('.')])
2458 set imdisable&
2459 set imsearch&
2460
2461 set imcmdline&
2462 %bwipe!
2463endfunc
2464
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002465" Test for using CTRL-_ in the command line with 'allowrevins'
2466func Test_cmdline_revins()
2467 CheckNotMSWindows
2468 CheckFeature rightleft
2469 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2470 call assert_equal("\"abc\<c-_>", @:)
2471 set allowrevins
2472 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2473 call assert_equal('"abcñèæ', @:)
2474 set allowrevins&
2475endfunc
2476
2477" Test for typing UTF-8 composing characters in the command line
2478func Test_cmdline_composing_chars()
2479 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2480 call assert_equal('"ゔ', @:)
2481endfunc
2482
Bram Moolenaar0e717042020-04-27 19:29:01 +02002483" test that ";" works to find a match at the start of the first line
2484func Test_zero_line_search()
2485 new
2486 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2487 call cursor(1,1)
2488 0;/pattern/d
2489 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2490 q!
2491endfunc
2492
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002493func Test_read_shellcmd()
2494 CheckUnix
2495 if executable('ls')
2496 " There should be ls in the $PATH
2497 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2498 call assert_match('^"r! .*\<ls\>', @:)
2499 endif
2500
2501 if executable('rm')
2502 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2503 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2504 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002505
2506 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2507 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2508 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002509 endif
2510endfunc
2511
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002512" Test for going up and down the directory tree using 'wildmenu'
2513func Test_wildmenu_dirstack()
2514 CheckUnix
2515 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002516 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002517 call writefile([], 'Xwildmenu/file1_1.txt')
2518 call writefile([], 'Xwildmenu/file1_2.txt')
2519 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2520 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2521 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2522 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2523 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2524 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002525 set wildmenu
2526
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002527 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002528 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002529 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002530 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002531 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002532 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002533 call assert_equal('"e ../../dir3/', @:)
2534 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2535 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002536 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002537 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002538 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002539 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002540 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002541 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2542 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002543
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002544 set wildmenu&
2545endfunc
2546
obcat71c6f7a2021-05-13 20:23:10 +02002547" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002548" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2549" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002550func Test_recalling_cmdline()
2551 CheckFeature cmdline_hist
2552
2553 let g:cmdlines = []
2554 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2555
2556 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002557 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2558 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2559 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2560 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002561 "\ TODO: {'name': 'debug', ...}
2562 \]
2563 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002564 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2565 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2566 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2567 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2568 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002569 \]
2570 let prefix = 'vi'
2571 for h in histories
2572 call histadd(h.name, 'vim')
2573 call histadd(h.name, 'virtue')
2574 call histadd(h.name, 'Virgo')
2575 call histadd(h.name, 'vogue')
2576 call histadd(h.name, 'emacs')
2577 for k in keypairs
2578 let g:cmdlines = []
2579 let keyseqs = h.enter
2580 \ .. prefix
2581 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2582 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2583 \ .. h.exit
2584 call feedkeys(keyseqs, 'xt')
2585 call histdel(h.name, -1) " delete the history added by feedkeys above
2586 let expect = k.prefixmatch
2587 \ ? ['virtue', 'vim', 'virtue', prefix]
2588 \ : ['emacs', 'vogue', 'emacs', prefix]
2589 call assert_equal(expect, g:cmdlines)
2590 endfor
2591 endfor
2592
2593 unlet g:cmdlines
2594 cunmap <Plug>(save-cmdline)
2595endfunc
2596
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002597func Test_cmd_map_cmdlineChanged()
2598 let g:log = []
2599 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002600 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002601 autocmd!
2602 autocmd CmdlineChanged : let g:log += [getcmdline()]
2603 augroup END
2604
2605 call feedkeys(":\<F1>\<CR>", 'xt')
2606 call assert_equal(['l', 'ls'], g:log)
2607
Bram Moolenaar796139a2021-05-18 21:38:45 +02002608 let @b = 'b'
2609 cnoremap <F1> a<C-R>b
2610 let g:log = []
2611 call feedkeys(":\<F1>\<CR>", 'xt')
2612 call assert_equal(['a', 'ab'], g:log)
2613
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002614 unlet g:log
2615 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002616 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002617 autocmd!
2618 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002619 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002620endfunc
2621
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002622" Test for the 'suffixes' option
2623func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002624 call writefile([], 'Xsuffile', 'D')
2625 call writefile([], 'Xsuffile.c', 'D')
2626 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002627 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002628 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2629 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2630 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2631 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002632 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002633 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2634 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2635 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2636 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002637 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002638 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2639 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2640 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2641 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002642 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002643 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002644 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2645 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002646endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002647
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002648" Test for using a popup menu for the command line completion matches
2649" (wildoptions=pum)
2650func Test_wildmenu_pum()
Drew Vogelea67ba72025-05-07 22:05:17 +02002651 CheckScreendump
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002652 CheckRunVimInTerminal
2653
2654 let commands =<< trim [CODE]
2655 set wildmenu
2656 set wildoptions=pum
2657 set shm+=I
2658 set noruler
2659 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002660
2661 func CmdCompl(a, b, c)
2662 return repeat(['aaaa'], 120)
2663 endfunc
2664 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002665
2666 func MyStatusLine() abort
2667 return 'status'
2668 endfunc
2669 func SetupStatusline()
2670 set statusline=%!MyStatusLine()
2671 set laststatus=2
2672 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002673
2674 func MyTabLine()
2675 return 'my tab line'
2676 endfunc
2677 func SetupTabline()
2678 set statusline=
2679 set tabline=%!MyTabLine()
2680 set showtabline=2
2681 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002682
2683 func DoFeedKeys()
2684 let &wildcharm = char2nr("\t")
2685 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2686 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002687 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002688 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689
2690 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2691
2692 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002693 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2694
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002695 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002696 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002697 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2698
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002699 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002700 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002701 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2702
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002703 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002704 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002705 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2706
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002707 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002708 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002709 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2710
2711 " pressing <C-E> should end completion and go back to the original match
2712 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002713 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2714
2715 " pressing <C-Y> should select the current match and end completion
2716 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002717 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2718
2719 " With 'wildmode' set to 'longest,full', completing a match should display
2720 " the longest match, the wildmenu should not be displayed.
2721 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2722 call TermWait(buf)
2723 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002724 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2725
2726 " pressing <Tab> should display the wildmenu
2727 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002728 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2729
2730 " pressing <Tab> second time should select the next entry in the menu
2731 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002732 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2733
2734 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002735 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002736 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002737 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2738
2739 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002740 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2741
2742 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002743 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2744
2745 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002746 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002747 call writefile([], 'Xnamedir/XfileA')
2748 call writefile([], 'Xnamedir/XdirA/XfileB')
2749 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002750
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002751 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002752 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2753
2754 " Pressing <Right> on a directory name should go into that directory
2755 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002756 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2757
2758 " Pressing <Left> on a directory name should go to the parent directory
2759 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002760 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2761
2762 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002763 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002764 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002765 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2766
2767 " Pressing <C-D> when the popup menu is displayed should remove the popup
2768 " menu
2769 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002770 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2771
2772 " Pressing <S-Tab> should open the popup menu with the last entry selected
2773 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002774 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2775
2776 " Pressing <Esc> should close the popup menu and cancel the cmd line
2777 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002778 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2779
2780 " Typing a character when the popup is open, should close the popup
2781 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002782 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2783
2784 " When the popup is open, entering the cmdline window should close the popup
2785 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002786 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2787 call term_sendkeys(buf, ":q\<CR>")
2788
2789 " After the last popup menu item, <C-N> should show the original string
2790 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002791 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2792
2793 " Use the popup menu for the command name
2794 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002795 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2796
2797 " Pressing the left arrow should remove the popup menu
2798 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002799 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2800
2801 " Pressing <BS> should remove the popup menu and erase the last character
2802 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002803 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2804
2805 " Pressing <C-W> should remove the popup menu and erase the previous word
2806 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002807 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2808
2809 " Pressing <C-U> should remove the popup menu and erase the entire line
2810 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002811 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2812
2813 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2814 " the cmdline from history
2815 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002816 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2817
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002818 " Check "list" still works
2819 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2820 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002821 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2822 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002823 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2824
rbtnn68cc2b82022-02-09 11:55:47 +00002825 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002826 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002827 call writefile([], 'Xnamedir/あいう/abc')
2828 call writefile([], 'Xnamedir/あいう/xyz')
2829 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002830
2831 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002832 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002833 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2834
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002835 " Pressing <C-A> when the popup menu is displayed should list all the
2836 " matches and pressing a key after that should remove the popup menu
2837 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2838 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2839 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2840
2841 " Pressing <C-A> when the popup menu is displayed should list all the
2842 " matches and pressing <Left> after that should move the cursor
2843 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2844 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2845 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2846
2847 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2848 " should be displayed correctly on the screen.
2849 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2850 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2851
2852 " After using <C-A> to expand all the filename matches, pressing <Up>
2853 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002854 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002855 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2856 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2857 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2858
2859 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2860 " crash Vim
2861 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2862 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2863
Bram Moolenaar414acd32022-02-10 21:09:45 +00002864 " After removing the pum the command line is redrawn
2865 call term_sendkeys(buf, ":edit foo\<CR>")
2866 call term_sendkeys(buf, ":edit bar\<CR>")
2867 call term_sendkeys(buf, ":ls\<CR>")
2868 call term_sendkeys(buf, ":com\<Tab> ")
2869 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002870 call term_sendkeys(buf, "\<C-U>\<CR>")
2871
2872 " Esc still works to abort the command when 'statusline' is set
2873 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2874 call term_sendkeys(buf, ":si\<Tab>")
2875 call term_sendkeys(buf, "\<Esc>")
2876 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002877
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002878 " Esc still works to abort the command when 'tabline' is set
2879 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2880 call term_sendkeys(buf, ":si\<Tab>")
2881 call term_sendkeys(buf, "\<Esc>")
2882 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2883
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002884 " popup is cleared also when 'lazyredraw' is set
2885 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2886 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2887 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2888 call term_sendkeys(buf, "\<Esc>")
2889
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002890 " Pressing <PageDown> should scroll the menu downward
2891 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2892 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2893 call term_sendkeys(buf, "\<PageDown>")
2894 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2895 call term_sendkeys(buf, "\<PageDown>")
2896 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2897 call term_sendkeys(buf, "\<PageDown>")
2898 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2899 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2900 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2901
2902 " Pressing <PageUp> should scroll the menu upward
2903 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2904 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2905 call term_sendkeys(buf, "\<PageUp>")
2906 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2907 call term_sendkeys(buf, "\<PageUp>")
2908 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2909 call term_sendkeys(buf, "\<PageUp>")
2910 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2911
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002912 " pressing <C-E> to end completion should work in middle of the line too
2913 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2914 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2915 call term_sendkeys(buf, "\<C-E>")
2916 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2917
2918 " pressing <C-Y> should select the current match and end completion
2919 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2920 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2921
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002922 call term_sendkeys(buf, "\<C-U>\<CR>")
2923 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002924endfunc
2925
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002926" Test for wildmenumode() with the cmdline popup menu
2927func Test_wildmenumode_with_pum()
2928 set wildmenu
2929 set wildoptions=pum
2930 cnoremap <expr> <F2> wildmenumode()
2931 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2932 call assert_equal('"sign define10', @:)
2933 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2934 call assert_equal('"sign define jump list place undefine unplace0', @:)
2935 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2936 call assert_equal('"sign 0', @:)
2937 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2938 call assert_equal('"sign define0', @:)
2939 set nowildmenu wildoptions&
2940 cunmap <F2>
2941endfunc
2942
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002943func Test_wildmenu_with_pum_foldexpr()
Drew Vogelea67ba72025-05-07 22:05:17 +02002944 CheckScreendump
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002945 CheckRunVimInTerminal
2946
2947 let lines =<< trim END
2948 call setline(1, ['folded one', 'folded two', 'some more text'])
2949 func MyFoldText()
2950 return 'foo'
2951 endfunc
2952 set foldtext=MyFoldText() wildoptions=pum
2953 normal ggzfj
2954 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002955 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002956 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2957 call term_sendkeys(buf, ":set\<Tab>")
2958 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2959
2960 call term_sendkeys(buf, "\<Esc>")
2961 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2962
2963 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002964endfunc
2965
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002966" Test for opening the cmdline completion popup menu from the terminal window.
2967" The popup menu should be positioned correctly over the status line of the
2968" bottom-most window.
2969func Test_wildmenu_pum_from_terminal()
Drew Vogelea67ba72025-05-07 22:05:17 +02002970 CheckScreendump
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002971 CheckRunVimInTerminal
2972 let python = PythonProg()
2973 call CheckPython(python)
2974
2975 %bw!
2976 let cmds = ['set wildmenu wildoptions=pum']
2977 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2978 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002979 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002980 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2981 call term_sendkeys(buf, "\r\r\r")
2982 call term_wait(buf)
2983 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2984 call term_wait(buf)
2985 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2986 call term_wait(buf)
2987 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002988endfunc
2989
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002990func Test_wildmenu_pum_odd_wildchar()
Drew Vogelea67ba72025-05-07 22:05:17 +02002991 CheckScreendump
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002992 CheckRunVimInTerminal
2993
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002994 " Test odd wildchar interactions with pum. Make sure they behave properly
2995 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002996 let lines =<< trim END
2997 set wildoptions=pum
2998 set wildchar=<C-E>
2999 END
3000 call writefile(lines, 'XwildmenuTest', 'D')
3001 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
3002
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003003 call term_sendkeys(buf, ":\<C-E>")
3004 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003005
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02003006 " <C-E> being a wildchar takes priority over its original functionality
3007 call term_sendkeys(buf, "\<C-E>")
3008 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
3009
3010 call term_sendkeys(buf, "\<Esc>")
3011 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3012
3013 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
3014 " command-line, and we need to make sure to clean up properly.
3015 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3016 call term_sendkeys(buf, ":\<Esc>")
3017 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3018
3019 call term_sendkeys(buf, "\<Esc>")
3020 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3021
3022 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3023 " and we again need to make sure we clean up properly.
3024 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3025 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3026 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3027
3028 call term_sendkeys(buf, "\<C-N>")
3029 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3030
3031 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003032endfunc
3033
zeertzjq883018f2024-06-15 15:37:11 +02003034" Test that 'rightleft' should not affect cmdline completion popup menu.
3035func Test_wildmenu_pum_rightleft()
3036 CheckFeature rightleft
3037 CheckScreendump
3038
3039 let lines =<< trim END
3040 set wildoptions=pum
3041 set rightleft
3042 END
3043 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3044 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3045
3046 call term_sendkeys(buf, ":sign \<Tab>")
3047 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3048
3049 call StopVimInTerminal(buf)
3050endfunc
3051
Girish Palya4ec46f32025-03-04 20:56:30 +01003052" Test highlighting when pattern matches non-first character of item
3053func Test_wildmenu_pum_hl_nonfirst()
3054 CheckScreendump
3055 let lines =<< trim END
3056 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3057 hi PmenuMatchSel ctermfg=6 ctermbg=7
3058 hi PmenuMatch ctermfg=4 ctermbg=225
3059 func T(a, c, p)
3060 return ["oneA", "o neBneB", "aoneC"]
3061 endfunc
3062 command -nargs=1 -complete=customlist,T MyCmd
3063 END
3064
3065 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3066 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3067
3068 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3069 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3070 call term_sendkeys(buf, "\<Esc>")
3071 call StopVimInTerminal(buf)
3072endfunc
3073
zeertzjqd8c93402024-06-17 18:25:32 +02003074" Test highlighting matched text in cmdline completion popup menu.
3075func Test_wildmenu_pum_hl_match()
3076 CheckScreendump
3077
3078 let lines =<< trim END
3079 set wildoptions=pum,fuzzy
3080 hi PmenuMatchSel ctermfg=6 ctermbg=7
3081 hi PmenuMatch ctermfg=4 ctermbg=225
3082 END
3083 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3084 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3085
3086 call term_sendkeys(buf, ":sign plc\<Tab>")
3087 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3088 call term_sendkeys(buf, "\<Tab>")
3089 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3090 call term_sendkeys(buf, "\<Tab>")
3091 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3092 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3093 call TermWait(buf)
3094 call term_sendkeys(buf, ":sign un\<Tab>")
3095 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3096 call term_sendkeys(buf, "\<Tab>")
3097 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3098 call term_sendkeys(buf, "\<Tab>")
3099 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3100 call term_sendkeys(buf, "\<Esc>")
3101
3102 call StopVimInTerminal(buf)
3103endfunc
3104
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003105" Test for completion after a :substitute command followed by a pipe (|)
3106" character
3107func Test_cmdline_complete_substitute()
Girish Palya6b49fba2025-06-28 19:47:34 +02003108 set wildchar=0
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003109 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3110 call assert_equal("\"s | \t", @:)
3111 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3112 call assert_equal("\"s/ | \t", @:)
3113 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3114 call assert_equal("\"s/one | \t", @:)
Girish Palya6b49fba2025-06-28 19:47:34 +02003115 set wildchar&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003116 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3117 call assert_equal("\"s/one/ | \t", @:)
3118 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3119 call assert_equal("\"s/one/two | \t", @:)
3120 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3121 call assert_equal('"s/one/two/ | chistory', @:)
3122 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3123 call assert_equal("\"s/one/two/g \t", @:)
3124 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3125 call assert_equal("\"s/one/two/g | chistory", @:)
3126 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3127 call assert_equal("\"s/one/t\\/ | \t", @:)
3128 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3129 call assert_equal('"s/one/t"o/ | chistory', @:)
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(":&\t\<C-B>\"\<CR>", 'xt')
3133 call assert_equal("\"&\t", @:)
3134endfunc
3135
3136" Test for the :dlist command completion
3137func Test_cmdline_complete_dlist()
3138 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3139 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3140 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3141 call assert_equal("\"dlist 10 /pat/ \t", @:)
3142 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3143 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3144 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3145 call assert_equal("\"dlist 10 /pat\\\t", @:)
3146 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3147 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3148endfunc
3149
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003150" argument list (only for :argdel) fuzzy completion
3151func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003152 argadd change.py count.py charge.py
3153 set wildoptions&
3154 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal('"argdel cge', @:)
3156 set wildoptions=fuzzy
3157 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal('"argdel change.py charge.py', @:)
3159 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003160 set wildoptions&
3161endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003162
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003163" autocmd group name fuzzy completion
3164func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003165 set wildoptions&
3166 augroup MyFuzzyGroup
3167 augroup END
3168 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal('"augroup mfg', @:)
3170 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"augroup MyFuzzyGroup', @:)
3172 set wildoptions=fuzzy
3173 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal('"augroup MyFuzzyGroup', @:)
3175 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal('"augroup My*p', @:)
3177 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003178 set wildoptions&
3179endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003180
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003181" buffer name fuzzy completion
3182func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003183 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003184 " Use a long name to reduce the risk of matching a random directory name
3185 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003186 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003187 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_equal('"b SRFWL', @:)
3189 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003191 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003192 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3194 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003196 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003197 set wildoptions&
3198endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003199
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003200" buffer name (full path) fuzzy completion
3201func Test_fuzzy_completion_bufname_fullpath()
3202 CheckUnix
3203 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003204 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003205 edit Xcmd/Xstate/Xfile.js
3206 cd Xcmd/Xstate
3207 enew
3208 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal('"b CmdStateFile', @:)
3210 set wildoptions=fuzzy
3211 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3212 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3213 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003214 set wildoptions&
3215endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003216
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003217" :behave suboptions fuzzy completion
3218func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003219 set wildoptions&
3220 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3221 call assert_equal('"behave xm', @:)
3222 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3223 call assert_equal('"behave xterm', @:)
3224 set wildoptions=fuzzy
3225 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal('"behave xterm', @:)
3227 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal('"behave xt*m', @:)
3229 let g:Sline = ''
3230 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal('mswin', g:Sline)
3232 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003233 set wildoptions&
3234endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003235
Christian Brabandta3422aa2025-04-23 21:04:24 +02003236" :filetype suboptions completion
3237func Test_completion_filetypecmd()
3238 set wildoptions&
3239 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal('"filetype indent off on plugin', @:)
3241 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal('"filetype plugin indent off on', @:)
3243 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal('"filetype indent off on plugin', @:)
3245 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal('"filetype indent', @:)
3247 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal('"filetype plugin', @:)
3249 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal('"filetype off on', @:)
3251 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal('"filetype indent off', @:)
3253 set wildoptions&
3254endfunc
3255
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003256" " colorscheme name fuzzy completion - NOT supported
3257" func Test_fuzzy_completion_colorscheme()
3258" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003259
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003260" built-in command name fuzzy completion
3261func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003262 set wildoptions&
3263 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal('"sbwin', @:)
3265 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"sbrewind', @:)
3267 set wildoptions=fuzzy
3268 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"sbrewind', @:)
3270 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003272 set wildoptions&
3273endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003274
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003275" " compiler name fuzzy completion - NOT supported
3276" func Test_fuzzy_completion_compiler()
3277" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003278
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003279" :cscope suboptions fuzzy completion
3280func Test_fuzzy_completion_cscope()
3281 CheckFeature cscope
3282 set wildoptions&
3283 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal('"cscope ret', @:)
3285 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal('"cscope reset', @:)
3287 set wildoptions=fuzzy
3288 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3289 call assert_equal('"cscope reset', @:)
3290 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal('"cscope re*t', @:)
3292 set wildoptions&
3293endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003294
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003295" :diffget/:diffput buffer name fuzzy completion
3296func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003297 new SomeBuffer
3298 diffthis
3299 new OtherBuffer
3300 diffthis
3301 set wildoptions&
3302 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3303 call assert_equal('"diffget sbuf', @:)
3304 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3305 call assert_equal('"diffput sbuf', @:)
3306 set wildoptions=fuzzy
3307 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3308 call assert_equal('"diffget SomeBuffer', @:)
3309 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"diffput SomeBuffer', @:)
3311 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003312 set wildoptions&
3313endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003314
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003315" " directory name fuzzy completion - NOT supported
3316" func Test_fuzzy_completion_dirname()
3317" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003318
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003319" environment variable name fuzzy completion
3320func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003321 set wildoptions&
3322 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3323 call assert_equal('"echo $VUT', @:)
3324 set wildoptions=fuzzy
3325 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3326 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003327 set wildoptions&
3328endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003329
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003330" autocmd event fuzzy completion
3331func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003332 set wildoptions&
3333 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3334 call assert_equal('"autocmd BWout', @:)
3335 set wildoptions=fuzzy
3336 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3337 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003338 set wildoptions&
3339endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003340
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003341" vim expression fuzzy completion
3342func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003343 let g:PerPlaceCount = 10
3344 set wildoptions&
3345 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3346 call assert_equal('"let c = ppc', @:)
3347 set wildoptions=fuzzy
3348 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3349 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003350 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003351endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003352
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003353" " file name fuzzy completion - NOT supported
3354" func Test_fuzzy_completion_filename()
3355" endfunc
3356
3357" " files in path fuzzy completion - NOT supported
3358" func Test_fuzzy_completion_filesinpath()
3359" endfunc
3360
3361" " filetype name fuzzy completion - NOT supported
3362" func Test_fuzzy_completion_filetype()
3363" endfunc
3364
3365" user defined function name completion
3366func Test_fuzzy_completion_userdefined_func()
3367 set wildoptions&
3368 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3369 call assert_equal('"call Test_f_u_f', @:)
3370 set wildoptions=fuzzy
3371 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3372 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3373 set wildoptions&
3374endfunc
3375
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003376" <SNR> functions should be sorted to the end
3377func Test_fuzzy_completion_userdefined_snr_func()
3378 func s:Sendmail()
3379 endfunc
3380 func SendSomemail()
3381 endfunc
3382 func S1e2n3dmail()
3383 endfunc
3384 set wildoptions=fuzzy
3385 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003386 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003387 set wildoptions&
3388 delfunc s:Sendmail
3389 delfunc SendSomemail
3390 delfunc S1e2n3dmail
3391endfunc
3392
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003393" user defined command name completion
3394func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003395 set wildoptions&
3396 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3397 call assert_equal('"MsFeat', @:)
3398 set wildoptions=fuzzy
3399 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3400 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003401 set wildoptions&
3402endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003403
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003404" " :help tag fuzzy completion - NOT supported
3405" func Test_fuzzy_completion_helptag()
3406" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003407
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003408" highlight group name fuzzy completion
3409func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003410 set wildoptions&
3411 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3412 call assert_equal('"highlight SKey', @:)
3413 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3414 call assert_equal('"highlight SpecialKey', @:)
3415 set wildoptions=fuzzy
3416 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3417 call assert_equal('"highlight SpecialKey', @:)
3418 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3419 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003420 set wildoptions&
3421endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003422
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003423" :history suboptions fuzzy completion
3424func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003425 set wildoptions&
3426 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3427 call assert_equal('"history dg', @:)
3428 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal('"history search', @:)
3430 set wildoptions=fuzzy
3431 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal('"history debug', @:)
3433 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3434 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003435 set wildoptions&
3436endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003437
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003438" :language locale name fuzzy completion
3439func Test_fuzzy_completion_lang()
3440 CheckUnix
3441 set wildoptions&
3442 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3443 call assert_equal('"lang psx', @:)
3444 set wildoptions=fuzzy
3445 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3446 call assert_equal('"lang POSIX', @:)
3447 set wildoptions&
3448endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003449
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003450" :mapclear buffer argument fuzzy completion
3451func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003452 set wildoptions&
3453 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3454 call assert_equal('"mapclear buf', @:)
3455 set wildoptions=fuzzy
3456 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3457 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003458 set wildoptions&
3459endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003460
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003461" map name fuzzy completion
3462func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003463 " test regex completion works
3464 set wildoptions=fuzzy
3465 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3466 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003467 nmap <plug>MyLongMap :p<CR>
3468 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3469 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3470 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3471 call assert_equal("\"nmap MLM \t", @:)
3472 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3473 call assert_equal("\"nmap <F2> one two \t", @:)
3474 " duplicate entries should be removed
3475 vmap <plug>MyLongMap :<C-U>#<CR>
3476 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3477 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3478 nunmap <plug>MyLongMap
3479 vunmap <plug>MyLongMap
3480 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3481 call assert_equal("\"nmap ABC\t", @:)
3482 " results should be sorted by best match
3483 nmap <Plug>format :
3484 nmap <Plug>goformat :
3485 nmap <Plug>TestFOrmat :
3486 nmap <Plug>fendoff :
3487 nmap <Plug>state :
3488 nmap <Plug>FendingOff :
3489 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3491 nunmap <Plug>format
3492 nunmap <Plug>goformat
3493 nunmap <Plug>TestFOrmat
3494 nunmap <Plug>fendoff
3495 nunmap <Plug>state
3496 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003497 set wildoptions&
3498endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003499
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003500" abbreviation fuzzy completion
3501func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003502 set wildoptions=fuzzy
3503 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3504 call assert_equal("\"iabbr <nowait>", @:)
3505 iabbr WaitForCompletion WFC
3506 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3507 call assert_equal("\"iabbr WaitForCompletion", @:)
3508 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3509 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003510
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003511 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003512 set wildoptions&
3513endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003514
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003515" menu name fuzzy completion
3516func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003517 CheckFeature menu
3518
3519 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003520 set wildoptions&
3521 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3522 call assert_equal('"menu pup', @:)
3523 set wildoptions=fuzzy
3524 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003526
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003527 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003528 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003529endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003530
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003531" :messages suboptions fuzzy completion
3532func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003533 set wildoptions&
3534 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3535 call assert_equal('"messages clr', @:)
3536 set wildoptions=fuzzy
3537 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3538 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003539 set wildoptions&
3540endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003541
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003542" :set option name fuzzy completion
3543func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003544 set wildoptions&
3545 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3546 call assert_equal('"set brkopt', @:)
3547 set wildoptions=fuzzy
3548 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3549 call assert_equal('"set breakindentopt', @:)
3550 set wildoptions&
3551 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal('"set fixendofline', @:)
3553 set wildoptions=fuzzy
3554 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3555 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003556 set wildoptions&
3557endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003558
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003559" :set <term_option>
3560func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003561 set wildoptions&
3562 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3563 call assert_equal('"set t_EC', @:)
3564 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3565 call assert_equal('"set <t_EC>', @:)
3566 set wildoptions=fuzzy
3567 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3568 call assert_equal('"set t_EC', @:)
3569 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003571 set wildoptions&
3572endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003573
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003574" " :packadd directory name fuzzy completion - NOT supported
3575" func Test_fuzzy_completion_packadd()
3576" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003577
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003578" " shell command name fuzzy completion - NOT supported
3579" func Test_fuzzy_completion_shellcmd()
3580" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003581
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003582" :sign suboptions fuzzy completion
3583func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003584 set wildoptions&
3585 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3586 call assert_equal('"sign ufe', @:)
3587 set wildoptions=fuzzy
3588 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3589 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003590 set wildoptions&
3591endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003592
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003593" :syntax suboptions fuzzy completion
3594func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003595 set wildoptions&
3596 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3597 call assert_equal('"syntax kwd', @:)
3598 set wildoptions=fuzzy
3599 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3600 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003601 set wildoptions&
3602endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003603
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003604" syntax group name fuzzy completion
3605func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003606 set wildoptions&
3607 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3608 call assert_equal('"syntax list mpar', @:)
3609 set wildoptions=fuzzy
3610 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3611 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003612 set wildoptions&
3613endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003614
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003615" :syntime suboptions fuzzy completion
3616func Test_fuzzy_completion_syntime()
3617 CheckFeature profile
3618 set wildoptions&
3619 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3620 call assert_equal('"syntime clr', @:)
3621 set wildoptions=fuzzy
3622 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3623 call assert_equal('"syntime clear', @:)
3624 set wildoptions&
3625endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003626
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003627" " tag name fuzzy completion - NOT supported
3628" func Test_fuzzy_completion_tagname()
3629" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003630
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003631" " tag name and file fuzzy completion - NOT supported
3632" func Test_fuzzy_completion_tagfile()
3633" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003634
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003635" " user names fuzzy completion - how to test this functionality?
3636" func Test_fuzzy_completion_username()
3637" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003638
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003639" user defined variable name fuzzy completion
3640func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003641 let g:SomeVariable=10
3642 set wildoptions&
3643 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3644 call assert_equal('"let SVar', @:)
3645 set wildoptions=fuzzy
3646 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3647 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003648 set wildoptions&
3649endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003650
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003651" Test for sorting the results by the best match
3652func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003653 %bw!
3654 command T123format :
3655 command T123goformat :
3656 command T123TestFOrmat :
3657 command T123fendoff :
3658 command T123state :
3659 command T123FendingOff :
3660 set wildoptions=fuzzy
3661 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3662 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3663 delcommand T123format
3664 delcommand T123goformat
3665 delcommand T123TestFOrmat
3666 delcommand T123fendoff
3667 delcommand T123state
3668 delcommand T123FendingOff
3669 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003670 set wildoptions&
3671endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003672
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003673" Test for fuzzy completion of a command with lower case letters and a number
3674func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003675 command Foo2Bar :
3676 set wildoptions=fuzzy
3677 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3678 call assert_equal('"Foo2Bar', @:)
3679 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3680 call assert_equal('"Foo2Bar', @:)
3681 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3682 call assert_equal('"Foo2Bar', @:)
3683 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003684 set wildoptions&
3685endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003686
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003687" Test for command completion for a command starting with 'k'
3688func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003689 command KillKillKill :
3690 set wildoptions&
3691 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3692 call assert_equal("\"killkill\<Tab>", @:)
3693 set wildoptions=fuzzy
3694 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3695 call assert_equal('"KillKillKill', @:)
3696 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003697 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003698endfunc
3699
3700" Test for fuzzy completion for user defined custom completion function
3701func Test_fuzzy_completion_custom_func()
3702 func Tcompl(a, c, p)
3703 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3704 endfunc
3705 command -nargs=* -complete=custom,Tcompl Fuzzy :
3706 set wildoptions&
3707 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3708 call assert_equal("\"Fuzzy format", @:)
3709 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3710 call assert_equal("\"Fuzzy xy", @:)
3711 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3712 call assert_equal("\"Fuzzy ttt", @:)
3713 set wildoptions=fuzzy
3714 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3715 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3716 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3717 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3718 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3719 call assert_equal("\"Fuzzy xy", @:)
3720 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3721 call assert_equal("\"Fuzzy TestFOrmat", @:)
3722 delcom Fuzzy
3723 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003724endfunc
3725
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003726" Test for fuzzy completion in the middle of a cmdline instead of at the end
3727func Test_fuzzy_completion_in_middle()
3728 set wildoptions=fuzzy
3729 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3730 call assert_equal("\"set wildchar wildcharm wrap", @:)
3731
3732 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"args ++encoding= zz", @:)
3734 set wildoptions&
3735endfunc
3736
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003737" Test for :breakadd argument completion
3738func Test_cmdline_complete_breakadd()
3739 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3740 call assert_equal("\"breakadd expr file func here", @:)
3741 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3742 call assert_equal("\"breakadd expr", @:)
3743 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3744 call assert_equal("\"breakadd expr", @:)
3745 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3746 call assert_equal("\"breakadd here", @:)
3747 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3748 call assert_equal("\"breakadd here", @:)
3749 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3750 call assert_equal("\"breakadd abc", @:)
3751 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3752 let l = getcompletion('not', 'breakpoint')
3753 call assert_equal([], l)
3754
3755 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003756 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003757 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3758 call assert_equal("\"breakadd file Xscript", @:)
3759 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3760 call assert_equal("\"breakadd file Xscript", @:)
3761 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3762 call assert_equal("\"breakadd file 20 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 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3766 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3767 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3768 call assert_equal("\"breakadd file 20\t", @:)
3769 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3770 call assert_equal("\"breakadd file 20x\t", @:)
3771 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3772 call assert_equal("\"breakadd file Xscript ", @:)
3773 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3774 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003775
3776 " Test for :breakadd func [lnum] <function>
3777 func Xbreak_func()
3778 endfunc
3779 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3780 call assert_equal("\"breakadd func Xbreak_func", @:)
3781 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3782 call assert_equal("\"breakadd func Xbreak_func", @:)
3783 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3784 call assert_equal("\"breakadd func 20 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 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3788 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3789 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3790 call assert_equal("\"breakadd func 20\t", @:)
3791 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3792 call assert_equal("\"breakadd func 20x\t", @:)
3793 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3794 call assert_equal("\"breakadd func Xbreak_func ", @:)
3795 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3796 call assert_equal("\"breakadd func X1B2C3", @:)
3797 delfunc Xbreak_func
3798
3799 " Test for :breakadd expr <expression>
3800 let g:Xtest_var = 10
3801 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3802 call assert_equal("\"breakadd expr Xtest_var", @:)
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_var \<Tab>\<C-B>\"\<CR>", 'tx')
3806 call assert_equal("\"breakadd expr Xtest_var ", @:)
3807 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3808 call assert_equal("\"breakadd expr X1B2C3", @:)
3809 unlet g:Xtest_var
3810
3811 " Test for :breakadd here
3812 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3813 call assert_equal("\"breakadd here Xtest", @:)
3814 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3815 call assert_equal("\"breakadd here Xtest", @:)
3816 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3817 call assert_equal("\"breakadd here ", @:)
3818endfunc
3819
3820" Test for :breakdel argument completion
3821func Test_cmdline_complete_breakdel()
3822 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3823 call assert_equal("\"breakdel file func here", @:)
3824 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3825 call assert_equal("\"breakdel file", @:)
3826 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3827 call assert_equal("\"breakdel file", @:)
3828 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3829 call assert_equal("\"breakdel here", @:)
3830 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3831 call assert_equal("\"breakdel here", @:)
3832 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3833 call assert_equal("\"breakdel abc", @:)
3834
3835 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003836 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003837 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3838 call assert_equal("\"breakdel file Xscript", @:)
3839 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3840 call assert_equal("\"breakdel file Xscript", @:)
3841 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3842 call assert_equal("\"breakdel file 20 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 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3846 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3847 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3848 call assert_equal("\"breakdel file 20\t", @:)
3849 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3850 call assert_equal("\"breakdel file 20x\t", @:)
3851 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3852 call assert_equal("\"breakdel file Xscript ", @:)
3853 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3854 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003855
3856 " Test for :breakdel func [lnum] <function>
3857 func Xbreak_func()
3858 endfunc
3859 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3860 call assert_equal("\"breakdel func Xbreak_func", @:)
3861 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3862 call assert_equal("\"breakdel func Xbreak_func", @:)
3863 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3864 call assert_equal("\"breakdel func 20 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 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3868 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3869 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3870 call assert_equal("\"breakdel func 20\t", @:)
3871 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3872 call assert_equal("\"breakdel func 20x\t", @:)
3873 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3874 call assert_equal("\"breakdel func Xbreak_func ", @:)
3875 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3876 call assert_equal("\"breakdel func X1B2C3", @:)
3877 delfunc Xbreak_func
3878
3879 " Test for :breakdel here
3880 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3881 call assert_equal("\"breakdel here Xtest", @:)
3882 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3883 call assert_equal("\"breakdel here Xtest", @:)
3884 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3885 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003886endfunc
3887
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003888" Test for :scriptnames argument completion
3889func Test_cmdline_complete_scriptnames()
3890 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003891 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003892 source Xa1b2c3.vim
3893 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3894 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3895 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3896 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3897 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3898 call assert_equal("\"script b2c3", @:)
3899 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3900 call assert_match("\"script 2\<Tab>$", @:)
3901 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3902 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3903 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3904 call assert_equal("\"script ", @:)
3905 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3906 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3907 new
3908 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3909 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3910 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003911 set wildmenu&
3912endfunc
3913
Bram Moolenaard8893442022-05-06 20:38:47 +01003914" this was going over the end of IObuff
3915func Test_report_error_with_composing()
3916 let caught = 'no'
3917 try
3918 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3919 catch /E492:/
3920 let caught = 'yes'
3921 endtry
3922 call assert_equal('yes', caught)
3923endfunc
3924
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003925" Test for expanding 2-letter and 3-letter :substitute command arguments.
3926" These commands don't accept an argument.
3927func Test_cmdline_complete_substitute_short()
3928 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3929 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3930 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3931 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3932 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3933 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3934 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3935 endfor
3936endfunc
3937
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003938" Test for shellcmdline command argument completion
3939func Test_cmdline_complete_shellcmdline_argument()
3940 command -nargs=+ -complete=shellcmdline MyCmd
3941
3942 set wildoptions=fuzzy
3943
3944 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3945 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003946 call assert_equal(['test_cmdline.vim'],
3947 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003948
3949 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3950 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003951 call assert_equal([],
3952 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003953
3954 let compl1 = getcompletion('', 'file')[0]
3955 let compl2 = getcompletion('', 'file')[1]
3956 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3957 call assert_equal('"MyCmd vim ' .. compl1, @:)
3958
3959 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3960 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3961
3962 let compl = getcompletion('', 'file')[1]
3963 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3964 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3965
3966 set wildoptions&
3967 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3968 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003969 call assert_equal(['test_cmdline.vim'],
3970 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003971
3972 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3973 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003974 call assert_equal([],
3975 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003976
3977 let compl1 = getcompletion('', 'file')[0]
3978 let compl2 = getcompletion('', 'file')[1]
3979 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3980 call assert_equal('"MyCmd vim ' .. compl1, @:)
3981
3982 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3983 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3984
3985 let compl = getcompletion('', 'file')[1]
3986 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3987 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3988
3989 delcommand MyCmd
3990endfunc
3991
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003992" Test for :! shell command argument completion
3993func Test_cmdline_complete_bang_cmd_argument()
3994 set wildoptions=fuzzy
3995 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3996 call assert_equal('"!vim test_cmdline.vim', @:)
3997 set wildoptions&
3998 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3999 call assert_equal('"!vim test_cmdline.vim', @:)
4000endfunc
4001
zeertzjq961b2e52023-04-17 15:53:24 +01004002func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004003 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004004endfunc
4005
4006func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01004007 call assert_equal(0, getcmdpos())
4008 call assert_equal(0, getcmdscreenpos())
4009 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004010 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01004011
zeertzjqa821b602024-06-18 20:31:08 +02004012 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01004013 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004014 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004015 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004016 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004017 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004018 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02004019
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004020 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4021 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02004022 let g:results = []
4023 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4024 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4025 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004026 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4027 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4028 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02004029
4030 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01004031 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004032endfunc
4033
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01004034func Test_recursive_register()
4035 let @= = ''
4036 silent! ?e/
4037 let caught = 'no'
4038 try
4039 normal //
4040 catch /E169:/
4041 let caught = 'yes'
4042 endtry
4043 call assert_equal('yes', caught)
4044endfunc
4045
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004046func Test_long_error_message()
4047 " the error should be truncated, not overrun IObuff
4048 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4049endfunc
4050
zeertzjq6791adc2022-07-26 20:42:25 +01004051func Test_cmdline_redraw_tabline()
4052 CheckRunVimInTerminal
4053
4054 let lines =<< trim END
4055 set showtabline=2
4056 autocmd CmdlineEnter * set tabline=foo
4057 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004058 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004059 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4060 call term_sendkeys(buf, ':')
4061 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4062
4063 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004064endfunc
4065
zeertzjqb82a2ab2022-08-21 14:33:57 +01004066func Test_wildmenu_pum_disable_while_shown()
4067 set wildoptions=pum
4068 set wildmenu
4069 cnoremap <F2> <Cmd>set nowildmenu<CR>
4070 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4071 call assert_equal(0, pumvisible())
4072 cunmap <F2>
4073 set wildoptions& wildmenu&
4074endfunc
4075
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004076func Test_setcmdline()
4077 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004078 call assert_equal(0, setcmdline(test_null_string()))
4079 call assert_equal('', getcmdline())
4080 call assert_equal(1, getcmdpos())
4081
4082 call assert_equal(0, setcmdline(''[: -1]))
4083 call assert_equal('', getcmdline())
4084 call assert_equal(1, getcmdpos())
4085
zeertzjq54acb902022-08-29 16:21:25 +01004086 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004087 call assert_equal(0, setcmdline(a:text))
4088 call assert_equal(a:text, getcmdline())
4089 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004090 call assert_equal(getcmdtype(), g:cmdtype)
4091 unlet g:cmdtype
4092 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004093
4094 call assert_equal(0, setcmdline(a:text, a:pos))
4095 call assert_equal(a:text, getcmdline())
4096 call assert_equal(a:pos, getcmdpos())
4097
4098 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004099 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4100 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004101
4102 return ''
4103 endfunc
4104
4105 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4106 call assert_equal('set rtp?', @:)
4107
zeertzjq54acb902022-08-29 16:21:25 +01004108 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4109 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4110 call assert_equal('foo', g:str)
4111 unlet g:str
4112
4113 delfunc SetText
4114
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004115 " setcmdline() returns 1 when not editing the command line.
4116 call assert_equal(1, 'foo'->setcmdline())
4117
4118 " Called in custom function
4119 func CustomComplete(A, L, P)
4120 call assert_equal(0, setcmdline("DoCmd "))
4121 return "January\nFebruary\nMars\n"
4122 endfunc
4123
4124 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4125 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4126 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004127 delcom DoCmd
4128 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004129
4130 " Called in <expr>
4131 cnoremap <expr>a setcmdline('let foo=')
4132 call feedkeys(":a\<CR>", 'tx')
4133 call assert_equal('let foo=0', @:)
4134 cunmap a
4135endfunc
4136
Sean Dewarfc8a6012023-04-17 16:41:20 +01004137func Test_rulerformat_position()
4138 CheckScreendump
4139
4140 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4141 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4142 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4143 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4144 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4145
4146 " clean up
4147 call StopVimInTerminal(buf)
4148endfunc
4149
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004150" Test for using "%!" in 'rulerformat' to use a function
4151func Test_rulerformat_function()
4152 CheckScreendump
4153
4154 let lines =<< trim END
4155 func TestRulerFn()
4156 return '10,20%=30%%'
4157 endfunc
4158 END
4159 call writefile(lines, 'Xrulerformat_function', 'D')
4160
4161 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4162 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4163 call term_sendkeys(buf, ":redraw!\<CR>")
4164 call term_wait(buf)
4165 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4166
4167 " clean up
4168 call StopVimInTerminal(buf)
4169endfunc
4170
zeertzjqe4c79d32023-08-15 22:41:53 +02004171func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004172 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004173
zeertzjqe4c79d32023-08-15 22:41:53 +02004174 call assert_equal(getcompletion('', 'cmdline'),
4175 \ getcompletion('TestCompletion ', 'cmdline'))
4176 call assert_equal(['<buffer>'],
4177 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4178
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004179 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004180endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004181
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004182func Test_custom_completion()
4183 func CustomComplete1(lead, line, pos)
4184 return "a\nb\nc"
4185 endfunc
4186 func CustomComplete2(lead, line, pos)
4187 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4188 endfunc
4189 func Check_custom_completion()
4190 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4191 return ''
4192 endfunc
4193 func Check_customlist_completion()
4194 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4195 return ''
4196 endfunc
4197
4198 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4199 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4200
4201 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4202 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
zeertzjqe2c0f812025-07-06 20:26:56 +02004203 call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 '))
4204 call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 '))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004205
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"])
Girish Palya93c2d5b2025-07-08 21:29:02 +02004475
Girish Palya6b49fba2025-06-28 19:47:34 +02004476 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4477 call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches)
4478 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4479 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4480 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004481 call assert_equal({}, g:compl_info)
Girish Palyaaf220072025-07-07 19:42:10 +02004482 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
4483 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
Girish Palya93c2d5b2025-07-08 21:29:02 +02004484
Girish Palya6b49fba2025-06-28 19:47:34 +02004485 set ignorecase
4486 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4487 call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches)
4488 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4489 call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches)
4490 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
4491 call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches)
Girish Palyaaf220072025-07-07 19:42:10 +02004492 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
4493 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
Girish Palya93c2d5b2025-07-08 21:29:02 +02004494
Girish Palya6b49fba2025-06-28 19:47:34 +02004495 set smartcase
4496 call feedkeys("gg/f\<tab>\<f9>", 'tx')
Girish Palyaaf220072025-07-07 19:42:10 +02004497 call assert_equal(['foobar', 'fooBAr', 'foobarr'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004498 call feedkeys("gg/Fo\<tab>\<f9>", 'tx')
4499 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4500 call feedkeys("gg/FO\<tab>\<f9>", 'tx')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004501 call assert_equal({}, g:compl_info)
4502
4503 " Issue #17680 (getcompletion() does not support search completion)
4504 let result = getcompletion('%s/', 'cmdline')
4505 call assert_equal([], result)
4506
Girish Palya93c2d5b2025-07-08 21:29:02 +02004507 call feedkeys("gg/foob\<tab>\<f9>", 'tx')
4508 call assert_equal(['foobar', 'foobarr'], g:compl_info.matches)
Girish Palyaaf220072025-07-07 19:42:10 +02004509 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx')
4510 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches)
4511 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx')
4512 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004513
Girish Palya93c2d5b2025-07-08 21:29:02 +02004514 set wildoptions+=exacttext ignorecase& smartcase&
4515 call feedkeys("gg/F\<tab>\<f9>", 'tx')
4516 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches)
4517 call feedkeys("gg/foob\<tab>\<f9>", 'tx')
4518 call assert_equal([], g:compl_info.matches)
4519 call feedkeys("gg/r\\n.\<tab>\<f9>", 'tx')
4520 call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches)
4521
4522 set ignorecase
4523 call feedkeys("gg/F\<tab>\<f9>", 'tx')
4524 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
4525 call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx')
4526 call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches)
4527
4528 set smartcase
4529 call feedkeys("gg/f\<tab>\<f9>", 'tx')
4530 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
4531 call feedkeys("gg/foob\<tab>\<f9>", 'tx')
4532 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches)
4533 call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx')
4534 call assert_equal({}, g:compl_info)
4535 call feedkeys("gg/r\\n.*\\n\<tab>\<f9>", 'tx')
4536 call assert_equal(['r\nFoobar\nfooBAr', 'r\nfooBAr\nFooBARR'], g:compl_info.matches)
4537
Girish Palya6b49fba2025-06-28 19:47:34 +02004538 bw!
4539 call test_override("char_avail", 0)
4540 delfunc GetComplInfo
4541 unlet! g:compl_info
Girish Palya93c2d5b2025-07-08 21:29:02 +02004542 set wildcharm=0 incsearch& ignorecase& smartcase& wildoptions&
Girish Palya6b49fba2025-06-28 19:47:34 +02004543endfunc
4544
4545func Test_search_wildmenu_screendump()
4546 CheckScreendump
4547
4548 let lines =<< trim [SCRIPT]
zeertzjq5e34eec2025-07-05 15:37:17 +02004549 call test_override('alloc_lines', 1)
Girish Palya6b49fba2025-06-28 19:47:34 +02004550 set wildmenu wildcharm=<f5>
4551 call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
4552 [SCRIPT]
4553 call writefile(lines, 'XTest_search_wildmenu', 'D')
4554 let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10})
4555
4556 " Pattern has newline at EOF
4557 call term_sendkeys(buf, "gg2j/e\\n\<f5>")
4558 call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {})
4559
4560 " longest:full
4561 call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>")
4562 call term_sendkeys(buf, "gg/t\<f5>")
4563 call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {})
4564
4565 " list:full
4566 call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>")
4567 call term_sendkeys(buf, "gg/t\<f5>")
4568 call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {})
4569
4570 " noselect:full
4571 call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>")
4572 call term_sendkeys(buf, "gg/t\<f5>")
4573 call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {})
4574
4575 " Multiline
4576 call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>")
4577 call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {})
4578
zeertzjq08e5b122025-07-06 11:06:44 +02004579 " 'incsearch' is redrawn after accepting completion
4580 call term_sendkeys(buf, "\<esc>:set wim=full\<cr>")
4581 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
4582 call term_sendkeys(buf, "/th")
4583 call VerifyScreenDump(buf, 'Test_search_wildmenu_6', {})
4584 call term_sendkeys(buf, "\<f5>")
4585 call VerifyScreenDump(buf, 'Test_search_wildmenu_7', {})
4586 call term_sendkeys(buf, "\<c-n>\<c-y>")
4587 call VerifyScreenDump(buf, 'Test_search_wildmenu_8', {})
4588
Girish Palya6b49fba2025-06-28 19:47:34 +02004589 call term_sendkeys(buf, "\<esc>")
4590 call StopVimInTerminal(buf)
4591endfunc
4592
4593" Test wildcharm completion for :s and :g with range
4594func Test_range_complete()
4595 set wildcharm=<c-z>
4596
4597 " Disable char_avail so that expansion of commandline works
4598 call test_override("char_avail", 1)
4599
4600 func GetComplInfo()
4601 let g:compl_info = cmdcomplete_info()
4602 return ''
4603 endfunc
4604 new
4605 cnoremap <buffer><expr> <F9> GetComplInfo()
4606
4607 call setline(1, ['ab', 'ba', 'ca', 'af'])
4608
4609 for trig in ["\<tab>", "\<c-z>"]
4610 call feedkeys($":%s/a{trig}\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004611 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004612 call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004613 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004614 endfor
4615
4616 call feedkeys(":%s/\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004617 call assert_equal({}, g:compl_info)
Girish Palya6b49fba2025-06-28 19:47:34 +02004618
4619 for cmd in ['s', 'g']
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004620 call feedkeys($":1,2{cmd}/a\<c-z>\<f9>", 'xt')
4621 call assert_equal(['ab', 'a'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004622 endfor
4623
4624 1
4625 call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004626 call assert_equal(['ab', 'a'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004627
4628 /f
4629 call feedkeys(":1,s/b\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004630 call assert_equal(['b', 'ba'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004631
4632 /c
4633 call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004634 call assert_equal(['a', 'af'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004635
4636 %s/c/c/
4637 call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004638 call assert_equal(['ab', 'a'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004639
4640 3
4641 normal! ma
4642 call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004643 call assert_equal(['a', 'af'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004644
4645 " Line number followed by a search pattern ([start]/pattern/[command])
4646 call feedkeys("3/a\<c-z>\<f9>", 'xt')
Christian Brabandtf2ec8d42025-07-08 22:04:10 +02004647 call assert_equal(['a', 'af', 'ab'], g:compl_info.matches)
Girish Palya6b49fba2025-06-28 19:47:34 +02004648
4649 bw!
4650 call test_override("char_avail", 0)
4651 delfunc GetComplInfo
4652 unlet! g:compl_info
4653 set wildcharm=0
4654endfunc
4655
Girish Palya0cd7f352025-07-07 19:47:53 +02004656" With 'noselect' in 'wildmode', ensure that the popup menu (pum) does not retain
4657" its scroll position after reopening. The menu should open showing the top items,
4658" regardless of previous scrolling.
4659func Test_pum_scroll_noselect()
4660 CheckScreendump
4661
4662 let lines =<< trim [SCRIPT]
4663 command! -nargs=* -complete=customlist,TestFn TestCmd echo
4664 func TestFn(a, b, c)
4665 return map(range(1, 50), 'printf("a%d", v:val)')
4666 endfunc
4667 set wildmode=noselect,full
4668 set wildoptions=pum
4669 set wildmenu
4670 set noruler
4671 [SCRIPT]
4672 call writefile(lines, 'XTest_pum_scroll', 'D')
4673 let buf = RunVimInTerminal('-S XTest_pum_scroll', {'rows': 10})
4674
4675 call term_sendkeys(buf, ":TestCmd \<tab>" . repeat("\<c-n>", 20))
4676 call TermWait(buf, 50)
4677 call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_1', {})
4678
4679 call term_sendkeys(buf, "\<esc>:TestCmd \<tab>")
4680 call TermWait(buf, 50)
4681 call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_2', {})
4682
4683 call term_sendkeys(buf, "\<esc>")
4684 call StopVimInTerminal(buf)
4685endfunc
4686
Bram Moolenaar309976e2019-12-05 18:16:33 +01004687" vim: shiftwidth=2 sts=2 expandtab