blob: 9a3fe20dfada4fafee681a35b86dd536ba84f0b0 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
zeertzjq1830e782025-03-13 20:29:13 +0100214func Test_wildmenu_with_input_func()
215 CheckScreendump
216
217 let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8})
218
219 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
220 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {})
221 call term_sendkeys(buf, "ech\<Tab>")
222 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {})
223 call term_sendkeys(buf, "\<Space>")
224 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {})
225 call term_sendkeys(buf, "bufn\<Tab>")
226 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {})
227 call term_sendkeys(buf, "\<CR>")
228
229 call term_sendkeys(buf, ":set wildoptions+=pum\<CR>")
230
231 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
232 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {})
233 call term_sendkeys(buf, "ech\<Tab>")
234 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {})
235 call term_sendkeys(buf, "\<Space>")
236 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {})
237 call term_sendkeys(buf, "bufn\<Tab>")
238 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {})
239 call term_sendkeys(buf, "\<CR>")
240
241 " clean up
242 call StopVimInTerminal(buf)
243endfunc
244
Bram Moolenaara653e532022-04-19 11:38:24 +0100245func Test_redraw_in_autocmd()
246 CheckScreendump
247
248 let lines =<< trim END
249 set cmdheight=2
250 autocmd CmdlineChanged * redraw
251 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100252 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100253
254 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
255 call term_sendkeys(buf, ":for i in range(3)\<CR>")
256 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
257
258 call term_sendkeys(buf, "let i =")
259 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
260
261 " clean up
262 call term_sendkeys(buf, "\<CR>")
263 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100264endfunc
265
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100266func Test_redrawstatus_in_autocmd()
267 CheckScreendump
268
269 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100270 set laststatus=2
271 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100272 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100273 END
274 call writefile(lines, 'XTest_redrawstatus', 'D')
275
276 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100277 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100278 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
279 call term_sendkeys(buf, ":foobar")
280 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100281 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100282 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100283 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100284 " with cmdheight=1 messages have scrolled when typing :endfor
285 call term_sendkeys(buf, "\<CR>:endfor")
286 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
287 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
288 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
289 call term_sendkeys(buf, ":for in in range(3)")
290 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
291 call term_sendkeys(buf, "\<CR>:endfor")
292 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100293
294 " clean up
295 call term_sendkeys(buf, "\<CR>")
296 call StopVimInTerminal(buf)
297endfunc
298
Bram Moolenaarf797e302022-08-11 13:17:30 +0100299func Test_changing_cmdheight()
300 CheckScreendump
301
302 let lines =<< trim END
303 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100304 func EchoOne()
305 set laststatus=2 cmdheight=1
306 echo 'foo'
307 echo 'bar'
308 set cmdheight=2
309 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 func EchoTwo()
311 set laststatus=2
312 set cmdheight=5
313 echo 'foo'
314 echo 'bar'
315 set cmdheight=1
316 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100317 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100318 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100319
320 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
321 call term_sendkeys(buf, ":resize -3\<CR>")
322 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
323
Luuk van Baale15cbc12025-01-04 17:18:08 +0100324 " :resize now also changes 'cmdheight' accordingly
325 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100326 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
327
328 " using more space moves the status line up
329 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
330 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
331
332 " reducing cmdheight moves status line down
Luuk van Baalc97e8692025-01-06 18:58:21 +0100333 call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100334 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
335
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000336 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100337 call term_sendkeys(buf, ":resize -1\<CR>")
338 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
339 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
340
Bram Moolenaar0816f472022-10-05 15:42:32 +0100341 " setting 'cmdheight' works after outputting two messages
342 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
343 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
344
Luuk van Baalc97e8692025-01-06 18:58:21 +0100345 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100346 call term_sendkeys(buf, ":call EchoOne()\<CR>")
347 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
348
Luuk van Baalc97e8692025-01-06 18:58:21 +0100349 " window commands do not reduce 'cmdheight' to value lower than :set by user
350 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
351 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
352
Bram Moolenaarf797e302022-08-11 13:17:30 +0100353 " clean up
354 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100355endfunc
356
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100357func Test_cmdheight_tabline()
358 CheckScreendump
359
360 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
361 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
362
363 " clean up
364 call StopVimInTerminal(buf)
365endfunc
366
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100367func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100368 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
369 call assert_equal('"map <unique> <silent>', getreg(':'))
370 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
371 call assert_equal('"map <script> <unique>', getreg(':'))
372 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
373 call assert_equal('"map <expr> <script>', getreg(':'))
374 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
375 call assert_equal('"map <buffer> <expr>', getreg(':'))
376 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal('"map <nowait> <buffer>', getreg(':'))
378 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
379 call assert_equal('"map <special> <nowait>', getreg(':'))
380 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
381 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200382
Bram Moolenaar1776a282019-05-03 16:05:41 +0200383 map <Middle>x middle
384
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200385 map ,f commaf
386 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200387 map <Left> left
388 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200389 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"map ,f', getreg(':'))
391 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200393 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"map <Left>', getreg(':'))
395 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200396 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000397 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200399 unmap ,f
400 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200401 unmap <Left>
402 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200403
zeertzjqc3a26c62023-02-17 16:40:20 +0000404 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200405 map <Left> left
406 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
407 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200408 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200409 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000410 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
411 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200412 unmap <Left>
413
414 set cpo+=<
415 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200416 exe "set t_k6=\<Esc>[17~"
417 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200418 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
419 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200420 if !has('gui_running')
421 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal("\"map <F6>x", getreg(':'))
423 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200424 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200425 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200426 set cpo-=<
427
428 set cpo+=B
429 map <Left> left
430 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
431 call assert_equal('"map <Left>', getreg(':'))
432 unmap <Left>
433 set cpo-=B
434
435 set cpo+=k
436 map <Left> left
437 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
438 call assert_equal('"map <Left>', getreg(':'))
439 unmap <Left>
440 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200441
Bram Moolenaar531be472020-09-23 22:38:05 +0200442 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
443
Bram Moolenaar1776a282019-05-03 16:05:41 +0200444 unmap <Middle>x
445 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100446endfunc
447
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100448func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100449 hi Aardig ctermfg=green
450 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000451 call assert_equal('"match Aardig', @:)
Yee Cheng China7b81202025-02-23 09:32:47 +0100452 call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt')
453 call assert_equal('"match NONE', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000454 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
455 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100456endfunc
457
458func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100459 hi Aardig ctermfg=green
460 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
461 call assert_equal('"hi Aardig', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100462
463 " hi default
Bram Moolenaarea588152017-04-10 22:45:30 +0200464 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
465 call assert_equal('"hi default Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100466 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
467 call assert_equal('"hi default', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100468 call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt')
469 call assert_equal('"hi default link Aardig', getreg(':'))
470
471 " hi clear only accepts one parameter
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100472 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
473 call assert_equal('"hi clear', getreg(':'))
Yee Cheng China7b81202025-02-23 09:32:47 +0100474 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
475 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200476 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
Yee Cheng China7b81202025-02-23 09:32:47 +0100477 call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':'))
478 " hi link accepts up to two parameters
479 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
480 call assert_equal('"hi link', getreg(':'))
481 call assert_equal('"hi link', getreg(':'))
482 call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt')
483 call assert_equal('"hi link Aardig', getreg(':'))
484 call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
485 call assert_equal("\"hi link Aardig Aardig", getreg(':'))
486 call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
487 call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':'))
488 " hi link will complete to "NONE" for second parameter
489 call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt')
490 call assert_equal("\"hi link NonText", getreg(':'))
491 call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt')
492 call assert_equal("\"hi link Aardig NONE", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200493
494 " A cleared group does not show up in completions.
495 hi Anders ctermfg=green
496 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
497 hi clear Aardig
498 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
499 hi clear Anders
500 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100501endfunc
502
Bram Moolenaar75e15672020-06-28 13:10:22 +0200503" Test for command-line expansion of "hi Ni " (easter egg)
504func Test_highlight_easter_egg()
505 call test_override('ui_delay', 1)
506 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
507 call assert_equal("\"hi Ni \<Tab>", @:)
508 call test_override('ALL', 0)
509endfunc
510
Yee Cheng China7b81202025-02-23 09:32:47 +0100511func Test_highlight_group_completion()
512 " Test completing keys
513 call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0])
514 call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0])
515 call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0])
516 set wildoptions+=fuzzy
517 call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0])
518 set wildoptions-=fuzzy
519
520 " Test completing the current value
521 hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100522 hi AlmostEmpty term=bold
Yee Cheng China7b81202025-02-23 09:32:47 +0100523 call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
524 call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
525 call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
526 call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
527 call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
528
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100529 " highlight group exists, but no value was set. Should not complete to
530 " existing value
531 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
532 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
533 call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
534 call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
535
536 " "bold,underline" is unique and creates an extra item. "undercurl" isn't
537 " and should be de-duplicated.
Yee Cheng China7b81202025-02-23 09:32:47 +0100538 call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
539 \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
540
541 " don't complete original value if we have user input already, similar to
542 " behavior in :set <option>=<pattern>
543 call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline'))
544 call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline'))
545
546 " start/stop do not fill their current value now as they are more
547 " complicated
548 hi FooBar start=123 stop=234
549 call assert_equal([], getcompletion('hi FooBar start=', 'cmdline'))
550 call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline'))
551
552 if has("gui") || has("termguicolors")
553 hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green
554 call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0])
555 call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0])
556 call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0])
557 call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0])
558
559 " Check that existing value is de-duplicated and doesn't show up later
560 call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
Yee Cheng Chin9b41e8f2025-02-25 20:41:52 +0100561
562 " highlight group exists, but no value was set. Should not complete to
563 " existing value
564 call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
565 call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
566 call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
567 call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
Yee Cheng China7b81202025-02-23 09:32:47 +0100568 endif
569
570 " Test completing attributes
571 call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline'))
572 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0])
573 call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted
574 call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma
575 if has("gui") || has("termguicolors")
576 set wildoptions+=fuzzy
577 call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0])
578 set wildoptions-=fuzzy
579 endif
580
581 " Test completing cterm colors
582 call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0])
583 call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0])
584 call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0])
585 call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0])
586 set wildoptions+=fuzzy
587 call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0])
588 call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0])
589 set wildoptions-=fuzzy
590
591 " Test completing gui colors
592 if has("gui") || has("termguicolors")
593 call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0])
594 call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0])
595 call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0])
596 call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0])
597 set wildoptions=fuzzy
598 call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0])
599 call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0])
600 set wildoptions-=fuzzy
601
602 " Test pruning bad color names with space. Vim doesn't support them.
603 let v:colornames['foobar with space'] = '#123456'
604 let v:colornames['foobarwithoutspace'] = '#234567'
605 call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline'))
606
607 " Test specialized sorting. First few items are special values that
608 " go first, after that it's a sorted list of color names.
609 call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2])
610 let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:]
611 let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1})
612 call assert_equal(len(gui_colors_no_space), len(completed_colors))
613 call assert_equal(sort(copy(completed_colors)), completed_colors)
614
615 " Test that the specialized sorting still works if we have some pattern matches
616 let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline')
617 call assert_equal(sort(copy(completed_colors)), completed_colors)
618 call assert_equal('aliceblue', completed_colors[0])
619 endif
620endfunc
621
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200622func Test_getcompletion()
623 let groupcount = len(getcompletion('', 'event'))
624 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200625 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200626 call assert_true(matchcount > 0)
627 call assert_true(groupcount > matchcount)
628
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200629 if has('menu')
630 source $VIMRUNTIME/menu.vim
631 let matchcount = len(getcompletion('', 'menu'))
632 call assert_true(matchcount > 0)
633 call assert_equal(['File.'], getcompletion('File', 'menu'))
634 call assert_true(matchcount > 0)
635 let matchcount = len(getcompletion('File.', 'menu'))
636 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000637 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200638 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200639
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200640 let l = getcompletion('v:n', 'var')
641 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200642 let l = getcompletion('v:notexists', 'var')
643 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200644
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200645 args a.c b.c
646 let l = getcompletion('', 'arglist')
647 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000648 let l = getcompletion('a.', 'buffer')
649 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200650 %argdelete
651
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200652 let l = getcompletion('', 'augroup')
653 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200654 let l = getcompletion('blahblah', 'augroup')
655 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200656
657 let l = getcompletion('', 'behave')
658 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200659 let l = getcompletion('not', 'behave')
660 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200661
662 let l = getcompletion('', 'color')
663 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200664 let l = getcompletion('dirty', 'color')
665 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200666
667 let l = getcompletion('', 'command')
668 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200669 let l = getcompletion('awake', 'command')
670 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200671
672 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200673 call assert_true(index(l, 'samples/') >= 0)
674 let l = getcompletion('NoMatch', 'dir')
675 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200676
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100677 if glob('~/*') !=# ''
678 let l = getcompletion('~/', 'dir')
679 call assert_true(l[0][0] ==# '~')
680 endif
681
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200682 let l = getcompletion('exe', 'expression')
683 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200684 let l = getcompletion('kill', 'expression')
685 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200686
Christian Brabandta3422aa2025-04-23 21:04:24 +0200687 let l = getcompletion('', 'filetypecmd')
688 call assert_equal(["indent", "off", "on", "plugin"], l)
689 let l = getcompletion('not', 'filetypecmd')
690 call assert_equal([], l)
691 let l = getcompletion('o', 'filetypecmd')
692 call assert_equal(['off', 'on'], l)
693
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200694 let l = getcompletion('tag', 'function')
695 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200696 let l = getcompletion('paint', 'function')
697 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200698
Kota Kato90c23532023-01-18 15:27:38 +0000699 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000700 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000701 let l = getcompletion('ruby', 'function')
702 call assert_equal([], l)
703 endif
704
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200705 let Flambda = {-> 'hello'}
706 let l = getcompletion('', 'function')
707 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200708 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200709
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200710 let l = getcompletion('run', 'file')
711 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200712 let l = getcompletion('walk', 'file')
713 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200714 set wildignore=*.vim
715 let l = getcompletion('run', 'file', 1)
716 call assert_true(index(l, 'runtest.vim') < 0)
717 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000718 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100719 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000720 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
721 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200722
723 let l = getcompletion('ha', 'filetype')
724 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200725 let l = getcompletion('horse', 'filetype')
726 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200727
Doug Kearns81642d92024-01-04 22:37:44 +0100728 if has('keymap')
729 let l = getcompletion('acc', 'keymap')
730 call assert_true(index(l, 'accents') >= 0)
731 let l = getcompletion('nullkeymap', 'keymap')
732 call assert_equal([], l)
733 endif
734
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200735 let l = getcompletion('z', 'syntax')
736 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200737 let l = getcompletion('emacs', 'syntax')
738 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200739
740 let l = getcompletion('jikes', 'compiler')
741 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200742 let l = getcompletion('break', 'compiler')
743 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200744
745 let l = getcompletion('last', 'help')
746 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200747 let l = getcompletion('giveup', 'help')
748 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200749
750 let l = getcompletion('time', 'option')
751 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200752 let l = getcompletion('space', 'option')
753 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200754
755 let l = getcompletion('er', 'highlight')
756 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200757 let l = getcompletion('dark', 'highlight')
758 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200759
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200760 let l = getcompletion('', 'messages')
761 call assert_true(index(l, 'clear') >= 0)
762 let l = getcompletion('not', 'messages')
763 call assert_equal([], l)
764
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200765 let l = getcompletion('', 'mapclear')
766 call assert_true(index(l, '<buffer>') >= 0)
767 let l = getcompletion('not', 'mapclear')
768 call assert_equal([], l)
769
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200770 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200771 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200772 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
773 let root = has('win32') ? 'C:\\' : '/'
774 let l = getcompletion(root, 'shellcmd')
775 let expected = map(filter(glob(root . '*', 0, 1),
776 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
777 call assert_equal(expected, l)
778
Bram Moolenaarb650b982016-08-05 20:35:13 +0200779 if has('cscope')
780 let l = getcompletion('', 'cscope')
781 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
782 call assert_equal(cmds, l)
783 " using cmdline completion must not change the result
784 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
785 let l = getcompletion('', 'cscope')
786 call assert_equal(cmds, l)
787 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
788 let l = getcompletion('find ', 'cscope')
789 call assert_equal(keys, l)
790 endif
791
Bram Moolenaar7522f692016-08-06 14:12:50 +0200792 if has('signs')
793 sign define Testing linehl=Comment
794 let l = getcompletion('', 'sign')
795 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
796 call assert_equal(cmds, l)
797 " using cmdline completion must not change the result
798 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
799 let l = getcompletion('', 'sign')
800 call assert_equal(cmds, l)
801 let l = getcompletion('list ', 'sign')
802 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000803 let l = getcompletion('de*', 'sign')
804 call assert_equal(['define'], l)
805 let l = getcompletion('p?', 'sign')
806 call assert_equal(['place'], l)
807 let l = getcompletion('j.', 'sign')
808 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200809 endif
810
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200811 " Command line completion tests
812 let l = getcompletion('cd ', 'cmdline')
813 call assert_true(index(l, 'samples/') >= 0)
814 let l = getcompletion('cd NoMatch', 'cmdline')
815 call assert_equal([], l)
816 let l = getcompletion('let v:n', 'cmdline')
817 call assert_true(index(l, 'v:null') >= 0)
818 let l = getcompletion('let v:notexists', 'cmdline')
819 call assert_equal([], l)
820 let l = getcompletion('call tag', 'cmdline')
821 call assert_true(index(l, 'taglist(') >= 0)
822 let l = getcompletion('call paint', 'cmdline')
823 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200824 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
825 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200826
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100827 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000828 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100829 return "oneA\noneB\noneC"
830 endfunc
831 command -nargs=1 -complete=custom,T MyCmd
832 let l = getcompletion('MyCmd ', 'cmdline')
833 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000834 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100835
836 delcommand MyCmd
837 delfunc T
ii144785fe02021-11-21 12:13:56 +0000838 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100839
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200840 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200841 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
842 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200843 if has('cmdline_hist')
844 call add(names, 'history')
845 endif
846 if has('gettext')
847 call add(names, 'locale')
848 endif
849 if has('profile')
850 call add(names, 'syntime')
851 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200852
853 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100854 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200855
856 for name in names
857 let matchcount = len(getcompletion('', name))
858 call assert_true(matchcount >= 0, 'No matches for ' . name)
859 endfor
860
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200861 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200862
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000863 edit a~b
864 enew
865 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
866 bw a~b
867
868 if has('unix')
869 edit Xtest\
870 enew
871 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
872 bw Xtest\
873 endif
874
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100875 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200876 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100877 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200878endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200879
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000880func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000881 " Get a dialog in the GUI
882 CheckNotGui
883
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000884 " This was using uninitialized memory.
885 let lines =<< trim END
886 set verbose=6
887 norm @=ٷ
888 qall!
889 END
890 call writefile(lines, 'XmultiScript', 'D')
891 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
892endfunc
893
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000894" Test for getcompletion() with "fuzzy" in 'wildoptions'
895func Test_getcompletion_wildoptions()
896 let save_wildoptions = &wildoptions
897 set wildoptions&
898 let l = getcompletion('space', 'option')
899 call assert_equal([], l)
900 let l = getcompletion('ier', 'command')
901 call assert_equal([], l)
902 set wildoptions=fuzzy
903 let l = getcompletion('space', 'option')
904 call assert_true(index(l, 'backspace') >= 0)
905 let l = getcompletion('ier', 'command')
906 call assert_true(index(l, 'compiler') >= 0)
907 let &wildoptions = save_wildoptions
908endfunc
909
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000910func Test_complete_autoload_error()
911 let save_rtp = &rtp
912 let lines =<< trim END
913 vim9script
914 export def Complete(..._): string
915 return 'match'
916 enddef
917 echo this will cause an error
918 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100919 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000920 call writefile(lines, 'Xdir/autoload/script.vim')
921 exe 'set rtp+=' .. getcwd() .. '/Xdir'
922
923 let lines =<< trim END
924 vim9script
925 import autoload 'script.vim'
926 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
927 &wildcharm = char2nr("\<Tab>")
928 feedkeys(":Cmd \<Tab>", 'xt')
929 END
930 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
931
932 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000933endfunc
934
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100935func Test_fullcommand()
936 let tests = {
937 \ '': '',
938 \ ':': '',
939 \ ':::': '',
940 \ ':::5': '',
941 \ 'not_a_cmd': '',
942 \ 'Check': '',
943 \ 'syntax': 'syntax',
944 \ ':syntax': 'syntax',
945 \ '::::syntax': 'syntax',
946 \ 'sy': 'syntax',
947 \ 'syn': 'syntax',
948 \ 'synt': 'syntax',
949 \ ':sy': 'syntax',
950 \ '::::sy': 'syntax',
951 \ 'match': 'match',
952 \ '2match': 'match',
953 \ '3match': 'match',
954 \ 'aboveleft': 'aboveleft',
955 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100956 \ 'en': 'endif',
957 \ 'end': 'endif',
958 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100959 \ 's': 'substitute',
960 \ '5s': 'substitute',
961 \ ':5s': 'substitute',
962 \ "'<,'>s": 'substitute',
963 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100964 \ 'CheckLin': 'CheckLinux',
965 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100966 \ }
967
968 for [in, want] in items(tests)
969 call assert_equal(want, fullcommand(in))
970 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200971 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100972
973 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200974
975 command -buffer BufferLocalCommand :
976 command GlobalCommand :
977 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
978 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
979 delcommand BufferLocalCommand
980 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100981endfunc
982
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200983func Test_shellcmd_completion()
984 let save_path = $PATH
985
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100986 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200987 call writefile([''], 'Xpathdir/Xfile.exe')
988 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
989
990 " Set PATH to example directory without trailing slash.
991 let $PATH = getcwd() . '/Xpathdir'
992
993 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
994 " dirs in the PATH, even though they won't be executed. We check that only
995 " subdirs of the PWD and executables from the PATH are included in the
996 " suggestions.
997 let actual = getcompletion('X', 'shellcmd')
998 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
999 call insert(expected, 'Xfile.exe')
1000 call assert_equal(expected, actual)
1001
Bram Moolenaar6ab9e422018-07-28 19:20:13 +02001002 let $PATH = save_path
1003endfunc
1004
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001005func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +01001006 call mkdir('a/b/c', 'pR')
1007 call writefile(['asdfasdf'], 'a/b/c/fileXname')
1008 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
1009 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +02001010 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001011endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +01001012
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001013func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +01001014 let @a = "def"
1015 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
1016 call assert_equal('"abc def ghi', @:)
1017
1018 new
1019 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
1020
1021 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1022 call assert_equal('"aaa asdf bbb', @:)
1023
1024 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
1025 call assert_equal('"aaa /tmp/some bbb', @:)
1026
Bram Moolenaare2c8d832018-05-01 19:24:03 +02001027 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
1028 call assert_equal('"aaa '.getline(1).' bbb', @:)
1029
Bram Moolenaar21efc362016-12-03 14:05:49 +01001030 set incsearch
1031 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1032 call assert_equal('"aaa verylongword bbb', @:)
1033
1034 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
1035 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001036
1037 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1038 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001039 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001040
1041 " Error while typing a command used to cause that it was not executed
1042 " in the end.
1043 new
1044 try
1045 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1046 catch /^Vim\%((\a\+)\)\=:E32/
1047 " ignore error E32
1048 endtry
1049 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001050
Bram Moolenaar578fe942020-02-27 21:32:51 +01001051 " Try to paste an invalid register using <C-R>
1052 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1053 call assert_equal('"onetwo', @:)
1054
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001055 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001056 let @a = "xy\<C-H>z"
1057 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1058 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001059 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1060 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001061 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1062 call assert_equal("\"xy\<C-H>z", @:)
1063
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001064 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1065 let @a = "xy\<C-V>z"
1066 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1067 call assert_equal('"xyz', @:)
1068 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1069 call assert_equal("\"xy\<C-V>z", @:)
1070
Bram Moolenaar578fe942020-02-27 21:32:51 +01001071 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1072
Bram Moolenaar72532d32018-04-07 19:09:09 +02001073 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001074endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001075
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001076func Test_cmdline_remove_char()
1077 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001078
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001079 for e in ['utf8', 'latin1']
1080 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001081
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001082 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1083 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001084
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001085 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1086 call assert_equal('"abcdef', @:)
1087
1088 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1089 call assert_equal('"abc ghi', @:, e)
1090
1091 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1092 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001093
1094 " This was going before the start in latin1.
1095 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001096 endfor
1097
1098 let &encoding = encoding_save
1099endfunc
1100
zeertzjqff2b79d2024-02-26 20:38:36 +01001101func Test_cmdline_del_utf8()
1102 let @s = '⒌'
1103 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1104 call assert_equal('",,', @:)
1105
1106 let @s = 'a̳'
1107 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1108 call assert_equal('",,', @:)
1109
1110 let @s = 'β̳'
1111 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1112 call assert_equal('",,', @:)
1113
1114 if has('arabic')
1115 let @s = 'لا'
1116 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1117 call assert_equal('",,', @:)
1118 endif
1119endfunc
1120
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001121func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001122 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001123
1124 set keymap=esperanto
1125 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1126 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1127 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001128endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001129
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001130func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001131 new
1132 2;'(
1133 2;')
1134 quit
1135endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001136
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001137func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001138 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001139 new
1140 source Xtest.vim
1141 " Trigger calling validate_cursor()
1142 diffsp Xtest.vim
1143 quit!
1144 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001145endfunc
1146
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001147func Test_mark_from_line_zero()
1148 " this was reading past the end of the first (empty) line
1149 new
1150 norm oxxxx
1151 call assert_fails("0;'(", 'E20:')
1152 bwipe!
1153endfunc
1154
Bram Moolenaarba47b512017-01-24 21:18:19 +01001155func Test_cmdline_complete_wildoptions()
1156 help
1157 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1158 let a = join(sort(split(@:)),' ')
1159 set wildoptions=tagfile
1160 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1161 let b = join(sort(split(@:)),' ')
1162 call assert_equal(a, b)
1163 bw!
1164endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001165
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001166func Test_cmdline_complete_user_cmd()
1167 command! -complete=color -nargs=1 Foo :
1168 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1169 call assert_equal('"Foo blue', @:)
1170 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1171 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001172 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1173 call assert_equal('"Foo a blue', @:)
1174 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1175 call assert_equal('"Foo b\', @:)
1176 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1177 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001178 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001179
1180 redraw
1181 call assert_equal('~', Screenline(&lines - 1))
1182 command! FooOne :
1183 command! FooTwo :
1184
1185 set nowildmenu
1186 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1187 call assert_equal('"FooOne', @:)
1188 call assert_equal('~', Screenline(&lines - 1))
1189
1190 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1191 call assert_equal('"FooTwo', @:)
1192 call assert_equal('~', Screenline(&lines - 1))
1193
1194 delcommand FooOne
1195 delcommand FooTwo
1196 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001197endfunc
1198
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001199func Test_complete_user_cmd()
1200 command FooBar echo 'global'
1201 command -buffer FooBar echo 'local'
1202 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1203 call assert_equal('"FooBar', @:)
1204
1205 delcommand -buffer FooBar
1206 delcommand FooBar
1207endfunc
1208
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001209func s:ScriptLocalFunction()
1210 echo 'yes'
1211endfunc
1212
1213func Test_cmdline_complete_user_func()
1214 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001215 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001216 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1217 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001218
1219 " g: prefix also works
1220 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1221 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001222
1223 " using g: prefix does not result in just "g:" matches from a lambda
1224 let Fx = { a -> a }
1225 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1226 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001227
1228 " existence of script-local dict function does not break user function name
1229 " completion
1230 function s:a_dict_func() dict
1231 endfunction
1232 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1233 call assert_match('"call Test_cmdline_complete_user_', @:)
1234 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001235endfunc
1236
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001237func Test_cmdline_complete_user_names()
1238 if has('unix') && executable('whoami')
1239 let whoami = systemlist('whoami')[0]
1240 let first_letter = whoami[0]
1241 if len(first_letter) > 0
1242 " Trying completion of :e ~x where x is the first letter of
1243 " the user name should complete to at least the user name.
1244 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1245 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1246 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001247 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001248 " Just in case: check that the system has an Administrator account.
1249 let names = system('net user')
1250 if names =~ 'Administrator'
1251 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001252 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001253 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001254 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001255 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001256 else
1257 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001258 endif
1259endfunc
1260
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001261func Test_cmdline_complete_shellcmdline()
1262 CheckExecutable whoami
1263 command -nargs=1 -complete=shellcmdline MyCmd
1264
1265 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1266 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001267 let l = getcompletion('whoam', 'shellcmdline')
1268 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001269
1270 delcommand MyCmd
1271endfunc
1272
Bram Moolenaar297610b2019-12-27 17:20:55 +01001273func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001274 CheckExecutable whoami
1275 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1276 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001277endfunc
1278
Bram Moolenaar8b633132020-03-20 18:20:51 +01001279func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001280 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1281 call assert_equal(lang, v:lc_time)
1282
1283 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1284 call assert_equal(lang, v:ctype)
1285
1286 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1287 call assert_equal(lang, v:collate)
1288
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001289 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001290 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001291
1292 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001293 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001294
Bram Moolenaarec680282020-06-12 19:35:32 +02001295 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001296
Bram Moolenaarec680282020-06-12 19:35:32 +02001297 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1298 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001299
Bram Moolenaarec680282020-06-12 19:35:32 +02001300 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1301 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001302
Bram Moolenaarec680282020-06-12 19:35:32 +02001303 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1304 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001305
1306 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1307 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001308endfunc
1309
Bram Moolenaar297610b2019-12-27 17:20:55 +01001310func Test_cmdline_complete_env_variable()
1311 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001312 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1313 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001314 unlet $X_VIM_TEST_COMPLETE_ENV
1315endfunc
1316
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001317func Test_cmdline_complete_expression()
1318 let g:SomeVar = 'blah'
1319 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1320 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1321 call assert_match('"' .. cmd .. ' SomeVar', @:)
1322 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1323 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1324 endfor
1325 unlet g:SomeVar
1326endfunc
1327
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001328func Test_cmdline_complete_argopt()
1329 " completion for ++opt=arg for file commands
1330 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1331 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1332 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1333
1334 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001335 " Test ++ff in the middle of the cmdline
1336 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1337 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001338
1339 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1340 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1341 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1342 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1343 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1344
1345 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1346
1347 " completion should skip the ++opt and continue
1348 call writefile([], 'Xaaaaa.txt', 'D')
1349 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1350 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1351
1352 if has('terminal')
1353 " completion for terminal's [options]
1354 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1355 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1356 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1357
1358 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1359
1360 " :terminal completion should skip the ++opt when considering what is the
1361 " first option, which is a list of shell commands, unlike second option
1362 " onwards.
1363 let first_param = getcompletion('terminal ', 'cmdline')
1364 let second_param = getcompletion('terminal foo ', 'cmdline')
1365 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1366 call assert_equal(first_param, skipped_opt_param)
1367 call assert_notequal(first_param, second_param)
1368 endif
1369endfunc
1370
Bram Moolenaar47016f52021-08-26 16:39:58 +02001371" Unique function name for completion below
1372func s:WeirdFunc()
1373 echo 'weird'
1374endfunc
1375
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001376" Test for various command-line completion
1377func Test_cmdline_complete_various()
1378 " completion for a command starting with a comment
1379 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1380 call assert_equal("\" :|\"\<C-A>", @:)
1381
1382 " completion for a range followed by a comment
1383 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1384 call assert_equal("\"1,2\"\<C-A>", @:)
1385
1386 " completion for :k command
1387 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1388 call assert_equal("\"ka\<C-A>", @:)
1389
Doug Kearnsea842022024-09-29 17:17:41 +02001390 " completion for :keepmarks command
1391 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1392 call assert_equal("\"kee edit", @:)
1393
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001394 " completion for short version of the :s command
1395 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1396 call assert_equal("\"sI \<C-A>", @:)
1397
1398 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001399 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001400 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001401 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001402 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001403 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1404 call assert_equal("\"w >> Xfile1", @:)
1405 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001406
1407 " completion for :w ! and :r ! commands
1408 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1409 call assert_equal("\"w !invalid_xyz_cmd", @:)
1410 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1411 call assert_equal("\"r !invalid_xyz_cmd", @:)
1412
1413 " completion for :>> and :<< commands
1414 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1415 call assert_equal("\">>>\<C-A>", @:)
1416 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1417 call assert_equal("\"<<<\<C-A>", @:)
1418
1419 " completion for command with +cmd argument
1420 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal("\"buffer +/pat Xabc", @:)
1422 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1423 call assert_equal("\"buffer +/pat\<C-A>", @:)
1424
1425 " completion for a command with a trailing comment
1426 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal("\"ls \" comment\<C-A>", @:)
1428
1429 " completion for a command with a trailing command
1430 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1431 call assert_equal("\"ls | ls", @:)
1432
1433 " completion for a command with an CTRL-V escaped argument
1434 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1435 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1436
1437 " completion for a command that doesn't take additional arguments
1438 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1439 call assert_equal("\"all abc\<C-A>", @:)
1440
zeertzjqd3de1782022-09-01 12:58:52 +01001441 " completion for :wincmd with :horizontal modifier
1442 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1443 call assert_equal("\"horizontal wincmd", @:)
1444
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001445 " completion for a command with a command modifier
1446 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1447 call assert_equal("\"topleft new", @:)
1448
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001449 " completion for vim9 and legacy commands
1450 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1451 call assert_equal("\"vim9 call strlen(", @:)
1452 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1453 call assert_equal("\"legac call strlen(", @:)
1454
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001455 " completion for the :disassemble command
1456 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1457 call assert_equal("\"disas debug", @:)
1458 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1459 call assert_equal("\"disas profile", @:)
1460 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1461 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1462 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001464 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1465 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001466
Bram Moolenaar47016f52021-08-26 16:39:58 +02001467 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001468 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001469
naohiro onodfe04db2021-09-12 15:45:10 +02001470 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1471 call assert_match('"disas <SNR>\d\+_', @:)
1472 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1473 call assert_match('"disas debug <SNR>\d\+_', @:)
1474
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001475 " completion for the :match command
1476 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1477 call assert_equal("\"match Search /pat/\<C-A>", @:)
1478
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001479 " completion for the :doautocmd command
1480 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1481 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1482
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001483 " completion of autocmd group after comma
1484 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1485 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1486
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001487 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001488 call writefile([], 'Xvarfile1', 'D')
1489 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001490 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1491 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001492
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001493 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001494 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001495 augroup END
1496 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001497 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001498
1499 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001500 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1501 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001502 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1503 call assert_equal("\"au XTest.test", @:)
1504
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001505 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001506
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001507 " autocmd pattern completion
1508 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1509 call assert_equal("\"au BufEnter *.py\t", @:)
1510
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001511 " completion for the :unlet command
1512 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1513 call assert_equal("\"unlet one two", @:)
1514
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001515 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001516 " FIXME: what should happen on MS-Windows?
1517 if !has('win32')
1518 edit \{someFile}
1519 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1520 call assert_equal("\"buf {someFile}", @:)
1521 bwipe {someFile}
1522 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001523
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001524 " completion for the :bdelete command
1525 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1526 call assert_equal("\"bdel a b c", @:)
1527
1528 " completion for the :mapclear command
1529 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1530 call assert_equal("\"mapclear <buffer>", @:)
1531
1532 " completion for user defined commands with menu names
1533 menu Test.foo :ls<CR>
1534 com -nargs=* -complete=menu MyCmd
1535 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1536 call assert_equal('"MyCmd Test.', @:)
1537 delcom MyCmd
1538 unmenu Test
1539
1540 " completion for user defined commands with mappings
1541 mapclear
1542 map <F3> :ls<CR>
1543 com -nargs=* -complete=mapping MyCmd
1544 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001545 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001546 mapclear
1547 delcom MyCmd
1548
Yee Cheng Chin54844852023-10-09 18:12:31 +02001549 " Prepare for path completion
1550 call mkdir('Xa b c', 'D')
1551 defer delete('Xcomma,foobar.txt')
1552 call writefile([], 'Xcomma,foobar.txt')
1553
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001554 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001555 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1556 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1557 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001558
1559 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001560 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1561 call assert_equal('"set dir=Xa\ b\ c/', @:)
1562 set dir&
1563
1564 " completion for :set tags= / set dictionary= with escaped commas
1565 if has('win32')
1566 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1567 " '\,'
1568 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1569 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1570
1571 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1572 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1573
1574 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1575 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1576
1577 " completion for :set dictionary= with escaped commas (same behavior, but
1578 " different internal code path from 'set tags=' for escaping the output)
1579 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1580 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1581 else
1582 " In other platforms, backslashes are rounded down (since '\,' itself will
1583 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1584 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1585 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1586
1587 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1588 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1589
1590 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1591 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1592
1593 " completion for :set dictionary= with escaped commas (same behavior, but
1594 " different internal code path from 'set tags=' for escaping the output)
1595 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1596 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1597 endif
1598 set tags&
1599 set dictionary&
1600
1601 " completion for :set makeprg= with no escaped commas
1602 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1603 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1604
1605 if !has('win32')
1606 " Cannot create file with backslash in file name in Windows, so only test
1607 " this elsewhere.
1608 defer delete('Xcomma\,fooslash.txt')
1609 call writefile([], 'Xcomma\,fooslash.txt')
1610 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1611 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1612 endif
1613 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001614
1615 " completion for the :py3 commands
1616 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1617 call assert_equal('"py3 py3do py3file', @:)
1618
Bram Moolenaardf749a22021-03-28 15:29:43 +02001619 " completion for the :vim9 commands
1620 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1621 call assert_equal('"vim9cmd vim9script', @:)
1622
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001623 " redir @" is not the start of a comment. So complete after that
1624 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1625 call assert_equal('"redir @" | cwindow', @:)
1626
1627 " completion after a backtick
1628 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1629 call assert_equal('"e `a1b2c', @:)
1630
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001631 " completion for :language command with an invalid argument
1632 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1633 call assert_equal("\"language dummy \t", @:)
1634
1635 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001636 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1637 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001638
1639 " completion with ambiguous user defined commands
1640 com TCmd1 echo 'TCmd1'
1641 com TCmd2 echo 'TCmd2'
1642 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1643 call assert_equal('"TCmd ', @:)
1644 delcom TCmd1
1645 delcom TCmd2
1646
1647 " completion after a range followed by a pipe (|) character
1648 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1649 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001650
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001651 " completion after a :global command
1652 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1653 call assert_equal('"g/a/chistory', @:)
1654 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1655 call assert_equal("\"g/a\\/chist\t", @:)
1656
Bram Moolenaar9c929712020-09-07 22:05:28 +02001657 " use <Esc> as the 'wildchar' for completion
1658 set wildchar=<Esc>
1659 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1660 call assert_equal('"g/a\xb/clearjumps', @:)
1661 " pressing <esc> twice should cancel the command
1662 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1663 call assert_equal('"g/a\xb/clearjumps', @:)
1664 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001665
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001666 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001667 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001668 call writefile([], '~Xtest')
1669 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1670 call assert_equal('"e \~Xtest', @:)
1671 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001672
1673 " should be able to complete a file name that has a '*'
1674 call writefile([], 'Xx*Yy')
1675 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1676 call assert_equal('"e Xx\*Yy', @:)
1677 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001678
1679 " use a literal star
1680 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1681 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001682 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001683
1684 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1685 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001686endfunc
1687
zeertzjq094dd152023-06-15 22:51:57 +01001688" Test that expanding a pattern doesn't interfere with cmdline completion.
1689func Test_expand_during_cmdline_completion()
1690 func ExpandStuff()
1691 badd <script>:p:h/README.*
1692 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1693 $bwipe
1694 call assert_equal('README.txt', expand('README.*'))
1695 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1696 endfunc
1697 augroup test_CmdlineChanged
1698 autocmd!
1699 autocmd CmdlineChanged * call ExpandStuff()
1700 augroup END
1701
1702 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1703 call assert_equal('"sign place', @:)
1704
1705 augroup test_CmdlineChanged
1706 au!
1707 augroup END
1708 augroup! test_CmdlineChanged
1709 delfunc ExpandStuff
1710endfunc
1711
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001712" Test for 'wildignorecase'
1713func Test_cmdline_wildignorecase()
1714 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001715 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001716 set wildignorecase
1717 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1718 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001719 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001720 let g:Sline = ''
1721 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1722 call assert_equal('"e xt', @:)
1723 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001724 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001725endfunc
1726
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001727func Test_cmdline_write_alternatefile()
1728 new
1729 call setline('.', ['one', 'two'])
1730 f foo.txt
1731 new
1732 f #-A
1733 call assert_equal('foo.txt-A', expand('%'))
1734 f #<-B.txt
1735 call assert_equal('foo-B.txt', expand('%'))
1736 f %<
1737 call assert_equal('foo-B', expand('%'))
1738 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001739 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001740 bw!
1741 f foo-B.txt
1742 f %<-A
1743 call assert_equal('foo-B-A', expand('%'))
1744 bw!
1745 bw!
1746endfunc
1747
Bram Moolenaarf5724372022-09-02 19:45:15 +01001748func Test_cmdline_expand_cur_alt_file()
1749 enew
1750 file http://some.com/file.txt
1751 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1752 call assert_equal('"e http://some.com/file.txt', @:)
1753 edit another
1754 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1755 call assert_equal('"e http://some.com/file.txt', @:)
1756 bwipe
1757 bwipe http://some.com/file.txt
1758endfunc
1759
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001760" using a leading backslash here
1761set cpo+=C
1762
1763func Test_cmdline_search_range()
1764 new
1765 call setline(1, ['a', 'b', 'c', 'd'])
1766 /d
1767 1,\/s/b/B/
1768 call assert_equal('B', getline(2))
1769
1770 /a
1771 $
1772 \?,4s/c/C/
1773 call assert_equal('C', getline(3))
1774
1775 call setline(1, ['a', 'b', 'c', 'd'])
1776 %s/c/c/
1777 1,\&s/b/B/
1778 call assert_equal('B', getline(2))
1779
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001780 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001781 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001782
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001783 bwipe!
1784endfunc
1785
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001786" Test for the tick mark (') in an excmd range
1787func Test_tick_mark_in_range()
1788 " If only the tick is passed as a range and no command is specified, there
1789 " should not be an error
1790 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001791 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001792 call assert_fails("',print", 'E78:')
1793endfunc
1794
1795" Test for using a line number followed by a search pattern as range
1796func Test_lnum_and_pattern_as_range()
1797 new
1798 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1799 let @" = ''
1800 2/foo/yank
1801 call assert_equal("foo 3\n", @")
1802 call assert_equal(1, line('.'))
1803 close!
1804endfunc
1805
Bram Moolenaar65189a12017-02-06 22:22:17 +01001806" Tests for getcmdline(), getcmdpos() and getcmdtype()
1807func Check_cmdline(cmdtype)
1808 call assert_equal('MyCmd a', getcmdline())
1809 call assert_equal(8, getcmdpos())
1810 call assert_equal(a:cmdtype, getcmdtype())
1811 return ''
1812endfunc
1813
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001814set cpo&
1815
Shougo Matsushita69084282024-09-23 20:34:47 +02001816func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001817 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1818
1819 let cmdtype = ''
1820 debuggreedy
1821 call feedkeys(":debug echo 'test'\<CR>", "t")
1822 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1823 call feedkeys("cont\<CR>", "xt")
1824 0debuggreedy
1825 call assert_equal('>', cmdtype)
1826
1827 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1828 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1829
1830 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001831 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001832
1833 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1834
1835 cnoremap <expr> <F6> Check_cmdline('=')
1836 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1837 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001838
1839 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001840
1841 call assert_equal('', getcmdprompt())
1842 augroup test_CmdlineEnter
1843 autocmd!
1844 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1845 augroup END
1846 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1847 call assert_equal('Answer?', g:cmdprompt)
1848 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001849 call feedkeys(":\<CR>\<ESC>", "xt")
1850 call assert_equal('', g:cmdprompt)
1851 call assert_equal('', getcmdprompt())
1852
1853 let str = "C" .. repeat("c", 1023) .. "xyz"
1854 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1855 call assert_equal(str, g:cmdprompt)
1856
1857 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1858 call assert_equal('Ans?', g:cmdprompt)
1859 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001860
1861 augroup test_CmdlineEnter
1862 au!
1863 augroup END
1864 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001865endfunc
1866
Bram Moolenaar52604f22017-04-07 16:17:39 +02001867func Test_verbosefile()
1868 set verbosefile=Xlog
1869 echomsg 'foo'
1870 echomsg 'bar'
1871 set verbosefile=
1872 let log = readfile('Xlog')
1873 call assert_match("foo\nbar", join(log, "\n"))
1874 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001875
1876 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001877 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001878endfunc
1879
Bram Moolenaar4facea32019-10-12 20:17:40 +02001880func Test_verbose_option()
1881 CheckScreendump
1882
1883 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001884 " clear the TermResponse autocommand from defaults.vim
1885 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001886 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1887 call feedkeys("\r", 't') " for the hit-enter prompt
1888 set verbose=20
1889 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001890 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001891
1892 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001893 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001894 call term_sendkeys(buf, ":DoSomething\<CR>")
1895 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1896
1897 " clean up
1898 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001899endfunc
1900
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001901func Test_setcmdpos()
1902 func InsertTextAtPos(text, pos)
1903 call assert_equal(0, setcmdpos(a:pos))
1904 return a:text
1905 endfunc
1906
1907 " setcmdpos() with position in the middle of the command line.
1908 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1909 call assert_equal('"1ab2', @:)
1910
1911 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1912 call assert_equal('"1b2a', @:)
1913
1914 " setcmdpos() with position beyond the end of the command line.
1915 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1916 call assert_equal('"12ab', @:)
1917
1918 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001919 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001920endfunc
1921
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001922func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001923 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001924 let encoding_save = &encoding
1925
1926 for e in encodings
1927 exe 'set encoding=' . e
1928
1929 " Test overstrike in the middle of the command line.
1930 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001931 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001932
1933 " Test overstrike going beyond end of command line.
1934 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001935 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001936
1937 " Test toggling insert/overstrike a few times.
1938 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001939 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001940 endfor
1941
Bram Moolenaar30276f22019-01-24 17:59:39 +01001942 " Test overstrike with multi-byte characters.
1943 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001944 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001945
1946 let &encoding = encoding_save
1947endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001948
Bram Moolenaar52410572019-10-27 05:12:45 +01001949func Test_buffers_lastused()
1950 " check that buffers are sorted by time when wildmode has lastused
1951 call test_settime(1550020000) " middle
1952 edit bufa
1953 enew
1954 call test_settime(1550030000) " newest
1955 edit bufb
1956 enew
1957 call test_settime(1550010000) " oldest
1958 edit bufc
1959 enew
1960 call test_settime(0)
1961 enew
1962
1963 call assert_equal(['bufa', 'bufb', 'bufc'],
1964 \ getcompletion('', 'buffer'))
1965
1966 let save_wildmode = &wildmode
1967 set wildmode=full:lastused
1968
1969 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1970 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1971 call assert_equal('b bufb', X)
1972 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1973 call assert_equal('b bufa', X)
1974 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1975 call assert_equal('b bufc', X)
1976 enew
1977
1978 edit other
1979 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1980 call assert_equal('b bufb', X)
1981 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1982 call assert_equal('b bufa', X)
1983 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1984 call assert_equal('b bufc', X)
1985 enew
1986
1987 let &wildmode = save_wildmode
1988
1989 bwipeout bufa
1990 bwipeout bufb
1991 bwipeout bufc
1992endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001993
Bram Moolenaar479950f2020-01-19 15:45:17 +01001994func Test_cmdlineclear_tabenter()
1995 CheckScreendump
1996
1997 let lines =<< trim [SCRIPT]
1998 call setline(1, range(30))
1999 [SCRIPT]
2000
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002001 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01002002 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02002003 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002004 " in one tab make the command line higher with CTRL-W -
2005 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
2006 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2007
2008 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002009endfunc
2010
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002011" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002012func Test_cmdline_expand_special()
2013 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02002014 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002015 call assert_fails('e <afile>', 'E495:')
2016 call assert_fails('e <abuf>', 'E496:')
2017 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002018
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002019 call writefile([], 'Xfile.cpp', 'D')
2020 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002021 new Xfile.cpp
2022 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2023 call assert_equal('"e Xfile.cpp Xfile.java', @:)
2024 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002025endfunc
2026
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002027" Test for backtick expression in the command line
2028func Test_cmd_backtick()
2029 %argd
2030 argadd `=['a', 'b', 'c']`
2031 call assert_equal(['a', 'b', 'c'], argv())
2032 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02002033
2034 argadd `echo abc def`
2035 call assert_equal(['abc def'], argv())
2036 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002037endfunc
2038
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002039" Test for the :! command
2040func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002041 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002042
2043 let lines =<< trim [SCRIPT]
2044 " Test for no previous command
2045 call assert_fails('!!', 'E34:')
2046 set nomore
2047 " Test for cmdline expansion with :!
2048 call setline(1, 'foo!')
2049 silent !echo <cWORD> > Xfile.out
2050 call assert_equal(['foo!'], readfile('Xfile.out'))
2051 " Test for using previous command
2052 silent !echo \! !
2053 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2054 call writefile(v:errors, 'Xresult')
2055 call delete('Xfile.out')
2056 qall!
2057 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002058 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002059 if RunVim([], [], '--clean -S Xscript')
2060 call assert_equal([], readfile('Xresult'))
2061 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002062 call delete('Xresult')
2063endfunc
2064
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002065" Test error: "E135: *Filter* Autocommands must not change current buffer"
2066func Test_cmd_bang_E135()
2067 new
2068 call setline(1, ['a', 'b', 'c', 'd'])
2069 augroup test_cmd_filter_E135
2070 au!
2071 autocmd FilterReadPost * help
2072 augroup END
2073 call assert_fails('2,3!echo "x"', 'E135:')
2074
2075 augroup test_cmd_filter_E135
2076 au!
2077 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002078 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002079 %bwipe!
2080endfunc
2081
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002082func Test_cmd_bang_args()
2083 new
2084 :.!
2085 call assert_equal(0, v:shell_error)
2086
2087 " Note that below there is one space char after the '!'. This caused a
2088 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2089 :.!
2090 call assert_equal(0, v:shell_error)
2091 bwipe!
2092
2093 CheckUnix
2094 :.!pwd
2095 call assert_equal(0, v:shell_error)
2096 :.! pwd
2097 call assert_equal(0, v:shell_error)
2098
2099 " Note there is one space after 'pwd'.
2100 :.! pwd
2101 call assert_equal(0, v:shell_error)
2102
2103 " Note there are two spaces after 'pwd'.
2104 :.! pwd
2105 call assert_equal(0, v:shell_error)
2106 :.!ls ~
2107 call assert_equal(0, v:shell_error)
2108
2109 " Note there is one space char after '~'.
2110 :.!ls ~
2111 call assert_equal(0, v:shell_error)
2112
2113 " Note there are two spaces after '~'.
2114 :.!ls ~
2115 call assert_equal(0, v:shell_error)
2116
2117 :.!echo "foo"
2118 call assert_equal(getline('.'), "foo")
2119 :.!echo "foo "
2120 call assert_equal(getline('.'), "foo ")
2121 :.!echo " foo "
2122 call assert_equal(getline('.'), " foo ")
2123 :.!echo " foo "
2124 call assert_equal(getline('.'), " foo ")
2125
2126 %bwipe!
2127endfunc
2128
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002129" Test for using ~ for home directory in cmdline completion matches
2130func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002131 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002132 call writefile([], 'Xexpdir/Xfile1')
2133 call writefile([], 'Xexpdir/Xfile2')
2134 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002135 let save_HOME = $HOME
2136 let $HOME = getcwd()
2137 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2138 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2139 let $HOME = save_HOME
2140 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002141endfunc
2142
Bram Moolenaar578fe942020-02-27 21:32:51 +01002143" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2144" or insert mode (when 'insertmode' is set)
2145func Test_cmdline_ctrl_g()
2146 new
2147 call setline(1, 'abc')
2148 call cursor(1, 3)
2149 " If command line is entered from insert mode, using C-\ C-G should back to
2150 " insert mode
2151 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2152 call assert_equal('abxyc', getline(1))
2153 call assert_equal(4, col('.'))
2154
2155 " If command line is entered in 'insertmode', using C-\ C-G should back to
2156 " 'insertmode'
2157 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2158 call assert_equal('ab12xyc', getline(1))
2159 close!
2160endfunc
2161
Bram Moolenaar578fe942020-02-27 21:32:51 +01002162" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002163func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002164 func T(a, c, p)
2165 return "oneA\noneB\noneC"
2166 endfunc
2167 command -nargs=1 -complete=custom,T MyCmd
2168
Bram Moolenaar578fe942020-02-27 21:32:51 +01002169 set nowildmenu
2170 set wildmode=full,list
2171 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002172 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002173 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002174 call assert_equal('"MyCmd oneA', @:)
2175
2176 set wildmode=longest,full
2177 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2178 call assert_equal('"MyCmd one', @:)
2179 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2180 call assert_equal('"MyCmd oneC', @:)
2181
2182 set wildmode=longest
2183 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2184 call assert_equal('"MyCmd one', @:)
2185
2186 set wildmode=list:longest
2187 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002188 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002189 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002190 call assert_equal('"MyCmd one', @:)
2191
2192 set wildmode=""
2193 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2194 call assert_equal('"MyCmd oneA', @:)
2195
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002196 " Test for wildmode=longest with 'fileignorecase' set
2197 set wildmode=longest
2198 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002199 argadd AAA AAAA AAAAA
2200 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2201 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002202 set fileignorecase&
2203
2204 " Test for listing files with wildmode=list
2205 set wildmode=list
2206 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002207 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002208 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002209 call assert_equal('"b A', @:)
2210
Girish Palya2bacc3e2025-03-02 22:55:57 +01002211 " When 'wildmenu' is not set, 'noselect' completes first item
2212 set wildmode=noselect
2213 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2214 call assert_equal('"MyCmd oneA', @:)
2215
2216 " When 'noselect' is present, do not complete first <tab>.
2217 set wildmenu
2218 set wildmode=noselect
2219 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2220 call assert_equal('"MyCmd o', @:)
2221 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2222 call assert_equal('"MyCmd o', @:)
2223 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2224 call assert_equal('"MyCmd o', @:)
2225
2226 " When 'full' is present, complete after first <tab>.
2227 set wildmode=noselect,full
2228 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2229 call assert_equal('"MyCmd o', @:)
2230 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2231 call assert_equal('"MyCmd oneA', @:)
2232 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2233 call assert_equal('"MyCmd oneB', @:)
2234 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2235 call assert_equal('"MyCmd oneB', @:)
2236
2237 " 'noselect' has no effect when 'longest' is present.
2238 set wildmode=noselect:longest
2239 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2240 call assert_equal('"MyCmd one', @:)
2241
2242 " Complete 'noselect' value in 'wildmode' option
2243 set wildmode&
2244 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2245 call assert_equal('"set wildmode=noselect', @:)
2246 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2247 call assert_equal('"set wildmode=noselect', @:)
2248
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002249 " when using longest completion match, matches shorter than the argument
2250 " should be ignored (happens with :help)
2251 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002252 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2253 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002254 " non existing file
2255 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2256 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002257
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002258 " Test for longest file name completion with 'fileignorecase'
2259 " On MS-Windows, file names are case insensitive.
2260 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002261 call writefile([], 'XTESTfoo', 'D')
2262 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002263 set nofileignorecase
2264 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2265 call assert_equal('"e XTESTfoo', @:)
2266 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2267 call assert_equal('"e Xtestbar', @:)
2268 set fileignorecase
2269 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2270 call assert_equal('"e Xtest', @:)
2271 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2272 call assert_equal('"e Xtest', @:)
2273 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002274 endif
2275
Girish Palya2bacc3e2025-03-02 22:55:57 +01002276 " If 'noselect' is present, single item menu should not insert item
2277 func! T(a, c, p)
2278 return "oneA"
2279 endfunc
2280 command! -nargs=1 -complete=custom,T MyCmd
2281 set wildmode=noselect,full
2282 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2283 call assert_equal('"MyCmd o', @:)
2284 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2285 call assert_equal('"MyCmd oneA', @:)
2286 " 'nowildmenu' should make 'noselect' ineffective
2287 set nowildmenu
2288 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2289 call assert_equal('"MyCmd oneA', @:)
2290
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002291 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002292 delcommand MyCmd
2293 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002294 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002295 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002296endfunc
2297
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002298func Test_wildmode()
2299 " Test with utf-8 encoding
2300 call Wildmode_tests()
2301
2302 " Test with latin1 encoding
2303 let save_encoding = &encoding
2304 set encoding=latin1
2305 call Wildmode_tests()
2306 let &encoding = save_encoding
2307endfunc
2308
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002309func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002310 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002311 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002312 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002313 let lines =<< trim END
2314 func vim8#Complete(a, c, p)
2315 return "oneA\noneB\noneC"
2316 endfunc
2317 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002318 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002319
2320 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2321 set nowildmenu
2322 set wildmode=full,list
2323 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2324 call assert_equal('"MyCmd oneA oneB oneC', @:)
2325
2326 let &rtp = save_rtp
2327 set wildmode& wildmenu&
2328 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002329endfunc
2330
Bram Moolenaar578fe942020-02-27 21:32:51 +01002331" Test for interrupting the command-line completion
2332func Test_interrupt_compl()
2333 func F(lead, cmdl, p)
2334 if a:lead =~ 'tw'
2335 call interrupt()
2336 return
2337 endif
2338 return "one\ntwo\nthree"
2339 endfunc
2340 command -nargs=1 -complete=custom,F Tcmd
2341
2342 set nowildmenu
2343 set wildmode=full
2344 let interrupted = 0
2345 try
2346 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2347 catch /^Vim:Interrupt$/
2348 let interrupted = 1
2349 endtry
2350 call assert_equal(1, interrupted)
2351
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002352 let interrupted = 0
2353 try
2354 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2355 catch /^Vim:Interrupt$/
2356 let interrupted = 1
2357 endtry
2358 call assert_equal(1, interrupted)
2359
Bram Moolenaar578fe942020-02-27 21:32:51 +01002360 delcommand Tcmd
2361 delfunc F
2362 set wildmode&
2363endfunc
2364
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002365" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002366func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002367 let str = ":one two\<C-U>"
2368 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002369 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002370 let str ..= "\<Left>five\<Right>"
2371 let str ..= "\<Home>two "
2372 let str ..= "\<C-Left>one "
2373 let str ..= "\<C-Right> three"
2374 let str ..= "\<End>\<S-Left>four "
2375 let str ..= "\<S-Right> six"
2376 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2377 call feedkeys(str, 'xt')
2378 call assert_equal("\"one two three four five six seven", @:)
2379endfunc
2380
2381" Test for moving the cursor on the / command line in 'rightleft' mode
2382func Test_cmdline_edit_rightleft()
2383 CheckFeature rightleft
2384 set rightleft
2385 set rightleftcmd=search
2386 let str = "/one two\<C-U>"
2387 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002388 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002389 let str ..= "\<Right>five\<Left>"
2390 let str ..= "\<Home>two "
2391 let str ..= "\<C-Right>one "
2392 let str ..= "\<C-Left> three"
2393 let str ..= "\<End>\<S-Right>four "
2394 let str ..= "\<S-Left> six"
2395 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2396 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2397 call assert_equal("\"one two three four five six seven", @/)
2398 set rightleftcmd&
2399 set rightleft&
2400endfunc
2401
2402" Test for using <C-\>e in the command line to evaluate an expression
2403func Test_cmdline_expr()
2404 " Evaluate an expression from the beginning of a command line
2405 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2406 call assert_equal('"hello', @:)
2407
2408 " Use an invalid expression for <C-\>e
2409 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2410
2411 " Insert literal <CTRL-\> in the command line
2412 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2413 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002414endfunc
2415
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002416" This was making the insert position negative
2417func Test_cmdline_expr_register()
2418 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2419endfunc
2420
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002421" Test for 'imcmdline' and 'imsearch'
2422" This test doesn't actually test the input method functionality.
2423func Test_cmdline_inputmethod()
2424 new
2425 call setline(1, ['', 'abc', ''])
2426 set imcmdline
2427
2428 call feedkeys(":\"abc\<CR>", 'xt')
2429 call assert_equal("\"abc", @:)
2430 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2431 call assert_equal("\"abc", @:)
2432 call feedkeys("/abc\<CR>", 'xt')
2433 call assert_equal([2, 1], [line('.'), col('.')])
2434 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2435 call assert_equal([2, 1], [line('.'), col('.')])
2436
2437 set imsearch=2
2438 call cursor(1, 1)
2439 call feedkeys("/abc\<CR>", 'xt')
2440 call assert_equal([2, 1], [line('.'), col('.')])
2441 call cursor(1, 1)
2442 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2443 call assert_equal([2, 1], [line('.'), col('.')])
2444 set imdisable
2445 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2446 call assert_equal([2, 1], [line('.'), col('.')])
2447 set imdisable&
2448 set imsearch&
2449
2450 set imcmdline&
2451 %bwipe!
2452endfunc
2453
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002454" Test for using CTRL-_ in the command line with 'allowrevins'
2455func Test_cmdline_revins()
2456 CheckNotMSWindows
2457 CheckFeature rightleft
2458 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2459 call assert_equal("\"abc\<c-_>", @:)
2460 set allowrevins
2461 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2462 call assert_equal('"abcñèæ', @:)
2463 set allowrevins&
2464endfunc
2465
2466" Test for typing UTF-8 composing characters in the command line
2467func Test_cmdline_composing_chars()
2468 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2469 call assert_equal('"ゔ', @:)
2470endfunc
2471
Bram Moolenaar0e717042020-04-27 19:29:01 +02002472" test that ";" works to find a match at the start of the first line
2473func Test_zero_line_search()
2474 new
2475 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2476 call cursor(1,1)
2477 0;/pattern/d
2478 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2479 q!
2480endfunc
2481
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002482func Test_read_shellcmd()
2483 CheckUnix
2484 if executable('ls')
2485 " There should be ls in the $PATH
2486 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2487 call assert_match('^"r! .*\<ls\>', @:)
2488 endif
2489
2490 if executable('rm')
2491 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2492 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2493 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002494
2495 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2496 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2497 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002498 endif
2499endfunc
2500
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002501" Test for going up and down the directory tree using 'wildmenu'
2502func Test_wildmenu_dirstack()
2503 CheckUnix
2504 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002505 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002506 call writefile([], 'Xwildmenu/file1_1.txt')
2507 call writefile([], 'Xwildmenu/file1_2.txt')
2508 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2509 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2510 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2511 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2512 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2513 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002514 set wildmenu
2515
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002516 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002517 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002518 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002519 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002520 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002521 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002522 call assert_equal('"e ../../dir3/', @:)
2523 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2524 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002525 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002526 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002527 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002528 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002529 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002530 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2531 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002532
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002533 set wildmenu&
2534endfunc
2535
obcat71c6f7a2021-05-13 20:23:10 +02002536" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002537" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2538" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002539func Test_recalling_cmdline()
2540 CheckFeature cmdline_hist
2541
2542 let g:cmdlines = []
2543 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2544
2545 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002546 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2547 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2548 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2549 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002550 "\ TODO: {'name': 'debug', ...}
2551 \]
2552 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002553 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2554 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2555 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2556 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2557 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002558 \]
2559 let prefix = 'vi'
2560 for h in histories
2561 call histadd(h.name, 'vim')
2562 call histadd(h.name, 'virtue')
2563 call histadd(h.name, 'Virgo')
2564 call histadd(h.name, 'vogue')
2565 call histadd(h.name, 'emacs')
2566 for k in keypairs
2567 let g:cmdlines = []
2568 let keyseqs = h.enter
2569 \ .. prefix
2570 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2571 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2572 \ .. h.exit
2573 call feedkeys(keyseqs, 'xt')
2574 call histdel(h.name, -1) " delete the history added by feedkeys above
2575 let expect = k.prefixmatch
2576 \ ? ['virtue', 'vim', 'virtue', prefix]
2577 \ : ['emacs', 'vogue', 'emacs', prefix]
2578 call assert_equal(expect, g:cmdlines)
2579 endfor
2580 endfor
2581
2582 unlet g:cmdlines
2583 cunmap <Plug>(save-cmdline)
2584endfunc
2585
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002586func Test_cmd_map_cmdlineChanged()
2587 let g:log = []
2588 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002589 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002590 autocmd!
2591 autocmd CmdlineChanged : let g:log += [getcmdline()]
2592 augroup END
2593
2594 call feedkeys(":\<F1>\<CR>", 'xt')
2595 call assert_equal(['l', 'ls'], g:log)
2596
Bram Moolenaar796139a2021-05-18 21:38:45 +02002597 let @b = 'b'
2598 cnoremap <F1> a<C-R>b
2599 let g:log = []
2600 call feedkeys(":\<F1>\<CR>", 'xt')
2601 call assert_equal(['a', 'ab'], g:log)
2602
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002603 unlet g:log
2604 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002605 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002606 autocmd!
2607 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002608 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002609endfunc
2610
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002611" Test for the 'suffixes' option
2612func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002613 call writefile([], 'Xsuffile', 'D')
2614 call writefile([], 'Xsuffile.c', 'D')
2615 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002616 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002617 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2618 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2619 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2620 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002621 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002622 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2623 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2624 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2625 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002626 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002627 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2628 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2629 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2630 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002631 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002632 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002633 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2634 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002635endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002636
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002637" Test for using a popup menu for the command line completion matches
2638" (wildoptions=pum)
2639func Test_wildmenu_pum()
Drew Vogelea67ba72025-05-07 22:05:17 +02002640 CheckScreendump
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002641 CheckRunVimInTerminal
2642
2643 let commands =<< trim [CODE]
2644 set wildmenu
2645 set wildoptions=pum
2646 set shm+=I
2647 set noruler
2648 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002649
2650 func CmdCompl(a, b, c)
2651 return repeat(['aaaa'], 120)
2652 endfunc
2653 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002654
2655 func MyStatusLine() abort
2656 return 'status'
2657 endfunc
2658 func SetupStatusline()
2659 set statusline=%!MyStatusLine()
2660 set laststatus=2
2661 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002662
2663 func MyTabLine()
2664 return 'my tab line'
2665 endfunc
2666 func SetupTabline()
2667 set statusline=
2668 set tabline=%!MyTabLine()
2669 set showtabline=2
2670 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002671
2672 func DoFeedKeys()
2673 let &wildcharm = char2nr("\t")
2674 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2675 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002676 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002677 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002678
2679 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2680
2681 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002682 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2683
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002684 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002685 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002686 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2687
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002688 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2691
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002692 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002693 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002694 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2695
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002696 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002697 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002698 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2699
2700 " pressing <C-E> should end completion and go back to the original match
2701 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002702 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2703
2704 " pressing <C-Y> should select the current match and end completion
2705 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002706 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2707
2708 " With 'wildmode' set to 'longest,full', completing a match should display
2709 " the longest match, the wildmenu should not be displayed.
2710 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2711 call TermWait(buf)
2712 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002713 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2714
2715 " pressing <Tab> should display the wildmenu
2716 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002717 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2718
2719 " pressing <Tab> second time should select the next entry in the menu
2720 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002721 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2722
2723 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002724 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002725 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002726 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2727
2728 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002729 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2730
2731 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002732 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2733
2734 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002735 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002736 call writefile([], 'Xnamedir/XfileA')
2737 call writefile([], 'Xnamedir/XdirA/XfileB')
2738 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002739
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002740 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002741 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2742
2743 " Pressing <Right> on a directory name should go into that directory
2744 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002745 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2746
2747 " Pressing <Left> on a directory name should go to the parent directory
2748 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002749 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2750
2751 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002752 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002753 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002754 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2755
2756 " Pressing <C-D> when the popup menu is displayed should remove the popup
2757 " menu
2758 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002759 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2760
2761 " Pressing <S-Tab> should open the popup menu with the last entry selected
2762 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002763 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2764
2765 " Pressing <Esc> should close the popup menu and cancel the cmd line
2766 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002767 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2768
2769 " Typing a character when the popup is open, should close the popup
2770 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002771 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2772
2773 " When the popup is open, entering the cmdline window should close the popup
2774 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002775 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2776 call term_sendkeys(buf, ":q\<CR>")
2777
2778 " After the last popup menu item, <C-N> should show the original string
2779 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002780 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2781
2782 " Use the popup menu for the command name
2783 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002784 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2785
2786 " Pressing the left arrow should remove the popup menu
2787 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002788 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2789
2790 " Pressing <BS> should remove the popup menu and erase the last character
2791 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002792 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2793
2794 " Pressing <C-W> should remove the popup menu and erase the previous word
2795 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002796 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2797
2798 " Pressing <C-U> should remove the popup menu and erase the entire line
2799 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002800 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2801
2802 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2803 " the cmdline from history
2804 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002805 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2806
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002807 " Check "list" still works
2808 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2809 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002810 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2811 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002812 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2813
rbtnn68cc2b82022-02-09 11:55:47 +00002814 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002815 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002816 call writefile([], 'Xnamedir/あいう/abc')
2817 call writefile([], 'Xnamedir/あいう/xyz')
2818 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002819
2820 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002821 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002822 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2823
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002824 " Pressing <C-A> when the popup menu is displayed should list all the
2825 " matches and pressing a key after that should remove the popup menu
2826 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2827 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2828 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2829
2830 " Pressing <C-A> when the popup menu is displayed should list all the
2831 " matches and pressing <Left> after that should move the cursor
2832 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2833 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2834 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2835
2836 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2837 " should be displayed correctly on the screen.
2838 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2839 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2840
2841 " After using <C-A> to expand all the filename matches, pressing <Up>
2842 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002843 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002844 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2845 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2846 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2847
2848 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2849 " crash Vim
2850 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2851 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2852
Bram Moolenaar414acd32022-02-10 21:09:45 +00002853 " After removing the pum the command line is redrawn
2854 call term_sendkeys(buf, ":edit foo\<CR>")
2855 call term_sendkeys(buf, ":edit bar\<CR>")
2856 call term_sendkeys(buf, ":ls\<CR>")
2857 call term_sendkeys(buf, ":com\<Tab> ")
2858 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002859 call term_sendkeys(buf, "\<C-U>\<CR>")
2860
2861 " Esc still works to abort the command when 'statusline' is set
2862 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2863 call term_sendkeys(buf, ":si\<Tab>")
2864 call term_sendkeys(buf, "\<Esc>")
2865 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002866
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002867 " Esc still works to abort the command when 'tabline' is set
2868 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2869 call term_sendkeys(buf, ":si\<Tab>")
2870 call term_sendkeys(buf, "\<Esc>")
2871 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2872
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002873 " popup is cleared also when 'lazyredraw' is set
2874 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2875 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2876 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2877 call term_sendkeys(buf, "\<Esc>")
2878
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002879 " Pressing <PageDown> should scroll the menu downward
2880 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2881 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2882 call term_sendkeys(buf, "\<PageDown>")
2883 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2884 call term_sendkeys(buf, "\<PageDown>")
2885 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2886 call term_sendkeys(buf, "\<PageDown>")
2887 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2888 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2889 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2890
2891 " Pressing <PageUp> should scroll the menu upward
2892 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2893 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2894 call term_sendkeys(buf, "\<PageUp>")
2895 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2896 call term_sendkeys(buf, "\<PageUp>")
2897 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2898 call term_sendkeys(buf, "\<PageUp>")
2899 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2900
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002901 " pressing <C-E> to end completion should work in middle of the line too
2902 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2903 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2904 call term_sendkeys(buf, "\<C-E>")
2905 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2906
2907 " pressing <C-Y> should select the current match and end completion
2908 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2909 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2910
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002911 call term_sendkeys(buf, "\<C-U>\<CR>")
2912 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002913endfunc
2914
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002915" Test for wildmenumode() with the cmdline popup menu
2916func Test_wildmenumode_with_pum()
2917 set wildmenu
2918 set wildoptions=pum
2919 cnoremap <expr> <F2> wildmenumode()
2920 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2921 call assert_equal('"sign define10', @:)
2922 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2923 call assert_equal('"sign define jump list place undefine unplace0', @:)
2924 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2925 call assert_equal('"sign 0', @:)
2926 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2927 call assert_equal('"sign define0', @:)
2928 set nowildmenu wildoptions&
2929 cunmap <F2>
2930endfunc
2931
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002932func Test_wildmenu_with_pum_foldexpr()
Drew Vogelea67ba72025-05-07 22:05:17 +02002933 CheckScreendump
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002934 CheckRunVimInTerminal
2935
2936 let lines =<< trim END
2937 call setline(1, ['folded one', 'folded two', 'some more text'])
2938 func MyFoldText()
2939 return 'foo'
2940 endfunc
2941 set foldtext=MyFoldText() wildoptions=pum
2942 normal ggzfj
2943 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002944 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002945 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2946 call term_sendkeys(buf, ":set\<Tab>")
2947 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2948
2949 call term_sendkeys(buf, "\<Esc>")
2950 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2951
2952 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002953endfunc
2954
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002955" Test for opening the cmdline completion popup menu from the terminal window.
2956" The popup menu should be positioned correctly over the status line of the
2957" bottom-most window.
2958func Test_wildmenu_pum_from_terminal()
Drew Vogelea67ba72025-05-07 22:05:17 +02002959 CheckScreendump
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002960 CheckRunVimInTerminal
2961 let python = PythonProg()
2962 call CheckPython(python)
2963
2964 %bw!
2965 let cmds = ['set wildmenu wildoptions=pum']
2966 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2967 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002968 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002969 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2970 call term_sendkeys(buf, "\r\r\r")
2971 call term_wait(buf)
2972 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2973 call term_wait(buf)
2974 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2975 call term_wait(buf)
2976 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002977endfunc
2978
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002979func Test_wildmenu_pum_odd_wildchar()
Drew Vogelea67ba72025-05-07 22:05:17 +02002980 CheckScreendump
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002981 CheckRunVimInTerminal
2982
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002983 " Test odd wildchar interactions with pum. Make sure they behave properly
2984 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002985 let lines =<< trim END
2986 set wildoptions=pum
2987 set wildchar=<C-E>
2988 END
2989 call writefile(lines, 'XwildmenuTest', 'D')
2990 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2991
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002992 call term_sendkeys(buf, ":\<C-E>")
2993 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002994
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002995 " <C-E> being a wildchar takes priority over its original functionality
2996 call term_sendkeys(buf, "\<C-E>")
2997 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2998
2999 call term_sendkeys(buf, "\<Esc>")
3000 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3001
3002 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
3003 " command-line, and we need to make sure to clean up properly.
3004 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3005 call term_sendkeys(buf, ":\<Esc>")
3006 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3007
3008 call term_sendkeys(buf, "\<Esc>")
3009 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3010
3011 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3012 " and we again need to make sure we clean up properly.
3013 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3014 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3015 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3016
3017 call term_sendkeys(buf, "\<C-N>")
3018 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3019
3020 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003021endfunc
3022
zeertzjq883018f2024-06-15 15:37:11 +02003023" Test that 'rightleft' should not affect cmdline completion popup menu.
3024func Test_wildmenu_pum_rightleft()
3025 CheckFeature rightleft
3026 CheckScreendump
3027
3028 let lines =<< trim END
3029 set wildoptions=pum
3030 set rightleft
3031 END
3032 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3033 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3034
3035 call term_sendkeys(buf, ":sign \<Tab>")
3036 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3037
3038 call StopVimInTerminal(buf)
3039endfunc
3040
Girish Palya4ec46f32025-03-04 20:56:30 +01003041" Test highlighting when pattern matches non-first character of item
3042func Test_wildmenu_pum_hl_nonfirst()
3043 CheckScreendump
3044 let lines =<< trim END
3045 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3046 hi PmenuMatchSel ctermfg=6 ctermbg=7
3047 hi PmenuMatch ctermfg=4 ctermbg=225
3048 func T(a, c, p)
3049 return ["oneA", "o neBneB", "aoneC"]
3050 endfunc
3051 command -nargs=1 -complete=customlist,T MyCmd
3052 END
3053
3054 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3055 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3056
3057 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3058 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3059 call term_sendkeys(buf, "\<Esc>")
3060 call StopVimInTerminal(buf)
3061endfunc
3062
zeertzjqd8c93402024-06-17 18:25:32 +02003063" Test highlighting matched text in cmdline completion popup menu.
3064func Test_wildmenu_pum_hl_match()
3065 CheckScreendump
3066
3067 let lines =<< trim END
3068 set wildoptions=pum,fuzzy
3069 hi PmenuMatchSel ctermfg=6 ctermbg=7
3070 hi PmenuMatch ctermfg=4 ctermbg=225
3071 END
3072 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3073 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3074
3075 call term_sendkeys(buf, ":sign plc\<Tab>")
3076 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3077 call term_sendkeys(buf, "\<Tab>")
3078 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3079 call term_sendkeys(buf, "\<Tab>")
3080 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3081 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3082 call TermWait(buf)
3083 call term_sendkeys(buf, ":sign un\<Tab>")
3084 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3085 call term_sendkeys(buf, "\<Tab>")
3086 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3087 call term_sendkeys(buf, "\<Tab>")
3088 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3089 call term_sendkeys(buf, "\<Esc>")
3090
3091 call StopVimInTerminal(buf)
3092endfunc
3093
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003094" Test for completion after a :substitute command followed by a pipe (|)
3095" character
3096func Test_cmdline_complete_substitute()
3097 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3098 call assert_equal("\"s | \t", @:)
3099 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3100 call assert_equal("\"s/ | \t", @:)
3101 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3102 call assert_equal("\"s/one | \t", @:)
3103 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3104 call assert_equal("\"s/one/ | \t", @:)
3105 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3106 call assert_equal("\"s/one/two | \t", @:)
3107 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3108 call assert_equal('"s/one/two/ | chistory', @:)
3109 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3110 call assert_equal("\"s/one/two/g \t", @:)
3111 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3112 call assert_equal("\"s/one/two/g | chistory", @:)
3113 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3114 call assert_equal("\"s/one/t\\/ | \t", @:)
3115 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3116 call assert_equal('"s/one/t"o/ | chistory', @:)
3117 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3118 call assert_equal('"s/one/t|o/ | chistory', @:)
3119 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3120 call assert_equal("\"&\t", @:)
3121endfunc
3122
3123" Test for the :dlist command completion
3124func Test_cmdline_complete_dlist()
3125 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3126 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3127 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3128 call assert_equal("\"dlist 10 /pat/ \t", @:)
3129 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3130 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3131 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3132 call assert_equal("\"dlist 10 /pat\\\t", @:)
3133 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3134 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3135endfunc
3136
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003137" argument list (only for :argdel) fuzzy completion
3138func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003139 argadd change.py count.py charge.py
3140 set wildoptions&
3141 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal('"argdel cge', @:)
3143 set wildoptions=fuzzy
3144 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal('"argdel change.py charge.py', @:)
3146 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003147 set wildoptions&
3148endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003149
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003150" autocmd group name fuzzy completion
3151func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003152 set wildoptions&
3153 augroup MyFuzzyGroup
3154 augroup END
3155 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal('"augroup mfg', @:)
3157 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal('"augroup MyFuzzyGroup', @:)
3159 set wildoptions=fuzzy
3160 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3161 call assert_equal('"augroup MyFuzzyGroup', @:)
3162 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal('"augroup My*p', @:)
3164 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003165 set wildoptions&
3166endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003167
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003168" buffer name fuzzy completion
3169func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003170 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003171 " Use a long name to reduce the risk of matching a random directory name
3172 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003173 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003174 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal('"b SRFWL', @:)
3176 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003178 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003179 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3181 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003183 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003184 set wildoptions&
3185endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003186
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003187" buffer name (full path) fuzzy completion
3188func Test_fuzzy_completion_bufname_fullpath()
3189 CheckUnix
3190 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003191 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003192 edit Xcmd/Xstate/Xfile.js
3193 cd Xcmd/Xstate
3194 enew
3195 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3196 call assert_equal('"b CmdStateFile', @:)
3197 set wildoptions=fuzzy
3198 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3200 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003201 set wildoptions&
3202endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003203
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003204" :behave suboptions fuzzy completion
3205func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003206 set wildoptions&
3207 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal('"behave xm', @:)
3209 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal('"behave xterm', @:)
3211 set wildoptions=fuzzy
3212 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3213 call assert_equal('"behave xterm', @:)
3214 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3215 call assert_equal('"behave xt*m', @:)
3216 let g:Sline = ''
3217 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal('mswin', g:Sline)
3219 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003220 set wildoptions&
3221endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003222
Christian Brabandta3422aa2025-04-23 21:04:24 +02003223" :filetype suboptions completion
3224func Test_completion_filetypecmd()
3225 set wildoptions&
3226 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3227 call assert_equal('"filetype indent off on plugin', @:)
3228 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3229 call assert_equal('"filetype plugin indent off on', @:)
3230 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal('"filetype indent off on plugin', @:)
3232 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal('"filetype indent', @:)
3234 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal('"filetype plugin', @:)
3236 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal('"filetype off on', @:)
3238 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3239 call assert_equal('"filetype indent off', @:)
3240 set wildoptions&
3241endfunc
3242
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003243" " colorscheme name fuzzy completion - NOT supported
3244" func Test_fuzzy_completion_colorscheme()
3245" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003246
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003247" built-in command name fuzzy completion
3248func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003249 set wildoptions&
3250 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3251 call assert_equal('"sbwin', @:)
3252 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3253 call assert_equal('"sbrewind', @:)
3254 set wildoptions=fuzzy
3255 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal('"sbrewind', @:)
3257 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003259 set wildoptions&
3260endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003261
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003262" " compiler name fuzzy completion - NOT supported
3263" func Test_fuzzy_completion_compiler()
3264" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003265
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003266" :cscope suboptions fuzzy completion
3267func Test_fuzzy_completion_cscope()
3268 CheckFeature cscope
3269 set wildoptions&
3270 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal('"cscope ret', @:)
3272 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal('"cscope reset', @:)
3274 set wildoptions=fuzzy
3275 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_equal('"cscope reset', @:)
3277 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_equal('"cscope re*t', @:)
3279 set wildoptions&
3280endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003281
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003282" :diffget/:diffput buffer name fuzzy completion
3283func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003284 new SomeBuffer
3285 diffthis
3286 new OtherBuffer
3287 diffthis
3288 set wildoptions&
3289 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal('"diffget sbuf', @:)
3291 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal('"diffput sbuf', @:)
3293 set wildoptions=fuzzy
3294 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3295 call assert_equal('"diffget SomeBuffer', @:)
3296 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3297 call assert_equal('"diffput SomeBuffer', @:)
3298 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003299 set wildoptions&
3300endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003301
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003302" " directory name fuzzy completion - NOT supported
3303" func Test_fuzzy_completion_dirname()
3304" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003305
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003306" environment variable name fuzzy completion
3307func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003308 set wildoptions&
3309 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"echo $VUT', @:)
3311 set wildoptions=fuzzy
3312 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3313 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003314 set wildoptions&
3315endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003316
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003317" autocmd event fuzzy completion
3318func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003319 set wildoptions&
3320 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal('"autocmd BWout', @:)
3322 set wildoptions=fuzzy
3323 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3324 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003325 set wildoptions&
3326endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003327
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003328" vim expression fuzzy completion
3329func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003330 let g:PerPlaceCount = 10
3331 set wildoptions&
3332 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3333 call assert_equal('"let c = ppc', @:)
3334 set wildoptions=fuzzy
3335 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3336 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003337 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003338endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003339
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003340" " file name fuzzy completion - NOT supported
3341" func Test_fuzzy_completion_filename()
3342" endfunc
3343
3344" " files in path fuzzy completion - NOT supported
3345" func Test_fuzzy_completion_filesinpath()
3346" endfunc
3347
3348" " filetype name fuzzy completion - NOT supported
3349" func Test_fuzzy_completion_filetype()
3350" endfunc
3351
3352" user defined function name completion
3353func Test_fuzzy_completion_userdefined_func()
3354 set wildoptions&
3355 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3356 call assert_equal('"call Test_f_u_f', @:)
3357 set wildoptions=fuzzy
3358 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3360 set wildoptions&
3361endfunc
3362
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003363" <SNR> functions should be sorted to the end
3364func Test_fuzzy_completion_userdefined_snr_func()
3365 func s:Sendmail()
3366 endfunc
3367 func SendSomemail()
3368 endfunc
3369 func S1e2n3dmail()
3370 endfunc
3371 set wildoptions=fuzzy
3372 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003373 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003374 set wildoptions&
3375 delfunc s:Sendmail
3376 delfunc SendSomemail
3377 delfunc S1e2n3dmail
3378endfunc
3379
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003380" user defined command name completion
3381func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003382 set wildoptions&
3383 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3384 call assert_equal('"MsFeat', @:)
3385 set wildoptions=fuzzy
3386 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3387 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003388 set wildoptions&
3389endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003390
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003391" " :help tag fuzzy completion - NOT supported
3392" func Test_fuzzy_completion_helptag()
3393" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003394
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003395" highlight group name fuzzy completion
3396func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003397 set wildoptions&
3398 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal('"highlight SKey', @:)
3400 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal('"highlight SpecialKey', @:)
3402 set wildoptions=fuzzy
3403 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3404 call assert_equal('"highlight SpecialKey', @:)
3405 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3406 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003407 set wildoptions&
3408endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003409
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003410" :history suboptions fuzzy completion
3411func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003412 set wildoptions&
3413 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3414 call assert_equal('"history dg', @:)
3415 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3416 call assert_equal('"history search', @:)
3417 set wildoptions=fuzzy
3418 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3419 call assert_equal('"history debug', @:)
3420 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3421 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003422 set wildoptions&
3423endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003424
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003425" :language locale name fuzzy completion
3426func Test_fuzzy_completion_lang()
3427 CheckUnix
3428 set wildoptions&
3429 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3430 call assert_equal('"lang psx', @:)
3431 set wildoptions=fuzzy
3432 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3433 call assert_equal('"lang POSIX', @:)
3434 set wildoptions&
3435endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003436
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003437" :mapclear buffer argument fuzzy completion
3438func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003439 set wildoptions&
3440 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3441 call assert_equal('"mapclear buf', @:)
3442 set wildoptions=fuzzy
3443 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3444 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003445 set wildoptions&
3446endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003447
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003448" map name fuzzy completion
3449func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003450 " test regex completion works
3451 set wildoptions=fuzzy
3452 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3453 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003454 nmap <plug>MyLongMap :p<CR>
3455 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3456 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3457 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3458 call assert_equal("\"nmap MLM \t", @:)
3459 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal("\"nmap <F2> one two \t", @:)
3461 " duplicate entries should be removed
3462 vmap <plug>MyLongMap :<C-U>#<CR>
3463 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3464 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3465 nunmap <plug>MyLongMap
3466 vunmap <plug>MyLongMap
3467 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3468 call assert_equal("\"nmap ABC\t", @:)
3469 " results should be sorted by best match
3470 nmap <Plug>format :
3471 nmap <Plug>goformat :
3472 nmap <Plug>TestFOrmat :
3473 nmap <Plug>fendoff :
3474 nmap <Plug>state :
3475 nmap <Plug>FendingOff :
3476 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3477 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3478 nunmap <Plug>format
3479 nunmap <Plug>goformat
3480 nunmap <Plug>TestFOrmat
3481 nunmap <Plug>fendoff
3482 nunmap <Plug>state
3483 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003484 set wildoptions&
3485endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003486
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003487" abbreviation fuzzy completion
3488func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003489 set wildoptions=fuzzy
3490 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3491 call assert_equal("\"iabbr <nowait>", @:)
3492 iabbr WaitForCompletion WFC
3493 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3494 call assert_equal("\"iabbr WaitForCompletion", @:)
3495 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3496 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003497
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003498 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003499 set wildoptions&
3500endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003501
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003502" menu name fuzzy completion
3503func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003504 CheckFeature menu
3505
3506 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003507 set wildoptions&
3508 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3509 call assert_equal('"menu pup', @:)
3510 set wildoptions=fuzzy
3511 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3512 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003513
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003514 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003515 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003516endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003517
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003518" :messages suboptions fuzzy completion
3519func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003520 set wildoptions&
3521 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3522 call assert_equal('"messages clr', @:)
3523 set wildoptions=fuzzy
3524 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003526 set wildoptions&
3527endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003528
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003529" :set option name fuzzy completion
3530func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003531 set wildoptions&
3532 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3533 call assert_equal('"set brkopt', @:)
3534 set wildoptions=fuzzy
3535 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3536 call assert_equal('"set breakindentopt', @:)
3537 set wildoptions&
3538 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3539 call assert_equal('"set fixendofline', @:)
3540 set wildoptions=fuzzy
3541 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3542 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003543 set wildoptions&
3544endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003545
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003546" :set <term_option>
3547func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003548 set wildoptions&
3549 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3550 call assert_equal('"set t_EC', @:)
3551 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal('"set <t_EC>', @:)
3553 set wildoptions=fuzzy
3554 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3555 call assert_equal('"set t_EC', @:)
3556 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3557 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003558 set wildoptions&
3559endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003560
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003561" " :packadd directory name fuzzy completion - NOT supported
3562" func Test_fuzzy_completion_packadd()
3563" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003564
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003565" " shell command name fuzzy completion - NOT supported
3566" func Test_fuzzy_completion_shellcmd()
3567" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003568
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003569" :sign suboptions fuzzy completion
3570func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003571 set wildoptions&
3572 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3573 call assert_equal('"sign ufe', @:)
3574 set wildoptions=fuzzy
3575 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3576 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003577 set wildoptions&
3578endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003579
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003580" :syntax suboptions fuzzy completion
3581func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003582 set wildoptions&
3583 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3584 call assert_equal('"syntax kwd', @:)
3585 set wildoptions=fuzzy
3586 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3587 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003588 set wildoptions&
3589endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003590
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003591" syntax group name fuzzy completion
3592func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003593 set wildoptions&
3594 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3595 call assert_equal('"syntax list mpar', @:)
3596 set wildoptions=fuzzy
3597 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3598 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003599 set wildoptions&
3600endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003601
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003602" :syntime suboptions fuzzy completion
3603func Test_fuzzy_completion_syntime()
3604 CheckFeature profile
3605 set wildoptions&
3606 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3607 call assert_equal('"syntime clr', @:)
3608 set wildoptions=fuzzy
3609 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3610 call assert_equal('"syntime clear', @:)
3611 set wildoptions&
3612endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003613
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003614" " tag name fuzzy completion - NOT supported
3615" func Test_fuzzy_completion_tagname()
3616" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003617
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003618" " tag name and file fuzzy completion - NOT supported
3619" func Test_fuzzy_completion_tagfile()
3620" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003621
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003622" " user names fuzzy completion - how to test this functionality?
3623" func Test_fuzzy_completion_username()
3624" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003625
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003626" user defined variable name fuzzy completion
3627func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003628 let g:SomeVariable=10
3629 set wildoptions&
3630 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3631 call assert_equal('"let SVar', @:)
3632 set wildoptions=fuzzy
3633 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3634 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003635 set wildoptions&
3636endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003637
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003638" Test for sorting the results by the best match
3639func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003640 %bw!
3641 command T123format :
3642 command T123goformat :
3643 command T123TestFOrmat :
3644 command T123fendoff :
3645 command T123state :
3646 command T123FendingOff :
3647 set wildoptions=fuzzy
3648 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3649 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3650 delcommand T123format
3651 delcommand T123goformat
3652 delcommand T123TestFOrmat
3653 delcommand T123fendoff
3654 delcommand T123state
3655 delcommand T123FendingOff
3656 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003657 set wildoptions&
3658endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003659
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003660" Test for fuzzy completion of a command with lower case letters and a number
3661func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003662 command Foo2Bar :
3663 set wildoptions=fuzzy
3664 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3665 call assert_equal('"Foo2Bar', @:)
3666 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3667 call assert_equal('"Foo2Bar', @:)
3668 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3669 call assert_equal('"Foo2Bar', @:)
3670 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003671 set wildoptions&
3672endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003673
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003674" Test for command completion for a command starting with 'k'
3675func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003676 command KillKillKill :
3677 set wildoptions&
3678 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3679 call assert_equal("\"killkill\<Tab>", @:)
3680 set wildoptions=fuzzy
3681 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3682 call assert_equal('"KillKillKill', @:)
3683 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003684 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003685endfunc
3686
3687" Test for fuzzy completion for user defined custom completion function
3688func Test_fuzzy_completion_custom_func()
3689 func Tcompl(a, c, p)
3690 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3691 endfunc
3692 command -nargs=* -complete=custom,Tcompl Fuzzy :
3693 set wildoptions&
3694 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3695 call assert_equal("\"Fuzzy format", @:)
3696 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3697 call assert_equal("\"Fuzzy xy", @:)
3698 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3699 call assert_equal("\"Fuzzy ttt", @:)
3700 set wildoptions=fuzzy
3701 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3702 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3703 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3704 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3705 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3706 call assert_equal("\"Fuzzy xy", @:)
3707 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3708 call assert_equal("\"Fuzzy TestFOrmat", @:)
3709 delcom Fuzzy
3710 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003711endfunc
3712
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003713" Test for fuzzy completion in the middle of a cmdline instead of at the end
3714func Test_fuzzy_completion_in_middle()
3715 set wildoptions=fuzzy
3716 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3717 call assert_equal("\"set wildchar wildcharm wrap", @:)
3718
3719 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3720 call assert_equal("\"args ++encoding= zz", @:)
3721 set wildoptions&
3722endfunc
3723
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003724" Test for :breakadd argument completion
3725func Test_cmdline_complete_breakadd()
3726 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3727 call assert_equal("\"breakadd expr file func here", @:)
3728 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3729 call assert_equal("\"breakadd expr", @:)
3730 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3731 call assert_equal("\"breakadd expr", @:)
3732 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"breakadd here", @:)
3734 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3735 call assert_equal("\"breakadd here", @:)
3736 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3737 call assert_equal("\"breakadd abc", @:)
3738 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3739 let l = getcompletion('not', 'breakpoint')
3740 call assert_equal([], l)
3741
3742 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003743 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003744 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3745 call assert_equal("\"breakadd file Xscript", @:)
3746 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3747 call assert_equal("\"breakadd file Xscript", @:)
3748 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3749 call assert_equal("\"breakadd file 20 Xscript", @:)
3750 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3751 call assert_equal("\"breakadd file 20 Xscript", @:)
3752 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3753 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3754 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3755 call assert_equal("\"breakadd file 20\t", @:)
3756 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3757 call assert_equal("\"breakadd file 20x\t", @:)
3758 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3759 call assert_equal("\"breakadd file Xscript ", @:)
3760 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3761 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003762
3763 " Test for :breakadd func [lnum] <function>
3764 func Xbreak_func()
3765 endfunc
3766 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3767 call assert_equal("\"breakadd func Xbreak_func", @:)
3768 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3769 call assert_equal("\"breakadd func Xbreak_func", @:)
3770 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3772 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3773 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3774 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3775 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3776 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3777 call assert_equal("\"breakadd func 20\t", @:)
3778 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3779 call assert_equal("\"breakadd func 20x\t", @:)
3780 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3781 call assert_equal("\"breakadd func Xbreak_func ", @:)
3782 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3783 call assert_equal("\"breakadd func X1B2C3", @:)
3784 delfunc Xbreak_func
3785
3786 " Test for :breakadd expr <expression>
3787 let g:Xtest_var = 10
3788 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3789 call assert_equal("\"breakadd expr Xtest_var", @:)
3790 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3791 call assert_equal("\"breakadd expr Xtest_var", @:)
3792 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3793 call assert_equal("\"breakadd expr Xtest_var ", @:)
3794 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3795 call assert_equal("\"breakadd expr X1B2C3", @:)
3796 unlet g:Xtest_var
3797
3798 " Test for :breakadd here
3799 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3800 call assert_equal("\"breakadd here Xtest", @:)
3801 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3802 call assert_equal("\"breakadd here Xtest", @:)
3803 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3804 call assert_equal("\"breakadd here ", @:)
3805endfunc
3806
3807" Test for :breakdel argument completion
3808func Test_cmdline_complete_breakdel()
3809 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3810 call assert_equal("\"breakdel file func here", @:)
3811 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3812 call assert_equal("\"breakdel file", @:)
3813 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3814 call assert_equal("\"breakdel file", @:)
3815 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3816 call assert_equal("\"breakdel here", @:)
3817 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3818 call assert_equal("\"breakdel here", @:)
3819 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3820 call assert_equal("\"breakdel abc", @:)
3821
3822 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003823 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003824 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3825 call assert_equal("\"breakdel file Xscript", @:)
3826 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3827 call assert_equal("\"breakdel file Xscript", @:)
3828 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3829 call assert_equal("\"breakdel file 20 Xscript", @:)
3830 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3831 call assert_equal("\"breakdel file 20 Xscript", @:)
3832 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3833 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3834 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3835 call assert_equal("\"breakdel file 20\t", @:)
3836 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3837 call assert_equal("\"breakdel file 20x\t", @:)
3838 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3839 call assert_equal("\"breakdel file Xscript ", @:)
3840 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3841 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003842
3843 " Test for :breakdel func [lnum] <function>
3844 func Xbreak_func()
3845 endfunc
3846 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3847 call assert_equal("\"breakdel func Xbreak_func", @:)
3848 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3849 call assert_equal("\"breakdel func Xbreak_func", @:)
3850 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3851 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3852 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3853 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3854 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3855 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3856 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3857 call assert_equal("\"breakdel func 20\t", @:)
3858 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3859 call assert_equal("\"breakdel func 20x\t", @:)
3860 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3861 call assert_equal("\"breakdel func Xbreak_func ", @:)
3862 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3863 call assert_equal("\"breakdel func X1B2C3", @:)
3864 delfunc Xbreak_func
3865
3866 " Test for :breakdel here
3867 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3868 call assert_equal("\"breakdel here Xtest", @:)
3869 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3870 call assert_equal("\"breakdel here Xtest", @:)
3871 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3872 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003873endfunc
3874
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003875" Test for :scriptnames argument completion
3876func Test_cmdline_complete_scriptnames()
3877 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003878 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003879 source Xa1b2c3.vim
3880 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3881 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3882 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3883 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3884 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3885 call assert_equal("\"script b2c3", @:)
3886 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3887 call assert_match("\"script 2\<Tab>$", @:)
3888 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3889 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3890 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3891 call assert_equal("\"script ", @:)
3892 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3893 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3894 new
3895 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3896 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3897 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003898 set wildmenu&
3899endfunc
3900
Bram Moolenaard8893442022-05-06 20:38:47 +01003901" this was going over the end of IObuff
3902func Test_report_error_with_composing()
3903 let caught = 'no'
3904 try
3905 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3906 catch /E492:/
3907 let caught = 'yes'
3908 endtry
3909 call assert_equal('yes', caught)
3910endfunc
3911
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003912" Test for expanding 2-letter and 3-letter :substitute command arguments.
3913" These commands don't accept an argument.
3914func Test_cmdline_complete_substitute_short()
3915 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3916 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3917 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3918 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3919 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3920 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3921 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3922 endfor
3923endfunc
3924
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003925" Test for shellcmdline command argument completion
3926func Test_cmdline_complete_shellcmdline_argument()
3927 command -nargs=+ -complete=shellcmdline MyCmd
3928
3929 set wildoptions=fuzzy
3930
3931 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3932 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003933 call assert_equal(['test_cmdline.vim'],
3934 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003935
3936 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3937 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003938 call assert_equal([],
3939 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003940
3941 let compl1 = getcompletion('', 'file')[0]
3942 let compl2 = getcompletion('', 'file')[1]
3943 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3944 call assert_equal('"MyCmd vim ' .. compl1, @:)
3945
3946 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3947 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3948
3949 let compl = getcompletion('', 'file')[1]
3950 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3951 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3952
3953 set wildoptions&
3954 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3955 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003956 call assert_equal(['test_cmdline.vim'],
3957 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003958
3959 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3960 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003961 call assert_equal([],
3962 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003963
3964 let compl1 = getcompletion('', 'file')[0]
3965 let compl2 = getcompletion('', 'file')[1]
3966 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3967 call assert_equal('"MyCmd vim ' .. compl1, @:)
3968
3969 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3970 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3971
3972 let compl = getcompletion('', 'file')[1]
3973 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3974 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3975
3976 delcommand MyCmd
3977endfunc
3978
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003979" Test for :! shell command argument completion
3980func Test_cmdline_complete_bang_cmd_argument()
3981 set wildoptions=fuzzy
3982 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3983 call assert_equal('"!vim test_cmdline.vim', @:)
3984 set wildoptions&
3985 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3986 call assert_equal('"!vim test_cmdline.vim', @:)
3987endfunc
3988
zeertzjq961b2e52023-04-17 15:53:24 +01003989func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003990 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003991endfunc
3992
3993func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003994 call assert_equal(0, getcmdpos())
3995 call assert_equal(0, getcmdscreenpos())
3996 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003997 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003998
zeertzjqa821b602024-06-18 20:31:08 +02003999 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01004000 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004001 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004002 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004003 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004004 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004005 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02004006
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004007 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4008 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02004009 let g:results = []
4010 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4011 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4012 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004013 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4014 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4015 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02004016
4017 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01004018 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004019endfunc
4020
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01004021func Test_recursive_register()
4022 let @= = ''
4023 silent! ?e/
4024 let caught = 'no'
4025 try
4026 normal //
4027 catch /E169:/
4028 let caught = 'yes'
4029 endtry
4030 call assert_equal('yes', caught)
4031endfunc
4032
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004033func Test_long_error_message()
4034 " the error should be truncated, not overrun IObuff
4035 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4036endfunc
4037
zeertzjq6791adc2022-07-26 20:42:25 +01004038func Test_cmdline_redraw_tabline()
4039 CheckRunVimInTerminal
4040
4041 let lines =<< trim END
4042 set showtabline=2
4043 autocmd CmdlineEnter * set tabline=foo
4044 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004045 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004046 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4047 call term_sendkeys(buf, ':')
4048 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4049
4050 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004051endfunc
4052
zeertzjqb82a2ab2022-08-21 14:33:57 +01004053func Test_wildmenu_pum_disable_while_shown()
4054 set wildoptions=pum
4055 set wildmenu
4056 cnoremap <F2> <Cmd>set nowildmenu<CR>
4057 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4058 call assert_equal(0, pumvisible())
4059 cunmap <F2>
4060 set wildoptions& wildmenu&
4061endfunc
4062
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004063func Test_setcmdline()
4064 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004065 call assert_equal(0, setcmdline(test_null_string()))
4066 call assert_equal('', getcmdline())
4067 call assert_equal(1, getcmdpos())
4068
4069 call assert_equal(0, setcmdline(''[: -1]))
4070 call assert_equal('', getcmdline())
4071 call assert_equal(1, getcmdpos())
4072
zeertzjq54acb902022-08-29 16:21:25 +01004073 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004074 call assert_equal(0, setcmdline(a:text))
4075 call assert_equal(a:text, getcmdline())
4076 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004077 call assert_equal(getcmdtype(), g:cmdtype)
4078 unlet g:cmdtype
4079 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004080
4081 call assert_equal(0, setcmdline(a:text, a:pos))
4082 call assert_equal(a:text, getcmdline())
4083 call assert_equal(a:pos, getcmdpos())
4084
4085 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004086 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4087 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004088
4089 return ''
4090 endfunc
4091
4092 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4093 call assert_equal('set rtp?', @:)
4094
zeertzjq54acb902022-08-29 16:21:25 +01004095 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4096 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4097 call assert_equal('foo', g:str)
4098 unlet g:str
4099
4100 delfunc SetText
4101
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004102 " setcmdline() returns 1 when not editing the command line.
4103 call assert_equal(1, 'foo'->setcmdline())
4104
4105 " Called in custom function
4106 func CustomComplete(A, L, P)
4107 call assert_equal(0, setcmdline("DoCmd "))
4108 return "January\nFebruary\nMars\n"
4109 endfunc
4110
4111 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4112 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4113 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004114 delcom DoCmd
4115 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004116
4117 " Called in <expr>
4118 cnoremap <expr>a setcmdline('let foo=')
4119 call feedkeys(":a\<CR>", 'tx')
4120 call assert_equal('let foo=0', @:)
4121 cunmap a
4122endfunc
4123
Sean Dewarfc8a6012023-04-17 16:41:20 +01004124func Test_rulerformat_position()
4125 CheckScreendump
4126
4127 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4128 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4129 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4130 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4131 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4132
4133 " clean up
4134 call StopVimInTerminal(buf)
4135endfunc
4136
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004137" Test for using "%!" in 'rulerformat' to use a function
4138func Test_rulerformat_function()
4139 CheckScreendump
4140
4141 let lines =<< trim END
4142 func TestRulerFn()
4143 return '10,20%=30%%'
4144 endfunc
4145 END
4146 call writefile(lines, 'Xrulerformat_function', 'D')
4147
4148 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4149 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4150 call term_sendkeys(buf, ":redraw!\<CR>")
4151 call term_wait(buf)
4152 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4153
4154 " clean up
4155 call StopVimInTerminal(buf)
4156endfunc
4157
zeertzjqe4c79d32023-08-15 22:41:53 +02004158func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004159 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004160
zeertzjqe4c79d32023-08-15 22:41:53 +02004161 call assert_equal(getcompletion('', 'cmdline'),
4162 \ getcompletion('TestCompletion ', 'cmdline'))
4163 call assert_equal(['<buffer>'],
4164 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4165
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004166 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004167endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004168
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004169func Test_custom_completion()
4170 func CustomComplete1(lead, line, pos)
4171 return "a\nb\nc"
4172 endfunc
4173 func CustomComplete2(lead, line, pos)
4174 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4175 endfunc
4176 func Check_custom_completion()
4177 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4178 return ''
4179 endfunc
4180 func Check_customlist_completion()
4181 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4182 return ''
4183 endfunc
4184
4185 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4186 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4187
4188 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4189 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4190
4191 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4192 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4193
zeertzjq757f3212024-04-15 19:01:04 +02004194 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4195 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4196 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004197
4198 delcom Test1
4199 delcom Test2
4200
4201 delfunc CustomComplete1
4202 delfunc CustomComplete2
4203 delfunc Check_custom_completion
4204 delfunc Check_customlist_completion
4205endfunc
4206
zeertzjq28a23602023-09-29 19:58:35 +02004207func Test_custom_completion_with_glob()
4208 func TestGlobComplete(A, L, P)
4209 return split(glob('Xglob*'), "\n")
4210 endfunc
4211
4212 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4213 call writefile([], 'Xglob1', 'D')
4214 call writefile([], 'Xglob2', 'D')
4215
4216 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4217 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4218
4219 delcommand TestGlobComplete
4220 delfunc TestGlobComplete
4221endfunc
4222
Christian Brabandt8610f742024-01-12 17:34:40 +01004223func Test_window_size_stays_same_after_changing_cmdheight()
4224 set laststatus=2
4225 let expected = winheight(0)
4226 function! Function_name() abort
4227 call feedkeys(":"..repeat('x', &columns), 'x')
4228 let &cmdheight=2
4229 let &cmdheight=1
4230 redraw
4231 endfunction
4232 call Function_name()
4233 call assert_equal(expected, winheight(0))
4234endfunc
4235
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004236" verify that buffer-completion finds all buffer names matching a pattern
4237func Test_buffer_completion()
4238 " should return empty list
4239 call assert_equal([], getcompletion('', 'buffer'))
4240
4241 call mkdir('Xbuf_complete', 'R')
4242 e Xbuf_complete/Foobar.c
4243 e Xbuf_complete/MyFoobar.c
4244 e AFoobar.h
4245 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4246
4247 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4248 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4249 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4250 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4251endfunc
4252
Anton Sharonov49528da2024-04-14 20:02:24 +02004253" :set t_??
4254func Test_term_option()
4255 set wildoptions&
4256 let _cpo = &cpo
4257 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004258 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004259 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'
4260 \ .. ' 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'
4261 \ .. ' 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'
4262 \ .. ' 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'
4263 \ .. ' 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 +02004264 \ .. ' 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 +02004265 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004266 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004267 let &cpo = _cpo
4268endfunc
4269
Christian Brabandt70a11a62024-07-26 19:13:55 +02004270func Test_ex_command_completion()
4271 " required for :*
4272 set cpo+=*
4273 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
Hirohito Higashifbe4a8f2025-04-27 15:28:30 +02004274 " :++ and :-- are only valid in Vim9 script context, so they can be ignored
Christian Brabandt70a11a62024-07-26 19:13:55 +02004275 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004276 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004277 call assert_equal(0, exists(':ke'))
4278 call assert_equal(1, exists(':kee'))
4279 call assert_equal(1, exists(':keep'))
4280 call assert_equal(1, exists(':keepm'))
4281 call assert_equal(1, exists(':keepma'))
4282 call assert_equal(1, exists(':keepmar'))
4283 call assert_equal(1, exists(':keepmark'))
4284 call assert_equal(2, exists(':keepmarks'))
4285 call assert_equal(2, exists(':keepalt'))
4286 call assert_equal(2, exists(':keepjumps'))
4287 call assert_equal(2, exists(':keeppatterns'))
4288 set cpo-=*
4289endfunc
4290
zeertzjq5df3cb22024-10-07 21:05:06 +02004291func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004292 CheckMSWindows
4293 let save_shellslash = &shellslash
4294 set noshellslash
4295 call system('mkdir XXXa\_b')
4296 defer delete('XXXa', 'rf')
4297 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4298 call assert_equal('"cd XXXa\_b\', @:)
4299 let &shellslash = save_shellslash
4300endfunc
4301
zeertzjqec270a52025-04-23 20:50:23 +02004302" Test cmdcomplete_info() with CmdlineLeavePre autocmd
Girish Palya92f68e22025-04-21 11:12:41 +02004303func Test_cmdcomplete_info()
4304 augroup test_CmdlineLeavePre
4305 autocmd!
zeertzjqec270a52025-04-23 20:50:23 +02004306 " Calling expand() should not interfere with cmdcomplete_info().
4307 autocmd CmdlineLeavePre * call expand('test_cmdline.*')
Girish Palya92f68e22025-04-21 11:12:41 +02004308 autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
4309 augroup END
4310 new
4311 call assert_equal({}, cmdcomplete_info())
4312 call feedkeys(":h echom\<cr>", "tx") " No expansion
4313 call assert_equal('{}', g:cmdcomplete_info)
4314 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4315 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4316 call feedkeys(":h echom\<tab>\<cr>", "tx")
4317 call assert_equal(
4318 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4319 \ g:cmdcomplete_info)
4320 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4321 call assert_equal(
4322 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4323 \ g:cmdcomplete_info)
4324 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4325 call assert_equal(
4326 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4327 \ g:cmdcomplete_info)
4328
4329 set wildoptions=pum
4330 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4331 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4332 call feedkeys(":h echom\<tab>\<cr>", "tx")
4333 call assert_equal(
4334 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4335 \ g:cmdcomplete_info)
4336 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4337 call assert_equal(
4338 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4339 \ g:cmdcomplete_info)
4340 call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
4341 call assert_equal(
4342 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
4343 \ g:cmdcomplete_info)
4344 bw!
4345 set wildoptions&
4346endfunc
4347
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02004348func Test_redrawtabpanel_error()
4349 CheckNotFeature tabpanel
4350 call assert_fails(':redrawtabpanel', 'E1547:')
4351endfunc
4352
Bram Moolenaar309976e2019-12-05 18:16:33 +01004353" vim: shiftwidth=2 sts=2 expandtab