blob: c4b7b5743efccb47475b43fcea98220c30732142 [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()
2640 CheckRunVimInTerminal
2641
2642 let commands =<< trim [CODE]
2643 set wildmenu
2644 set wildoptions=pum
2645 set shm+=I
2646 set noruler
2647 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002648
2649 func CmdCompl(a, b, c)
2650 return repeat(['aaaa'], 120)
2651 endfunc
2652 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002653
2654 func MyStatusLine() abort
2655 return 'status'
2656 endfunc
2657 func SetupStatusline()
2658 set statusline=%!MyStatusLine()
2659 set laststatus=2
2660 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002661
2662 func MyTabLine()
2663 return 'my tab line'
2664 endfunc
2665 func SetupTabline()
2666 set statusline=
2667 set tabline=%!MyTabLine()
2668 set showtabline=2
2669 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002670
2671 func DoFeedKeys()
2672 let &wildcharm = char2nr("\t")
2673 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2674 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002675 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002676 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002677
2678 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2679
2680 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002681 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2682
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002683 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002684 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002685 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2686
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002687 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002688 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2690
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002691 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002692 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002693 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2694
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002695 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002696 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002697 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2698
2699 " pressing <C-E> should end completion and go back to the original match
2700 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002701 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2702
2703 " pressing <C-Y> should select the current match and end completion
2704 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002705 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2706
2707 " With 'wildmode' set to 'longest,full', completing a match should display
2708 " the longest match, the wildmenu should not be displayed.
2709 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2710 call TermWait(buf)
2711 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002712 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2713
2714 " pressing <Tab> should display the wildmenu
2715 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002716 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2717
2718 " pressing <Tab> second time should select the next entry in the menu
2719 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002720 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2721
2722 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002723 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002724 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002725 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2726
2727 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002728 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2729
2730 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002731 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2732
2733 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002734 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002735 call writefile([], 'Xnamedir/XfileA')
2736 call writefile([], 'Xnamedir/XdirA/XfileB')
2737 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002738
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002739 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002740 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2741
2742 " Pressing <Right> on a directory name should go into that directory
2743 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002744 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2745
2746 " Pressing <Left> on a directory name should go to the parent directory
2747 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002748 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2749
2750 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002751 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002752 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002753 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2754
2755 " Pressing <C-D> when the popup menu is displayed should remove the popup
2756 " menu
2757 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002758 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2759
2760 " Pressing <S-Tab> should open the popup menu with the last entry selected
2761 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002762 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2763
2764 " Pressing <Esc> should close the popup menu and cancel the cmd line
2765 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002766 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2767
2768 " Typing a character when the popup is open, should close the popup
2769 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002770 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2771
2772 " When the popup is open, entering the cmdline window should close the popup
2773 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002774 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2775 call term_sendkeys(buf, ":q\<CR>")
2776
2777 " After the last popup menu item, <C-N> should show the original string
2778 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002779 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2780
2781 " Use the popup menu for the command name
2782 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002783 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2784
2785 " Pressing the left arrow should remove the popup menu
2786 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002787 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2788
2789 " Pressing <BS> should remove the popup menu and erase the last character
2790 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002791 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2792
2793 " Pressing <C-W> should remove the popup menu and erase the previous word
2794 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002795 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2796
2797 " Pressing <C-U> should remove the popup menu and erase the entire line
2798 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002799 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2800
2801 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2802 " the cmdline from history
2803 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002804 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2805
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002806 " Check "list" still works
2807 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2808 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002809 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2810 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002811 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2812
rbtnn68cc2b82022-02-09 11:55:47 +00002813 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002814 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002815 call writefile([], 'Xnamedir/あいう/abc')
2816 call writefile([], 'Xnamedir/あいう/xyz')
2817 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002818
2819 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002820 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002821 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2822
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002823 " Pressing <C-A> when the popup menu is displayed should list all the
2824 " matches and pressing a key after that should remove the popup menu
2825 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2826 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2827 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2828
2829 " Pressing <C-A> when the popup menu is displayed should list all the
2830 " matches and pressing <Left> after that should move the cursor
2831 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2832 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2833 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2834
2835 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2836 " should be displayed correctly on the screen.
2837 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2838 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2839
2840 " After using <C-A> to expand all the filename matches, pressing <Up>
2841 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002842 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002843 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2844 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2845 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2846
2847 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2848 " crash Vim
2849 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2850 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2851
Bram Moolenaar414acd32022-02-10 21:09:45 +00002852 " After removing the pum the command line is redrawn
2853 call term_sendkeys(buf, ":edit foo\<CR>")
2854 call term_sendkeys(buf, ":edit bar\<CR>")
2855 call term_sendkeys(buf, ":ls\<CR>")
2856 call term_sendkeys(buf, ":com\<Tab> ")
2857 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002858 call term_sendkeys(buf, "\<C-U>\<CR>")
2859
2860 " Esc still works to abort the command when 'statusline' is set
2861 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2862 call term_sendkeys(buf, ":si\<Tab>")
2863 call term_sendkeys(buf, "\<Esc>")
2864 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002865
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002866 " Esc still works to abort the command when 'tabline' is set
2867 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2868 call term_sendkeys(buf, ":si\<Tab>")
2869 call term_sendkeys(buf, "\<Esc>")
2870 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2871
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002872 " popup is cleared also when 'lazyredraw' is set
2873 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2874 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2875 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2876 call term_sendkeys(buf, "\<Esc>")
2877
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002878 " Pressing <PageDown> should scroll the menu downward
2879 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2880 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2881 call term_sendkeys(buf, "\<PageDown>")
2882 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2883 call term_sendkeys(buf, "\<PageDown>")
2884 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2885 call term_sendkeys(buf, "\<PageDown>")
2886 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2887 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2888 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2889
2890 " Pressing <PageUp> should scroll the menu upward
2891 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2892 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2893 call term_sendkeys(buf, "\<PageUp>")
2894 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2895 call term_sendkeys(buf, "\<PageUp>")
2896 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2897 call term_sendkeys(buf, "\<PageUp>")
2898 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2899
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002900 " pressing <C-E> to end completion should work in middle of the line too
2901 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2902 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2903 call term_sendkeys(buf, "\<C-E>")
2904 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2905
2906 " pressing <C-Y> should select the current match and end completion
2907 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2908 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2909
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002910 call term_sendkeys(buf, "\<C-U>\<CR>")
2911 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002912endfunc
2913
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002914" Test for wildmenumode() with the cmdline popup menu
2915func Test_wildmenumode_with_pum()
2916 set wildmenu
2917 set wildoptions=pum
2918 cnoremap <expr> <F2> wildmenumode()
2919 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2920 call assert_equal('"sign define10', @:)
2921 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2922 call assert_equal('"sign define jump list place undefine unplace0', @:)
2923 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2924 call assert_equal('"sign 0', @:)
2925 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2926 call assert_equal('"sign define0', @:)
2927 set nowildmenu wildoptions&
2928 cunmap <F2>
2929endfunc
2930
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002931func Test_wildmenu_with_pum_foldexpr()
2932 CheckRunVimInTerminal
2933
2934 let lines =<< trim END
2935 call setline(1, ['folded one', 'folded two', 'some more text'])
2936 func MyFoldText()
2937 return 'foo'
2938 endfunc
2939 set foldtext=MyFoldText() wildoptions=pum
2940 normal ggzfj
2941 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002942 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002943 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2944 call term_sendkeys(buf, ":set\<Tab>")
2945 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2946
2947 call term_sendkeys(buf, "\<Esc>")
2948 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2949
2950 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002951endfunc
2952
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002953" Test for opening the cmdline completion popup menu from the terminal window.
2954" The popup menu should be positioned correctly over the status line of the
2955" bottom-most window.
2956func Test_wildmenu_pum_from_terminal()
2957 CheckRunVimInTerminal
2958 let python = PythonProg()
2959 call CheckPython(python)
2960
2961 %bw!
2962 let cmds = ['set wildmenu wildoptions=pum']
2963 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2964 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002965 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002966 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2967 call term_sendkeys(buf, "\r\r\r")
2968 call term_wait(buf)
2969 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2970 call term_wait(buf)
2971 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2972 call term_wait(buf)
2973 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002974endfunc
2975
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002976func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002977 CheckRunVimInTerminal
2978
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002979 " Test odd wildchar interactions with pum. Make sure they behave properly
2980 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002981 let lines =<< trim END
2982 set wildoptions=pum
2983 set wildchar=<C-E>
2984 END
2985 call writefile(lines, 'XwildmenuTest', 'D')
2986 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2987
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002988 call term_sendkeys(buf, ":\<C-E>")
2989 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002990
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002991 " <C-E> being a wildchar takes priority over its original functionality
2992 call term_sendkeys(buf, "\<C-E>")
2993 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2994
2995 call term_sendkeys(buf, "\<Esc>")
2996 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2997
2998 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2999 " command-line, and we need to make sure to clean up properly.
3000 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
3001 call term_sendkeys(buf, ":\<Esc>")
3002 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3003
3004 call term_sendkeys(buf, "\<Esc>")
3005 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3006
3007 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3008 " and we again need to make sure we clean up properly.
3009 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3010 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3011 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3012
3013 call term_sendkeys(buf, "\<C-N>")
3014 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3015
3016 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003017endfunc
3018
zeertzjq883018f2024-06-15 15:37:11 +02003019" Test that 'rightleft' should not affect cmdline completion popup menu.
3020func Test_wildmenu_pum_rightleft()
3021 CheckFeature rightleft
3022 CheckScreendump
3023
3024 let lines =<< trim END
3025 set wildoptions=pum
3026 set rightleft
3027 END
3028 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3029 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3030
3031 call term_sendkeys(buf, ":sign \<Tab>")
3032 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3033
3034 call StopVimInTerminal(buf)
3035endfunc
3036
Girish Palya4ec46f32025-03-04 20:56:30 +01003037" Test highlighting when pattern matches non-first character of item
3038func Test_wildmenu_pum_hl_nonfirst()
3039 CheckScreendump
3040 let lines =<< trim END
3041 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3042 hi PmenuMatchSel ctermfg=6 ctermbg=7
3043 hi PmenuMatch ctermfg=4 ctermbg=225
3044 func T(a, c, p)
3045 return ["oneA", "o neBneB", "aoneC"]
3046 endfunc
3047 command -nargs=1 -complete=customlist,T MyCmd
3048 END
3049
3050 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3051 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3052
3053 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3054 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3055 call term_sendkeys(buf, "\<Esc>")
3056 call StopVimInTerminal(buf)
3057endfunc
3058
zeertzjqd8c93402024-06-17 18:25:32 +02003059" Test highlighting matched text in cmdline completion popup menu.
3060func Test_wildmenu_pum_hl_match()
3061 CheckScreendump
3062
3063 let lines =<< trim END
3064 set wildoptions=pum,fuzzy
3065 hi PmenuMatchSel ctermfg=6 ctermbg=7
3066 hi PmenuMatch ctermfg=4 ctermbg=225
3067 END
3068 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3069 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3070
3071 call term_sendkeys(buf, ":sign plc\<Tab>")
3072 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3073 call term_sendkeys(buf, "\<Tab>")
3074 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3075 call term_sendkeys(buf, "\<Tab>")
3076 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3077 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3078 call TermWait(buf)
3079 call term_sendkeys(buf, ":sign un\<Tab>")
3080 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3081 call term_sendkeys(buf, "\<Tab>")
3082 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3083 call term_sendkeys(buf, "\<Tab>")
3084 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3085 call term_sendkeys(buf, "\<Esc>")
3086
3087 call StopVimInTerminal(buf)
3088endfunc
3089
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003090" Test for completion after a :substitute command followed by a pipe (|)
3091" character
3092func Test_cmdline_complete_substitute()
3093 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3094 call assert_equal("\"s | \t", @:)
3095 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3096 call assert_equal("\"s/ | \t", @:)
3097 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3098 call assert_equal("\"s/one | \t", @:)
3099 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3100 call assert_equal("\"s/one/ | \t", @:)
3101 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3102 call assert_equal("\"s/one/two | \t", @:)
3103 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3104 call assert_equal('"s/one/two/ | chistory', @:)
3105 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3106 call assert_equal("\"s/one/two/g \t", @:)
3107 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3108 call assert_equal("\"s/one/two/g | chistory", @:)
3109 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3110 call assert_equal("\"s/one/t\\/ | \t", @:)
3111 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3112 call assert_equal('"s/one/t"o/ | chistory', @:)
3113 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3114 call assert_equal('"s/one/t|o/ | chistory', @:)
3115 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3116 call assert_equal("\"&\t", @:)
3117endfunc
3118
3119" Test for the :dlist command completion
3120func Test_cmdline_complete_dlist()
3121 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3122 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3123 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3124 call assert_equal("\"dlist 10 /pat/ \t", @:)
3125 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3126 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3127 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3128 call assert_equal("\"dlist 10 /pat\\\t", @:)
3129 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3130 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3131endfunc
3132
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003133" argument list (only for :argdel) fuzzy completion
3134func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003135 argadd change.py count.py charge.py
3136 set wildoptions&
3137 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal('"argdel cge', @:)
3139 set wildoptions=fuzzy
3140 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal('"argdel change.py charge.py', @:)
3142 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003143 set wildoptions&
3144endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003145
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003146" autocmd group name fuzzy completion
3147func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003148 set wildoptions&
3149 augroup MyFuzzyGroup
3150 augroup END
3151 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal('"augroup mfg', @:)
3153 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal('"augroup MyFuzzyGroup', @:)
3155 set wildoptions=fuzzy
3156 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3157 call assert_equal('"augroup MyFuzzyGroup', @:)
3158 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3159 call assert_equal('"augroup My*p', @:)
3160 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003161 set wildoptions&
3162endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003163
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003164" buffer name fuzzy completion
3165func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003166 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003167 " Use a long name to reduce the risk of matching a random directory name
3168 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003169 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003170 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"b SRFWL', @:)
3172 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003174 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003175 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3177 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003179 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003180 set wildoptions&
3181endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003182
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003183" buffer name (full path) fuzzy completion
3184func Test_fuzzy_completion_bufname_fullpath()
3185 CheckUnix
3186 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003187 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003188 edit Xcmd/Xstate/Xfile.js
3189 cd Xcmd/Xstate
3190 enew
3191 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal('"b CmdStateFile', @:)
3193 set wildoptions=fuzzy
3194 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3196 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003197 set wildoptions&
3198endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003199
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003200" :behave suboptions fuzzy completion
3201func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003202 set wildoptions&
3203 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal('"behave xm', @:)
3205 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal('"behave xterm', @:)
3207 set wildoptions=fuzzy
3208 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal('"behave xterm', @:)
3210 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal('"behave xt*m', @:)
3212 let g:Sline = ''
3213 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal('mswin', g:Sline)
3215 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003216 set wildoptions&
3217endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003218
Christian Brabandta3422aa2025-04-23 21:04:24 +02003219" :filetype suboptions completion
3220func Test_completion_filetypecmd()
3221 set wildoptions&
3222 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
3223 call assert_equal('"filetype indent off on plugin', @:)
3224 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
3225 call assert_equal('"filetype plugin indent off on', @:)
3226 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
3227 call assert_equal('"filetype indent off on plugin', @:)
3228 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
3229 call assert_equal('"filetype indent', @:)
3230 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
3231 call assert_equal('"filetype plugin', @:)
3232 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
3233 call assert_equal('"filetype off on', @:)
3234 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal('"filetype indent off', @:)
3236 set wildoptions&
3237endfunc
3238
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003239" " colorscheme name fuzzy completion - NOT supported
3240" func Test_fuzzy_completion_colorscheme()
3241" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003242
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003243" built-in command name fuzzy completion
3244func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003245 set wildoptions&
3246 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal('"sbwin', @:)
3248 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3249 call assert_equal('"sbrewind', @:)
3250 set wildoptions=fuzzy
3251 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal('"sbrewind', @:)
3253 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3254 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003255 set wildoptions&
3256endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003257
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003258" " compiler name fuzzy completion - NOT supported
3259" func Test_fuzzy_completion_compiler()
3260" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003261
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003262" :cscope suboptions fuzzy completion
3263func Test_fuzzy_completion_cscope()
3264 CheckFeature cscope
3265 set wildoptions&
3266 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal('"cscope ret', @:)
3268 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"cscope reset', @:)
3270 set wildoptions=fuzzy
3271 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal('"cscope reset', @:)
3273 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal('"cscope re*t', @:)
3275 set wildoptions&
3276endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003277
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003278" :diffget/:diffput buffer name fuzzy completion
3279func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003280 new SomeBuffer
3281 diffthis
3282 new OtherBuffer
3283 diffthis
3284 set wildoptions&
3285 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal('"diffget sbuf', @:)
3287 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal('"diffput sbuf', @:)
3289 set wildoptions=fuzzy
3290 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal('"diffget SomeBuffer', @:)
3292 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3293 call assert_equal('"diffput SomeBuffer', @:)
3294 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003295 set wildoptions&
3296endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003297
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003298" " directory name fuzzy completion - NOT supported
3299" func Test_fuzzy_completion_dirname()
3300" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003301
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003302" environment variable name fuzzy completion
3303func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003304 set wildoptions&
3305 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal('"echo $VUT', @:)
3307 set wildoptions=fuzzy
3308 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003310 set wildoptions&
3311endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003312
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003313" autocmd event fuzzy completion
3314func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003315 set wildoptions&
3316 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3317 call assert_equal('"autocmd BWout', @:)
3318 set wildoptions=fuzzy
3319 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003321 set wildoptions&
3322endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003323
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003324" vim expression fuzzy completion
3325func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003326 let g:PerPlaceCount = 10
3327 set wildoptions&
3328 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3329 call assert_equal('"let c = ppc', @:)
3330 set wildoptions=fuzzy
3331 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003333 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003334endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003335
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003336" " file name fuzzy completion - NOT supported
3337" func Test_fuzzy_completion_filename()
3338" endfunc
3339
3340" " files in path fuzzy completion - NOT supported
3341" func Test_fuzzy_completion_filesinpath()
3342" endfunc
3343
3344" " filetype name fuzzy completion - NOT supported
3345" func Test_fuzzy_completion_filetype()
3346" endfunc
3347
3348" user defined function name completion
3349func Test_fuzzy_completion_userdefined_func()
3350 set wildoptions&
3351 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3352 call assert_equal('"call Test_f_u_f', @:)
3353 set wildoptions=fuzzy
3354 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3355 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3356 set wildoptions&
3357endfunc
3358
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003359" <SNR> functions should be sorted to the end
3360func Test_fuzzy_completion_userdefined_snr_func()
3361 func s:Sendmail()
3362 endfunc
3363 func SendSomemail()
3364 endfunc
3365 func S1e2n3dmail()
3366 endfunc
3367 set wildoptions=fuzzy
3368 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003369 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003370 set wildoptions&
3371 delfunc s:Sendmail
3372 delfunc SendSomemail
3373 delfunc S1e2n3dmail
3374endfunc
3375
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003376" user defined command name completion
3377func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003378 set wildoptions&
3379 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3380 call assert_equal('"MsFeat', @:)
3381 set wildoptions=fuzzy
3382 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3383 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003384 set wildoptions&
3385endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003386
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003387" " :help tag fuzzy completion - NOT supported
3388" func Test_fuzzy_completion_helptag()
3389" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003390
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003391" highlight group name fuzzy completion
3392func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003393 set wildoptions&
3394 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3395 call assert_equal('"highlight SKey', @:)
3396 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3397 call assert_equal('"highlight SpecialKey', @:)
3398 set wildoptions=fuzzy
3399 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3400 call assert_equal('"highlight SpecialKey', @:)
3401 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003403 set wildoptions&
3404endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003405
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003406" :history suboptions fuzzy completion
3407func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003408 set wildoptions&
3409 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3410 call assert_equal('"history dg', @:)
3411 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3412 call assert_equal('"history search', @:)
3413 set wildoptions=fuzzy
3414 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3415 call assert_equal('"history debug', @:)
3416 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3417 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003418 set wildoptions&
3419endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003420
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003421" :language locale name fuzzy completion
3422func Test_fuzzy_completion_lang()
3423 CheckUnix
3424 set wildoptions&
3425 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3426 call assert_equal('"lang psx', @:)
3427 set wildoptions=fuzzy
3428 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal('"lang POSIX', @:)
3430 set wildoptions&
3431endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003432
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003433" :mapclear buffer argument fuzzy completion
3434func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003435 set wildoptions&
3436 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3437 call assert_equal('"mapclear buf', @:)
3438 set wildoptions=fuzzy
3439 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3440 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003441 set wildoptions&
3442endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003443
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003444" map name fuzzy completion
3445func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003446 " test regex completion works
3447 set wildoptions=fuzzy
3448 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3449 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003450 nmap <plug>MyLongMap :p<CR>
3451 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3452 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3453 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3454 call assert_equal("\"nmap MLM \t", @:)
3455 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3456 call assert_equal("\"nmap <F2> one two \t", @:)
3457 " duplicate entries should be removed
3458 vmap <plug>MyLongMap :<C-U>#<CR>
3459 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3461 nunmap <plug>MyLongMap
3462 vunmap <plug>MyLongMap
3463 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3464 call assert_equal("\"nmap ABC\t", @:)
3465 " results should be sorted by best match
3466 nmap <Plug>format :
3467 nmap <Plug>goformat :
3468 nmap <Plug>TestFOrmat :
3469 nmap <Plug>fendoff :
3470 nmap <Plug>state :
3471 nmap <Plug>FendingOff :
3472 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3473 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3474 nunmap <Plug>format
3475 nunmap <Plug>goformat
3476 nunmap <Plug>TestFOrmat
3477 nunmap <Plug>fendoff
3478 nunmap <Plug>state
3479 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003480 set wildoptions&
3481endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003482
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003483" abbreviation fuzzy completion
3484func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003485 set wildoptions=fuzzy
3486 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3487 call assert_equal("\"iabbr <nowait>", @:)
3488 iabbr WaitForCompletion WFC
3489 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal("\"iabbr WaitForCompletion", @:)
3491 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3492 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003493
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003494 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003495 set wildoptions&
3496endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003497
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003498" menu name fuzzy completion
3499func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003500 CheckFeature menu
3501
3502 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003503 set wildoptions&
3504 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3505 call assert_equal('"menu pup', @:)
3506 set wildoptions=fuzzy
3507 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3508 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003509
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003510 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003511 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003512endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003513
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003514" :messages suboptions fuzzy completion
3515func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003516 set wildoptions&
3517 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3518 call assert_equal('"messages clr', @:)
3519 set wildoptions=fuzzy
3520 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3521 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003522 set wildoptions&
3523endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003524
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003525" :set option name fuzzy completion
3526func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003527 set wildoptions&
3528 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3529 call assert_equal('"set brkopt', @:)
3530 set wildoptions=fuzzy
3531 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3532 call assert_equal('"set breakindentopt', @:)
3533 set wildoptions&
3534 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3535 call assert_equal('"set fixendofline', @:)
3536 set wildoptions=fuzzy
3537 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3538 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003539 set wildoptions&
3540endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003541
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003542" :set <term_option>
3543func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003544 set wildoptions&
3545 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3546 call assert_equal('"set t_EC', @:)
3547 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3548 call assert_equal('"set <t_EC>', @:)
3549 set wildoptions=fuzzy
3550 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3551 call assert_equal('"set t_EC', @:)
3552 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3553 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003554 set wildoptions&
3555endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003556
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003557" " :packadd directory name fuzzy completion - NOT supported
3558" func Test_fuzzy_completion_packadd()
3559" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003560
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003561" " shell command name fuzzy completion - NOT supported
3562" func Test_fuzzy_completion_shellcmd()
3563" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003564
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003565" :sign suboptions fuzzy completion
3566func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003567 set wildoptions&
3568 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3569 call assert_equal('"sign ufe', @:)
3570 set wildoptions=fuzzy
3571 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003573 set wildoptions&
3574endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003575
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003576" :syntax suboptions fuzzy completion
3577func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003578 set wildoptions&
3579 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3580 call assert_equal('"syntax kwd', @:)
3581 set wildoptions=fuzzy
3582 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3583 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003584 set wildoptions&
3585endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003586
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003587" syntax group name fuzzy completion
3588func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003589 set wildoptions&
3590 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3591 call assert_equal('"syntax list mpar', @:)
3592 set wildoptions=fuzzy
3593 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3594 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003595 set wildoptions&
3596endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003597
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003598" :syntime suboptions fuzzy completion
3599func Test_fuzzy_completion_syntime()
3600 CheckFeature profile
3601 set wildoptions&
3602 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal('"syntime clr', @:)
3604 set wildoptions=fuzzy
3605 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3606 call assert_equal('"syntime clear', @:)
3607 set wildoptions&
3608endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003609
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003610" " tag name fuzzy completion - NOT supported
3611" func Test_fuzzy_completion_tagname()
3612" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003613
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003614" " tag name and file fuzzy completion - NOT supported
3615" func Test_fuzzy_completion_tagfile()
3616" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003617
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003618" " user names fuzzy completion - how to test this functionality?
3619" func Test_fuzzy_completion_username()
3620" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003621
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003622" user defined variable name fuzzy completion
3623func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003624 let g:SomeVariable=10
3625 set wildoptions&
3626 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3627 call assert_equal('"let SVar', @:)
3628 set wildoptions=fuzzy
3629 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3630 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003631 set wildoptions&
3632endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003633
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003634" Test for sorting the results by the best match
3635func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003636 %bw!
3637 command T123format :
3638 command T123goformat :
3639 command T123TestFOrmat :
3640 command T123fendoff :
3641 command T123state :
3642 command T123FendingOff :
3643 set wildoptions=fuzzy
3644 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3645 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3646 delcommand T123format
3647 delcommand T123goformat
3648 delcommand T123TestFOrmat
3649 delcommand T123fendoff
3650 delcommand T123state
3651 delcommand T123FendingOff
3652 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003653 set wildoptions&
3654endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003655
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003656" Test for fuzzy completion of a command with lower case letters and a number
3657func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003658 command Foo2Bar :
3659 set wildoptions=fuzzy
3660 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3661 call assert_equal('"Foo2Bar', @:)
3662 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3663 call assert_equal('"Foo2Bar', @:)
3664 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3665 call assert_equal('"Foo2Bar', @:)
3666 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003667 set wildoptions&
3668endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003669
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003670" Test for command completion for a command starting with 'k'
3671func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003672 command KillKillKill :
3673 set wildoptions&
3674 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3675 call assert_equal("\"killkill\<Tab>", @:)
3676 set wildoptions=fuzzy
3677 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3678 call assert_equal('"KillKillKill', @:)
3679 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003680 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003681endfunc
3682
3683" Test for fuzzy completion for user defined custom completion function
3684func Test_fuzzy_completion_custom_func()
3685 func Tcompl(a, c, p)
3686 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3687 endfunc
3688 command -nargs=* -complete=custom,Tcompl Fuzzy :
3689 set wildoptions&
3690 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3691 call assert_equal("\"Fuzzy format", @:)
3692 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3693 call assert_equal("\"Fuzzy xy", @:)
3694 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3695 call assert_equal("\"Fuzzy ttt", @:)
3696 set wildoptions=fuzzy
3697 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3698 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3699 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3700 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3701 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3702 call assert_equal("\"Fuzzy xy", @:)
3703 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3704 call assert_equal("\"Fuzzy TestFOrmat", @:)
3705 delcom Fuzzy
3706 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003707endfunc
3708
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003709" Test for fuzzy completion in the middle of a cmdline instead of at the end
3710func Test_fuzzy_completion_in_middle()
3711 set wildoptions=fuzzy
3712 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3713 call assert_equal("\"set wildchar wildcharm wrap", @:)
3714
3715 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3716 call assert_equal("\"args ++encoding= zz", @:)
3717 set wildoptions&
3718endfunc
3719
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003720" Test for :breakadd argument completion
3721func Test_cmdline_complete_breakadd()
3722 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3723 call assert_equal("\"breakadd expr file func here", @:)
3724 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3725 call assert_equal("\"breakadd expr", @:)
3726 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3727 call assert_equal("\"breakadd expr", @:)
3728 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3729 call assert_equal("\"breakadd here", @:)
3730 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3731 call assert_equal("\"breakadd here", @:)
3732 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3733 call assert_equal("\"breakadd abc", @:)
3734 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3735 let l = getcompletion('not', 'breakpoint')
3736 call assert_equal([], l)
3737
3738 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003739 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003740 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3741 call assert_equal("\"breakadd file Xscript", @:)
3742 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3743 call assert_equal("\"breakadd file Xscript", @:)
3744 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3745 call assert_equal("\"breakadd file 20 Xscript", @:)
3746 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3747 call assert_equal("\"breakadd file 20 Xscript", @:)
3748 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3749 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3750 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3751 call assert_equal("\"breakadd file 20\t", @:)
3752 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3753 call assert_equal("\"breakadd file 20x\t", @:)
3754 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3755 call assert_equal("\"breakadd file Xscript ", @:)
3756 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3757 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003758
3759 " Test for :breakadd func [lnum] <function>
3760 func Xbreak_func()
3761 endfunc
3762 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3763 call assert_equal("\"breakadd func Xbreak_func", @:)
3764 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3765 call assert_equal("\"breakadd func Xbreak_func", @:)
3766 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3767 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3768 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3769 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3770 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3772 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3773 call assert_equal("\"breakadd func 20\t", @:)
3774 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3775 call assert_equal("\"breakadd func 20x\t", @:)
3776 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3777 call assert_equal("\"breakadd func Xbreak_func ", @:)
3778 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3779 call assert_equal("\"breakadd func X1B2C3", @:)
3780 delfunc Xbreak_func
3781
3782 " Test for :breakadd expr <expression>
3783 let g:Xtest_var = 10
3784 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3785 call assert_equal("\"breakadd expr Xtest_var", @:)
3786 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3787 call assert_equal("\"breakadd expr Xtest_var", @:)
3788 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3789 call assert_equal("\"breakadd expr Xtest_var ", @:)
3790 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3791 call assert_equal("\"breakadd expr X1B2C3", @:)
3792 unlet g:Xtest_var
3793
3794 " Test for :breakadd here
3795 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3796 call assert_equal("\"breakadd here Xtest", @:)
3797 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3798 call assert_equal("\"breakadd here Xtest", @:)
3799 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3800 call assert_equal("\"breakadd here ", @:)
3801endfunc
3802
3803" Test for :breakdel argument completion
3804func Test_cmdline_complete_breakdel()
3805 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3806 call assert_equal("\"breakdel file func here", @:)
3807 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3808 call assert_equal("\"breakdel file", @:)
3809 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3810 call assert_equal("\"breakdel file", @:)
3811 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3812 call assert_equal("\"breakdel here", @:)
3813 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3814 call assert_equal("\"breakdel here", @:)
3815 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3816 call assert_equal("\"breakdel abc", @:)
3817
3818 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003819 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003820 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3821 call assert_equal("\"breakdel file Xscript", @:)
3822 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3823 call assert_equal("\"breakdel file Xscript", @:)
3824 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3825 call assert_equal("\"breakdel file 20 Xscript", @:)
3826 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3827 call assert_equal("\"breakdel file 20 Xscript", @:)
3828 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3829 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3830 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3831 call assert_equal("\"breakdel file 20\t", @:)
3832 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3833 call assert_equal("\"breakdel file 20x\t", @:)
3834 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3835 call assert_equal("\"breakdel file Xscript ", @:)
3836 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3837 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003838
3839 " Test for :breakdel func [lnum] <function>
3840 func Xbreak_func()
3841 endfunc
3842 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3843 call assert_equal("\"breakdel func Xbreak_func", @:)
3844 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3845 call assert_equal("\"breakdel func Xbreak_func", @:)
3846 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3847 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3848 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3849 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3850 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3851 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3852 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3853 call assert_equal("\"breakdel func 20\t", @:)
3854 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3855 call assert_equal("\"breakdel func 20x\t", @:)
3856 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3857 call assert_equal("\"breakdel func Xbreak_func ", @:)
3858 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3859 call assert_equal("\"breakdel func X1B2C3", @:)
3860 delfunc Xbreak_func
3861
3862 " Test for :breakdel here
3863 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3864 call assert_equal("\"breakdel here Xtest", @:)
3865 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3866 call assert_equal("\"breakdel here Xtest", @:)
3867 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3868 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003869endfunc
3870
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003871" Test for :scriptnames argument completion
3872func Test_cmdline_complete_scriptnames()
3873 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003874 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003875 source Xa1b2c3.vim
3876 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3877 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3878 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3879 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3880 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3881 call assert_equal("\"script b2c3", @:)
3882 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3883 call assert_match("\"script 2\<Tab>$", @:)
3884 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3885 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3886 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3887 call assert_equal("\"script ", @:)
3888 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3889 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3890 new
3891 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3892 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3893 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003894 set wildmenu&
3895endfunc
3896
Bram Moolenaard8893442022-05-06 20:38:47 +01003897" this was going over the end of IObuff
3898func Test_report_error_with_composing()
3899 let caught = 'no'
3900 try
3901 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3902 catch /E492:/
3903 let caught = 'yes'
3904 endtry
3905 call assert_equal('yes', caught)
3906endfunc
3907
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003908" Test for expanding 2-letter and 3-letter :substitute command arguments.
3909" These commands don't accept an argument.
3910func Test_cmdline_complete_substitute_short()
3911 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3912 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3913 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3914 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3915 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3916 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3917 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3918 endfor
3919endfunc
3920
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003921" Test for shellcmdline command argument completion
3922func Test_cmdline_complete_shellcmdline_argument()
3923 command -nargs=+ -complete=shellcmdline MyCmd
3924
3925 set wildoptions=fuzzy
3926
3927 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3928 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003929 call assert_equal(['test_cmdline.vim'],
3930 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003931
3932 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3933 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003934 call assert_equal([],
3935 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003936
3937 let compl1 = getcompletion('', 'file')[0]
3938 let compl2 = getcompletion('', 'file')[1]
3939 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3940 call assert_equal('"MyCmd vim ' .. compl1, @:)
3941
3942 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3943 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3944
3945 let compl = getcompletion('', 'file')[1]
3946 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3947 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3948
3949 set wildoptions&
3950 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3951 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003952 call assert_equal(['test_cmdline.vim'],
3953 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003954
3955 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3956 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003957 call assert_equal([],
3958 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003959
3960 let compl1 = getcompletion('', 'file')[0]
3961 let compl2 = getcompletion('', 'file')[1]
3962 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3963 call assert_equal('"MyCmd vim ' .. compl1, @:)
3964
3965 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3966 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3967
3968 let compl = getcompletion('', 'file')[1]
3969 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3970 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3971
3972 delcommand MyCmd
3973endfunc
3974
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003975" Test for :! shell command argument completion
3976func Test_cmdline_complete_bang_cmd_argument()
3977 set wildoptions=fuzzy
3978 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3979 call assert_equal('"!vim test_cmdline.vim', @:)
3980 set wildoptions&
3981 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3982 call assert_equal('"!vim test_cmdline.vim', @:)
3983endfunc
3984
zeertzjq961b2e52023-04-17 15:53:24 +01003985func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003986 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003987endfunc
3988
3989func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003990 call assert_equal(0, getcmdpos())
3991 call assert_equal(0, getcmdscreenpos())
3992 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003993 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003994
zeertzjqa821b602024-06-18 20:31:08 +02003995 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003996 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003997 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003998 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003999 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01004000 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004001 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02004002
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004003 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
4004 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02004005 let g:results = []
4006 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
4007 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
4008 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004009 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
4010 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
4011 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02004012
4013 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01004014 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004015endfunc
4016
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01004017func Test_recursive_register()
4018 let @= = ''
4019 silent! ?e/
4020 let caught = 'no'
4021 try
4022 normal //
4023 catch /E169:/
4024 let caught = 'yes'
4025 endtry
4026 call assert_equal('yes', caught)
4027endfunc
4028
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004029func Test_long_error_message()
4030 " the error should be truncated, not overrun IObuff
4031 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4032endfunc
4033
zeertzjq6791adc2022-07-26 20:42:25 +01004034func Test_cmdline_redraw_tabline()
4035 CheckRunVimInTerminal
4036
4037 let lines =<< trim END
4038 set showtabline=2
4039 autocmd CmdlineEnter * set tabline=foo
4040 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004041 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004042 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4043 call term_sendkeys(buf, ':')
4044 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4045
4046 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004047endfunc
4048
zeertzjqb82a2ab2022-08-21 14:33:57 +01004049func Test_wildmenu_pum_disable_while_shown()
4050 set wildoptions=pum
4051 set wildmenu
4052 cnoremap <F2> <Cmd>set nowildmenu<CR>
4053 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4054 call assert_equal(0, pumvisible())
4055 cunmap <F2>
4056 set wildoptions& wildmenu&
4057endfunc
4058
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004059func Test_setcmdline()
4060 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004061 call assert_equal(0, setcmdline(test_null_string()))
4062 call assert_equal('', getcmdline())
4063 call assert_equal(1, getcmdpos())
4064
4065 call assert_equal(0, setcmdline(''[: -1]))
4066 call assert_equal('', getcmdline())
4067 call assert_equal(1, getcmdpos())
4068
zeertzjq54acb902022-08-29 16:21:25 +01004069 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004070 call assert_equal(0, setcmdline(a:text))
4071 call assert_equal(a:text, getcmdline())
4072 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004073 call assert_equal(getcmdtype(), g:cmdtype)
4074 unlet g:cmdtype
4075 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004076
4077 call assert_equal(0, setcmdline(a:text, a:pos))
4078 call assert_equal(a:text, getcmdline())
4079 call assert_equal(a:pos, getcmdpos())
4080
4081 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004082 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4083 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004084
4085 return ''
4086 endfunc
4087
4088 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4089 call assert_equal('set rtp?', @:)
4090
zeertzjq54acb902022-08-29 16:21:25 +01004091 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4092 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4093 call assert_equal('foo', g:str)
4094 unlet g:str
4095
4096 delfunc SetText
4097
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004098 " setcmdline() returns 1 when not editing the command line.
4099 call assert_equal(1, 'foo'->setcmdline())
4100
4101 " Called in custom function
4102 func CustomComplete(A, L, P)
4103 call assert_equal(0, setcmdline("DoCmd "))
4104 return "January\nFebruary\nMars\n"
4105 endfunc
4106
4107 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4108 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4109 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004110 delcom DoCmd
4111 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004112
4113 " Called in <expr>
4114 cnoremap <expr>a setcmdline('let foo=')
4115 call feedkeys(":a\<CR>", 'tx')
4116 call assert_equal('let foo=0', @:)
4117 cunmap a
4118endfunc
4119
Sean Dewarfc8a6012023-04-17 16:41:20 +01004120func Test_rulerformat_position()
4121 CheckScreendump
4122
4123 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4124 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4125 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4126 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4127 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4128
4129 " clean up
4130 call StopVimInTerminal(buf)
4131endfunc
4132
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004133" Test for using "%!" in 'rulerformat' to use a function
4134func Test_rulerformat_function()
4135 CheckScreendump
4136
4137 let lines =<< trim END
4138 func TestRulerFn()
4139 return '10,20%=30%%'
4140 endfunc
4141 END
4142 call writefile(lines, 'Xrulerformat_function', 'D')
4143
4144 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4145 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4146 call term_sendkeys(buf, ":redraw!\<CR>")
4147 call term_wait(buf)
4148 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4149
4150 " clean up
4151 call StopVimInTerminal(buf)
4152endfunc
4153
zeertzjqe4c79d32023-08-15 22:41:53 +02004154func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004155 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004156
zeertzjqe4c79d32023-08-15 22:41:53 +02004157 call assert_equal(getcompletion('', 'cmdline'),
4158 \ getcompletion('TestCompletion ', 'cmdline'))
4159 call assert_equal(['<buffer>'],
4160 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4161
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004162 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004163endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004164
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004165func Test_custom_completion()
4166 func CustomComplete1(lead, line, pos)
4167 return "a\nb\nc"
4168 endfunc
4169 func CustomComplete2(lead, line, pos)
4170 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4171 endfunc
4172 func Check_custom_completion()
4173 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4174 return ''
4175 endfunc
4176 func Check_customlist_completion()
4177 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4178 return ''
4179 endfunc
4180
4181 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4182 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4183
4184 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4185 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4186
4187 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4188 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4189
zeertzjq757f3212024-04-15 19:01:04 +02004190 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4191 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4192 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004193
4194 delcom Test1
4195 delcom Test2
4196
4197 delfunc CustomComplete1
4198 delfunc CustomComplete2
4199 delfunc Check_custom_completion
4200 delfunc Check_customlist_completion
4201endfunc
4202
zeertzjq28a23602023-09-29 19:58:35 +02004203func Test_custom_completion_with_glob()
4204 func TestGlobComplete(A, L, P)
4205 return split(glob('Xglob*'), "\n")
4206 endfunc
4207
4208 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4209 call writefile([], 'Xglob1', 'D')
4210 call writefile([], 'Xglob2', 'D')
4211
4212 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4213 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4214
4215 delcommand TestGlobComplete
4216 delfunc TestGlobComplete
4217endfunc
4218
Christian Brabandt8610f742024-01-12 17:34:40 +01004219func Test_window_size_stays_same_after_changing_cmdheight()
4220 set laststatus=2
4221 let expected = winheight(0)
4222 function! Function_name() abort
4223 call feedkeys(":"..repeat('x', &columns), 'x')
4224 let &cmdheight=2
4225 let &cmdheight=1
4226 redraw
4227 endfunction
4228 call Function_name()
4229 call assert_equal(expected, winheight(0))
4230endfunc
4231
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004232" verify that buffer-completion finds all buffer names matching a pattern
4233func Test_buffer_completion()
4234 " should return empty list
4235 call assert_equal([], getcompletion('', 'buffer'))
4236
4237 call mkdir('Xbuf_complete', 'R')
4238 e Xbuf_complete/Foobar.c
4239 e Xbuf_complete/MyFoobar.c
4240 e AFoobar.h
4241 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4242
4243 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4244 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4245 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4246 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4247endfunc
4248
Anton Sharonov49528da2024-04-14 20:02:24 +02004249" :set t_??
4250func Test_term_option()
4251 set wildoptions&
4252 let _cpo = &cpo
4253 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004254 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004255 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'
4256 \ .. ' 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'
4257 \ .. ' 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'
4258 \ .. ' 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'
4259 \ .. ' 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 +02004260 \ .. ' 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 +02004261 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004262 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004263 let &cpo = _cpo
4264endfunc
4265
Christian Brabandt70a11a62024-07-26 19:13:55 +02004266func Test_ex_command_completion()
4267 " required for :*
4268 set cpo+=*
4269 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4270 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4271 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004272 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004273 call assert_equal(0, exists(':ke'))
4274 call assert_equal(1, exists(':kee'))
4275 call assert_equal(1, exists(':keep'))
4276 call assert_equal(1, exists(':keepm'))
4277 call assert_equal(1, exists(':keepma'))
4278 call assert_equal(1, exists(':keepmar'))
4279 call assert_equal(1, exists(':keepmark'))
4280 call assert_equal(2, exists(':keepmarks'))
4281 call assert_equal(2, exists(':keepalt'))
4282 call assert_equal(2, exists(':keepjumps'))
4283 call assert_equal(2, exists(':keeppatterns'))
4284 set cpo-=*
4285endfunc
4286
zeertzjq5df3cb22024-10-07 21:05:06 +02004287func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004288 CheckMSWindows
4289 let save_shellslash = &shellslash
4290 set noshellslash
4291 call system('mkdir XXXa\_b')
4292 defer delete('XXXa', 'rf')
4293 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4294 call assert_equal('"cd XXXa\_b\', @:)
4295 let &shellslash = save_shellslash
4296endfunc
4297
zeertzjqec270a52025-04-23 20:50:23 +02004298" Test cmdcomplete_info() with CmdlineLeavePre autocmd
Girish Palya92f68e22025-04-21 11:12:41 +02004299func Test_cmdcomplete_info()
4300 augroup test_CmdlineLeavePre
4301 autocmd!
zeertzjqec270a52025-04-23 20:50:23 +02004302 " Calling expand() should not interfere with cmdcomplete_info().
4303 autocmd CmdlineLeavePre * call expand('test_cmdline.*')
Girish Palya92f68e22025-04-21 11:12:41 +02004304 autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
4305 augroup END
4306 new
4307 call assert_equal({}, cmdcomplete_info())
4308 call feedkeys(":h echom\<cr>", "tx") " No expansion
4309 call assert_equal('{}', g:cmdcomplete_info)
4310 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4311 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4312 call feedkeys(":h echom\<tab>\<cr>", "tx")
4313 call assert_equal(
4314 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4315 \ g:cmdcomplete_info)
4316 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4317 call assert_equal(
4318 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4319 \ g:cmdcomplete_info)
4320 call feedkeys(":h echom\<tab>\<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
4325 set wildoptions=pum
4326 call feedkeys(":h echoms\<tab>\<cr>", "tx")
4327 call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4328 call feedkeys(":h echom\<tab>\<cr>", "tx")
4329 call assert_equal(
4330 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
4331 \ g:cmdcomplete_info)
4332 call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
4333 call assert_equal(
4334 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
4335 \ g:cmdcomplete_info)
4336 call feedkeys(":h echom\<tab>\<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 bw!
4341 set wildoptions&
4342endfunc
4343
Bram Moolenaar309976e2019-12-05 18:16:33 +01004344" vim: shiftwidth=2 sts=2 expandtab