blob: 57b57cb8d17001d219894cb3586e2dcb3bb7c3d0 [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
687 let l = getcompletion('tag', 'function')
688 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200689 let l = getcompletion('paint', 'function')
690 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200691
Kota Kato90c23532023-01-18 15:27:38 +0000692 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000693 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000694 let l = getcompletion('ruby', 'function')
695 call assert_equal([], l)
696 endif
697
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200698 let Flambda = {-> 'hello'}
699 let l = getcompletion('', 'function')
700 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200701 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200702
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200703 let l = getcompletion('run', 'file')
704 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200705 let l = getcompletion('walk', 'file')
706 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200707 set wildignore=*.vim
708 let l = getcompletion('run', 'file', 1)
709 call assert_true(index(l, 'runtest.vim') < 0)
710 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000711 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100712 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000713 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
714 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200715
716 let l = getcompletion('ha', 'filetype')
717 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200718 let l = getcompletion('horse', 'filetype')
719 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200720
Doug Kearns81642d92024-01-04 22:37:44 +0100721 if has('keymap')
722 let l = getcompletion('acc', 'keymap')
723 call assert_true(index(l, 'accents') >= 0)
724 let l = getcompletion('nullkeymap', 'keymap')
725 call assert_equal([], l)
726 endif
727
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200728 let l = getcompletion('z', 'syntax')
729 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200730 let l = getcompletion('emacs', 'syntax')
731 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200732
733 let l = getcompletion('jikes', 'compiler')
734 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200735 let l = getcompletion('break', 'compiler')
736 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200737
738 let l = getcompletion('last', 'help')
739 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200740 let l = getcompletion('giveup', 'help')
741 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200742
743 let l = getcompletion('time', 'option')
744 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200745 let l = getcompletion('space', 'option')
746 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200747
748 let l = getcompletion('er', 'highlight')
749 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200750 let l = getcompletion('dark', 'highlight')
751 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200752
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200753 let l = getcompletion('', 'messages')
754 call assert_true(index(l, 'clear') >= 0)
755 let l = getcompletion('not', 'messages')
756 call assert_equal([], l)
757
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200758 let l = getcompletion('', 'mapclear')
759 call assert_true(index(l, '<buffer>') >= 0)
760 let l = getcompletion('not', 'mapclear')
761 call assert_equal([], l)
762
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200763 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200764 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200765 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
766 let root = has('win32') ? 'C:\\' : '/'
767 let l = getcompletion(root, 'shellcmd')
768 let expected = map(filter(glob(root . '*', 0, 1),
769 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
770 call assert_equal(expected, l)
771
Bram Moolenaarb650b982016-08-05 20:35:13 +0200772 if has('cscope')
773 let l = getcompletion('', 'cscope')
774 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
775 call assert_equal(cmds, l)
776 " using cmdline completion must not change the result
777 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
778 let l = getcompletion('', 'cscope')
779 call assert_equal(cmds, l)
780 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
781 let l = getcompletion('find ', 'cscope')
782 call assert_equal(keys, l)
783 endif
784
Bram Moolenaar7522f692016-08-06 14:12:50 +0200785 if has('signs')
786 sign define Testing linehl=Comment
787 let l = getcompletion('', 'sign')
788 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
789 call assert_equal(cmds, l)
790 " using cmdline completion must not change the result
791 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
792 let l = getcompletion('', 'sign')
793 call assert_equal(cmds, l)
794 let l = getcompletion('list ', 'sign')
795 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000796 let l = getcompletion('de*', 'sign')
797 call assert_equal(['define'], l)
798 let l = getcompletion('p?', 'sign')
799 call assert_equal(['place'], l)
800 let l = getcompletion('j.', 'sign')
801 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200802 endif
803
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200804 " Command line completion tests
805 let l = getcompletion('cd ', 'cmdline')
806 call assert_true(index(l, 'samples/') >= 0)
807 let l = getcompletion('cd NoMatch', 'cmdline')
808 call assert_equal([], l)
809 let l = getcompletion('let v:n', 'cmdline')
810 call assert_true(index(l, 'v:null') >= 0)
811 let l = getcompletion('let v:notexists', 'cmdline')
812 call assert_equal([], l)
813 let l = getcompletion('call tag', 'cmdline')
814 call assert_true(index(l, 'taglist(') >= 0)
815 let l = getcompletion('call paint', 'cmdline')
816 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200817 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
818 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200819
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100820 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000821 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100822 return "oneA\noneB\noneC"
823 endfunc
824 command -nargs=1 -complete=custom,T MyCmd
825 let l = getcompletion('MyCmd ', 'cmdline')
826 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000827 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100828
829 delcommand MyCmd
830 delfunc T
ii144785fe02021-11-21 12:13:56 +0000831 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100832
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200833 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200834 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
835 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200836 if has('cmdline_hist')
837 call add(names, 'history')
838 endif
839 if has('gettext')
840 call add(names, 'locale')
841 endif
842 if has('profile')
843 call add(names, 'syntime')
844 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200845
846 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100847 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200848
849 for name in names
850 let matchcount = len(getcompletion('', name))
851 call assert_true(matchcount >= 0, 'No matches for ' . name)
852 endfor
853
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200854 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200855
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000856 edit a~b
857 enew
858 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
859 bw a~b
860
861 if has('unix')
862 edit Xtest\
863 enew
864 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
865 bw Xtest\
866 endif
867
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100868 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200869 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100870 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200871endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200872
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000873func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000874 " Get a dialog in the GUI
875 CheckNotGui
876
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000877 " This was using uninitialized memory.
878 let lines =<< trim END
879 set verbose=6
880 norm @=ٷ
881 qall!
882 END
883 call writefile(lines, 'XmultiScript', 'D')
884 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
885endfunc
886
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000887" Test for getcompletion() with "fuzzy" in 'wildoptions'
888func Test_getcompletion_wildoptions()
889 let save_wildoptions = &wildoptions
890 set wildoptions&
891 let l = getcompletion('space', 'option')
892 call assert_equal([], l)
893 let l = getcompletion('ier', 'command')
894 call assert_equal([], l)
895 set wildoptions=fuzzy
896 let l = getcompletion('space', 'option')
897 call assert_true(index(l, 'backspace') >= 0)
898 let l = getcompletion('ier', 'command')
899 call assert_true(index(l, 'compiler') >= 0)
900 let &wildoptions = save_wildoptions
901endfunc
902
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000903func Test_complete_autoload_error()
904 let save_rtp = &rtp
905 let lines =<< trim END
906 vim9script
907 export def Complete(..._): string
908 return 'match'
909 enddef
910 echo this will cause an error
911 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100912 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000913 call writefile(lines, 'Xdir/autoload/script.vim')
914 exe 'set rtp+=' .. getcwd() .. '/Xdir'
915
916 let lines =<< trim END
917 vim9script
918 import autoload 'script.vim'
919 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
920 &wildcharm = char2nr("\<Tab>")
921 feedkeys(":Cmd \<Tab>", 'xt')
922 END
923 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
924
925 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000926endfunc
927
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100928func Test_fullcommand()
929 let tests = {
930 \ '': '',
931 \ ':': '',
932 \ ':::': '',
933 \ ':::5': '',
934 \ 'not_a_cmd': '',
935 \ 'Check': '',
936 \ 'syntax': 'syntax',
937 \ ':syntax': 'syntax',
938 \ '::::syntax': 'syntax',
939 \ 'sy': 'syntax',
940 \ 'syn': 'syntax',
941 \ 'synt': 'syntax',
942 \ ':sy': 'syntax',
943 \ '::::sy': 'syntax',
944 \ 'match': 'match',
945 \ '2match': 'match',
946 \ '3match': 'match',
947 \ 'aboveleft': 'aboveleft',
948 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100949 \ 'en': 'endif',
950 \ 'end': 'endif',
951 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100952 \ 's': 'substitute',
953 \ '5s': 'substitute',
954 \ ':5s': 'substitute',
955 \ "'<,'>s": 'substitute',
956 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100957 \ 'CheckLin': 'CheckLinux',
958 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100959 \ }
960
961 for [in, want] in items(tests)
962 call assert_equal(want, fullcommand(in))
963 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200964 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100965
966 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200967
968 command -buffer BufferLocalCommand :
969 command GlobalCommand :
970 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
971 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
972 delcommand BufferLocalCommand
973 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100974endfunc
975
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200976func Test_shellcmd_completion()
977 let save_path = $PATH
978
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100979 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200980 call writefile([''], 'Xpathdir/Xfile.exe')
981 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
982
983 " Set PATH to example directory without trailing slash.
984 let $PATH = getcwd() . '/Xpathdir'
985
986 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
987 " dirs in the PATH, even though they won't be executed. We check that only
988 " subdirs of the PWD and executables from the PATH are included in the
989 " suggestions.
990 let actual = getcompletion('X', 'shellcmd')
991 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
992 call insert(expected, 'Xfile.exe')
993 call assert_equal(expected, actual)
994
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200995 let $PATH = save_path
996endfunc
997
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200998func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100999 call mkdir('a/b/c', 'pR')
1000 call writefile(['asdfasdf'], 'a/b/c/fileXname')
1001 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
1002 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +02001003 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +02001004endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +01001005
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001006func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +01001007 let @a = "def"
1008 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
1009 call assert_equal('"abc def ghi', @:)
1010
1011 new
1012 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
1013
1014 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1015 call assert_equal('"aaa asdf bbb', @:)
1016
1017 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
1018 call assert_equal('"aaa /tmp/some bbb', @:)
1019
Bram Moolenaare2c8d832018-05-01 19:24:03 +02001020 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
1021 call assert_equal('"aaa '.getline(1).' bbb', @:)
1022
Bram Moolenaar21efc362016-12-03 14:05:49 +01001023 set incsearch
1024 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
1025 call assert_equal('"aaa verylongword bbb', @:)
1026
1027 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
1028 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001029
1030 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
1031 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +01001032 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +02001033
1034 " Error while typing a command used to cause that it was not executed
1035 " in the end.
1036 new
1037 try
1038 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
1039 catch /^Vim\%((\a\+)\)\=:E32/
1040 " ignore error E32
1041 endtry
1042 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001043
Bram Moolenaar578fe942020-02-27 21:32:51 +01001044 " Try to paste an invalid register using <C-R>
1045 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
1046 call assert_equal('"onetwo', @:)
1047
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001048 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +01001049 let @a = "xy\<C-H>z"
1050 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
1051 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001052 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
1053 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001054 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
1055 call assert_equal("\"xy\<C-H>z", @:)
1056
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001057 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
1058 let @a = "xy\<C-V>z"
1059 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
1060 call assert_equal('"xyz', @:)
1061 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
1062 call assert_equal("\"xy\<C-V>z", @:)
1063
Bram Moolenaar578fe942020-02-27 21:32:51 +01001064 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
1065
Bram Moolenaar72532d32018-04-07 19:09:09 +02001066 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +01001067endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001068
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001069func Test_cmdline_remove_char()
1070 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001071
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001072 for e in ['utf8', 'latin1']
1073 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001074
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001075 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
1076 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001077
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001078 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
1079 call assert_equal('"abcdef', @:)
1080
1081 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
1082 call assert_equal('"abc ghi', @:, e)
1083
1084 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
1085 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +01001086
1087 " This was going before the start in latin1.
1088 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001089 endfor
1090
1091 let &encoding = encoding_save
1092endfunc
1093
zeertzjqff2b79d2024-02-26 20:38:36 +01001094func Test_cmdline_del_utf8()
1095 let @s = '⒌'
1096 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1097 call assert_equal('",,', @:)
1098
1099 let @s = 'a̳'
1100 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1101 call assert_equal('",,', @:)
1102
1103 let @s = 'β̳'
1104 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1105 call assert_equal('",,', @:)
1106
1107 if has('arabic')
1108 let @s = 'لا'
1109 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
1110 call assert_equal('",,', @:)
1111 endif
1112endfunc
1113
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001114func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001115 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001116
1117 set keymap=esperanto
1118 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
1119 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
1120 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +01001121endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001122
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001123func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +01001124 new
1125 2;'(
1126 2;')
1127 quit
1128endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +01001129
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001130func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001131 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001132 new
1133 source Xtest.vim
1134 " Trigger calling validate_cursor()
1135 diffsp Xtest.vim
1136 quit!
1137 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +01001138endfunc
1139
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +01001140func Test_mark_from_line_zero()
1141 " this was reading past the end of the first (empty) line
1142 new
1143 norm oxxxx
1144 call assert_fails("0;'(", 'E20:')
1145 bwipe!
1146endfunc
1147
Bram Moolenaarba47b512017-01-24 21:18:19 +01001148func Test_cmdline_complete_wildoptions()
1149 help
1150 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1151 let a = join(sort(split(@:)),' ')
1152 set wildoptions=tagfile
1153 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
1154 let b = join(sort(split(@:)),' ')
1155 call assert_equal(a, b)
1156 bw!
1157endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001158
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001159func Test_cmdline_complete_user_cmd()
1160 command! -complete=color -nargs=1 Foo :
1161 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1162 call assert_equal('"Foo blue', @:)
1163 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1164 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001165 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1166 call assert_equal('"Foo a blue', @:)
1167 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1168 call assert_equal('"Foo b\', @:)
1169 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1170 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001171 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001172
1173 redraw
1174 call assert_equal('~', Screenline(&lines - 1))
1175 command! FooOne :
1176 command! FooTwo :
1177
1178 set nowildmenu
1179 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1180 call assert_equal('"FooOne', @:)
1181 call assert_equal('~', Screenline(&lines - 1))
1182
1183 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1184 call assert_equal('"FooTwo', @:)
1185 call assert_equal('~', Screenline(&lines - 1))
1186
1187 delcommand FooOne
1188 delcommand FooTwo
1189 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001190endfunc
1191
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001192func Test_complete_user_cmd()
1193 command FooBar echo 'global'
1194 command -buffer FooBar echo 'local'
1195 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1196 call assert_equal('"FooBar', @:)
1197
1198 delcommand -buffer FooBar
1199 delcommand FooBar
1200endfunc
1201
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001202func s:ScriptLocalFunction()
1203 echo 'yes'
1204endfunc
1205
1206func Test_cmdline_complete_user_func()
1207 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001208 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001209 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1210 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001211
1212 " g: prefix also works
1213 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1214 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001215
1216 " using g: prefix does not result in just "g:" matches from a lambda
1217 let Fx = { a -> a }
1218 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1219 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001220
1221 " existence of script-local dict function does not break user function name
1222 " completion
1223 function s:a_dict_func() dict
1224 endfunction
1225 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1226 call assert_match('"call Test_cmdline_complete_user_', @:)
1227 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001228endfunc
1229
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001230func Test_cmdline_complete_user_names()
1231 if has('unix') && executable('whoami')
1232 let whoami = systemlist('whoami')[0]
1233 let first_letter = whoami[0]
1234 if len(first_letter) > 0
1235 " Trying completion of :e ~x where x is the first letter of
1236 " the user name should complete to at least the user name.
1237 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1238 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1239 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001240 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001241 " Just in case: check that the system has an Administrator account.
1242 let names = system('net user')
1243 if names =~ 'Administrator'
1244 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001245 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001246 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001247 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001248 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001249 else
1250 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001251 endif
1252endfunc
1253
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001254func Test_cmdline_complete_shellcmdline()
1255 CheckExecutable whoami
1256 command -nargs=1 -complete=shellcmdline MyCmd
1257
1258 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1259 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001260 let l = getcompletion('whoam', 'shellcmdline')
1261 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001262
1263 delcommand MyCmd
1264endfunc
1265
Bram Moolenaar297610b2019-12-27 17:20:55 +01001266func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001267 CheckExecutable whoami
1268 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1269 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001270endfunc
1271
Bram Moolenaar8b633132020-03-20 18:20:51 +01001272func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001273 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1274 call assert_equal(lang, v:lc_time)
1275
1276 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1277 call assert_equal(lang, v:ctype)
1278
1279 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1280 call assert_equal(lang, v:collate)
1281
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001282 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001283 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001284
1285 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001286 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001287
Bram Moolenaarec680282020-06-12 19:35:32 +02001288 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001289
Bram Moolenaarec680282020-06-12 19:35:32 +02001290 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1291 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001292
Bram Moolenaarec680282020-06-12 19:35:32 +02001293 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1294 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001295
Bram Moolenaarec680282020-06-12 19:35:32 +02001296 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1297 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001298
1299 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1300 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001301endfunc
1302
Bram Moolenaar297610b2019-12-27 17:20:55 +01001303func Test_cmdline_complete_env_variable()
1304 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001305 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1306 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001307 unlet $X_VIM_TEST_COMPLETE_ENV
1308endfunc
1309
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001310func Test_cmdline_complete_expression()
1311 let g:SomeVar = 'blah'
1312 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1313 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1314 call assert_match('"' .. cmd .. ' SomeVar', @:)
1315 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1316 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1317 endfor
1318 unlet g:SomeVar
1319endfunc
1320
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001321func Test_cmdline_complete_argopt()
1322 " completion for ++opt=arg for file commands
1323 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1324 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1325 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1326
1327 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001328 " Test ++ff in the middle of the cmdline
1329 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1330 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001331
1332 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1333 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1334 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1335 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1336 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1337
1338 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1339
1340 " completion should skip the ++opt and continue
1341 call writefile([], 'Xaaaaa.txt', 'D')
1342 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1343 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1344
1345 if has('terminal')
1346 " completion for terminal's [options]
1347 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1348 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1349 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1350
1351 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1352
1353 " :terminal completion should skip the ++opt when considering what is the
1354 " first option, which is a list of shell commands, unlike second option
1355 " onwards.
1356 let first_param = getcompletion('terminal ', 'cmdline')
1357 let second_param = getcompletion('terminal foo ', 'cmdline')
1358 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1359 call assert_equal(first_param, skipped_opt_param)
1360 call assert_notequal(first_param, second_param)
1361 endif
1362endfunc
1363
Bram Moolenaar47016f52021-08-26 16:39:58 +02001364" Unique function name for completion below
1365func s:WeirdFunc()
1366 echo 'weird'
1367endfunc
1368
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001369" Test for various command-line completion
1370func Test_cmdline_complete_various()
1371 " completion for a command starting with a comment
1372 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1373 call assert_equal("\" :|\"\<C-A>", @:)
1374
1375 " completion for a range followed by a comment
1376 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1377 call assert_equal("\"1,2\"\<C-A>", @:)
1378
1379 " completion for :k command
1380 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1381 call assert_equal("\"ka\<C-A>", @:)
1382
Doug Kearnsea842022024-09-29 17:17:41 +02001383 " completion for :keepmarks command
1384 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1385 call assert_equal("\"kee edit", @:)
1386
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001387 " completion for short version of the :s command
1388 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1389 call assert_equal("\"sI \<C-A>", @:)
1390
1391 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001392 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001393 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001394 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001395 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001396 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1397 call assert_equal("\"w >> Xfile1", @:)
1398 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001399
1400 " completion for :w ! and :r ! commands
1401 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1402 call assert_equal("\"w !invalid_xyz_cmd", @:)
1403 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1404 call assert_equal("\"r !invalid_xyz_cmd", @:)
1405
1406 " completion for :>> and :<< commands
1407 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1408 call assert_equal("\">>>\<C-A>", @:)
1409 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1410 call assert_equal("\"<<<\<C-A>", @:)
1411
1412 " completion for command with +cmd argument
1413 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1414 call assert_equal("\"buffer +/pat Xabc", @:)
1415 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1416 call assert_equal("\"buffer +/pat\<C-A>", @:)
1417
1418 " completion for a command with a trailing comment
1419 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1420 call assert_equal("\"ls \" comment\<C-A>", @:)
1421
1422 " completion for a command with a trailing command
1423 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1424 call assert_equal("\"ls | ls", @:)
1425
1426 " completion for a command with an CTRL-V escaped argument
1427 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1428 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1429
1430 " completion for a command that doesn't take additional arguments
1431 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1432 call assert_equal("\"all abc\<C-A>", @:)
1433
zeertzjqd3de1782022-09-01 12:58:52 +01001434 " completion for :wincmd with :horizontal modifier
1435 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1436 call assert_equal("\"horizontal wincmd", @:)
1437
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001438 " completion for a command with a command modifier
1439 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1440 call assert_equal("\"topleft new", @:)
1441
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001442 " completion for vim9 and legacy commands
1443 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1444 call assert_equal("\"vim9 call strlen(", @:)
1445 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1446 call assert_equal("\"legac call strlen(", @:)
1447
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001448 " completion for the :disassemble command
1449 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1450 call assert_equal("\"disas debug", @:)
1451 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1452 call assert_equal("\"disas profile", @:)
1453 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1454 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1455 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1456 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001457 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1458 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001459
Bram Moolenaar47016f52021-08-26 16:39:58 +02001460 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001461 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001462
naohiro onodfe04db2021-09-12 15:45:10 +02001463 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1464 call assert_match('"disas <SNR>\d\+_', @:)
1465 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1466 call assert_match('"disas debug <SNR>\d\+_', @:)
1467
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001468 " completion for the :match command
1469 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1470 call assert_equal("\"match Search /pat/\<C-A>", @:)
1471
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001472 " completion for the :doautocmd command
1473 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1474 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1475
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001476 " completion of autocmd group after comma
1477 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1478 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1479
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001480 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001481 call writefile([], 'Xvarfile1', 'D')
1482 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001483 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1484 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001485
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001486 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001487 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001488 augroup END
1489 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001490 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001491
1492 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001493 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1494 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001495 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1496 call assert_equal("\"au XTest.test", @:)
1497
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001498 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001499
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001500 " autocmd pattern completion
1501 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1502 call assert_equal("\"au BufEnter *.py\t", @:)
1503
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001504 " completion for the :unlet command
1505 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1506 call assert_equal("\"unlet one two", @:)
1507
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001508 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001509 " FIXME: what should happen on MS-Windows?
1510 if !has('win32')
1511 edit \{someFile}
1512 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1513 call assert_equal("\"buf {someFile}", @:)
1514 bwipe {someFile}
1515 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001516
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001517 " completion for the :bdelete command
1518 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1519 call assert_equal("\"bdel a b c", @:)
1520
1521 " completion for the :mapclear command
1522 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1523 call assert_equal("\"mapclear <buffer>", @:)
1524
1525 " completion for user defined commands with menu names
1526 menu Test.foo :ls<CR>
1527 com -nargs=* -complete=menu MyCmd
1528 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1529 call assert_equal('"MyCmd Test.', @:)
1530 delcom MyCmd
1531 unmenu Test
1532
1533 " completion for user defined commands with mappings
1534 mapclear
1535 map <F3> :ls<CR>
1536 com -nargs=* -complete=mapping MyCmd
1537 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001538 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001539 mapclear
1540 delcom MyCmd
1541
Yee Cheng Chin54844852023-10-09 18:12:31 +02001542 " Prepare for path completion
1543 call mkdir('Xa b c', 'D')
1544 defer delete('Xcomma,foobar.txt')
1545 call writefile([], 'Xcomma,foobar.txt')
1546
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001547 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001548 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1549 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1550 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001551
1552 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001553 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1554 call assert_equal('"set dir=Xa\ b\ c/', @:)
1555 set dir&
1556
1557 " completion for :set tags= / set dictionary= with escaped commas
1558 if has('win32')
1559 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1560 " '\,'
1561 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1562 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1563
1564 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1565 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1566
1567 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1568 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1569
1570 " completion for :set dictionary= with escaped commas (same behavior, but
1571 " different internal code path from 'set tags=' for escaping the output)
1572 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1573 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1574 else
1575 " In other platforms, backslashes are rounded down (since '\,' itself will
1576 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1577 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1578 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1579
1580 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1581 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1582
1583 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1584 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1585
1586 " completion for :set dictionary= with escaped commas (same behavior, but
1587 " different internal code path from 'set tags=' for escaping the output)
1588 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1589 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1590 endif
1591 set tags&
1592 set dictionary&
1593
1594 " completion for :set makeprg= with no escaped commas
1595 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1596 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1597
1598 if !has('win32')
1599 " Cannot create file with backslash in file name in Windows, so only test
1600 " this elsewhere.
1601 defer delete('Xcomma\,fooslash.txt')
1602 call writefile([], 'Xcomma\,fooslash.txt')
1603 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1604 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1605 endif
1606 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001607
1608 " completion for the :py3 commands
1609 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1610 call assert_equal('"py3 py3do py3file', @:)
1611
Bram Moolenaardf749a22021-03-28 15:29:43 +02001612 " completion for the :vim9 commands
1613 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1614 call assert_equal('"vim9cmd vim9script', @:)
1615
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001616 " redir @" is not the start of a comment. So complete after that
1617 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1618 call assert_equal('"redir @" | cwindow', @:)
1619
1620 " completion after a backtick
1621 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1622 call assert_equal('"e `a1b2c', @:)
1623
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001624 " completion for :language command with an invalid argument
1625 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1626 call assert_equal("\"language dummy \t", @:)
1627
1628 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001629 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1630 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001631
1632 " completion with ambiguous user defined commands
1633 com TCmd1 echo 'TCmd1'
1634 com TCmd2 echo 'TCmd2'
1635 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1636 call assert_equal('"TCmd ', @:)
1637 delcom TCmd1
1638 delcom TCmd2
1639
1640 " completion after a range followed by a pipe (|) character
1641 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1642 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001643
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001644 " completion after a :global command
1645 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1646 call assert_equal('"g/a/chistory', @:)
1647 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1648 call assert_equal("\"g/a\\/chist\t", @:)
1649
Bram Moolenaar9c929712020-09-07 22:05:28 +02001650 " use <Esc> as the 'wildchar' for completion
1651 set wildchar=<Esc>
1652 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1653 call assert_equal('"g/a\xb/clearjumps', @:)
1654 " pressing <esc> twice should cancel the command
1655 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1656 call assert_equal('"g/a\xb/clearjumps', @:)
1657 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001658
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001659 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001660 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001661 call writefile([], '~Xtest')
1662 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1663 call assert_equal('"e \~Xtest', @:)
1664 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001665
1666 " should be able to complete a file name that has a '*'
1667 call writefile([], 'Xx*Yy')
1668 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1669 call assert_equal('"e Xx\*Yy', @:)
1670 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001671
1672 " use a literal star
1673 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1674 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001675 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001676
1677 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1678 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001679endfunc
1680
zeertzjq094dd152023-06-15 22:51:57 +01001681" Test that expanding a pattern doesn't interfere with cmdline completion.
1682func Test_expand_during_cmdline_completion()
1683 func ExpandStuff()
1684 badd <script>:p:h/README.*
1685 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1686 $bwipe
1687 call assert_equal('README.txt', expand('README.*'))
1688 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1689 endfunc
1690 augroup test_CmdlineChanged
1691 autocmd!
1692 autocmd CmdlineChanged * call ExpandStuff()
1693 augroup END
1694
1695 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1696 call assert_equal('"sign place', @:)
1697
1698 augroup test_CmdlineChanged
1699 au!
1700 augroup END
1701 augroup! test_CmdlineChanged
1702 delfunc ExpandStuff
1703endfunc
1704
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001705" Test for 'wildignorecase'
1706func Test_cmdline_wildignorecase()
1707 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001708 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001709 set wildignorecase
1710 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1711 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001712 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001713 let g:Sline = ''
1714 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1715 call assert_equal('"e xt', @:)
1716 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001717 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001718endfunc
1719
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001720func Test_cmdline_write_alternatefile()
1721 new
1722 call setline('.', ['one', 'two'])
1723 f foo.txt
1724 new
1725 f #-A
1726 call assert_equal('foo.txt-A', expand('%'))
1727 f #<-B.txt
1728 call assert_equal('foo-B.txt', expand('%'))
1729 f %<
1730 call assert_equal('foo-B', expand('%'))
1731 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001732 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001733 bw!
1734 f foo-B.txt
1735 f %<-A
1736 call assert_equal('foo-B-A', expand('%'))
1737 bw!
1738 bw!
1739endfunc
1740
Bram Moolenaarf5724372022-09-02 19:45:15 +01001741func Test_cmdline_expand_cur_alt_file()
1742 enew
1743 file http://some.com/file.txt
1744 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1745 call assert_equal('"e http://some.com/file.txt', @:)
1746 edit another
1747 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1748 call assert_equal('"e http://some.com/file.txt', @:)
1749 bwipe
1750 bwipe http://some.com/file.txt
1751endfunc
1752
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001753" using a leading backslash here
1754set cpo+=C
1755
1756func Test_cmdline_search_range()
1757 new
1758 call setline(1, ['a', 'b', 'c', 'd'])
1759 /d
1760 1,\/s/b/B/
1761 call assert_equal('B', getline(2))
1762
1763 /a
1764 $
1765 \?,4s/c/C/
1766 call assert_equal('C', getline(3))
1767
1768 call setline(1, ['a', 'b', 'c', 'd'])
1769 %s/c/c/
1770 1,\&s/b/B/
1771 call assert_equal('B', getline(2))
1772
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001773 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001774 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001775
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001776 bwipe!
1777endfunc
1778
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001779" Test for the tick mark (') in an excmd range
1780func Test_tick_mark_in_range()
1781 " If only the tick is passed as a range and no command is specified, there
1782 " should not be an error
1783 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001784 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001785 call assert_fails("',print", 'E78:')
1786endfunc
1787
1788" Test for using a line number followed by a search pattern as range
1789func Test_lnum_and_pattern_as_range()
1790 new
1791 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1792 let @" = ''
1793 2/foo/yank
1794 call assert_equal("foo 3\n", @")
1795 call assert_equal(1, line('.'))
1796 close!
1797endfunc
1798
Bram Moolenaar65189a12017-02-06 22:22:17 +01001799" Tests for getcmdline(), getcmdpos() and getcmdtype()
1800func Check_cmdline(cmdtype)
1801 call assert_equal('MyCmd a', getcmdline())
1802 call assert_equal(8, getcmdpos())
1803 call assert_equal(a:cmdtype, getcmdtype())
1804 return ''
1805endfunc
1806
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001807set cpo&
1808
Shougo Matsushita69084282024-09-23 20:34:47 +02001809func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001810 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1811
1812 let cmdtype = ''
1813 debuggreedy
1814 call feedkeys(":debug echo 'test'\<CR>", "t")
1815 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1816 call feedkeys("cont\<CR>", "xt")
1817 0debuggreedy
1818 call assert_equal('>', cmdtype)
1819
1820 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1821 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1822
1823 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001824 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001825
1826 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1827
1828 cnoremap <expr> <F6> Check_cmdline('=')
1829 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1830 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001831
1832 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001833
1834 call assert_equal('', getcmdprompt())
1835 augroup test_CmdlineEnter
1836 autocmd!
1837 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1838 augroup END
1839 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1840 call assert_equal('Answer?', g:cmdprompt)
1841 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001842 call feedkeys(":\<CR>\<ESC>", "xt")
1843 call assert_equal('', g:cmdprompt)
1844 call assert_equal('', getcmdprompt())
1845
1846 let str = "C" .. repeat("c", 1023) .. "xyz"
1847 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1848 call assert_equal(str, g:cmdprompt)
1849
1850 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1851 call assert_equal('Ans?', g:cmdprompt)
1852 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001853
1854 augroup test_CmdlineEnter
1855 au!
1856 augroup END
1857 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001858endfunc
1859
Bram Moolenaar52604f22017-04-07 16:17:39 +02001860func Test_verbosefile()
1861 set verbosefile=Xlog
1862 echomsg 'foo'
1863 echomsg 'bar'
1864 set verbosefile=
1865 let log = readfile('Xlog')
1866 call assert_match("foo\nbar", join(log, "\n"))
1867 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001868
1869 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001870 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001871endfunc
1872
Bram Moolenaar4facea32019-10-12 20:17:40 +02001873func Test_verbose_option()
1874 CheckScreendump
1875
1876 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001877 " clear the TermResponse autocommand from defaults.vim
1878 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001879 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1880 call feedkeys("\r", 't') " for the hit-enter prompt
1881 set verbose=20
1882 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001883 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001884
1885 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001886 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001887 call term_sendkeys(buf, ":DoSomething\<CR>")
1888 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1889
1890 " clean up
1891 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001892endfunc
1893
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001894func Test_setcmdpos()
1895 func InsertTextAtPos(text, pos)
1896 call assert_equal(0, setcmdpos(a:pos))
1897 return a:text
1898 endfunc
1899
1900 " setcmdpos() with position in the middle of the command line.
1901 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1902 call assert_equal('"1ab2', @:)
1903
1904 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1905 call assert_equal('"1b2a', @:)
1906
1907 " setcmdpos() with position beyond the end of the command line.
1908 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1909 call assert_equal('"12ab', @:)
1910
1911 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001912 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001913endfunc
1914
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001915func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001916 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001917 let encoding_save = &encoding
1918
1919 for e in encodings
1920 exe 'set encoding=' . e
1921
1922 " Test overstrike in the middle of the command line.
1923 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001924 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001925
1926 " Test overstrike going beyond end of command line.
1927 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001928 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001929
1930 " Test toggling insert/overstrike a few times.
1931 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001932 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001933 endfor
1934
Bram Moolenaar30276f22019-01-24 17:59:39 +01001935 " Test overstrike with multi-byte characters.
1936 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001937 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001938
1939 let &encoding = encoding_save
1940endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001941
Bram Moolenaar52410572019-10-27 05:12:45 +01001942func Test_buffers_lastused()
1943 " check that buffers are sorted by time when wildmode has lastused
1944 call test_settime(1550020000) " middle
1945 edit bufa
1946 enew
1947 call test_settime(1550030000) " newest
1948 edit bufb
1949 enew
1950 call test_settime(1550010000) " oldest
1951 edit bufc
1952 enew
1953 call test_settime(0)
1954 enew
1955
1956 call assert_equal(['bufa', 'bufb', 'bufc'],
1957 \ getcompletion('', 'buffer'))
1958
1959 let save_wildmode = &wildmode
1960 set wildmode=full:lastused
1961
1962 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1963 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1964 call assert_equal('b bufb', X)
1965 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1966 call assert_equal('b bufa', X)
1967 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1968 call assert_equal('b bufc', X)
1969 enew
1970
1971 edit other
1972 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1973 call assert_equal('b bufb', X)
1974 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1975 call assert_equal('b bufa', X)
1976 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1977 call assert_equal('b bufc', X)
1978 enew
1979
1980 let &wildmode = save_wildmode
1981
1982 bwipeout bufa
1983 bwipeout bufb
1984 bwipeout bufc
1985endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001986
Bram Moolenaar479950f2020-01-19 15:45:17 +01001987func Test_cmdlineclear_tabenter()
1988 CheckScreendump
1989
1990 let lines =<< trim [SCRIPT]
1991 call setline(1, range(30))
1992 [SCRIPT]
1993
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001994 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001995 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001996 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001997 " in one tab make the command line higher with CTRL-W -
1998 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1999 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
2000
2001 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01002002endfunc
2003
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002004" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002005func Test_cmdline_expand_special()
2006 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02002007 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002008 call assert_fails('e <afile>', 'E495:')
2009 call assert_fails('e <abuf>', 'E496:')
2010 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002011
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002012 call writefile([], 'Xfile.cpp', 'D')
2013 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002014 new Xfile.cpp
2015 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
2016 call assert_equal('"e Xfile.cpp Xfile.java', @:)
2017 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01002018endfunc
2019
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002020" Test for backtick expression in the command line
2021func Test_cmd_backtick()
2022 %argd
2023 argadd `=['a', 'b', 'c']`
2024 call assert_equal(['a', 'b', 'c'], argv())
2025 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02002026
2027 argadd `echo abc def`
2028 call assert_equal(['abc def'], argv())
2029 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002030endfunc
2031
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002032" Test for the :! command
2033func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002034 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002035
2036 let lines =<< trim [SCRIPT]
2037 " Test for no previous command
2038 call assert_fails('!!', 'E34:')
2039 set nomore
2040 " Test for cmdline expansion with :!
2041 call setline(1, 'foo!')
2042 silent !echo <cWORD> > Xfile.out
2043 call assert_equal(['foo!'], readfile('Xfile.out'))
2044 " Test for using previous command
2045 silent !echo \! !
2046 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
2047 call writefile(v:errors, 'Xresult')
2048 call delete('Xfile.out')
2049 qall!
2050 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002051 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002052 if RunVim([], [], '--clean -S Xscript')
2053 call assert_equal([], readfile('Xresult'))
2054 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002055 call delete('Xresult')
2056endfunc
2057
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002058" Test error: "E135: *Filter* Autocommands must not change current buffer"
2059func Test_cmd_bang_E135()
2060 new
2061 call setline(1, ['a', 'b', 'c', 'd'])
2062 augroup test_cmd_filter_E135
2063 au!
2064 autocmd FilterReadPost * help
2065 augroup END
2066 call assert_fails('2,3!echo "x"', 'E135:')
2067
2068 augroup test_cmd_filter_E135
2069 au!
2070 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002071 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02002072 %bwipe!
2073endfunc
2074
shane.xb.qian4e7590e2022-11-08 21:40:04 +00002075func Test_cmd_bang_args()
2076 new
2077 :.!
2078 call assert_equal(0, v:shell_error)
2079
2080 " Note that below there is one space char after the '!'. This caused a
2081 " shell error in the past, see https://github.com/vim/vim/issues/11495.
2082 :.!
2083 call assert_equal(0, v:shell_error)
2084 bwipe!
2085
2086 CheckUnix
2087 :.!pwd
2088 call assert_equal(0, v:shell_error)
2089 :.! pwd
2090 call assert_equal(0, v:shell_error)
2091
2092 " Note there is one space after 'pwd'.
2093 :.! pwd
2094 call assert_equal(0, v:shell_error)
2095
2096 " Note there are two spaces after 'pwd'.
2097 :.! pwd
2098 call assert_equal(0, v:shell_error)
2099 :.!ls ~
2100 call assert_equal(0, v:shell_error)
2101
2102 " Note there is one space char after '~'.
2103 :.!ls ~
2104 call assert_equal(0, v:shell_error)
2105
2106 " Note there are two spaces after '~'.
2107 :.!ls ~
2108 call assert_equal(0, v:shell_error)
2109
2110 :.!echo "foo"
2111 call assert_equal(getline('.'), "foo")
2112 :.!echo "foo "
2113 call assert_equal(getline('.'), "foo ")
2114 :.!echo " foo "
2115 call assert_equal(getline('.'), " foo ")
2116 :.!echo " foo "
2117 call assert_equal(getline('.'), " foo ")
2118
2119 %bwipe!
2120endfunc
2121
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002122" Test for using ~ for home directory in cmdline completion matches
2123func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002124 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002125 call writefile([], 'Xexpdir/Xfile1')
2126 call writefile([], 'Xexpdir/Xfile2')
2127 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002128 let save_HOME = $HOME
2129 let $HOME = getcwd()
2130 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
2131 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
2132 let $HOME = save_HOME
2133 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01002134endfunc
2135
Bram Moolenaar578fe942020-02-27 21:32:51 +01002136" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
2137" or insert mode (when 'insertmode' is set)
2138func Test_cmdline_ctrl_g()
2139 new
2140 call setline(1, 'abc')
2141 call cursor(1, 3)
2142 " If command line is entered from insert mode, using C-\ C-G should back to
2143 " insert mode
2144 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
2145 call assert_equal('abxyc', getline(1))
2146 call assert_equal(4, col('.'))
2147
2148 " If command line is entered in 'insertmode', using C-\ C-G should back to
2149 " 'insertmode'
2150 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
2151 call assert_equal('ab12xyc', getline(1))
2152 close!
2153endfunc
2154
Bram Moolenaar578fe942020-02-27 21:32:51 +01002155" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002156func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01002157 func T(a, c, p)
2158 return "oneA\noneB\noneC"
2159 endfunc
2160 command -nargs=1 -complete=custom,T MyCmd
2161
Bram Moolenaar578fe942020-02-27 21:32:51 +01002162 set nowildmenu
2163 set wildmode=full,list
2164 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002165 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002166 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002167 call assert_equal('"MyCmd oneA', @:)
2168
2169 set wildmode=longest,full
2170 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2171 call assert_equal('"MyCmd one', @:)
2172 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2173 call assert_equal('"MyCmd oneC', @:)
2174
2175 set wildmode=longest
2176 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2177 call assert_equal('"MyCmd one', @:)
2178
2179 set wildmode=list:longest
2180 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002181 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002182 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002183 call assert_equal('"MyCmd one', @:)
2184
2185 set wildmode=""
2186 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2187 call assert_equal('"MyCmd oneA', @:)
2188
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002189 " Test for wildmode=longest with 'fileignorecase' set
2190 set wildmode=longest
2191 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002192 argadd AAA AAAA AAAAA
2193 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2194 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002195 set fileignorecase&
2196
2197 " Test for listing files with wildmode=list
2198 set wildmode=list
2199 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002200 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002201 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002202 call assert_equal('"b A', @:)
2203
Girish Palya2bacc3e2025-03-02 22:55:57 +01002204 " When 'wildmenu' is not set, 'noselect' completes first item
2205 set wildmode=noselect
2206 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2207 call assert_equal('"MyCmd oneA', @:)
2208
2209 " When 'noselect' is present, do not complete first <tab>.
2210 set wildmenu
2211 set wildmode=noselect
2212 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2213 call assert_equal('"MyCmd o', @:)
2214 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2215 call assert_equal('"MyCmd o', @:)
2216 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2217 call assert_equal('"MyCmd o', @:)
2218
2219 " When 'full' is present, complete after first <tab>.
2220 set wildmode=noselect,full
2221 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2222 call assert_equal('"MyCmd o', @:)
2223 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2224 call assert_equal('"MyCmd oneA', @:)
2225 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
2226 call assert_equal('"MyCmd oneB', @:)
2227 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
2228 call assert_equal('"MyCmd oneB', @:)
2229
2230 " 'noselect' has no effect when 'longest' is present.
2231 set wildmode=noselect:longest
2232 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2233 call assert_equal('"MyCmd one', @:)
2234
2235 " Complete 'noselect' value in 'wildmode' option
2236 set wildmode&
2237 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
2238 call assert_equal('"set wildmode=noselect', @:)
2239 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
2240 call assert_equal('"set wildmode=noselect', @:)
2241
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002242 " when using longest completion match, matches shorter than the argument
2243 " should be ignored (happens with :help)
2244 set wildmode=longest,full
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002245 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2246 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002247 " non existing file
2248 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2249 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002250
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002251 " Test for longest file name completion with 'fileignorecase'
2252 " On MS-Windows, file names are case insensitive.
2253 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002254 call writefile([], 'XTESTfoo', 'D')
2255 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002256 set nofileignorecase
2257 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2258 call assert_equal('"e XTESTfoo', @:)
2259 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2260 call assert_equal('"e Xtestbar', @:)
2261 set fileignorecase
2262 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2263 call assert_equal('"e Xtest', @:)
2264 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2265 call assert_equal('"e Xtest', @:)
2266 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002267 endif
2268
Girish Palya2bacc3e2025-03-02 22:55:57 +01002269 " If 'noselect' is present, single item menu should not insert item
2270 func! T(a, c, p)
2271 return "oneA"
2272 endfunc
2273 command! -nargs=1 -complete=custom,T MyCmd
2274 set wildmode=noselect,full
2275 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2276 call assert_equal('"MyCmd o', @:)
2277 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
2278 call assert_equal('"MyCmd oneA', @:)
2279 " 'nowildmenu' should make 'noselect' ineffective
2280 set nowildmenu
2281 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2282 call assert_equal('"MyCmd oneA', @:)
2283
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002284 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002285 delcommand MyCmd
2286 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002287 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002288 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002289endfunc
2290
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002291func Test_wildmode()
2292 " Test with utf-8 encoding
2293 call Wildmode_tests()
2294
2295 " Test with latin1 encoding
2296 let save_encoding = &encoding
2297 set encoding=latin1
2298 call Wildmode_tests()
2299 let &encoding = save_encoding
2300endfunc
2301
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002302func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002303 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002304 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002305 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002306 let lines =<< trim END
2307 func vim8#Complete(a, c, p)
2308 return "oneA\noneB\noneC"
2309 endfunc
2310 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002311 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002312
2313 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2314 set nowildmenu
2315 set wildmode=full,list
2316 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2317 call assert_equal('"MyCmd oneA oneB oneC', @:)
2318
2319 let &rtp = save_rtp
2320 set wildmode& wildmenu&
2321 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002322endfunc
2323
Bram Moolenaar578fe942020-02-27 21:32:51 +01002324" Test for interrupting the command-line completion
2325func Test_interrupt_compl()
2326 func F(lead, cmdl, p)
2327 if a:lead =~ 'tw'
2328 call interrupt()
2329 return
2330 endif
2331 return "one\ntwo\nthree"
2332 endfunc
2333 command -nargs=1 -complete=custom,F Tcmd
2334
2335 set nowildmenu
2336 set wildmode=full
2337 let interrupted = 0
2338 try
2339 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2340 catch /^Vim:Interrupt$/
2341 let interrupted = 1
2342 endtry
2343 call assert_equal(1, interrupted)
2344
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002345 let interrupted = 0
2346 try
2347 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2348 catch /^Vim:Interrupt$/
2349 let interrupted = 1
2350 endtry
2351 call assert_equal(1, interrupted)
2352
Bram Moolenaar578fe942020-02-27 21:32:51 +01002353 delcommand Tcmd
2354 delfunc F
2355 set wildmode&
2356endfunc
2357
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002358" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002359func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002360 let str = ":one two\<C-U>"
2361 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002362 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002363 let str ..= "\<Left>five\<Right>"
2364 let str ..= "\<Home>two "
2365 let str ..= "\<C-Left>one "
2366 let str ..= "\<C-Right> three"
2367 let str ..= "\<End>\<S-Left>four "
2368 let str ..= "\<S-Right> six"
2369 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2370 call feedkeys(str, 'xt')
2371 call assert_equal("\"one two three four five six seven", @:)
2372endfunc
2373
2374" Test for moving the cursor on the / command line in 'rightleft' mode
2375func Test_cmdline_edit_rightleft()
2376 CheckFeature rightleft
2377 set rightleft
2378 set rightleftcmd=search
2379 let str = "/one two\<C-U>"
2380 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002381 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002382 let str ..= "\<Right>five\<Left>"
2383 let str ..= "\<Home>two "
2384 let str ..= "\<C-Right>one "
2385 let str ..= "\<C-Left> three"
2386 let str ..= "\<End>\<S-Right>four "
2387 let str ..= "\<S-Left> six"
2388 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2389 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2390 call assert_equal("\"one two three four five six seven", @/)
2391 set rightleftcmd&
2392 set rightleft&
2393endfunc
2394
2395" Test for using <C-\>e in the command line to evaluate an expression
2396func Test_cmdline_expr()
2397 " Evaluate an expression from the beginning of a command line
2398 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2399 call assert_equal('"hello', @:)
2400
2401 " Use an invalid expression for <C-\>e
2402 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2403
2404 " Insert literal <CTRL-\> in the command line
2405 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2406 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002407endfunc
2408
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002409" This was making the insert position negative
2410func Test_cmdline_expr_register()
2411 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2412endfunc
2413
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002414" Test for 'imcmdline' and 'imsearch'
2415" This test doesn't actually test the input method functionality.
2416func Test_cmdline_inputmethod()
2417 new
2418 call setline(1, ['', 'abc', ''])
2419 set imcmdline
2420
2421 call feedkeys(":\"abc\<CR>", 'xt')
2422 call assert_equal("\"abc", @:)
2423 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2424 call assert_equal("\"abc", @:)
2425 call feedkeys("/abc\<CR>", 'xt')
2426 call assert_equal([2, 1], [line('.'), col('.')])
2427 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2428 call assert_equal([2, 1], [line('.'), col('.')])
2429
2430 set imsearch=2
2431 call cursor(1, 1)
2432 call feedkeys("/abc\<CR>", 'xt')
2433 call assert_equal([2, 1], [line('.'), col('.')])
2434 call cursor(1, 1)
2435 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2436 call assert_equal([2, 1], [line('.'), col('.')])
2437 set imdisable
2438 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2439 call assert_equal([2, 1], [line('.'), col('.')])
2440 set imdisable&
2441 set imsearch&
2442
2443 set imcmdline&
2444 %bwipe!
2445endfunc
2446
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002447" Test for using CTRL-_ in the command line with 'allowrevins'
2448func Test_cmdline_revins()
2449 CheckNotMSWindows
2450 CheckFeature rightleft
2451 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2452 call assert_equal("\"abc\<c-_>", @:)
2453 set allowrevins
2454 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2455 call assert_equal('"abcñèæ', @:)
2456 set allowrevins&
2457endfunc
2458
2459" Test for typing UTF-8 composing characters in the command line
2460func Test_cmdline_composing_chars()
2461 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2462 call assert_equal('"ゔ', @:)
2463endfunc
2464
Bram Moolenaar0e717042020-04-27 19:29:01 +02002465" test that ";" works to find a match at the start of the first line
2466func Test_zero_line_search()
2467 new
2468 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2469 call cursor(1,1)
2470 0;/pattern/d
2471 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2472 q!
2473endfunc
2474
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002475func Test_read_shellcmd()
2476 CheckUnix
2477 if executable('ls')
2478 " There should be ls in the $PATH
2479 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2480 call assert_match('^"r! .*\<ls\>', @:)
2481 endif
2482
2483 if executable('rm')
2484 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2485 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2486 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002487
2488 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2489 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2490 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002491 endif
2492endfunc
2493
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002494" Test for going up and down the directory tree using 'wildmenu'
2495func Test_wildmenu_dirstack()
2496 CheckUnix
2497 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002498 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002499 call writefile([], 'Xwildmenu/file1_1.txt')
2500 call writefile([], 'Xwildmenu/file1_2.txt')
2501 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2502 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2503 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2504 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2505 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2506 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002507 set wildmenu
2508
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002509 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002510 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002511 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002512 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002513 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002514 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002515 call assert_equal('"e ../../dir3/', @:)
2516 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2517 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002518 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002519 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002520 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002521 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002522 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002523 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2524 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002525
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002526 set wildmenu&
2527endfunc
2528
obcat71c6f7a2021-05-13 20:23:10 +02002529" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002530" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2531" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002532func Test_recalling_cmdline()
2533 CheckFeature cmdline_hist
2534
2535 let g:cmdlines = []
2536 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2537
2538 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002539 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2540 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2541 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2542 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002543 "\ TODO: {'name': 'debug', ...}
2544 \]
2545 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002546 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2547 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2548 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2549 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2550 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002551 \]
2552 let prefix = 'vi'
2553 for h in histories
2554 call histadd(h.name, 'vim')
2555 call histadd(h.name, 'virtue')
2556 call histadd(h.name, 'Virgo')
2557 call histadd(h.name, 'vogue')
2558 call histadd(h.name, 'emacs')
2559 for k in keypairs
2560 let g:cmdlines = []
2561 let keyseqs = h.enter
2562 \ .. prefix
2563 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2564 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2565 \ .. h.exit
2566 call feedkeys(keyseqs, 'xt')
2567 call histdel(h.name, -1) " delete the history added by feedkeys above
2568 let expect = k.prefixmatch
2569 \ ? ['virtue', 'vim', 'virtue', prefix]
2570 \ : ['emacs', 'vogue', 'emacs', prefix]
2571 call assert_equal(expect, g:cmdlines)
2572 endfor
2573 endfor
2574
2575 unlet g:cmdlines
2576 cunmap <Plug>(save-cmdline)
2577endfunc
2578
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002579func Test_cmd_map_cmdlineChanged()
2580 let g:log = []
2581 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002582 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002583 autocmd!
2584 autocmd CmdlineChanged : let g:log += [getcmdline()]
2585 augroup END
2586
2587 call feedkeys(":\<F1>\<CR>", 'xt')
2588 call assert_equal(['l', 'ls'], g:log)
2589
Bram Moolenaar796139a2021-05-18 21:38:45 +02002590 let @b = 'b'
2591 cnoremap <F1> a<C-R>b
2592 let g:log = []
2593 call feedkeys(":\<F1>\<CR>", 'xt')
2594 call assert_equal(['a', 'ab'], g:log)
2595
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002596 unlet g:log
2597 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002598 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002599 autocmd!
2600 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002601 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002602endfunc
2603
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002604" Test for the 'suffixes' option
2605func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002606 call writefile([], 'Xsuffile', 'D')
2607 call writefile([], 'Xsuffile.c', 'D')
2608 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002609 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002610 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2611 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2612 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2613 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002614 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002615 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2616 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2617 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2618 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002619 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002620 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2621 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2622 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2623 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002624 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002625 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002626 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2627 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002628endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002629
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002630" Test for using a popup menu for the command line completion matches
2631" (wildoptions=pum)
2632func Test_wildmenu_pum()
2633 CheckRunVimInTerminal
2634
2635 let commands =<< trim [CODE]
2636 set wildmenu
2637 set wildoptions=pum
2638 set shm+=I
2639 set noruler
2640 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002641
2642 func CmdCompl(a, b, c)
2643 return repeat(['aaaa'], 120)
2644 endfunc
2645 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002646
2647 func MyStatusLine() abort
2648 return 'status'
2649 endfunc
2650 func SetupStatusline()
2651 set statusline=%!MyStatusLine()
2652 set laststatus=2
2653 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002654
2655 func MyTabLine()
2656 return 'my tab line'
2657 endfunc
2658 func SetupTabline()
2659 set statusline=
2660 set tabline=%!MyTabLine()
2661 set showtabline=2
2662 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002663
2664 func DoFeedKeys()
2665 let &wildcharm = char2nr("\t")
2666 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2667 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002668 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002669 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002670
2671 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2672
2673 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002674 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2675
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002676 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002677 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002678 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2679
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002680 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002681 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002682 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2683
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002684 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002685 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002686 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2687
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002688 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2691
2692 " pressing <C-E> should end completion and go back to the original match
2693 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002694 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2695
2696 " pressing <C-Y> should select the current match and end completion
2697 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002698 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2699
2700 " With 'wildmode' set to 'longest,full', completing a match should display
2701 " the longest match, the wildmenu should not be displayed.
2702 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2703 call TermWait(buf)
2704 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002705 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2706
2707 " pressing <Tab> should display the wildmenu
2708 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002709 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2710
2711 " pressing <Tab> second time should select the next entry in the menu
2712 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002713 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2714
2715 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002716 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002717 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002718 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2719
2720 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002721 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2722
2723 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002724 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2725
2726 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002727 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002728 call writefile([], 'Xnamedir/XfileA')
2729 call writefile([], 'Xnamedir/XdirA/XfileB')
2730 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002731
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002732 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002733 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2734
2735 " Pressing <Right> on a directory name should go into that directory
2736 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002737 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2738
2739 " Pressing <Left> on a directory name should go to the parent directory
2740 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002741 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2742
2743 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002744 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002745 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002746 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2747
2748 " Pressing <C-D> when the popup menu is displayed should remove the popup
2749 " menu
2750 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002751 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2752
2753 " Pressing <S-Tab> should open the popup menu with the last entry selected
2754 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002755 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2756
2757 " Pressing <Esc> should close the popup menu and cancel the cmd line
2758 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002759 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2760
2761 " Typing a character when the popup is open, should close the popup
2762 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002763 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2764
2765 " When the popup is open, entering the cmdline window should close the popup
2766 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002767 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2768 call term_sendkeys(buf, ":q\<CR>")
2769
2770 " After the last popup menu item, <C-N> should show the original string
2771 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002772 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2773
2774 " Use the popup menu for the command name
2775 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002776 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2777
2778 " Pressing the left arrow should remove the popup menu
2779 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002780 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2781
2782 " Pressing <BS> should remove the popup menu and erase the last character
2783 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002784 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2785
2786 " Pressing <C-W> should remove the popup menu and erase the previous word
2787 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002788 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2789
2790 " Pressing <C-U> should remove the popup menu and erase the entire line
2791 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002792 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2793
2794 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2795 " the cmdline from history
2796 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002797 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2798
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002799 " Check "list" still works
2800 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2801 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002802 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2803 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002804 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2805
rbtnn68cc2b82022-02-09 11:55:47 +00002806 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002807 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002808 call writefile([], 'Xnamedir/あいう/abc')
2809 call writefile([], 'Xnamedir/あいう/xyz')
2810 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002811
2812 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002813 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002814 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2815
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002816 " Pressing <C-A> when the popup menu is displayed should list all the
2817 " matches and pressing a key after that should remove the popup menu
2818 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2819 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2820 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2821
2822 " Pressing <C-A> when the popup menu is displayed should list all the
2823 " matches and pressing <Left> after that should move the cursor
2824 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2825 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2826 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2827
2828 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2829 " should be displayed correctly on the screen.
2830 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2831 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2832
2833 " After using <C-A> to expand all the filename matches, pressing <Up>
2834 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002835 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002836 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2837 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2838 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2839
2840 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2841 " crash Vim
2842 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2843 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2844
Bram Moolenaar414acd32022-02-10 21:09:45 +00002845 " After removing the pum the command line is redrawn
2846 call term_sendkeys(buf, ":edit foo\<CR>")
2847 call term_sendkeys(buf, ":edit bar\<CR>")
2848 call term_sendkeys(buf, ":ls\<CR>")
2849 call term_sendkeys(buf, ":com\<Tab> ")
2850 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002851 call term_sendkeys(buf, "\<C-U>\<CR>")
2852
2853 " Esc still works to abort the command when 'statusline' is set
2854 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2855 call term_sendkeys(buf, ":si\<Tab>")
2856 call term_sendkeys(buf, "\<Esc>")
2857 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002858
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002859 " Esc still works to abort the command when 'tabline' is set
2860 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2861 call term_sendkeys(buf, ":si\<Tab>")
2862 call term_sendkeys(buf, "\<Esc>")
2863 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2864
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002865 " popup is cleared also when 'lazyredraw' is set
2866 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2867 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2868 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2869 call term_sendkeys(buf, "\<Esc>")
2870
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002871 " Pressing <PageDown> should scroll the menu downward
2872 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2873 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2874 call term_sendkeys(buf, "\<PageDown>")
2875 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2876 call term_sendkeys(buf, "\<PageDown>")
2877 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2878 call term_sendkeys(buf, "\<PageDown>")
2879 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2880 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2881 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2882
2883 " Pressing <PageUp> should scroll the menu upward
2884 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2885 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2886 call term_sendkeys(buf, "\<PageUp>")
2887 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2888 call term_sendkeys(buf, "\<PageUp>")
2889 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2890 call term_sendkeys(buf, "\<PageUp>")
2891 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2892
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002893 " pressing <C-E> to end completion should work in middle of the line too
2894 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2895 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2896 call term_sendkeys(buf, "\<C-E>")
2897 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2898
2899 " pressing <C-Y> should select the current match and end completion
2900 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2901 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2902
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002903 call term_sendkeys(buf, "\<C-U>\<CR>")
2904 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002905endfunc
2906
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002907" Test for wildmenumode() with the cmdline popup menu
2908func Test_wildmenumode_with_pum()
2909 set wildmenu
2910 set wildoptions=pum
2911 cnoremap <expr> <F2> wildmenumode()
2912 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2913 call assert_equal('"sign define10', @:)
2914 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2915 call assert_equal('"sign define jump list place undefine unplace0', @:)
2916 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2917 call assert_equal('"sign 0', @:)
2918 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2919 call assert_equal('"sign define0', @:)
2920 set nowildmenu wildoptions&
2921 cunmap <F2>
2922endfunc
2923
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002924func Test_wildmenu_with_pum_foldexpr()
2925 CheckRunVimInTerminal
2926
2927 let lines =<< trim END
2928 call setline(1, ['folded one', 'folded two', 'some more text'])
2929 func MyFoldText()
2930 return 'foo'
2931 endfunc
2932 set foldtext=MyFoldText() wildoptions=pum
2933 normal ggzfj
2934 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002935 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002936 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2937 call term_sendkeys(buf, ":set\<Tab>")
2938 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2939
2940 call term_sendkeys(buf, "\<Esc>")
2941 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2942
2943 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002944endfunc
2945
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002946" Test for opening the cmdline completion popup menu from the terminal window.
2947" The popup menu should be positioned correctly over the status line of the
2948" bottom-most window.
2949func Test_wildmenu_pum_from_terminal()
2950 CheckRunVimInTerminal
2951 let python = PythonProg()
2952 call CheckPython(python)
2953
2954 %bw!
2955 let cmds = ['set wildmenu wildoptions=pum']
2956 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2957 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002958 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002959 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2960 call term_sendkeys(buf, "\r\r\r")
2961 call term_wait(buf)
2962 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2963 call term_wait(buf)
2964 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2965 call term_wait(buf)
2966 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002967endfunc
2968
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002969func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002970 CheckRunVimInTerminal
2971
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002972 " Test odd wildchar interactions with pum. Make sure they behave properly
2973 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002974 let lines =<< trim END
2975 set wildoptions=pum
2976 set wildchar=<C-E>
2977 END
2978 call writefile(lines, 'XwildmenuTest', 'D')
2979 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2980
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002981 call term_sendkeys(buf, ":\<C-E>")
2982 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002983
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002984 " <C-E> being a wildchar takes priority over its original functionality
2985 call term_sendkeys(buf, "\<C-E>")
2986 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2987
2988 call term_sendkeys(buf, "\<Esc>")
2989 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2990
2991 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2992 " command-line, and we need to make sure to clean up properly.
2993 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2994 call term_sendkeys(buf, ":\<Esc>")
2995 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2996
2997 call term_sendkeys(buf, "\<Esc>")
2998 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2999
3000 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
3001 " and we again need to make sure we clean up properly.
3002 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
3003 call term_sendkeys(buf, ":\<C-\>\<C-\>")
3004 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
3005
3006 call term_sendkeys(buf, "\<C-N>")
3007 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
3008
3009 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00003010endfunc
3011
zeertzjq883018f2024-06-15 15:37:11 +02003012" Test that 'rightleft' should not affect cmdline completion popup menu.
3013func Test_wildmenu_pum_rightleft()
3014 CheckFeature rightleft
3015 CheckScreendump
3016
3017 let lines =<< trim END
3018 set wildoptions=pum
3019 set rightleft
3020 END
3021 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
3022 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
3023
3024 call term_sendkeys(buf, ":sign \<Tab>")
3025 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
3026
3027 call StopVimInTerminal(buf)
3028endfunc
3029
Girish Palya4ec46f32025-03-04 20:56:30 +01003030" Test highlighting when pattern matches non-first character of item
3031func Test_wildmenu_pum_hl_nonfirst()
3032 CheckScreendump
3033 let lines =<< trim END
3034 set wildoptions=pum wildchar=<tab> wildmode=noselect,full
3035 hi PmenuMatchSel ctermfg=6 ctermbg=7
3036 hi PmenuMatch ctermfg=4 ctermbg=225
3037 func T(a, c, p)
3038 return ["oneA", "o neBneB", "aoneC"]
3039 endfunc
3040 command -nargs=1 -complete=customlist,T MyCmd
3041 END
3042
3043 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
3044 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
3045
3046 call term_sendkeys(buf, ":MyCmd ne\<tab>")
3047 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
3048 call term_sendkeys(buf, "\<Esc>")
3049 call StopVimInTerminal(buf)
3050endfunc
3051
zeertzjqd8c93402024-06-17 18:25:32 +02003052" Test highlighting matched text in cmdline completion popup menu.
3053func Test_wildmenu_pum_hl_match()
3054 CheckScreendump
3055
3056 let lines =<< trim END
3057 set wildoptions=pum,fuzzy
3058 hi PmenuMatchSel ctermfg=6 ctermbg=7
3059 hi PmenuMatch ctermfg=4 ctermbg=225
3060 END
3061 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
3062 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
3063
3064 call term_sendkeys(buf, ":sign plc\<Tab>")
3065 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
3066 call term_sendkeys(buf, "\<Tab>")
3067 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
3068 call term_sendkeys(buf, "\<Tab>")
3069 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
3070 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
3071 call TermWait(buf)
3072 call term_sendkeys(buf, ":sign un\<Tab>")
3073 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
3074 call term_sendkeys(buf, "\<Tab>")
3075 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
3076 call term_sendkeys(buf, "\<Tab>")
3077 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
3078 call term_sendkeys(buf, "\<Esc>")
3079
3080 call StopVimInTerminal(buf)
3081endfunc
3082
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00003083" Test for completion after a :substitute command followed by a pipe (|)
3084" character
3085func Test_cmdline_complete_substitute()
3086 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
3087 call assert_equal("\"s | \t", @:)
3088 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
3089 call assert_equal("\"s/ | \t", @:)
3090 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
3091 call assert_equal("\"s/one | \t", @:)
3092 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
3093 call assert_equal("\"s/one/ | \t", @:)
3094 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
3095 call assert_equal("\"s/one/two | \t", @:)
3096 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
3097 call assert_equal('"s/one/two/ | chistory', @:)
3098 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
3099 call assert_equal("\"s/one/two/g \t", @:)
3100 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
3101 call assert_equal("\"s/one/two/g | chistory", @:)
3102 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
3103 call assert_equal("\"s/one/t\\/ | \t", @:)
3104 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
3105 call assert_equal('"s/one/t"o/ | chistory', @:)
3106 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
3107 call assert_equal('"s/one/t|o/ | chistory', @:)
3108 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
3109 call assert_equal("\"&\t", @:)
3110endfunc
3111
3112" Test for the :dlist command completion
3113func Test_cmdline_complete_dlist()
3114 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
3115 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
3116 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
3117 call assert_equal("\"dlist 10 /pat/ \t", @:)
3118 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
3119 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
3120 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
3121 call assert_equal("\"dlist 10 /pat\\\t", @:)
3122 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
3123 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
3124endfunc
3125
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003126" argument list (only for :argdel) fuzzy completion
3127func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003128 argadd change.py count.py charge.py
3129 set wildoptions&
3130 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3131 call assert_equal('"argdel cge', @:)
3132 set wildoptions=fuzzy
3133 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal('"argdel change.py charge.py', @:)
3135 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003136 set wildoptions&
3137endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003138
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003139" autocmd group name fuzzy completion
3140func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003141 set wildoptions&
3142 augroup MyFuzzyGroup
3143 augroup END
3144 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal('"augroup mfg', @:)
3146 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal('"augroup MyFuzzyGroup', @:)
3148 set wildoptions=fuzzy
3149 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal('"augroup MyFuzzyGroup', @:)
3151 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal('"augroup My*p', @:)
3153 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003154 set wildoptions&
3155endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003156
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003157" buffer name fuzzy completion
3158func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003159 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003160 " Use a long name to reduce the risk of matching a random directory name
3161 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003162 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003163 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal('"b SRFWL', @:)
3165 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003167 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01003168 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
3170 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003172 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003173 set wildoptions&
3174endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003175
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003176" buffer name (full path) fuzzy completion
3177func Test_fuzzy_completion_bufname_fullpath()
3178 CheckUnix
3179 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003180 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003181 edit Xcmd/Xstate/Xfile.js
3182 cd Xcmd/Xstate
3183 enew
3184 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3185 call assert_equal('"b CmdStateFile', @:)
3186 set wildoptions=fuzzy
3187 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
3189 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003190 set wildoptions&
3191endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003192
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003193" :behave suboptions fuzzy completion
3194func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003195 set wildoptions&
3196 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal('"behave xm', @:)
3198 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal('"behave xterm', @:)
3200 set wildoptions=fuzzy
3201 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
3202 call assert_equal('"behave xterm', @:)
3203 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal('"behave xt*m', @:)
3205 let g:Sline = ''
3206 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
3207 call assert_equal('mswin', g:Sline)
3208 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003209 set wildoptions&
3210endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003211
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003212" " colorscheme name fuzzy completion - NOT supported
3213" func Test_fuzzy_completion_colorscheme()
3214" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003215
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003216" built-in command name fuzzy completion
3217func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003218 set wildoptions&
3219 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal('"sbwin', @:)
3221 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal('"sbrewind', @:)
3223 set wildoptions=fuzzy
3224 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
3225 call assert_equal('"sbrewind', @:)
3226 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
3227 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003228 set wildoptions&
3229endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003230
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003231" " compiler name fuzzy completion - NOT supported
3232" func Test_fuzzy_completion_compiler()
3233" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003234
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003235" :cscope suboptions fuzzy completion
3236func Test_fuzzy_completion_cscope()
3237 CheckFeature cscope
3238 set wildoptions&
3239 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal('"cscope ret', @:)
3241 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal('"cscope reset', @:)
3243 set wildoptions=fuzzy
3244 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal('"cscope reset', @:)
3246 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3247 call assert_equal('"cscope re*t', @:)
3248 set wildoptions&
3249endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003250
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003251" :diffget/:diffput buffer name fuzzy completion
3252func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003253 new SomeBuffer
3254 diffthis
3255 new OtherBuffer
3256 diffthis
3257 set wildoptions&
3258 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal('"diffget sbuf', @:)
3260 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3261 call assert_equal('"diffput sbuf', @:)
3262 set wildoptions=fuzzy
3263 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal('"diffget SomeBuffer', @:)
3265 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"diffput SomeBuffer', @:)
3267 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003268 set wildoptions&
3269endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003270
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003271" " directory name fuzzy completion - NOT supported
3272" func Test_fuzzy_completion_dirname()
3273" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003274
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003275" environment variable name fuzzy completion
3276func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003277 set wildoptions&
3278 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3279 call assert_equal('"echo $VUT', @:)
3280 set wildoptions=fuzzy
3281 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003283 set wildoptions&
3284endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003285
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003286" autocmd event fuzzy completion
3287func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003288 set wildoptions&
3289 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal('"autocmd BWout', @:)
3291 set wildoptions=fuzzy
3292 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3293 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003294 set wildoptions&
3295endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003296
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003297" vim expression fuzzy completion
3298func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003299 let g:PerPlaceCount = 10
3300 set wildoptions&
3301 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3302 call assert_equal('"let c = ppc', @:)
3303 set wildoptions=fuzzy
3304 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3305 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003306 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003307endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003308
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003309" " file name fuzzy completion - NOT supported
3310" func Test_fuzzy_completion_filename()
3311" endfunc
3312
3313" " files in path fuzzy completion - NOT supported
3314" func Test_fuzzy_completion_filesinpath()
3315" endfunc
3316
3317" " filetype name fuzzy completion - NOT supported
3318" func Test_fuzzy_completion_filetype()
3319" endfunc
3320
3321" user defined function name completion
3322func Test_fuzzy_completion_userdefined_func()
3323 set wildoptions&
3324 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3325 call assert_equal('"call Test_f_u_f', @:)
3326 set wildoptions=fuzzy
3327 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3328 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3329 set wildoptions&
3330endfunc
3331
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003332" <SNR> functions should be sorted to the end
3333func Test_fuzzy_completion_userdefined_snr_func()
3334 func s:Sendmail()
3335 endfunc
3336 func SendSomemail()
3337 endfunc
3338 func S1e2n3dmail()
3339 endfunc
3340 set wildoptions=fuzzy
3341 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003342 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003343 set wildoptions&
3344 delfunc s:Sendmail
3345 delfunc SendSomemail
3346 delfunc S1e2n3dmail
3347endfunc
3348
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003349" user defined command name completion
3350func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003351 set wildoptions&
3352 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3353 call assert_equal('"MsFeat', @:)
3354 set wildoptions=fuzzy
3355 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3356 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003357 set wildoptions&
3358endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003359
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003360" " :help tag fuzzy completion - NOT supported
3361" func Test_fuzzy_completion_helptag()
3362" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003363
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003364" highlight group name fuzzy completion
3365func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003366 set wildoptions&
3367 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_equal('"highlight SKey', @:)
3369 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3370 call assert_equal('"highlight SpecialKey', @:)
3371 set wildoptions=fuzzy
3372 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3373 call assert_equal('"highlight SpecialKey', @:)
3374 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3375 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003376 set wildoptions&
3377endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003378
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003379" :history suboptions fuzzy completion
3380func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003381 set wildoptions&
3382 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3383 call assert_equal('"history dg', @:)
3384 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3385 call assert_equal('"history search', @:)
3386 set wildoptions=fuzzy
3387 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3388 call assert_equal('"history debug', @:)
3389 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3390 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003391 set wildoptions&
3392endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003393
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003394" :language locale name fuzzy completion
3395func Test_fuzzy_completion_lang()
3396 CheckUnix
3397 set wildoptions&
3398 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal('"lang psx', @:)
3400 set wildoptions=fuzzy
3401 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"lang POSIX', @:)
3403 set wildoptions&
3404endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003405
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003406" :mapclear buffer argument fuzzy completion
3407func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003408 set wildoptions&
3409 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3410 call assert_equal('"mapclear buf', @:)
3411 set wildoptions=fuzzy
3412 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3413 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003414 set wildoptions&
3415endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003416
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003417" map name fuzzy completion
3418func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003419 " test regex completion works
3420 set wildoptions=fuzzy
3421 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3422 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003423 nmap <plug>MyLongMap :p<CR>
3424 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3425 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3426 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3427 call assert_equal("\"nmap MLM \t", @:)
3428 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal("\"nmap <F2> one two \t", @:)
3430 " duplicate entries should be removed
3431 vmap <plug>MyLongMap :<C-U>#<CR>
3432 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3433 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3434 nunmap <plug>MyLongMap
3435 vunmap <plug>MyLongMap
3436 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3437 call assert_equal("\"nmap ABC\t", @:)
3438 " results should be sorted by best match
3439 nmap <Plug>format :
3440 nmap <Plug>goformat :
3441 nmap <Plug>TestFOrmat :
3442 nmap <Plug>fendoff :
3443 nmap <Plug>state :
3444 nmap <Plug>FendingOff :
3445 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3446 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3447 nunmap <Plug>format
3448 nunmap <Plug>goformat
3449 nunmap <Plug>TestFOrmat
3450 nunmap <Plug>fendoff
3451 nunmap <Plug>state
3452 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003453 set wildoptions&
3454endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003455
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003456" abbreviation fuzzy completion
3457func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003458 set wildoptions=fuzzy
3459 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal("\"iabbr <nowait>", @:)
3461 iabbr WaitForCompletion WFC
3462 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3463 call assert_equal("\"iabbr WaitForCompletion", @:)
3464 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3465 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003466
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003467 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003468 set wildoptions&
3469endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003470
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003471" menu name fuzzy completion
3472func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003473 CheckFeature menu
3474
3475 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003476 set wildoptions&
3477 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3478 call assert_equal('"menu pup', @:)
3479 set wildoptions=fuzzy
3480 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3481 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003482
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003483 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003484 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003485endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003486
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003487" :messages suboptions fuzzy completion
3488func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003489 set wildoptions&
3490 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3491 call assert_equal('"messages clr', @:)
3492 set wildoptions=fuzzy
3493 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3494 call assert_equal('"messages clear', @:)
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" :set option name fuzzy completion
3499func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003500 set wildoptions&
3501 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3502 call assert_equal('"set brkopt', @:)
3503 set wildoptions=fuzzy
3504 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3505 call assert_equal('"set breakindentopt', @:)
3506 set wildoptions&
3507 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3508 call assert_equal('"set fixendofline', @:)
3509 set wildoptions=fuzzy
3510 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3511 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003512 set wildoptions&
3513endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003514
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003515" :set <term_option>
3516func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003517 set wildoptions&
3518 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3519 call assert_equal('"set t_EC', @:)
3520 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3521 call assert_equal('"set <t_EC>', @:)
3522 set wildoptions=fuzzy
3523 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3524 call assert_equal('"set t_EC', @:)
3525 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3526 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003527 set wildoptions&
3528endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003529
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003530" " :packadd directory name fuzzy completion - NOT supported
3531" func Test_fuzzy_completion_packadd()
3532" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003533
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003534" " shell command name fuzzy completion - NOT supported
3535" func Test_fuzzy_completion_shellcmd()
3536" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003537
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003538" :sign suboptions fuzzy completion
3539func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003540 set wildoptions&
3541 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3542 call assert_equal('"sign ufe', @:)
3543 set wildoptions=fuzzy
3544 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3545 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003546 set wildoptions&
3547endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003548
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003549" :syntax suboptions fuzzy completion
3550func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003551 set wildoptions&
3552 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3553 call assert_equal('"syntax kwd', @:)
3554 set wildoptions=fuzzy
3555 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3556 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003557 set wildoptions&
3558endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003559
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003560" syntax group name fuzzy completion
3561func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003562 set wildoptions&
3563 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3564 call assert_equal('"syntax list mpar', @:)
3565 set wildoptions=fuzzy
3566 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3567 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003568 set wildoptions&
3569endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003570
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003571" :syntime suboptions fuzzy completion
3572func Test_fuzzy_completion_syntime()
3573 CheckFeature profile
3574 set wildoptions&
3575 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3576 call assert_equal('"syntime clr', @:)
3577 set wildoptions=fuzzy
3578 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3579 call assert_equal('"syntime clear', @:)
3580 set wildoptions&
3581endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003582
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003583" " tag name fuzzy completion - NOT supported
3584" func Test_fuzzy_completion_tagname()
3585" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003586
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003587" " tag name and file fuzzy completion - NOT supported
3588" func Test_fuzzy_completion_tagfile()
3589" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003590
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003591" " user names fuzzy completion - how to test this functionality?
3592" func Test_fuzzy_completion_username()
3593" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003594
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003595" user defined variable name fuzzy completion
3596func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003597 let g:SomeVariable=10
3598 set wildoptions&
3599 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3600 call assert_equal('"let SVar', @:)
3601 set wildoptions=fuzzy
3602 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003604 set wildoptions&
3605endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003606
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003607" Test for sorting the results by the best match
3608func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003609 %bw!
3610 command T123format :
3611 command T123goformat :
3612 command T123TestFOrmat :
3613 command T123fendoff :
3614 command T123state :
3615 command T123FendingOff :
3616 set wildoptions=fuzzy
3617 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3618 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3619 delcommand T123format
3620 delcommand T123goformat
3621 delcommand T123TestFOrmat
3622 delcommand T123fendoff
3623 delcommand T123state
3624 delcommand T123FendingOff
3625 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003626 set wildoptions&
3627endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003628
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003629" Test for fuzzy completion of a command with lower case letters and a number
3630func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003631 command Foo2Bar :
3632 set wildoptions=fuzzy
3633 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3634 call assert_equal('"Foo2Bar', @:)
3635 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3636 call assert_equal('"Foo2Bar', @:)
3637 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3638 call assert_equal('"Foo2Bar', @:)
3639 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003640 set wildoptions&
3641endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003642
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003643" Test for command completion for a command starting with 'k'
3644func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003645 command KillKillKill :
3646 set wildoptions&
3647 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3648 call assert_equal("\"killkill\<Tab>", @:)
3649 set wildoptions=fuzzy
3650 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3651 call assert_equal('"KillKillKill', @:)
3652 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003653 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003654endfunc
3655
3656" Test for fuzzy completion for user defined custom completion function
3657func Test_fuzzy_completion_custom_func()
3658 func Tcompl(a, c, p)
3659 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3660 endfunc
3661 command -nargs=* -complete=custom,Tcompl Fuzzy :
3662 set wildoptions&
3663 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3664 call assert_equal("\"Fuzzy format", @:)
3665 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3666 call assert_equal("\"Fuzzy xy", @:)
3667 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3668 call assert_equal("\"Fuzzy ttt", @:)
3669 set wildoptions=fuzzy
3670 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3671 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3672 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3673 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3674 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3675 call assert_equal("\"Fuzzy xy", @:)
3676 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3677 call assert_equal("\"Fuzzy TestFOrmat", @:)
3678 delcom Fuzzy
3679 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003680endfunc
3681
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003682" Test for fuzzy completion in the middle of a cmdline instead of at the end
3683func Test_fuzzy_completion_in_middle()
3684 set wildoptions=fuzzy
3685 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3686 call assert_equal("\"set wildchar wildcharm wrap", @:)
3687
3688 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3689 call assert_equal("\"args ++encoding= zz", @:)
3690 set wildoptions&
3691endfunc
3692
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003693" Test for :breakadd argument completion
3694func Test_cmdline_complete_breakadd()
3695 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3696 call assert_equal("\"breakadd expr file func here", @:)
3697 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3698 call assert_equal("\"breakadd expr", @:)
3699 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3700 call assert_equal("\"breakadd expr", @:)
3701 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3702 call assert_equal("\"breakadd here", @:)
3703 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3704 call assert_equal("\"breakadd here", @:)
3705 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3706 call assert_equal("\"breakadd abc", @:)
3707 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3708 let l = getcompletion('not', 'breakpoint')
3709 call assert_equal([], l)
3710
3711 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003712 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003713 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3714 call assert_equal("\"breakadd file Xscript", @:)
3715 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3716 call assert_equal("\"breakadd file Xscript", @:)
3717 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3718 call assert_equal("\"breakadd file 20 Xscript", @:)
3719 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3720 call assert_equal("\"breakadd file 20 Xscript", @:)
3721 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3722 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3723 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3724 call assert_equal("\"breakadd file 20\t", @:)
3725 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3726 call assert_equal("\"breakadd file 20x\t", @:)
3727 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3728 call assert_equal("\"breakadd file Xscript ", @:)
3729 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3730 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003731
3732 " Test for :breakadd func [lnum] <function>
3733 func Xbreak_func()
3734 endfunc
3735 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3736 call assert_equal("\"breakadd func Xbreak_func", @:)
3737 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3738 call assert_equal("\"breakadd func Xbreak_func", @:)
3739 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3740 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3741 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3742 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3743 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3744 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3745 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3746 call assert_equal("\"breakadd func 20\t", @:)
3747 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3748 call assert_equal("\"breakadd func 20x\t", @:)
3749 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3750 call assert_equal("\"breakadd func Xbreak_func ", @:)
3751 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3752 call assert_equal("\"breakadd func X1B2C3", @:)
3753 delfunc Xbreak_func
3754
3755 " Test for :breakadd expr <expression>
3756 let g:Xtest_var = 10
3757 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3758 call assert_equal("\"breakadd expr Xtest_var", @:)
3759 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3760 call assert_equal("\"breakadd expr Xtest_var", @:)
3761 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3762 call assert_equal("\"breakadd expr Xtest_var ", @:)
3763 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3764 call assert_equal("\"breakadd expr X1B2C3", @:)
3765 unlet g:Xtest_var
3766
3767 " Test for :breakadd here
3768 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3769 call assert_equal("\"breakadd here Xtest", @:)
3770 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3771 call assert_equal("\"breakadd here Xtest", @:)
3772 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3773 call assert_equal("\"breakadd here ", @:)
3774endfunc
3775
3776" Test for :breakdel argument completion
3777func Test_cmdline_complete_breakdel()
3778 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3779 call assert_equal("\"breakdel file func here", @:)
3780 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3781 call assert_equal("\"breakdel file", @:)
3782 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3783 call assert_equal("\"breakdel file", @:)
3784 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3785 call assert_equal("\"breakdel here", @:)
3786 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3787 call assert_equal("\"breakdel here", @:)
3788 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3789 call assert_equal("\"breakdel abc", @:)
3790
3791 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003792 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003793 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3794 call assert_equal("\"breakdel file Xscript", @:)
3795 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3796 call assert_equal("\"breakdel file Xscript", @:)
3797 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3798 call assert_equal("\"breakdel file 20 Xscript", @:)
3799 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3800 call assert_equal("\"breakdel file 20 Xscript", @:)
3801 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3802 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3803 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3804 call assert_equal("\"breakdel file 20\t", @:)
3805 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3806 call assert_equal("\"breakdel file 20x\t", @:)
3807 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3808 call assert_equal("\"breakdel file Xscript ", @:)
3809 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3810 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003811
3812 " Test for :breakdel func [lnum] <function>
3813 func Xbreak_func()
3814 endfunc
3815 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3816 call assert_equal("\"breakdel func Xbreak_func", @:)
3817 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3818 call assert_equal("\"breakdel func Xbreak_func", @:)
3819 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3820 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3821 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3822 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3823 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3824 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3825 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3826 call assert_equal("\"breakdel func 20\t", @:)
3827 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3828 call assert_equal("\"breakdel func 20x\t", @:)
3829 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3830 call assert_equal("\"breakdel func Xbreak_func ", @:)
3831 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3832 call assert_equal("\"breakdel func X1B2C3", @:)
3833 delfunc Xbreak_func
3834
3835 " Test for :breakdel here
3836 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3837 call assert_equal("\"breakdel here Xtest", @:)
3838 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3839 call assert_equal("\"breakdel here Xtest", @:)
3840 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3841 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003842endfunc
3843
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003844" Test for :scriptnames argument completion
3845func Test_cmdline_complete_scriptnames()
3846 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003847 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003848 source Xa1b2c3.vim
3849 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3850 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3851 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3852 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3853 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3854 call assert_equal("\"script b2c3", @:)
3855 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3856 call assert_match("\"script 2\<Tab>$", @:)
3857 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3858 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3859 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3860 call assert_equal("\"script ", @:)
3861 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3862 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3863 new
3864 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3865 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3866 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003867 set wildmenu&
3868endfunc
3869
Bram Moolenaard8893442022-05-06 20:38:47 +01003870" this was going over the end of IObuff
3871func Test_report_error_with_composing()
3872 let caught = 'no'
3873 try
3874 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3875 catch /E492:/
3876 let caught = 'yes'
3877 endtry
3878 call assert_equal('yes', caught)
3879endfunc
3880
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003881" Test for expanding 2-letter and 3-letter :substitute command arguments.
3882" These commands don't accept an argument.
3883func Test_cmdline_complete_substitute_short()
3884 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3885 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3886 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3887 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3888 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3889 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3890 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3891 endfor
3892endfunc
3893
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003894" Test for shellcmdline command argument completion
3895func Test_cmdline_complete_shellcmdline_argument()
3896 command -nargs=+ -complete=shellcmdline MyCmd
3897
3898 set wildoptions=fuzzy
3899
3900 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3901 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003902 call assert_equal(['test_cmdline.vim'],
3903 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003904
3905 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3906 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003907 call assert_equal([],
3908 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003909
3910 let compl1 = getcompletion('', 'file')[0]
3911 let compl2 = getcompletion('', 'file')[1]
3912 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3913 call assert_equal('"MyCmd vim ' .. compl1, @:)
3914
3915 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3916 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3917
3918 let compl = getcompletion('', 'file')[1]
3919 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3920 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3921
3922 set wildoptions&
3923 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3924 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003925 call assert_equal(['test_cmdline.vim'],
3926 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003927
3928 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3929 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003930 call assert_equal([],
3931 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003932
3933 let compl1 = getcompletion('', 'file')[0]
3934 let compl2 = getcompletion('', 'file')[1]
3935 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3936 call assert_equal('"MyCmd vim ' .. compl1, @:)
3937
3938 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3939 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3940
3941 let compl = getcompletion('', 'file')[1]
3942 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3943 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3944
3945 delcommand MyCmd
3946endfunc
3947
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003948" Test for :! shell command argument completion
3949func Test_cmdline_complete_bang_cmd_argument()
3950 set wildoptions=fuzzy
3951 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3952 call assert_equal('"!vim test_cmdline.vim', @:)
3953 set wildoptions&
3954 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3955 call assert_equal('"!vim test_cmdline.vim', @:)
3956endfunc
3957
zeertzjq961b2e52023-04-17 15:53:24 +01003958func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003959 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003960endfunc
3961
3962func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003963 call assert_equal(0, getcmdpos())
3964 call assert_equal(0, getcmdscreenpos())
3965 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003966 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003967
zeertzjqa821b602024-06-18 20:31:08 +02003968 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003969 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003970 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003971 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003972 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003973 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003974 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003975
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003976 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3977 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003978 let g:results = []
3979 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3980 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3981 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003982 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3983 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3984 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003985
3986 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003987 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003988endfunc
3989
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003990func Test_recursive_register()
3991 let @= = ''
3992 silent! ?e/
3993 let caught = 'no'
3994 try
3995 normal //
3996 catch /E169:/
3997 let caught = 'yes'
3998 endtry
3999 call assert_equal('yes', caught)
4000endfunc
4001
Bram Moolenaar44a3f332022-06-06 15:38:21 +01004002func Test_long_error_message()
4003 " the error should be truncated, not overrun IObuff
4004 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
4005endfunc
4006
zeertzjq6791adc2022-07-26 20:42:25 +01004007func Test_cmdline_redraw_tabline()
4008 CheckRunVimInTerminal
4009
4010 let lines =<< trim END
4011 set showtabline=2
4012 autocmd CmdlineEnter * set tabline=foo
4013 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01004014 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01004015 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
4016 call term_sendkeys(buf, ':')
4017 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
4018
4019 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01004020endfunc
4021
zeertzjqb82a2ab2022-08-21 14:33:57 +01004022func Test_wildmenu_pum_disable_while_shown()
4023 set wildoptions=pum
4024 set wildmenu
4025 cnoremap <F2> <Cmd>set nowildmenu<CR>
4026 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
4027 call assert_equal(0, pumvisible())
4028 cunmap <F2>
4029 set wildoptions& wildmenu&
4030endfunc
4031
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004032func Test_setcmdline()
4033 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01004034 call assert_equal(0, setcmdline(test_null_string()))
4035 call assert_equal('', getcmdline())
4036 call assert_equal(1, getcmdpos())
4037
4038 call assert_equal(0, setcmdline(''[: -1]))
4039 call assert_equal('', getcmdline())
4040 call assert_equal(1, getcmdpos())
4041
zeertzjq54acb902022-08-29 16:21:25 +01004042 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004043 call assert_equal(0, setcmdline(a:text))
4044 call assert_equal(a:text, getcmdline())
4045 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01004046 call assert_equal(getcmdtype(), g:cmdtype)
4047 unlet g:cmdtype
4048 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004049
4050 call assert_equal(0, setcmdline(a:text, a:pos))
4051 call assert_equal(a:text, getcmdline())
4052 call assert_equal(a:pos, getcmdpos())
4053
4054 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01004055 call assert_fails('call setcmdline({}, 0)', 'E1174:')
4056 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004057
4058 return ''
4059 endfunc
4060
4061 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
4062 call assert_equal('set rtp?', @:)
4063
zeertzjq54acb902022-08-29 16:21:25 +01004064 call feedkeys(":let g:str = input('? ')\<CR>", 't')
4065 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
4066 call assert_equal('foo', g:str)
4067 unlet g:str
4068
4069 delfunc SetText
4070
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004071 " setcmdline() returns 1 when not editing the command line.
4072 call assert_equal(1, 'foo'->setcmdline())
4073
4074 " Called in custom function
4075 func CustomComplete(A, L, P)
4076 call assert_equal(0, setcmdline("DoCmd "))
4077 return "January\nFebruary\nMars\n"
4078 endfunc
4079
4080 com! -nargs=* -complete=custom,CustomComplete DoCmd :
4081 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
4082 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01004083 delcom DoCmd
4084 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004085
4086 " Called in <expr>
4087 cnoremap <expr>a setcmdline('let foo=')
4088 call feedkeys(":a\<CR>", 'tx')
4089 call assert_equal('let foo=0', @:)
4090 cunmap a
4091endfunc
4092
Sean Dewarfc8a6012023-04-17 16:41:20 +01004093func Test_rulerformat_position()
4094 CheckScreendump
4095
4096 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
4097 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
4098 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
4099 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
4100 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
4101
4102 " clean up
4103 call StopVimInTerminal(buf)
4104endfunc
4105
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01004106" Test for using "%!" in 'rulerformat' to use a function
4107func Test_rulerformat_function()
4108 CheckScreendump
4109
4110 let lines =<< trim END
4111 func TestRulerFn()
4112 return '10,20%=30%%'
4113 endfunc
4114 END
4115 call writefile(lines, 'Xrulerformat_function', 'D')
4116
4117 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
4118 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
4119 call term_sendkeys(buf, ":redraw!\<CR>")
4120 call term_wait(buf)
4121 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
4122
4123 " clean up
4124 call StopVimInTerminal(buf)
4125endfunc
4126
zeertzjqe4c79d32023-08-15 22:41:53 +02004127func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004128 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004129
zeertzjqe4c79d32023-08-15 22:41:53 +02004130 call assert_equal(getcompletion('', 'cmdline'),
4131 \ getcompletion('TestCompletion ', 'cmdline'))
4132 call assert_equal(['<buffer>'],
4133 \ getcompletion('TestCompletion map <bu', 'cmdline'))
4134
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004135 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02004136endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02004137
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004138func Test_custom_completion()
4139 func CustomComplete1(lead, line, pos)
4140 return "a\nb\nc"
4141 endfunc
4142 func CustomComplete2(lead, line, pos)
4143 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
4144 endfunc
4145 func Check_custom_completion()
4146 call assert_equal('custom,CustomComplete1', getcmdcompltype())
4147 return ''
4148 endfunc
4149 func Check_customlist_completion()
4150 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
4151 return ''
4152 endfunc
4153
4154 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
4155 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
4156
4157 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
4158 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
4159
4160 call assert_fails("call getcompletion('', 'custom')", 'E475:')
4161 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
4162
zeertzjq757f3212024-04-15 19:01:04 +02004163 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
4164 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
4165 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004166
4167 delcom Test1
4168 delcom Test2
4169
4170 delfunc CustomComplete1
4171 delfunc CustomComplete2
4172 delfunc Check_custom_completion
4173 delfunc Check_customlist_completion
4174endfunc
4175
zeertzjq28a23602023-09-29 19:58:35 +02004176func Test_custom_completion_with_glob()
4177 func TestGlobComplete(A, L, P)
4178 return split(glob('Xglob*'), "\n")
4179 endfunc
4180
4181 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
4182 call writefile([], 'Xglob1', 'D')
4183 call writefile([], 'Xglob2', 'D')
4184
4185 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
4186 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
4187
4188 delcommand TestGlobComplete
4189 delfunc TestGlobComplete
4190endfunc
4191
Christian Brabandt8610f742024-01-12 17:34:40 +01004192func Test_window_size_stays_same_after_changing_cmdheight()
4193 set laststatus=2
4194 let expected = winheight(0)
4195 function! Function_name() abort
4196 call feedkeys(":"..repeat('x', &columns), 'x')
4197 let &cmdheight=2
4198 let &cmdheight=1
4199 redraw
4200 endfunction
4201 call Function_name()
4202 call assert_equal(expected, winheight(0))
4203endfunc
4204
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01004205" verify that buffer-completion finds all buffer names matching a pattern
4206func Test_buffer_completion()
4207 " should return empty list
4208 call assert_equal([], getcompletion('', 'buffer'))
4209
4210 call mkdir('Xbuf_complete', 'R')
4211 e Xbuf_complete/Foobar.c
4212 e Xbuf_complete/MyFoobar.c
4213 e AFoobar.h
4214 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
4215
4216 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
4217 call assert_equal(expected, getcompletion('Foo', 'buffer'))
4218 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
4219 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
4220endfunc
4221
Anton Sharonov49528da2024-04-14 20:02:24 +02004222" :set t_??
4223func Test_term_option()
4224 set wildoptions&
4225 let _cpo = &cpo
4226 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004227 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02004228 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'
4229 \ .. ' 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'
4230 \ .. ' 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'
4231 \ .. ' 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'
4232 \ .. ' 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 +02004233 \ .. ' 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 +02004234 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004235 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004236 let &cpo = _cpo
4237endfunc
4238
Christian Brabandt70a11a62024-07-26 19:13:55 +02004239func Test_ex_command_completion()
4240 " required for :*
4241 set cpo+=*
4242 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4243 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4244 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004245 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004246 call assert_equal(0, exists(':ke'))
4247 call assert_equal(1, exists(':kee'))
4248 call assert_equal(1, exists(':keep'))
4249 call assert_equal(1, exists(':keepm'))
4250 call assert_equal(1, exists(':keepma'))
4251 call assert_equal(1, exists(':keepmar'))
4252 call assert_equal(1, exists(':keepmark'))
4253 call assert_equal(2, exists(':keepmarks'))
4254 call assert_equal(2, exists(':keepalt'))
4255 call assert_equal(2, exists(':keepjumps'))
4256 call assert_equal(2, exists(':keeppatterns'))
4257 set cpo-=*
4258endfunc
4259
zeertzjq5df3cb22024-10-07 21:05:06 +02004260func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004261 CheckMSWindows
4262 let save_shellslash = &shellslash
4263 set noshellslash
4264 call system('mkdir XXXa\_b')
4265 defer delete('XXXa', 'rf')
4266 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4267 call assert_equal('"cd XXXa\_b\', @:)
4268 let &shellslash = save_shellslash
4269endfunc
4270
Bram Moolenaar309976e2019-12-05 18:16:33 +01004271" vim: shiftwidth=2 sts=2 expandtab