blob: 2b81dc05a9cdff54dffa19bf2c65d41770c77a3d [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
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100273 func EchoOne()
274 set laststatus=2 cmdheight=1
275 echo 'foo'
276 echo 'bar'
277 set cmdheight=2
278 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100279 func EchoTwo()
280 set laststatus=2
281 set cmdheight=5
282 echo 'foo'
283 echo 'bar'
284 set cmdheight=1
285 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100287 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288
289 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
290 call term_sendkeys(buf, ":resize -3\<CR>")
291 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
292
Luuk van Baale15cbc12025-01-04 17:18:08 +0100293 " :resize now also changes 'cmdheight' accordingly
294 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100295 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
Luuk van Baale15cbc12025-01-04 17:18:08 +0100296 call term_sendkeys(buf, ":set cmdheight-=1\<CR>")
Bram Moolenaarf797e302022-08-11 13:17:30 +0100297
298 " using more space moves the status line up
299 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
300 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
301
302 " reducing cmdheight moves status line down
303 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
304 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
305
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000306 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100307 call term_sendkeys(buf, ":resize -1\<CR>")
308 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
309 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
310
Bram Moolenaar0816f472022-10-05 15:42:32 +0100311 " setting 'cmdheight' works after outputting two messages
312 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
313 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
314
Luuk van Baale15cbc12025-01-04 17:18:08 +0100315 " decreasing 'cmdheight' doesn't clear the messages that need hit-enter
nwounkn2e485672024-11-11 21:48:30 +0100316 call term_sendkeys(buf, ":call EchoOne()\<CR>")
317 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
318
Bram Moolenaarf797e302022-08-11 13:17:30 +0100319 " clean up
320 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100321endfunc
322
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100323func Test_cmdheight_tabline()
324 CheckScreendump
325
326 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
327 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
328
329 " clean up
330 call StopVimInTerminal(buf)
331endfunc
332
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100333func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100334 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
335 call assert_equal('"map <unique> <silent>', getreg(':'))
336 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
337 call assert_equal('"map <script> <unique>', getreg(':'))
338 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
339 call assert_equal('"map <expr> <script>', getreg(':'))
340 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
341 call assert_equal('"map <buffer> <expr>', getreg(':'))
342 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
343 call assert_equal('"map <nowait> <buffer>', getreg(':'))
344 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
345 call assert_equal('"map <special> <nowait>', getreg(':'))
346 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
347 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200348
Bram Moolenaar1776a282019-05-03 16:05:41 +0200349 map <Middle>x middle
350
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351 map ,f commaf
352 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200353 map <Left> left
354 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200355 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
356 call assert_equal('"map ,f', getreg(':'))
357 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
358 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200359 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"map <Left>', getreg(':'))
361 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200362 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000363 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
364 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200365 unmap ,f
366 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200367 unmap <Left>
368 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200369
zeertzjqc3a26c62023-02-17 16:40:20 +0000370 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200371 map <Left> left
372 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
373 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200374 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200375 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000376 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200378 unmap <Left>
379
380 set cpo+=<
381 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200382 exe "set t_k6=\<Esc>[17~"
383 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200384 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
385 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200386 if !has('gui_running')
387 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
388 call assert_equal("\"map <F6>x", getreg(':'))
389 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200390 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200391 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200392 set cpo-=<
393
394 set cpo+=B
395 map <Left> left
396 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
397 call assert_equal('"map <Left>', getreg(':'))
398 unmap <Left>
399 set cpo-=B
400
401 set cpo+=k
402 map <Left> left
403 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
404 call assert_equal('"map <Left>', getreg(':'))
405 unmap <Left>
406 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200407
Bram Moolenaar531be472020-09-23 22:38:05 +0200408 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
409
Bram Moolenaar1776a282019-05-03 16:05:41 +0200410 unmap <Middle>x
411 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100412endfunc
413
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100414func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100415 hi Aardig ctermfg=green
416 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000417 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100418 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000419 call assert_equal('"match none', @:)
420 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
421 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100422endfunc
423
424func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100425 hi Aardig ctermfg=green
426 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
427 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200428 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
429 call assert_equal('"hi default Aardig', getreg(':'))
430 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
431 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100432 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
433 call assert_equal('"hi link', getreg(':'))
434 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
435 call assert_equal('"hi default', getreg(':'))
436 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
437 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200438 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
439 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
440 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
441 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200442
443 " A cleared group does not show up in completions.
444 hi Anders ctermfg=green
445 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
446 hi clear Aardig
447 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
448 hi clear Anders
449 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100450endfunc
451
Bram Moolenaar75e15672020-06-28 13:10:22 +0200452" Test for command-line expansion of "hi Ni " (easter egg)
453func Test_highlight_easter_egg()
454 call test_override('ui_delay', 1)
455 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
456 call assert_equal("\"hi Ni \<Tab>", @:)
457 call test_override('ALL', 0)
458endfunc
459
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200460func Test_getcompletion()
461 let groupcount = len(getcompletion('', 'event'))
462 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200463 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200464 call assert_true(matchcount > 0)
465 call assert_true(groupcount > matchcount)
466
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200467 if has('menu')
468 source $VIMRUNTIME/menu.vim
469 let matchcount = len(getcompletion('', 'menu'))
470 call assert_true(matchcount > 0)
471 call assert_equal(['File.'], getcompletion('File', 'menu'))
472 call assert_true(matchcount > 0)
473 let matchcount = len(getcompletion('File.', 'menu'))
474 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000475 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200476 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200477
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200478 let l = getcompletion('v:n', 'var')
479 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200480 let l = getcompletion('v:notexists', 'var')
481 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200483 args a.c b.c
484 let l = getcompletion('', 'arglist')
485 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000486 let l = getcompletion('a.', 'buffer')
487 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200488 %argdelete
489
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200490 let l = getcompletion('', 'augroup')
491 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200492 let l = getcompletion('blahblah', 'augroup')
493 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200494
495 let l = getcompletion('', 'behave')
496 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200497 let l = getcompletion('not', 'behave')
498 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200499
500 let l = getcompletion('', 'color')
501 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200502 let l = getcompletion('dirty', 'color')
503 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200504
505 let l = getcompletion('', 'command')
506 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200507 let l = getcompletion('awake', 'command')
508 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509
510 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200511 call assert_true(index(l, 'samples/') >= 0)
512 let l = getcompletion('NoMatch', 'dir')
513 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200514
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100515 if glob('~/*') !=# ''
516 let l = getcompletion('~/', 'dir')
517 call assert_true(l[0][0] ==# '~')
518 endif
519
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200520 let l = getcompletion('exe', 'expression')
521 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200522 let l = getcompletion('kill', 'expression')
523 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200524
525 let l = getcompletion('tag', 'function')
526 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200527 let l = getcompletion('paint', 'function')
528 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200529
Kota Kato90c23532023-01-18 15:27:38 +0000530 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000531 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000532 let l = getcompletion('ruby', 'function')
533 call assert_equal([], l)
534 endif
535
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200536 let Flambda = {-> 'hello'}
537 let l = getcompletion('', 'function')
538 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200539 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200540
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200541 let l = getcompletion('run', 'file')
542 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200543 let l = getcompletion('walk', 'file')
544 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200545 set wildignore=*.vim
546 let l = getcompletion('run', 'file', 1)
547 call assert_true(index(l, 'runtest.vim') < 0)
548 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000549 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100550 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000551 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
552 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200553
554 let l = getcompletion('ha', 'filetype')
555 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200556 let l = getcompletion('horse', 'filetype')
557 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200558
Doug Kearns81642d92024-01-04 22:37:44 +0100559 if has('keymap')
560 let l = getcompletion('acc', 'keymap')
561 call assert_true(index(l, 'accents') >= 0)
562 let l = getcompletion('nullkeymap', 'keymap')
563 call assert_equal([], l)
564 endif
565
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200566 let l = getcompletion('z', 'syntax')
567 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200568 let l = getcompletion('emacs', 'syntax')
569 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200570
571 let l = getcompletion('jikes', 'compiler')
572 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200573 let l = getcompletion('break', 'compiler')
574 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200575
576 let l = getcompletion('last', 'help')
577 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200578 let l = getcompletion('giveup', 'help')
579 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200580
581 let l = getcompletion('time', 'option')
582 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200583 let l = getcompletion('space', 'option')
584 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200585
586 let l = getcompletion('er', 'highlight')
587 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200588 let l = getcompletion('dark', 'highlight')
589 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200590
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200591 let l = getcompletion('', 'messages')
592 call assert_true(index(l, 'clear') >= 0)
593 let l = getcompletion('not', 'messages')
594 call assert_equal([], l)
595
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200596 let l = getcompletion('', 'mapclear')
597 call assert_true(index(l, '<buffer>') >= 0)
598 let l = getcompletion('not', 'mapclear')
599 call assert_equal([], l)
600
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200601 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200602 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200603 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
604 let root = has('win32') ? 'C:\\' : '/'
605 let l = getcompletion(root, 'shellcmd')
606 let expected = map(filter(glob(root . '*', 0, 1),
607 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
608 call assert_equal(expected, l)
609
Bram Moolenaarb650b982016-08-05 20:35:13 +0200610 if has('cscope')
611 let l = getcompletion('', 'cscope')
612 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
613 call assert_equal(cmds, l)
614 " using cmdline completion must not change the result
615 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
616 let l = getcompletion('', 'cscope')
617 call assert_equal(cmds, l)
618 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
619 let l = getcompletion('find ', 'cscope')
620 call assert_equal(keys, l)
621 endif
622
Bram Moolenaar7522f692016-08-06 14:12:50 +0200623 if has('signs')
624 sign define Testing linehl=Comment
625 let l = getcompletion('', 'sign')
626 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
627 call assert_equal(cmds, l)
628 " using cmdline completion must not change the result
629 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
630 let l = getcompletion('', 'sign')
631 call assert_equal(cmds, l)
632 let l = getcompletion('list ', 'sign')
633 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000634 let l = getcompletion('de*', 'sign')
635 call assert_equal(['define'], l)
636 let l = getcompletion('p?', 'sign')
637 call assert_equal(['place'], l)
638 let l = getcompletion('j.', 'sign')
639 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200640 endif
641
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200642 " Command line completion tests
643 let l = getcompletion('cd ', 'cmdline')
644 call assert_true(index(l, 'samples/') >= 0)
645 let l = getcompletion('cd NoMatch', 'cmdline')
646 call assert_equal([], l)
647 let l = getcompletion('let v:n', 'cmdline')
648 call assert_true(index(l, 'v:null') >= 0)
649 let l = getcompletion('let v:notexists', 'cmdline')
650 call assert_equal([], l)
651 let l = getcompletion('call tag', 'cmdline')
652 call assert_true(index(l, 'taglist(') >= 0)
653 let l = getcompletion('call paint', 'cmdline')
654 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200655 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
656 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200657
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100658 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000659 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100660 return "oneA\noneB\noneC"
661 endfunc
662 command -nargs=1 -complete=custom,T MyCmd
663 let l = getcompletion('MyCmd ', 'cmdline')
664 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000665 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100666
667 delcommand MyCmd
668 delfunc T
ii144785fe02021-11-21 12:13:56 +0000669 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100670
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200671 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200672 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
673 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200674 if has('cmdline_hist')
675 call add(names, 'history')
676 endif
677 if has('gettext')
678 call add(names, 'locale')
679 endif
680 if has('profile')
681 call add(names, 'syntime')
682 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200683
684 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100685 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200686
687 for name in names
688 let matchcount = len(getcompletion('', name))
689 call assert_true(matchcount >= 0, 'No matches for ' . name)
690 endfor
691
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200692 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200693
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000694 edit a~b
695 enew
696 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
697 bw a~b
698
699 if has('unix')
700 edit Xtest\
701 enew
702 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
703 bw Xtest\
704 endif
705
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100706 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200707 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100708 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200709endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200710
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000711func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000712 " Get a dialog in the GUI
713 CheckNotGui
714
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000715 " This was using uninitialized memory.
716 let lines =<< trim END
717 set verbose=6
718 norm @=ٷ
719 qall!
720 END
721 call writefile(lines, 'XmultiScript', 'D')
722 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
723endfunc
724
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000725" Test for getcompletion() with "fuzzy" in 'wildoptions'
726func Test_getcompletion_wildoptions()
727 let save_wildoptions = &wildoptions
728 set wildoptions&
729 let l = getcompletion('space', 'option')
730 call assert_equal([], l)
731 let l = getcompletion('ier', 'command')
732 call assert_equal([], l)
733 set wildoptions=fuzzy
734 let l = getcompletion('space', 'option')
735 call assert_true(index(l, 'backspace') >= 0)
736 let l = getcompletion('ier', 'command')
737 call assert_true(index(l, 'compiler') >= 0)
738 let &wildoptions = save_wildoptions
739endfunc
740
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000741func Test_complete_autoload_error()
742 let save_rtp = &rtp
743 let lines =<< trim END
744 vim9script
745 export def Complete(..._): string
746 return 'match'
747 enddef
748 echo this will cause an error
749 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100750 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000751 call writefile(lines, 'Xdir/autoload/script.vim')
752 exe 'set rtp+=' .. getcwd() .. '/Xdir'
753
754 let lines =<< trim END
755 vim9script
756 import autoload 'script.vim'
757 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
758 &wildcharm = char2nr("\<Tab>")
759 feedkeys(":Cmd \<Tab>", 'xt')
760 END
761 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
762
763 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000764endfunc
765
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100766func Test_fullcommand()
767 let tests = {
768 \ '': '',
769 \ ':': '',
770 \ ':::': '',
771 \ ':::5': '',
772 \ 'not_a_cmd': '',
773 \ 'Check': '',
774 \ 'syntax': 'syntax',
775 \ ':syntax': 'syntax',
776 \ '::::syntax': 'syntax',
777 \ 'sy': 'syntax',
778 \ 'syn': 'syntax',
779 \ 'synt': 'syntax',
780 \ ':sy': 'syntax',
781 \ '::::sy': 'syntax',
782 \ 'match': 'match',
783 \ '2match': 'match',
784 \ '3match': 'match',
785 \ 'aboveleft': 'aboveleft',
786 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100787 \ 'en': 'endif',
788 \ 'end': 'endif',
789 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100790 \ 's': 'substitute',
791 \ '5s': 'substitute',
792 \ ':5s': 'substitute',
793 \ "'<,'>s": 'substitute',
794 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100795 \ 'CheckLin': 'CheckLinux',
796 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100797 \ }
798
799 for [in, want] in items(tests)
800 call assert_equal(want, fullcommand(in))
801 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200802 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100803
804 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200805
806 command -buffer BufferLocalCommand :
807 command GlobalCommand :
808 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
809 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
810 delcommand BufferLocalCommand
811 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100812endfunc
813
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200814func Test_shellcmd_completion()
815 let save_path = $PATH
816
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100817 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200818 call writefile([''], 'Xpathdir/Xfile.exe')
819 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
820
821 " Set PATH to example directory without trailing slash.
822 let $PATH = getcwd() . '/Xpathdir'
823
824 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
825 " dirs in the PATH, even though they won't be executed. We check that only
826 " subdirs of the PWD and executables from the PATH are included in the
827 " suggestions.
828 let actual = getcompletion('X', 'shellcmd')
829 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
830 call insert(expected, 'Xfile.exe')
831 call assert_equal(expected, actual)
832
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200833 let $PATH = save_path
834endfunc
835
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200836func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100837 call mkdir('a/b/c', 'pR')
838 call writefile(['asdfasdf'], 'a/b/c/fileXname')
839 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
840 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200841 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200842endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100843
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100844func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100845 let @a = "def"
846 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
847 call assert_equal('"abc def ghi', @:)
848
849 new
850 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
851
852 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
853 call assert_equal('"aaa asdf bbb', @:)
854
855 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
856 call assert_equal('"aaa /tmp/some bbb', @:)
857
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200858 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
859 call assert_equal('"aaa '.getline(1).' bbb', @:)
860
Bram Moolenaar21efc362016-12-03 14:05:49 +0100861 set incsearch
862 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
863 call assert_equal('"aaa verylongword bbb', @:)
864
865 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
866 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100867
868 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
869 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100870 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200871
872 " Error while typing a command used to cause that it was not executed
873 " in the end.
874 new
875 try
876 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
877 catch /^Vim\%((\a\+)\)\=:E32/
878 " ignore error E32
879 endtry
880 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100881
Bram Moolenaar578fe942020-02-27 21:32:51 +0100882 " Try to paste an invalid register using <C-R>
883 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
884 call assert_equal('"onetwo', @:)
885
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100886 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100887 let @a = "xy\<C-H>z"
888 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
889 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100890 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
891 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100892 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
893 call assert_equal("\"xy\<C-H>z", @:)
894
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100895 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
896 let @a = "xy\<C-V>z"
897 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
898 call assert_equal('"xyz', @:)
899 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
900 call assert_equal("\"xy\<C-V>z", @:)
901
Bram Moolenaar578fe942020-02-27 21:32:51 +0100902 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
903
Bram Moolenaar72532d32018-04-07 19:09:09 +0200904 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100905endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100906
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100907func Test_cmdline_remove_char()
908 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100909
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100910 for e in ['utf8', 'latin1']
911 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100912
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100913 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
914 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100915
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100916 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
917 call assert_equal('"abcdef', @:)
918
919 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
920 call assert_equal('"abc ghi', @:, e)
921
922 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
923 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100924
925 " This was going before the start in latin1.
926 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100927 endfor
928
929 let &encoding = encoding_save
930endfunc
931
zeertzjqff2b79d2024-02-26 20:38:36 +0100932func Test_cmdline_del_utf8()
933 let @s = '⒌'
934 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
935 call assert_equal('",,', @:)
936
937 let @s = 'a̳'
938 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
939 call assert_equal('",,', @:)
940
941 let @s = 'β̳'
942 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
943 call assert_equal('",,', @:)
944
945 if has('arabic')
946 let @s = 'لا'
947 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
948 call assert_equal('",,', @:)
949 endif
950endfunc
951
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100952func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200953 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100954
955 set keymap=esperanto
956 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
957 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
958 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100959endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100960
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100961func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100962 new
963 2;'(
964 2;')
965 quit
966endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100967
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100968func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100969 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100970 new
971 source Xtest.vim
972 " Trigger calling validate_cursor()
973 diffsp Xtest.vim
974 quit!
975 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100976endfunc
977
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100978func Test_mark_from_line_zero()
979 " this was reading past the end of the first (empty) line
980 new
981 norm oxxxx
982 call assert_fails("0;'(", 'E20:')
983 bwipe!
984endfunc
985
Bram Moolenaarba47b512017-01-24 21:18:19 +0100986func Test_cmdline_complete_wildoptions()
987 help
988 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
989 let a = join(sort(split(@:)),' ')
990 set wildoptions=tagfile
991 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
992 let b = join(sort(split(@:)),' ')
993 call assert_equal(a, b)
994 bw!
995endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100996
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200997func Test_cmdline_complete_user_cmd()
998 command! -complete=color -nargs=1 Foo :
999 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
1000 call assert_equal('"Foo blue', @:)
1001 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1002 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001003 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1004 call assert_equal('"Foo a blue', @:)
1005 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1006 call assert_equal('"Foo b\', @:)
1007 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1008 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001009 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001010
1011 redraw
1012 call assert_equal('~', Screenline(&lines - 1))
1013 command! FooOne :
1014 command! FooTwo :
1015
1016 set nowildmenu
1017 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1018 call assert_equal('"FooOne', @:)
1019 call assert_equal('~', Screenline(&lines - 1))
1020
1021 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1022 call assert_equal('"FooTwo', @:)
1023 call assert_equal('~', Screenline(&lines - 1))
1024
1025 delcommand FooOne
1026 delcommand FooTwo
1027 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001028endfunc
1029
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001030func Test_complete_user_cmd()
1031 command FooBar echo 'global'
1032 command -buffer FooBar echo 'local'
1033 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1034 call assert_equal('"FooBar', @:)
1035
1036 delcommand -buffer FooBar
1037 delcommand FooBar
1038endfunc
1039
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001040func s:ScriptLocalFunction()
1041 echo 'yes'
1042endfunc
1043
1044func Test_cmdline_complete_user_func()
1045 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001046 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001047 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1048 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001049
1050 " g: prefix also works
1051 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1052 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001053
1054 " using g: prefix does not result in just "g:" matches from a lambda
1055 let Fx = { a -> a }
1056 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1057 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001058
1059 " existence of script-local dict function does not break user function name
1060 " completion
1061 function s:a_dict_func() dict
1062 endfunction
1063 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1064 call assert_match('"call Test_cmdline_complete_user_', @:)
1065 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001066endfunc
1067
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001068func Test_cmdline_complete_user_names()
1069 if has('unix') && executable('whoami')
1070 let whoami = systemlist('whoami')[0]
1071 let first_letter = whoami[0]
1072 if len(first_letter) > 0
1073 " Trying completion of :e ~x where x is the first letter of
1074 " the user name should complete to at least the user name.
1075 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1076 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1077 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001078 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001079 " Just in case: check that the system has an Administrator account.
1080 let names = system('net user')
1081 if names =~ 'Administrator'
1082 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001083 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001084 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001085 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001086 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001087 else
1088 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001089 endif
1090endfunc
1091
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001092func Test_cmdline_complete_shellcmdline()
1093 CheckExecutable whoami
1094 command -nargs=1 -complete=shellcmdline MyCmd
1095
1096 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1097 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001098 let l = getcompletion('whoam', 'shellcmdline')
1099 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001100
1101 delcommand MyCmd
1102endfunc
1103
Bram Moolenaar297610b2019-12-27 17:20:55 +01001104func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001105 CheckExecutable whoami
1106 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1107 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001108endfunc
1109
Bram Moolenaar8b633132020-03-20 18:20:51 +01001110func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001111 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1112 call assert_equal(lang, v:lc_time)
1113
1114 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1115 call assert_equal(lang, v:ctype)
1116
1117 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1118 call assert_equal(lang, v:collate)
1119
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001120 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001121 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001122
1123 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001124 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001125
Bram Moolenaarec680282020-06-12 19:35:32 +02001126 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001127
Bram Moolenaarec680282020-06-12 19:35:32 +02001128 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1129 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001130
Bram Moolenaarec680282020-06-12 19:35:32 +02001131 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1132 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001133
Bram Moolenaarec680282020-06-12 19:35:32 +02001134 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1135 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001136
1137 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1138 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001139endfunc
1140
Bram Moolenaar297610b2019-12-27 17:20:55 +01001141func Test_cmdline_complete_env_variable()
1142 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001143 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1144 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001145 unlet $X_VIM_TEST_COMPLETE_ENV
1146endfunc
1147
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001148func Test_cmdline_complete_expression()
1149 let g:SomeVar = 'blah'
1150 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1151 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1152 call assert_match('"' .. cmd .. ' SomeVar', @:)
1153 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1154 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1155 endfor
1156 unlet g:SomeVar
1157endfunc
1158
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001159func Test_cmdline_complete_argopt()
1160 " completion for ++opt=arg for file commands
1161 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1162 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1163 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1164
1165 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001166 " Test ++ff in the middle of the cmdline
1167 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001169
1170 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1171 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1172 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1173 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1174 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1175
1176 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1177
1178 " completion should skip the ++opt and continue
1179 call writefile([], 'Xaaaaa.txt', 'D')
1180 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1181 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1182
1183 if has('terminal')
1184 " completion for terminal's [options]
1185 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1186 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1187 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1188
1189 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1190
1191 " :terminal completion should skip the ++opt when considering what is the
1192 " first option, which is a list of shell commands, unlike second option
1193 " onwards.
1194 let first_param = getcompletion('terminal ', 'cmdline')
1195 let second_param = getcompletion('terminal foo ', 'cmdline')
1196 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1197 call assert_equal(first_param, skipped_opt_param)
1198 call assert_notequal(first_param, second_param)
1199 endif
1200endfunc
1201
Bram Moolenaar47016f52021-08-26 16:39:58 +02001202" Unique function name for completion below
1203func s:WeirdFunc()
1204 echo 'weird'
1205endfunc
1206
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001207" Test for various command-line completion
1208func Test_cmdline_complete_various()
1209 " completion for a command starting with a comment
1210 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1211 call assert_equal("\" :|\"\<C-A>", @:)
1212
1213 " completion for a range followed by a comment
1214 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1215 call assert_equal("\"1,2\"\<C-A>", @:)
1216
1217 " completion for :k command
1218 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1219 call assert_equal("\"ka\<C-A>", @:)
1220
Doug Kearnsea842022024-09-29 17:17:41 +02001221 " completion for :keepmarks command
1222 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1223 call assert_equal("\"kee edit", @:)
1224
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001225 " completion for short version of the :s command
1226 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1227 call assert_equal("\"sI \<C-A>", @:)
1228
1229 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001230 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001231 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001232 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001233 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001234 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1235 call assert_equal("\"w >> Xfile1", @:)
1236 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001237
1238 " completion for :w ! and :r ! commands
1239 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1240 call assert_equal("\"w !invalid_xyz_cmd", @:)
1241 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1242 call assert_equal("\"r !invalid_xyz_cmd", @:)
1243
1244 " completion for :>> and :<< commands
1245 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1246 call assert_equal("\">>>\<C-A>", @:)
1247 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1248 call assert_equal("\"<<<\<C-A>", @:)
1249
1250 " completion for command with +cmd argument
1251 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1252 call assert_equal("\"buffer +/pat Xabc", @:)
1253 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1254 call assert_equal("\"buffer +/pat\<C-A>", @:)
1255
1256 " completion for a command with a trailing comment
1257 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1258 call assert_equal("\"ls \" comment\<C-A>", @:)
1259
1260 " completion for a command with a trailing command
1261 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1262 call assert_equal("\"ls | ls", @:)
1263
1264 " completion for a command with an CTRL-V escaped argument
1265 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1266 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1267
1268 " completion for a command that doesn't take additional arguments
1269 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1270 call assert_equal("\"all abc\<C-A>", @:)
1271
zeertzjqd3de1782022-09-01 12:58:52 +01001272 " completion for :wincmd with :horizontal modifier
1273 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1274 call assert_equal("\"horizontal wincmd", @:)
1275
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001276 " completion for a command with a command modifier
1277 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1278 call assert_equal("\"topleft new", @:)
1279
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001280 " completion for vim9 and legacy commands
1281 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1282 call assert_equal("\"vim9 call strlen(", @:)
1283 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1284 call assert_equal("\"legac call strlen(", @:)
1285
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001286 " completion for the :disassemble command
1287 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1288 call assert_equal("\"disas debug", @:)
1289 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1290 call assert_equal("\"disas profile", @:)
1291 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1292 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1293 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1294 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001295 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1296 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001297
Bram Moolenaar47016f52021-08-26 16:39:58 +02001298 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001299 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001300
naohiro onodfe04db2021-09-12 15:45:10 +02001301 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1302 call assert_match('"disas <SNR>\d\+_', @:)
1303 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1304 call assert_match('"disas debug <SNR>\d\+_', @:)
1305
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001306 " completion for the :match command
1307 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1308 call assert_equal("\"match Search /pat/\<C-A>", @:)
1309
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001310 " completion for the :doautocmd command
1311 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1312 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1313
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001314 " completion of autocmd group after comma
1315 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1317
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001318 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001319 call writefile([], 'Xvarfile1', 'D')
1320 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001321 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1322 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001323
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001324 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001325 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001326 augroup END
1327 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001328 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001329
1330 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001331 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1332 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001333 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1334 call assert_equal("\"au XTest.test", @:)
1335
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001336 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001337
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001338 " autocmd pattern completion
1339 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1340 call assert_equal("\"au BufEnter *.py\t", @:)
1341
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001342 " completion for the :unlet command
1343 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1344 call assert_equal("\"unlet one two", @:)
1345
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001346 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001347 " FIXME: what should happen on MS-Windows?
1348 if !has('win32')
1349 edit \{someFile}
1350 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1351 call assert_equal("\"buf {someFile}", @:)
1352 bwipe {someFile}
1353 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001354
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001355 " completion for the :bdelete command
1356 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1357 call assert_equal("\"bdel a b c", @:)
1358
1359 " completion for the :mapclear command
1360 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1361 call assert_equal("\"mapclear <buffer>", @:)
1362
1363 " completion for user defined commands with menu names
1364 menu Test.foo :ls<CR>
1365 com -nargs=* -complete=menu MyCmd
1366 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1367 call assert_equal('"MyCmd Test.', @:)
1368 delcom MyCmd
1369 unmenu Test
1370
1371 " completion for user defined commands with mappings
1372 mapclear
1373 map <F3> :ls<CR>
1374 com -nargs=* -complete=mapping MyCmd
1375 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001376 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001377 mapclear
1378 delcom MyCmd
1379
Yee Cheng Chin54844852023-10-09 18:12:31 +02001380 " Prepare for path completion
1381 call mkdir('Xa b c', 'D')
1382 defer delete('Xcomma,foobar.txt')
1383 call writefile([], 'Xcomma,foobar.txt')
1384
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001385 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001386 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1387 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1388 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001389
1390 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001391 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1392 call assert_equal('"set dir=Xa\ b\ c/', @:)
1393 set dir&
1394
1395 " completion for :set tags= / set dictionary= with escaped commas
1396 if has('win32')
1397 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1398 " '\,'
1399 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1400 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1401
1402 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1403 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1404
1405 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1406 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1407
1408 " completion for :set dictionary= with escaped commas (same behavior, but
1409 " different internal code path from 'set tags=' for escaping the output)
1410 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1411 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1412 else
1413 " In other platforms, backslashes are rounded down (since '\,' itself will
1414 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1415 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1416 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1417
1418 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1419 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1420
1421 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1422 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1423
1424 " completion for :set dictionary= with escaped commas (same behavior, but
1425 " different internal code path from 'set tags=' for escaping the output)
1426 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1428 endif
1429 set tags&
1430 set dictionary&
1431
1432 " completion for :set makeprg= with no escaped commas
1433 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1434 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1435
1436 if !has('win32')
1437 " Cannot create file with backslash in file name in Windows, so only test
1438 " this elsewhere.
1439 defer delete('Xcomma\,fooslash.txt')
1440 call writefile([], 'Xcomma\,fooslash.txt')
1441 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1442 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1443 endif
1444 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001445
1446 " completion for the :py3 commands
1447 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1448 call assert_equal('"py3 py3do py3file', @:)
1449
Bram Moolenaardf749a22021-03-28 15:29:43 +02001450 " completion for the :vim9 commands
1451 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1452 call assert_equal('"vim9cmd vim9script', @:)
1453
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001454 " redir @" is not the start of a comment. So complete after that
1455 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1456 call assert_equal('"redir @" | cwindow', @:)
1457
1458 " completion after a backtick
1459 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1460 call assert_equal('"e `a1b2c', @:)
1461
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001462 " completion for :language command with an invalid argument
1463 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1464 call assert_equal("\"language dummy \t", @:)
1465
1466 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001467 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1468 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001469
1470 " completion with ambiguous user defined commands
1471 com TCmd1 echo 'TCmd1'
1472 com TCmd2 echo 'TCmd2'
1473 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1474 call assert_equal('"TCmd ', @:)
1475 delcom TCmd1
1476 delcom TCmd2
1477
1478 " completion after a range followed by a pipe (|) character
1479 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1480 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001481
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001482 " completion after a :global command
1483 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1484 call assert_equal('"g/a/chistory', @:)
1485 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1486 call assert_equal("\"g/a\\/chist\t", @:)
1487
Bram Moolenaar9c929712020-09-07 22:05:28 +02001488 " use <Esc> as the 'wildchar' for completion
1489 set wildchar=<Esc>
1490 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1491 call assert_equal('"g/a\xb/clearjumps', @:)
1492 " pressing <esc> twice should cancel the command
1493 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1494 call assert_equal('"g/a\xb/clearjumps', @:)
1495 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001496
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001497 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001498 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001499 call writefile([], '~Xtest')
1500 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1501 call assert_equal('"e \~Xtest', @:)
1502 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001503
1504 " should be able to complete a file name that has a '*'
1505 call writefile([], 'Xx*Yy')
1506 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1507 call assert_equal('"e Xx\*Yy', @:)
1508 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001509
1510 " use a literal star
1511 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1512 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001513 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001514
1515 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1516 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001517endfunc
1518
zeertzjq094dd152023-06-15 22:51:57 +01001519" Test that expanding a pattern doesn't interfere with cmdline completion.
1520func Test_expand_during_cmdline_completion()
1521 func ExpandStuff()
1522 badd <script>:p:h/README.*
1523 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1524 $bwipe
1525 call assert_equal('README.txt', expand('README.*'))
1526 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1527 endfunc
1528 augroup test_CmdlineChanged
1529 autocmd!
1530 autocmd CmdlineChanged * call ExpandStuff()
1531 augroup END
1532
1533 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1534 call assert_equal('"sign place', @:)
1535
1536 augroup test_CmdlineChanged
1537 au!
1538 augroup END
1539 augroup! test_CmdlineChanged
1540 delfunc ExpandStuff
1541endfunc
1542
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001543" Test for 'wildignorecase'
1544func Test_cmdline_wildignorecase()
1545 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001546 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001547 set wildignorecase
1548 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1549 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001550 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001551 let g:Sline = ''
1552 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1553 call assert_equal('"e xt', @:)
1554 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001555 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001556endfunc
1557
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001558func Test_cmdline_write_alternatefile()
1559 new
1560 call setline('.', ['one', 'two'])
1561 f foo.txt
1562 new
1563 f #-A
1564 call assert_equal('foo.txt-A', expand('%'))
1565 f #<-B.txt
1566 call assert_equal('foo-B.txt', expand('%'))
1567 f %<
1568 call assert_equal('foo-B', expand('%'))
1569 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001570 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001571 bw!
1572 f foo-B.txt
1573 f %<-A
1574 call assert_equal('foo-B-A', expand('%'))
1575 bw!
1576 bw!
1577endfunc
1578
Bram Moolenaarf5724372022-09-02 19:45:15 +01001579func Test_cmdline_expand_cur_alt_file()
1580 enew
1581 file http://some.com/file.txt
1582 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1583 call assert_equal('"e http://some.com/file.txt', @:)
1584 edit another
1585 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1586 call assert_equal('"e http://some.com/file.txt', @:)
1587 bwipe
1588 bwipe http://some.com/file.txt
1589endfunc
1590
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001591" using a leading backslash here
1592set cpo+=C
1593
1594func Test_cmdline_search_range()
1595 new
1596 call setline(1, ['a', 'b', 'c', 'd'])
1597 /d
1598 1,\/s/b/B/
1599 call assert_equal('B', getline(2))
1600
1601 /a
1602 $
1603 \?,4s/c/C/
1604 call assert_equal('C', getline(3))
1605
1606 call setline(1, ['a', 'b', 'c', 'd'])
1607 %s/c/c/
1608 1,\&s/b/B/
1609 call assert_equal('B', getline(2))
1610
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001611 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001612 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001613
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001614 bwipe!
1615endfunc
1616
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001617" Test for the tick mark (') in an excmd range
1618func Test_tick_mark_in_range()
1619 " If only the tick is passed as a range and no command is specified, there
1620 " should not be an error
1621 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001622 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001623 call assert_fails("',print", 'E78:')
1624endfunc
1625
1626" Test for using a line number followed by a search pattern as range
1627func Test_lnum_and_pattern_as_range()
1628 new
1629 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1630 let @" = ''
1631 2/foo/yank
1632 call assert_equal("foo 3\n", @")
1633 call assert_equal(1, line('.'))
1634 close!
1635endfunc
1636
Bram Moolenaar65189a12017-02-06 22:22:17 +01001637" Tests for getcmdline(), getcmdpos() and getcmdtype()
1638func Check_cmdline(cmdtype)
1639 call assert_equal('MyCmd a', getcmdline())
1640 call assert_equal(8, getcmdpos())
1641 call assert_equal(a:cmdtype, getcmdtype())
1642 return ''
1643endfunc
1644
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001645set cpo&
1646
Shougo Matsushita69084282024-09-23 20:34:47 +02001647func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001648 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1649
1650 let cmdtype = ''
1651 debuggreedy
1652 call feedkeys(":debug echo 'test'\<CR>", "t")
1653 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1654 call feedkeys("cont\<CR>", "xt")
1655 0debuggreedy
1656 call assert_equal('>', cmdtype)
1657
1658 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1659 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1660
1661 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001662 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001663
1664 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1665
1666 cnoremap <expr> <F6> Check_cmdline('=')
1667 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1668 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001669
1670 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001671
1672 call assert_equal('', getcmdprompt())
1673 augroup test_CmdlineEnter
1674 autocmd!
1675 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1676 augroup END
1677 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1678 call assert_equal('Answer?', g:cmdprompt)
1679 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001680 call feedkeys(":\<CR>\<ESC>", "xt")
1681 call assert_equal('', g:cmdprompt)
1682 call assert_equal('', getcmdprompt())
1683
1684 let str = "C" .. repeat("c", 1023) .. "xyz"
1685 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1686 call assert_equal(str, g:cmdprompt)
1687
1688 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1689 call assert_equal('Ans?', g:cmdprompt)
1690 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001691
1692 augroup test_CmdlineEnter
1693 au!
1694 augroup END
1695 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001696endfunc
1697
Bram Moolenaar52604f22017-04-07 16:17:39 +02001698func Test_verbosefile()
1699 set verbosefile=Xlog
1700 echomsg 'foo'
1701 echomsg 'bar'
1702 set verbosefile=
1703 let log = readfile('Xlog')
1704 call assert_match("foo\nbar", join(log, "\n"))
1705 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001706
1707 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001708 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001709endfunc
1710
Bram Moolenaar4facea32019-10-12 20:17:40 +02001711func Test_verbose_option()
1712 CheckScreendump
1713
1714 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001715 " clear the TermResponse autocommand from defaults.vim
1716 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001717 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1718 call feedkeys("\r", 't') " for the hit-enter prompt
1719 set verbose=20
1720 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001721 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001722
1723 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001724 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001725 call term_sendkeys(buf, ":DoSomething\<CR>")
1726 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1727
1728 " clean up
1729 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001730endfunc
1731
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001732func Test_setcmdpos()
1733 func InsertTextAtPos(text, pos)
1734 call assert_equal(0, setcmdpos(a:pos))
1735 return a:text
1736 endfunc
1737
1738 " setcmdpos() with position in the middle of the command line.
1739 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1740 call assert_equal('"1ab2', @:)
1741
1742 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1743 call assert_equal('"1b2a', @:)
1744
1745 " setcmdpos() with position beyond the end of the command line.
1746 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1747 call assert_equal('"12ab', @:)
1748
1749 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001750 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001751endfunc
1752
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001753func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001754 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001755 let encoding_save = &encoding
1756
1757 for e in encodings
1758 exe 'set encoding=' . e
1759
1760 " Test overstrike in the middle of the command line.
1761 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001762 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001763
1764 " Test overstrike going beyond end of command line.
1765 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001766 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001767
1768 " Test toggling insert/overstrike a few times.
1769 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001770 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001771 endfor
1772
Bram Moolenaar30276f22019-01-24 17:59:39 +01001773 " Test overstrike with multi-byte characters.
1774 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001775 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001776
1777 let &encoding = encoding_save
1778endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001779
Bram Moolenaar52410572019-10-27 05:12:45 +01001780func Test_buffers_lastused()
1781 " check that buffers are sorted by time when wildmode has lastused
1782 call test_settime(1550020000) " middle
1783 edit bufa
1784 enew
1785 call test_settime(1550030000) " newest
1786 edit bufb
1787 enew
1788 call test_settime(1550010000) " oldest
1789 edit bufc
1790 enew
1791 call test_settime(0)
1792 enew
1793
1794 call assert_equal(['bufa', 'bufb', 'bufc'],
1795 \ getcompletion('', 'buffer'))
1796
1797 let save_wildmode = &wildmode
1798 set wildmode=full:lastused
1799
1800 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1801 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1802 call assert_equal('b bufb', X)
1803 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1804 call assert_equal('b bufa', X)
1805 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1806 call assert_equal('b bufc', X)
1807 enew
1808
1809 edit other
1810 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1811 call assert_equal('b bufb', X)
1812 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1813 call assert_equal('b bufa', X)
1814 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1815 call assert_equal('b bufc', X)
1816 enew
1817
1818 let &wildmode = save_wildmode
1819
1820 bwipeout bufa
1821 bwipeout bufb
1822 bwipeout bufc
1823endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001824
Bram Moolenaar479950f2020-01-19 15:45:17 +01001825func Test_cmdlineclear_tabenter()
1826 CheckScreendump
1827
1828 let lines =<< trim [SCRIPT]
1829 call setline(1, range(30))
1830 [SCRIPT]
1831
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001832 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001833 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001834 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001835 " in one tab make the command line higher with CTRL-W -
1836 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1837 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1838
1839 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001840endfunc
1841
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001842" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001843func Test_cmdline_expand_special()
1844 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001845 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001846 call assert_fails('e <afile>', 'E495:')
1847 call assert_fails('e <abuf>', 'E496:')
1848 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001849
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001850 call writefile([], 'Xfile.cpp', 'D')
1851 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001852 new Xfile.cpp
1853 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1854 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1855 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001856endfunc
1857
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001858" Test for backtick expression in the command line
1859func Test_cmd_backtick()
1860 %argd
1861 argadd `=['a', 'b', 'c']`
1862 call assert_equal(['a', 'b', 'c'], argv())
1863 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001864
1865 argadd `echo abc def`
1866 call assert_equal(['abc def'], argv())
1867 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001868endfunc
1869
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001870" Test for the :! command
1871func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001872 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001873
1874 let lines =<< trim [SCRIPT]
1875 " Test for no previous command
1876 call assert_fails('!!', 'E34:')
1877 set nomore
1878 " Test for cmdline expansion with :!
1879 call setline(1, 'foo!')
1880 silent !echo <cWORD> > Xfile.out
1881 call assert_equal(['foo!'], readfile('Xfile.out'))
1882 " Test for using previous command
1883 silent !echo \! !
1884 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1885 call writefile(v:errors, 'Xresult')
1886 call delete('Xfile.out')
1887 qall!
1888 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001889 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001890 if RunVim([], [], '--clean -S Xscript')
1891 call assert_equal([], readfile('Xresult'))
1892 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001893 call delete('Xresult')
1894endfunc
1895
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001896" Test error: "E135: *Filter* Autocommands must not change current buffer"
1897func Test_cmd_bang_E135()
1898 new
1899 call setline(1, ['a', 'b', 'c', 'd'])
1900 augroup test_cmd_filter_E135
1901 au!
1902 autocmd FilterReadPost * help
1903 augroup END
1904 call assert_fails('2,3!echo "x"', 'E135:')
1905
1906 augroup test_cmd_filter_E135
1907 au!
1908 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001909 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001910 %bwipe!
1911endfunc
1912
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001913func Test_cmd_bang_args()
1914 new
1915 :.!
1916 call assert_equal(0, v:shell_error)
1917
1918 " Note that below there is one space char after the '!'. This caused a
1919 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1920 :.!
1921 call assert_equal(0, v:shell_error)
1922 bwipe!
1923
1924 CheckUnix
1925 :.!pwd
1926 call assert_equal(0, v:shell_error)
1927 :.! pwd
1928 call assert_equal(0, v:shell_error)
1929
1930 " Note there is one space after 'pwd'.
1931 :.! pwd
1932 call assert_equal(0, v:shell_error)
1933
1934 " Note there are two spaces after 'pwd'.
1935 :.! pwd
1936 call assert_equal(0, v:shell_error)
1937 :.!ls ~
1938 call assert_equal(0, v:shell_error)
1939
1940 " Note there is one space char after '~'.
1941 :.!ls ~
1942 call assert_equal(0, v:shell_error)
1943
1944 " Note there are two spaces after '~'.
1945 :.!ls ~
1946 call assert_equal(0, v:shell_error)
1947
1948 :.!echo "foo"
1949 call assert_equal(getline('.'), "foo")
1950 :.!echo "foo "
1951 call assert_equal(getline('.'), "foo ")
1952 :.!echo " foo "
1953 call assert_equal(getline('.'), " foo ")
1954 :.!echo " foo "
1955 call assert_equal(getline('.'), " foo ")
1956
1957 %bwipe!
1958endfunc
1959
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001960" Test for using ~ for home directory in cmdline completion matches
1961func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001962 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001963 call writefile([], 'Xexpdir/Xfile1')
1964 call writefile([], 'Xexpdir/Xfile2')
1965 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001966 let save_HOME = $HOME
1967 let $HOME = getcwd()
1968 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1969 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1970 let $HOME = save_HOME
1971 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001972endfunc
1973
Bram Moolenaar578fe942020-02-27 21:32:51 +01001974" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1975" or insert mode (when 'insertmode' is set)
1976func Test_cmdline_ctrl_g()
1977 new
1978 call setline(1, 'abc')
1979 call cursor(1, 3)
1980 " If command line is entered from insert mode, using C-\ C-G should back to
1981 " insert mode
1982 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1983 call assert_equal('abxyc', getline(1))
1984 call assert_equal(4, col('.'))
1985
1986 " If command line is entered in 'insertmode', using C-\ C-G should back to
1987 " 'insertmode'
1988 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1989 call assert_equal('ab12xyc', getline(1))
1990 close!
1991endfunc
1992
Bram Moolenaar578fe942020-02-27 21:32:51 +01001993" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001994func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001995 func T(a, c, p)
1996 return "oneA\noneB\noneC"
1997 endfunc
1998 command -nargs=1 -complete=custom,T MyCmd
1999
Bram Moolenaar578fe942020-02-27 21:32:51 +01002000 set nowildmenu
2001 set wildmode=full,list
2002 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002003 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002004 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002005 call assert_equal('"MyCmd oneA', @:)
2006
2007 set wildmode=longest,full
2008 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2009 call assert_equal('"MyCmd one', @:)
2010 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2011 call assert_equal('"MyCmd oneC', @:)
2012
2013 set wildmode=longest
2014 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2015 call assert_equal('"MyCmd one', @:)
2016
2017 set wildmode=list:longest
2018 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002019 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002020 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002021 call assert_equal('"MyCmd one', @:)
2022
2023 set wildmode=""
2024 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2025 call assert_equal('"MyCmd oneA', @:)
2026
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002027 " Test for wildmode=longest with 'fileignorecase' set
2028 set wildmode=longest
2029 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002030 argadd AAA AAAA AAAAA
2031 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2032 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002033 set fileignorecase&
2034
2035 " Test for listing files with wildmode=list
2036 set wildmode=list
2037 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002038 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002039 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002040 call assert_equal('"b A', @:)
2041
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002042 " when using longest completion match, matches shorter than the argument
2043 " should be ignored (happens with :help)
2044 set wildmode=longest,full
2045 set wildmenu
2046 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2047 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002048 " non existing file
2049 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2050 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002051 set wildmenu&
2052
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002053 " Test for longest file name completion with 'fileignorecase'
2054 " On MS-Windows, file names are case insensitive.
2055 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002056 call writefile([], 'XTESTfoo', 'D')
2057 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002058 set nofileignorecase
2059 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2060 call assert_equal('"e XTESTfoo', @:)
2061 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2062 call assert_equal('"e Xtestbar', @:)
2063 set fileignorecase
2064 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2065 call assert_equal('"e Xtest', @:)
2066 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2067 call assert_equal('"e Xtest', @:)
2068 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002069 endif
2070
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002071 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002072 delcommand MyCmd
2073 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002074 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002075 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002076endfunc
2077
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002078func Test_wildmode()
2079 " Test with utf-8 encoding
2080 call Wildmode_tests()
2081
2082 " Test with latin1 encoding
2083 let save_encoding = &encoding
2084 set encoding=latin1
2085 call Wildmode_tests()
2086 let &encoding = save_encoding
2087endfunc
2088
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002089func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002090 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002091 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002092 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002093 let lines =<< trim END
2094 func vim8#Complete(a, c, p)
2095 return "oneA\noneB\noneC"
2096 endfunc
2097 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002098 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002099
2100 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2101 set nowildmenu
2102 set wildmode=full,list
2103 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2104 call assert_equal('"MyCmd oneA oneB oneC', @:)
2105
2106 let &rtp = save_rtp
2107 set wildmode& wildmenu&
2108 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002109endfunc
2110
Bram Moolenaar578fe942020-02-27 21:32:51 +01002111" Test for interrupting the command-line completion
2112func Test_interrupt_compl()
2113 func F(lead, cmdl, p)
2114 if a:lead =~ 'tw'
2115 call interrupt()
2116 return
2117 endif
2118 return "one\ntwo\nthree"
2119 endfunc
2120 command -nargs=1 -complete=custom,F Tcmd
2121
2122 set nowildmenu
2123 set wildmode=full
2124 let interrupted = 0
2125 try
2126 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2127 catch /^Vim:Interrupt$/
2128 let interrupted = 1
2129 endtry
2130 call assert_equal(1, interrupted)
2131
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002132 let interrupted = 0
2133 try
2134 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2135 catch /^Vim:Interrupt$/
2136 let interrupted = 1
2137 endtry
2138 call assert_equal(1, interrupted)
2139
Bram Moolenaar578fe942020-02-27 21:32:51 +01002140 delcommand Tcmd
2141 delfunc F
2142 set wildmode&
2143endfunc
2144
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002145" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002146func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002147 let str = ":one two\<C-U>"
2148 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002149 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002150 let str ..= "\<Left>five\<Right>"
2151 let str ..= "\<Home>two "
2152 let str ..= "\<C-Left>one "
2153 let str ..= "\<C-Right> three"
2154 let str ..= "\<End>\<S-Left>four "
2155 let str ..= "\<S-Right> six"
2156 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2157 call feedkeys(str, 'xt')
2158 call assert_equal("\"one two three four five six seven", @:)
2159endfunc
2160
2161" Test for moving the cursor on the / command line in 'rightleft' mode
2162func Test_cmdline_edit_rightleft()
2163 CheckFeature rightleft
2164 set rightleft
2165 set rightleftcmd=search
2166 let str = "/one two\<C-U>"
2167 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002168 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002169 let str ..= "\<Right>five\<Left>"
2170 let str ..= "\<Home>two "
2171 let str ..= "\<C-Right>one "
2172 let str ..= "\<C-Left> three"
2173 let str ..= "\<End>\<S-Right>four "
2174 let str ..= "\<S-Left> six"
2175 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2176 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2177 call assert_equal("\"one two three four five six seven", @/)
2178 set rightleftcmd&
2179 set rightleft&
2180endfunc
2181
2182" Test for using <C-\>e in the command line to evaluate an expression
2183func Test_cmdline_expr()
2184 " Evaluate an expression from the beginning of a command line
2185 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2186 call assert_equal('"hello', @:)
2187
2188 " Use an invalid expression for <C-\>e
2189 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2190
2191 " Insert literal <CTRL-\> in the command line
2192 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2193 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002194endfunc
2195
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002196" This was making the insert position negative
2197func Test_cmdline_expr_register()
2198 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2199endfunc
2200
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002201" Test for 'imcmdline' and 'imsearch'
2202" This test doesn't actually test the input method functionality.
2203func Test_cmdline_inputmethod()
2204 new
2205 call setline(1, ['', 'abc', ''])
2206 set imcmdline
2207
2208 call feedkeys(":\"abc\<CR>", 'xt')
2209 call assert_equal("\"abc", @:)
2210 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2211 call assert_equal("\"abc", @:)
2212 call feedkeys("/abc\<CR>", 'xt')
2213 call assert_equal([2, 1], [line('.'), col('.')])
2214 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2215 call assert_equal([2, 1], [line('.'), col('.')])
2216
2217 set imsearch=2
2218 call cursor(1, 1)
2219 call feedkeys("/abc\<CR>", 'xt')
2220 call assert_equal([2, 1], [line('.'), col('.')])
2221 call cursor(1, 1)
2222 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2223 call assert_equal([2, 1], [line('.'), col('.')])
2224 set imdisable
2225 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2226 call assert_equal([2, 1], [line('.'), col('.')])
2227 set imdisable&
2228 set imsearch&
2229
2230 set imcmdline&
2231 %bwipe!
2232endfunc
2233
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002234" Test for using CTRL-_ in the command line with 'allowrevins'
2235func Test_cmdline_revins()
2236 CheckNotMSWindows
2237 CheckFeature rightleft
2238 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2239 call assert_equal("\"abc\<c-_>", @:)
2240 set allowrevins
2241 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2242 call assert_equal('"abcñèæ', @:)
2243 set allowrevins&
2244endfunc
2245
2246" Test for typing UTF-8 composing characters in the command line
2247func Test_cmdline_composing_chars()
2248 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2249 call assert_equal('"ゔ', @:)
2250endfunc
2251
Bram Moolenaar0e717042020-04-27 19:29:01 +02002252" test that ";" works to find a match at the start of the first line
2253func Test_zero_line_search()
2254 new
2255 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2256 call cursor(1,1)
2257 0;/pattern/d
2258 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2259 q!
2260endfunc
2261
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002262func Test_read_shellcmd()
2263 CheckUnix
2264 if executable('ls')
2265 " There should be ls in the $PATH
2266 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2267 call assert_match('^"r! .*\<ls\>', @:)
2268 endif
2269
2270 if executable('rm')
2271 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2272 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2273 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002274
2275 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2276 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2277 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002278 endif
2279endfunc
2280
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002281" Test for going up and down the directory tree using 'wildmenu'
2282func Test_wildmenu_dirstack()
2283 CheckUnix
2284 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002285 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002286 call writefile([], 'Xwildmenu/file1_1.txt')
2287 call writefile([], 'Xwildmenu/file1_2.txt')
2288 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2289 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2290 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2291 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2292 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2293 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002294 set wildmenu
2295
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002296 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002297 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002298 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002299 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002300 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002301 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002302 call assert_equal('"e ../../dir3/', @:)
2303 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2304 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002305 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002306 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002307 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002308 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002309 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002310 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2311 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002312
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002313 set wildmenu&
2314endfunc
2315
obcat71c6f7a2021-05-13 20:23:10 +02002316" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002317" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2318" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002319func Test_recalling_cmdline()
2320 CheckFeature cmdline_hist
2321
2322 let g:cmdlines = []
2323 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2324
2325 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002326 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2327 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2328 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2329 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002330 "\ TODO: {'name': 'debug', ...}
2331 \]
2332 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002333 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2334 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2335 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2336 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2337 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002338 \]
2339 let prefix = 'vi'
2340 for h in histories
2341 call histadd(h.name, 'vim')
2342 call histadd(h.name, 'virtue')
2343 call histadd(h.name, 'Virgo')
2344 call histadd(h.name, 'vogue')
2345 call histadd(h.name, 'emacs')
2346 for k in keypairs
2347 let g:cmdlines = []
2348 let keyseqs = h.enter
2349 \ .. prefix
2350 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2351 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2352 \ .. h.exit
2353 call feedkeys(keyseqs, 'xt')
2354 call histdel(h.name, -1) " delete the history added by feedkeys above
2355 let expect = k.prefixmatch
2356 \ ? ['virtue', 'vim', 'virtue', prefix]
2357 \ : ['emacs', 'vogue', 'emacs', prefix]
2358 call assert_equal(expect, g:cmdlines)
2359 endfor
2360 endfor
2361
2362 unlet g:cmdlines
2363 cunmap <Plug>(save-cmdline)
2364endfunc
2365
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002366func Test_cmd_map_cmdlineChanged()
2367 let g:log = []
2368 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002369 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002370 autocmd!
2371 autocmd CmdlineChanged : let g:log += [getcmdline()]
2372 augroup END
2373
2374 call feedkeys(":\<F1>\<CR>", 'xt')
2375 call assert_equal(['l', 'ls'], g:log)
2376
Bram Moolenaar796139a2021-05-18 21:38:45 +02002377 let @b = 'b'
2378 cnoremap <F1> a<C-R>b
2379 let g:log = []
2380 call feedkeys(":\<F1>\<CR>", 'xt')
2381 call assert_equal(['a', 'ab'], g:log)
2382
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002383 unlet g:log
2384 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002385 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002386 autocmd!
2387 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002388 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002389endfunc
2390
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002391" Test for the 'suffixes' option
2392func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002393 call writefile([], 'Xsuffile', 'D')
2394 call writefile([], 'Xsuffile.c', 'D')
2395 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002396 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002397 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2398 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2399 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2400 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002401 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002402 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2403 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2404 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2405 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002406 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002407 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2408 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2409 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2410 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002411 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002412 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002413 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2414 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002415endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002416
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002417" Test for using a popup menu for the command line completion matches
2418" (wildoptions=pum)
2419func Test_wildmenu_pum()
2420 CheckRunVimInTerminal
2421
2422 let commands =<< trim [CODE]
2423 set wildmenu
2424 set wildoptions=pum
2425 set shm+=I
2426 set noruler
2427 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002428
2429 func CmdCompl(a, b, c)
2430 return repeat(['aaaa'], 120)
2431 endfunc
2432 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002433
2434 func MyStatusLine() abort
2435 return 'status'
2436 endfunc
2437 func SetupStatusline()
2438 set statusline=%!MyStatusLine()
2439 set laststatus=2
2440 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002441
2442 func MyTabLine()
2443 return 'my tab line'
2444 endfunc
2445 func SetupTabline()
2446 set statusline=
2447 set tabline=%!MyTabLine()
2448 set showtabline=2
2449 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002450
2451 func DoFeedKeys()
2452 let &wildcharm = char2nr("\t")
2453 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2454 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002455 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002456 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002457
2458 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2459
2460 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002461 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2462
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002463 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002464 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002465 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2466
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002467 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002468 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002469 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2470
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002471 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002472 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002473 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2474
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002475 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002476 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002477 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2478
2479 " pressing <C-E> should end completion and go back to the original match
2480 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002481 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2482
2483 " pressing <C-Y> should select the current match and end completion
2484 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002485 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2486
2487 " With 'wildmode' set to 'longest,full', completing a match should display
2488 " the longest match, the wildmenu should not be displayed.
2489 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2490 call TermWait(buf)
2491 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002492 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2493
2494 " pressing <Tab> should display the wildmenu
2495 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002496 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2497
2498 " pressing <Tab> second time should select the next entry in the menu
2499 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002500 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2501
2502 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002503 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002504 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002505 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2506
2507 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002508 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2509
2510 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002511 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2512
2513 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002514 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002515 call writefile([], 'Xnamedir/XfileA')
2516 call writefile([], 'Xnamedir/XdirA/XfileB')
2517 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002518
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002519 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002520 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2521
2522 " Pressing <Right> on a directory name should go into that directory
2523 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002524 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2525
2526 " Pressing <Left> on a directory name should go to the parent directory
2527 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002528 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2529
2530 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002531 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002532 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002533 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2534
2535 " Pressing <C-D> when the popup menu is displayed should remove the popup
2536 " menu
2537 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002538 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2539
2540 " Pressing <S-Tab> should open the popup menu with the last entry selected
2541 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002542 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2543
2544 " Pressing <Esc> should close the popup menu and cancel the cmd line
2545 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002546 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2547
2548 " Typing a character when the popup is open, should close the popup
2549 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002550 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2551
2552 " When the popup is open, entering the cmdline window should close the popup
2553 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002554 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2555 call term_sendkeys(buf, ":q\<CR>")
2556
2557 " After the last popup menu item, <C-N> should show the original string
2558 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002559 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2560
2561 " Use the popup menu for the command name
2562 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002563 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2564
2565 " Pressing the left arrow should remove the popup menu
2566 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002567 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2568
2569 " Pressing <BS> should remove the popup menu and erase the last character
2570 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002571 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2572
2573 " Pressing <C-W> should remove the popup menu and erase the previous word
2574 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002575 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2576
2577 " Pressing <C-U> should remove the popup menu and erase the entire line
2578 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002579 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2580
2581 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2582 " the cmdline from history
2583 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002584 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2585
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002586 " Check "list" still works
2587 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2588 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002589 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2590 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002591 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2592
rbtnn68cc2b82022-02-09 11:55:47 +00002593 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002594 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002595 call writefile([], 'Xnamedir/あいう/abc')
2596 call writefile([], 'Xnamedir/あいう/xyz')
2597 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002598
2599 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002600 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002601 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2602
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002603 " Pressing <C-A> when the popup menu is displayed should list all the
2604 " matches and pressing a key after that should remove the popup menu
2605 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2606 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2607 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2608
2609 " Pressing <C-A> when the popup menu is displayed should list all the
2610 " matches and pressing <Left> after that should move the cursor
2611 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2612 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2613 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2614
2615 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2616 " should be displayed correctly on the screen.
2617 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2618 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2619
2620 " After using <C-A> to expand all the filename matches, pressing <Up>
2621 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002622 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002623 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2624 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2625 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2626
2627 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2628 " crash Vim
2629 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2630 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2631
Bram Moolenaar414acd32022-02-10 21:09:45 +00002632 " After removing the pum the command line is redrawn
2633 call term_sendkeys(buf, ":edit foo\<CR>")
2634 call term_sendkeys(buf, ":edit bar\<CR>")
2635 call term_sendkeys(buf, ":ls\<CR>")
2636 call term_sendkeys(buf, ":com\<Tab> ")
2637 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002638 call term_sendkeys(buf, "\<C-U>\<CR>")
2639
2640 " Esc still works to abort the command when 'statusline' is set
2641 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2642 call term_sendkeys(buf, ":si\<Tab>")
2643 call term_sendkeys(buf, "\<Esc>")
2644 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002645
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002646 " Esc still works to abort the command when 'tabline' is set
2647 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2648 call term_sendkeys(buf, ":si\<Tab>")
2649 call term_sendkeys(buf, "\<Esc>")
2650 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2651
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002652 " popup is cleared also when 'lazyredraw' is set
2653 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2654 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2655 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2656 call term_sendkeys(buf, "\<Esc>")
2657
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002658 " Pressing <PageDown> should scroll the menu downward
2659 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2660 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2661 call term_sendkeys(buf, "\<PageDown>")
2662 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2663 call term_sendkeys(buf, "\<PageDown>")
2664 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2665 call term_sendkeys(buf, "\<PageDown>")
2666 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2667 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2668 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2669
2670 " Pressing <PageUp> should scroll the menu upward
2671 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2672 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2673 call term_sendkeys(buf, "\<PageUp>")
2674 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2675 call term_sendkeys(buf, "\<PageUp>")
2676 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2677 call term_sendkeys(buf, "\<PageUp>")
2678 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2679
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002680 " pressing <C-E> to end completion should work in middle of the line too
2681 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2682 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2683 call term_sendkeys(buf, "\<C-E>")
2684 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2685
2686 " pressing <C-Y> should select the current match and end completion
2687 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2688 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2689
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002690 call term_sendkeys(buf, "\<C-U>\<CR>")
2691 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002692endfunc
2693
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002694" Test for wildmenumode() with the cmdline popup menu
2695func Test_wildmenumode_with_pum()
2696 set wildmenu
2697 set wildoptions=pum
2698 cnoremap <expr> <F2> wildmenumode()
2699 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2700 call assert_equal('"sign define10', @:)
2701 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2702 call assert_equal('"sign define jump list place undefine unplace0', @:)
2703 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2704 call assert_equal('"sign 0', @:)
2705 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2706 call assert_equal('"sign define0', @:)
2707 set nowildmenu wildoptions&
2708 cunmap <F2>
2709endfunc
2710
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002711func Test_wildmenu_with_pum_foldexpr()
2712 CheckRunVimInTerminal
2713
2714 let lines =<< trim END
2715 call setline(1, ['folded one', 'folded two', 'some more text'])
2716 func MyFoldText()
2717 return 'foo'
2718 endfunc
2719 set foldtext=MyFoldText() wildoptions=pum
2720 normal ggzfj
2721 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002722 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002723 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2724 call term_sendkeys(buf, ":set\<Tab>")
2725 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2726
2727 call term_sendkeys(buf, "\<Esc>")
2728 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2729
2730 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002731endfunc
2732
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002733" Test for opening the cmdline completion popup menu from the terminal window.
2734" The popup menu should be positioned correctly over the status line of the
2735" bottom-most window.
2736func Test_wildmenu_pum_from_terminal()
2737 CheckRunVimInTerminal
2738 let python = PythonProg()
2739 call CheckPython(python)
2740
2741 %bw!
2742 let cmds = ['set wildmenu wildoptions=pum']
2743 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2744 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002745 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002746 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2747 call term_sendkeys(buf, "\r\r\r")
2748 call term_wait(buf)
2749 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2750 call term_wait(buf)
2751 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2752 call term_wait(buf)
2753 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002754endfunc
2755
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002756func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002757 CheckRunVimInTerminal
2758
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002759 " Test odd wildchar interactions with pum. Make sure they behave properly
2760 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002761 let lines =<< trim END
2762 set wildoptions=pum
2763 set wildchar=<C-E>
2764 END
2765 call writefile(lines, 'XwildmenuTest', 'D')
2766 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2767
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002768 call term_sendkeys(buf, ":\<C-E>")
2769 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002770
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002771 " <C-E> being a wildchar takes priority over its original functionality
2772 call term_sendkeys(buf, "\<C-E>")
2773 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2774
2775 call term_sendkeys(buf, "\<Esc>")
2776 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2777
2778 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2779 " command-line, and we need to make sure to clean up properly.
2780 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2781 call term_sendkeys(buf, ":\<Esc>")
2782 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2783
2784 call term_sendkeys(buf, "\<Esc>")
2785 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2786
2787 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2788 " and we again need to make sure we clean up properly.
2789 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2790 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2791 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2792
2793 call term_sendkeys(buf, "\<C-N>")
2794 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2795
2796 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002797endfunc
2798
zeertzjq883018f2024-06-15 15:37:11 +02002799" Test that 'rightleft' should not affect cmdline completion popup menu.
2800func Test_wildmenu_pum_rightleft()
2801 CheckFeature rightleft
2802 CheckScreendump
2803
2804 let lines =<< trim END
2805 set wildoptions=pum
2806 set rightleft
2807 END
2808 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2809 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2810
2811 call term_sendkeys(buf, ":sign \<Tab>")
2812 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2813
2814 call StopVimInTerminal(buf)
2815endfunc
2816
zeertzjqd8c93402024-06-17 18:25:32 +02002817" Test highlighting matched text in cmdline completion popup menu.
2818func Test_wildmenu_pum_hl_match()
2819 CheckScreendump
2820
2821 let lines =<< trim END
2822 set wildoptions=pum,fuzzy
2823 hi PmenuMatchSel ctermfg=6 ctermbg=7
2824 hi PmenuMatch ctermfg=4 ctermbg=225
2825 END
2826 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2827 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2828
2829 call term_sendkeys(buf, ":sign plc\<Tab>")
2830 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2831 call term_sendkeys(buf, "\<Tab>")
2832 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2833 call term_sendkeys(buf, "\<Tab>")
2834 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2835 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2836 call TermWait(buf)
2837 call term_sendkeys(buf, ":sign un\<Tab>")
2838 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2839 call term_sendkeys(buf, "\<Tab>")
2840 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2841 call term_sendkeys(buf, "\<Tab>")
2842 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2843 call term_sendkeys(buf, "\<Esc>")
2844
2845 call StopVimInTerminal(buf)
2846endfunc
2847
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002848" Test for completion after a :substitute command followed by a pipe (|)
2849" character
2850func Test_cmdline_complete_substitute()
2851 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2852 call assert_equal("\"s | \t", @:)
2853 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2854 call assert_equal("\"s/ | \t", @:)
2855 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2856 call assert_equal("\"s/one | \t", @:)
2857 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2858 call assert_equal("\"s/one/ | \t", @:)
2859 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2860 call assert_equal("\"s/one/two | \t", @:)
2861 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2862 call assert_equal('"s/one/two/ | chistory', @:)
2863 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2864 call assert_equal("\"s/one/two/g \t", @:)
2865 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2866 call assert_equal("\"s/one/two/g | chistory", @:)
2867 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2868 call assert_equal("\"s/one/t\\/ | \t", @:)
2869 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2870 call assert_equal('"s/one/t"o/ | chistory', @:)
2871 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2872 call assert_equal('"s/one/t|o/ | chistory', @:)
2873 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2874 call assert_equal("\"&\t", @:)
2875endfunc
2876
2877" Test for the :dlist command completion
2878func Test_cmdline_complete_dlist()
2879 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2880 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2881 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2882 call assert_equal("\"dlist 10 /pat/ \t", @:)
2883 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2884 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2885 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2886 call assert_equal("\"dlist 10 /pat\\\t", @:)
2887 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2888 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2889endfunc
2890
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002891" argument list (only for :argdel) fuzzy completion
2892func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002893 argadd change.py count.py charge.py
2894 set wildoptions&
2895 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2896 call assert_equal('"argdel cge', @:)
2897 set wildoptions=fuzzy
2898 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"argdel change.py charge.py', @:)
2900 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002901 set wildoptions&
2902endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002903
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002904" autocmd group name fuzzy completion
2905func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002906 set wildoptions&
2907 augroup MyFuzzyGroup
2908 augroup END
2909 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2910 call assert_equal('"augroup mfg', @:)
2911 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2912 call assert_equal('"augroup MyFuzzyGroup', @:)
2913 set wildoptions=fuzzy
2914 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2915 call assert_equal('"augroup MyFuzzyGroup', @:)
2916 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal('"augroup My*p', @:)
2918 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002919 set wildoptions&
2920endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002921
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002922" buffer name fuzzy completion
2923func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002924 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002925 " Use a long name to reduce the risk of matching a random directory name
2926 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002927 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002928 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2929 call assert_equal('"b SRFWL', @:)
2930 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2931 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002933 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2934 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2935 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2936 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002937 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002938 set wildoptions&
2939endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941" buffer name (full path) fuzzy completion
2942func Test_fuzzy_completion_bufname_fullpath()
2943 CheckUnix
2944 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002945 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002946 edit Xcmd/Xstate/Xfile.js
2947 cd Xcmd/Xstate
2948 enew
2949 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2950 call assert_equal('"b CmdStateFile', @:)
2951 set wildoptions=fuzzy
2952 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2953 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2954 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002955 set wildoptions&
2956endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002957
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958" :behave suboptions fuzzy completion
2959func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960 set wildoptions&
2961 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2962 call assert_equal('"behave xm', @:)
2963 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2964 call assert_equal('"behave xterm', @:)
2965 set wildoptions=fuzzy
2966 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal('"behave xterm', @:)
2968 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2969 call assert_equal('"behave xt*m', @:)
2970 let g:Sline = ''
2971 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal('mswin', g:Sline)
2973 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002974 set wildoptions&
2975endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002976
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977" " colorscheme name fuzzy completion - NOT supported
2978" func Test_fuzzy_completion_colorscheme()
2979" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002980
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002981" built-in command name fuzzy completion
2982func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002983 set wildoptions&
2984 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2985 call assert_equal('"sbwin', @:)
2986 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2987 call assert_equal('"sbrewind', @:)
2988 set wildoptions=fuzzy
2989 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2990 call assert_equal('"sbrewind', @:)
2991 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2992 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002993 set wildoptions&
2994endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002995
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002996" " compiler name fuzzy completion - NOT supported
2997" func Test_fuzzy_completion_compiler()
2998" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002999
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003000" :cscope suboptions fuzzy completion
3001func Test_fuzzy_completion_cscope()
3002 CheckFeature cscope
3003 set wildoptions&
3004 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3005 call assert_equal('"cscope ret', @:)
3006 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal('"cscope reset', @:)
3008 set wildoptions=fuzzy
3009 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"cscope reset', @:)
3011 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3012 call assert_equal('"cscope re*t', @:)
3013 set wildoptions&
3014endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003015
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003016" :diffget/:diffput buffer name fuzzy completion
3017func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003018 new SomeBuffer
3019 diffthis
3020 new OtherBuffer
3021 diffthis
3022 set wildoptions&
3023 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3024 call assert_equal('"diffget sbuf', @:)
3025 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3026 call assert_equal('"diffput sbuf', @:)
3027 set wildoptions=fuzzy
3028 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3029 call assert_equal('"diffget SomeBuffer', @:)
3030 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3031 call assert_equal('"diffput SomeBuffer', @:)
3032 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003033 set wildoptions&
3034endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003035
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003036" " directory name fuzzy completion - NOT supported
3037" func Test_fuzzy_completion_dirname()
3038" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003039
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003040" environment variable name fuzzy completion
3041func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003042 set wildoptions&
3043 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3044 call assert_equal('"echo $VUT', @:)
3045 set wildoptions=fuzzy
3046 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003048 set wildoptions&
3049endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003050
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003051" autocmd event fuzzy completion
3052func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003053 set wildoptions&
3054 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3055 call assert_equal('"autocmd BWout', @:)
3056 set wildoptions=fuzzy
3057 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3058 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003059 set wildoptions&
3060endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003061
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003062" vim expression fuzzy completion
3063func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003064 let g:PerPlaceCount = 10
3065 set wildoptions&
3066 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal('"let c = ppc', @:)
3068 set wildoptions=fuzzy
3069 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003071 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003072endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003073
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003074" " file name fuzzy completion - NOT supported
3075" func Test_fuzzy_completion_filename()
3076" endfunc
3077
3078" " files in path fuzzy completion - NOT supported
3079" func Test_fuzzy_completion_filesinpath()
3080" endfunc
3081
3082" " filetype name fuzzy completion - NOT supported
3083" func Test_fuzzy_completion_filetype()
3084" endfunc
3085
3086" user defined function name completion
3087func Test_fuzzy_completion_userdefined_func()
3088 set wildoptions&
3089 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal('"call Test_f_u_f', @:)
3091 set wildoptions=fuzzy
3092 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3093 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3094 set wildoptions&
3095endfunc
3096
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003097" <SNR> functions should be sorted to the end
3098func Test_fuzzy_completion_userdefined_snr_func()
3099 func s:Sendmail()
3100 endfunc
3101 func SendSomemail()
3102 endfunc
3103 func S1e2n3dmail()
3104 endfunc
3105 set wildoptions=fuzzy
3106 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003107 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003108 set wildoptions&
3109 delfunc s:Sendmail
3110 delfunc SendSomemail
3111 delfunc S1e2n3dmail
3112endfunc
3113
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003114" user defined command name completion
3115func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003116 set wildoptions&
3117 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal('"MsFeat', @:)
3119 set wildoptions=fuzzy
3120 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003122 set wildoptions&
3123endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003124
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003125" " :help tag fuzzy completion - NOT supported
3126" func Test_fuzzy_completion_helptag()
3127" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003128
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003129" highlight group name fuzzy completion
3130func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003131 set wildoptions&
3132 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3133 call assert_equal('"highlight SKey', @:)
3134 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3135 call assert_equal('"highlight SpecialKey', @:)
3136 set wildoptions=fuzzy
3137 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal('"highlight SpecialKey', @:)
3139 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003141 set wildoptions&
3142endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003143
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003144" :history suboptions fuzzy completion
3145func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003146 set wildoptions&
3147 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal('"history dg', @:)
3149 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal('"history search', @:)
3151 set wildoptions=fuzzy
3152 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal('"history debug', @:)
3154 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3155 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003156 set wildoptions&
3157endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003158
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003159" :language locale name fuzzy completion
3160func Test_fuzzy_completion_lang()
3161 CheckUnix
3162 set wildoptions&
3163 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal('"lang psx', @:)
3165 set wildoptions=fuzzy
3166 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal('"lang POSIX', @:)
3168 set wildoptions&
3169endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003170
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003171" :mapclear buffer argument fuzzy completion
3172func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003173 set wildoptions&
3174 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal('"mapclear buf', @:)
3176 set wildoptions=fuzzy
3177 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003179 set wildoptions&
3180endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003181
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003182" map name fuzzy completion
3183func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003184 " test regex completion works
3185 set wildoptions=fuzzy
3186 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003188 nmap <plug>MyLongMap :p<CR>
3189 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3191 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal("\"nmap MLM \t", @:)
3193 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3194 call assert_equal("\"nmap <F2> one two \t", @:)
3195 " duplicate entries should be removed
3196 vmap <plug>MyLongMap :<C-U>#<CR>
3197 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3198 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3199 nunmap <plug>MyLongMap
3200 vunmap <plug>MyLongMap
3201 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3202 call assert_equal("\"nmap ABC\t", @:)
3203 " results should be sorted by best match
3204 nmap <Plug>format :
3205 nmap <Plug>goformat :
3206 nmap <Plug>TestFOrmat :
3207 nmap <Plug>fendoff :
3208 nmap <Plug>state :
3209 nmap <Plug>FendingOff :
3210 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3212 nunmap <Plug>format
3213 nunmap <Plug>goformat
3214 nunmap <Plug>TestFOrmat
3215 nunmap <Plug>fendoff
3216 nunmap <Plug>state
3217 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003218 set wildoptions&
3219endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003220
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003221" abbreviation fuzzy completion
3222func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003223 set wildoptions=fuzzy
3224 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3225 call assert_equal("\"iabbr <nowait>", @:)
3226 iabbr WaitForCompletion WFC
3227 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"iabbr WaitForCompletion", @:)
3229 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003231
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003232 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003233 set wildoptions&
3234endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003235
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003236" menu name fuzzy completion
3237func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003238 CheckFeature menu
3239
3240 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003241 set wildoptions&
3242 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3243 call assert_equal('"menu pup', @:)
3244 set wildoptions=fuzzy
3245 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003247
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003248 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003249 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003250endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003251
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003252" :messages suboptions fuzzy completion
3253func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003254 set wildoptions&
3255 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal('"messages clr', @:)
3257 set wildoptions=fuzzy
3258 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003260 set wildoptions&
3261endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003262
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003263" :set option name fuzzy completion
3264func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003265 set wildoptions&
3266 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal('"set brkopt', @:)
3268 set wildoptions=fuzzy
3269 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3270 call assert_equal('"set breakindentopt', @:)
3271 set wildoptions&
3272 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal('"set fixendofline', @:)
3274 set wildoptions=fuzzy
3275 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003277 set wildoptions&
3278endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003279
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003280" :set <term_option>
3281func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003282 set wildoptions&
3283 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal('"set t_EC', @:)
3285 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal('"set <t_EC>', @:)
3287 set wildoptions=fuzzy
3288 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3289 call assert_equal('"set t_EC', @:)
3290 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003292 set wildoptions&
3293endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003294
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003295" " :packadd directory name fuzzy completion - NOT supported
3296" func Test_fuzzy_completion_packadd()
3297" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003298
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003299" " shell command name fuzzy completion - NOT supported
3300" func Test_fuzzy_completion_shellcmd()
3301" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003302
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003303" :sign suboptions fuzzy completion
3304func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003305 set wildoptions&
3306 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3307 call assert_equal('"sign ufe', @:)
3308 set wildoptions=fuzzy
3309 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003311 set wildoptions&
3312endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003313
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003314" :syntax suboptions fuzzy completion
3315func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003316 set wildoptions&
3317 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_equal('"syntax kwd', @:)
3319 set wildoptions=fuzzy
3320 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003322 set wildoptions&
3323endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003324
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003325" syntax group name fuzzy completion
3326func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003327 set wildoptions&
3328 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3329 call assert_equal('"syntax list mpar', @:)
3330 set wildoptions=fuzzy
3331 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003333 set wildoptions&
3334endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003335
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003336" :syntime suboptions fuzzy completion
3337func Test_fuzzy_completion_syntime()
3338 CheckFeature profile
3339 set wildoptions&
3340 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3341 call assert_equal('"syntime clr', @:)
3342 set wildoptions=fuzzy
3343 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3344 call assert_equal('"syntime clear', @:)
3345 set wildoptions&
3346endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003347
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003348" " tag name fuzzy completion - NOT supported
3349" func Test_fuzzy_completion_tagname()
3350" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003351
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003352" " tag name and file fuzzy completion - NOT supported
3353" func Test_fuzzy_completion_tagfile()
3354" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003355
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003356" " user names fuzzy completion - how to test this functionality?
3357" func Test_fuzzy_completion_username()
3358" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003359
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003360" user defined variable name fuzzy completion
3361func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003362 let g:SomeVariable=10
3363 set wildoptions&
3364 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3365 call assert_equal('"let SVar', @:)
3366 set wildoptions=fuzzy
3367 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003369 set wildoptions&
3370endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003371
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003372" Test for sorting the results by the best match
3373func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003374 %bw!
3375 command T123format :
3376 command T123goformat :
3377 command T123TestFOrmat :
3378 command T123fendoff :
3379 command T123state :
3380 command T123FendingOff :
3381 set wildoptions=fuzzy
3382 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3383 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3384 delcommand T123format
3385 delcommand T123goformat
3386 delcommand T123TestFOrmat
3387 delcommand T123fendoff
3388 delcommand T123state
3389 delcommand T123FendingOff
3390 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003391 set wildoptions&
3392endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003393
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003394" Test for fuzzy completion of a command with lower case letters and a number
3395func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003396 command Foo2Bar :
3397 set wildoptions=fuzzy
3398 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal('"Foo2Bar', @:)
3400 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal('"Foo2Bar', @:)
3402 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3403 call assert_equal('"Foo2Bar', @:)
3404 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003405 set wildoptions&
3406endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003407
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003408" Test for command completion for a command starting with 'k'
3409func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003410 command KillKillKill :
3411 set wildoptions&
3412 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3413 call assert_equal("\"killkill\<Tab>", @:)
3414 set wildoptions=fuzzy
3415 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3416 call assert_equal('"KillKillKill', @:)
3417 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003418 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003419endfunc
3420
3421" Test for fuzzy completion for user defined custom completion function
3422func Test_fuzzy_completion_custom_func()
3423 func Tcompl(a, c, p)
3424 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3425 endfunc
3426 command -nargs=* -complete=custom,Tcompl Fuzzy :
3427 set wildoptions&
3428 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal("\"Fuzzy format", @:)
3430 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3431 call assert_equal("\"Fuzzy xy", @:)
3432 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3433 call assert_equal("\"Fuzzy ttt", @:)
3434 set wildoptions=fuzzy
3435 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3436 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3437 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3438 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3439 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3440 call assert_equal("\"Fuzzy xy", @:)
3441 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3442 call assert_equal("\"Fuzzy TestFOrmat", @:)
3443 delcom Fuzzy
3444 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003445endfunc
3446
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003447" Test for fuzzy completion in the middle of a cmdline instead of at the end
3448func Test_fuzzy_completion_in_middle()
3449 set wildoptions=fuzzy
3450 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3451 call assert_equal("\"set wildchar wildcharm wrap", @:)
3452
3453 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3454 call assert_equal("\"args ++encoding= zz", @:)
3455 set wildoptions&
3456endfunc
3457
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003458" Test for :breakadd argument completion
3459func Test_cmdline_complete_breakadd()
3460 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3461 call assert_equal("\"breakadd expr file func here", @:)
3462 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3463 call assert_equal("\"breakadd expr", @:)
3464 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3465 call assert_equal("\"breakadd expr", @:)
3466 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3467 call assert_equal("\"breakadd here", @:)
3468 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3469 call assert_equal("\"breakadd here", @:)
3470 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3471 call assert_equal("\"breakadd abc", @:)
3472 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3473 let l = getcompletion('not', 'breakpoint')
3474 call assert_equal([], l)
3475
3476 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003477 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003478 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3479 call assert_equal("\"breakadd file Xscript", @:)
3480 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3481 call assert_equal("\"breakadd file Xscript", @:)
3482 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3483 call assert_equal("\"breakadd file 20 Xscript", @:)
3484 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3485 call assert_equal("\"breakadd file 20 Xscript", @:)
3486 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3487 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3488 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3489 call assert_equal("\"breakadd file 20\t", @:)
3490 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3491 call assert_equal("\"breakadd file 20x\t", @:)
3492 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3493 call assert_equal("\"breakadd file Xscript ", @:)
3494 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3495 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003496
3497 " Test for :breakadd func [lnum] <function>
3498 func Xbreak_func()
3499 endfunc
3500 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3501 call assert_equal("\"breakadd func Xbreak_func", @:)
3502 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3503 call assert_equal("\"breakadd func Xbreak_func", @:)
3504 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3505 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3506 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3507 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3508 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3509 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3510 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3511 call assert_equal("\"breakadd func 20\t", @:)
3512 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3513 call assert_equal("\"breakadd func 20x\t", @:)
3514 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3515 call assert_equal("\"breakadd func Xbreak_func ", @:)
3516 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3517 call assert_equal("\"breakadd func X1B2C3", @:)
3518 delfunc Xbreak_func
3519
3520 " Test for :breakadd expr <expression>
3521 let g:Xtest_var = 10
3522 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3523 call assert_equal("\"breakadd expr Xtest_var", @:)
3524 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal("\"breakadd expr Xtest_var", @:)
3526 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3527 call assert_equal("\"breakadd expr Xtest_var ", @:)
3528 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3529 call assert_equal("\"breakadd expr X1B2C3", @:)
3530 unlet g:Xtest_var
3531
3532 " Test for :breakadd here
3533 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3534 call assert_equal("\"breakadd here Xtest", @:)
3535 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3536 call assert_equal("\"breakadd here Xtest", @:)
3537 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3538 call assert_equal("\"breakadd here ", @:)
3539endfunc
3540
3541" Test for :breakdel argument completion
3542func Test_cmdline_complete_breakdel()
3543 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3544 call assert_equal("\"breakdel file func here", @:)
3545 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3546 call assert_equal("\"breakdel file", @:)
3547 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3548 call assert_equal("\"breakdel file", @:)
3549 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3550 call assert_equal("\"breakdel here", @:)
3551 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal("\"breakdel here", @:)
3553 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3554 call assert_equal("\"breakdel abc", @:)
3555
3556 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003557 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003558 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3559 call assert_equal("\"breakdel file Xscript", @:)
3560 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3561 call assert_equal("\"breakdel file Xscript", @:)
3562 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3563 call assert_equal("\"breakdel file 20 Xscript", @:)
3564 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3565 call assert_equal("\"breakdel file 20 Xscript", @:)
3566 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3567 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3568 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3569 call assert_equal("\"breakdel file 20\t", @:)
3570 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3571 call assert_equal("\"breakdel file 20x\t", @:)
3572 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3573 call assert_equal("\"breakdel file Xscript ", @:)
3574 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3575 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003576
3577 " Test for :breakdel func [lnum] <function>
3578 func Xbreak_func()
3579 endfunc
3580 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3581 call assert_equal("\"breakdel func Xbreak_func", @:)
3582 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3583 call assert_equal("\"breakdel func Xbreak_func", @:)
3584 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3585 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3586 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3587 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3588 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3589 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3590 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3591 call assert_equal("\"breakdel func 20\t", @:)
3592 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3593 call assert_equal("\"breakdel func 20x\t", @:)
3594 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3595 call assert_equal("\"breakdel func Xbreak_func ", @:)
3596 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3597 call assert_equal("\"breakdel func X1B2C3", @:)
3598 delfunc Xbreak_func
3599
3600 " Test for :breakdel here
3601 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3602 call assert_equal("\"breakdel here Xtest", @:)
3603 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3604 call assert_equal("\"breakdel here Xtest", @:)
3605 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3606 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003607endfunc
3608
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003609" Test for :scriptnames argument completion
3610func Test_cmdline_complete_scriptnames()
3611 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003612 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003613 source Xa1b2c3.vim
3614 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3615 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3616 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3617 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3618 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3619 call assert_equal("\"script b2c3", @:)
3620 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3621 call assert_match("\"script 2\<Tab>$", @:)
3622 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3623 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3624 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3625 call assert_equal("\"script ", @:)
3626 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3627 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3628 new
3629 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3630 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3631 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003632 set wildmenu&
3633endfunc
3634
Bram Moolenaard8893442022-05-06 20:38:47 +01003635" this was going over the end of IObuff
3636func Test_report_error_with_composing()
3637 let caught = 'no'
3638 try
3639 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3640 catch /E492:/
3641 let caught = 'yes'
3642 endtry
3643 call assert_equal('yes', caught)
3644endfunc
3645
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003646" Test for expanding 2-letter and 3-letter :substitute command arguments.
3647" These commands don't accept an argument.
3648func Test_cmdline_complete_substitute_short()
3649 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3650 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3651 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3652 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3653 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3654 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3655 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3656 endfor
3657endfunc
3658
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003659" Test for shellcmdline command argument completion
3660func Test_cmdline_complete_shellcmdline_argument()
3661 command -nargs=+ -complete=shellcmdline MyCmd
3662
3663 set wildoptions=fuzzy
3664
3665 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3666 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003667 call assert_equal(['test_cmdline.vim'],
3668 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003669
3670 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3671 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003672 call assert_equal([],
3673 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003674
3675 let compl1 = getcompletion('', 'file')[0]
3676 let compl2 = getcompletion('', 'file')[1]
3677 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3678 call assert_equal('"MyCmd vim ' .. compl1, @:)
3679
3680 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3681 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3682
3683 let compl = getcompletion('', 'file')[1]
3684 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3685 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3686
3687 set wildoptions&
3688 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3689 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003690 call assert_equal(['test_cmdline.vim'],
3691 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003692
3693 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3694 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003695 call assert_equal([],
3696 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003697
3698 let compl1 = getcompletion('', 'file')[0]
3699 let compl2 = getcompletion('', 'file')[1]
3700 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3701 call assert_equal('"MyCmd vim ' .. compl1, @:)
3702
3703 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3704 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3705
3706 let compl = getcompletion('', 'file')[1]
3707 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3708 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3709
3710 delcommand MyCmd
3711endfunc
3712
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003713" Test for :! shell command argument completion
3714func Test_cmdline_complete_bang_cmd_argument()
3715 set wildoptions=fuzzy
3716 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3717 call assert_equal('"!vim test_cmdline.vim', @:)
3718 set wildoptions&
3719 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3720 call assert_equal('"!vim test_cmdline.vim', @:)
3721endfunc
3722
zeertzjq961b2e52023-04-17 15:53:24 +01003723func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003724 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003725endfunc
3726
3727func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003728 call assert_equal(0, getcmdpos())
3729 call assert_equal(0, getcmdscreenpos())
3730 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003731 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003732
zeertzjqa821b602024-06-18 20:31:08 +02003733 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003734 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003735 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003736 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003737 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003738 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003739 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003740
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003741 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3742 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003743 let g:results = []
3744 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3745 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3746 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003747 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3748 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3749 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003750
3751 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003752 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003753endfunc
3754
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003755func Test_recursive_register()
3756 let @= = ''
3757 silent! ?e/
3758 let caught = 'no'
3759 try
3760 normal //
3761 catch /E169:/
3762 let caught = 'yes'
3763 endtry
3764 call assert_equal('yes', caught)
3765endfunc
3766
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003767func Test_long_error_message()
3768 " the error should be truncated, not overrun IObuff
3769 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3770endfunc
3771
zeertzjq6791adc2022-07-26 20:42:25 +01003772func Test_cmdline_redraw_tabline()
3773 CheckRunVimInTerminal
3774
3775 let lines =<< trim END
3776 set showtabline=2
3777 autocmd CmdlineEnter * set tabline=foo
3778 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003779 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003780 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3781 call term_sendkeys(buf, ':')
3782 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3783
3784 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003785endfunc
3786
zeertzjqb82a2ab2022-08-21 14:33:57 +01003787func Test_wildmenu_pum_disable_while_shown()
3788 set wildoptions=pum
3789 set wildmenu
3790 cnoremap <F2> <Cmd>set nowildmenu<CR>
3791 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3792 call assert_equal(0, pumvisible())
3793 cunmap <F2>
3794 set wildoptions& wildmenu&
3795endfunc
3796
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003797func Test_setcmdline()
3798 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003799 call assert_equal(0, setcmdline(test_null_string()))
3800 call assert_equal('', getcmdline())
3801 call assert_equal(1, getcmdpos())
3802
3803 call assert_equal(0, setcmdline(''[: -1]))
3804 call assert_equal('', getcmdline())
3805 call assert_equal(1, getcmdpos())
3806
zeertzjq54acb902022-08-29 16:21:25 +01003807 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003808 call assert_equal(0, setcmdline(a:text))
3809 call assert_equal(a:text, getcmdline())
3810 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003811 call assert_equal(getcmdtype(), g:cmdtype)
3812 unlet g:cmdtype
3813 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003814
3815 call assert_equal(0, setcmdline(a:text, a:pos))
3816 call assert_equal(a:text, getcmdline())
3817 call assert_equal(a:pos, getcmdpos())
3818
3819 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003820 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3821 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003822
3823 return ''
3824 endfunc
3825
3826 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3827 call assert_equal('set rtp?', @:)
3828
zeertzjq54acb902022-08-29 16:21:25 +01003829 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3830 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3831 call assert_equal('foo', g:str)
3832 unlet g:str
3833
3834 delfunc SetText
3835
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003836 " setcmdline() returns 1 when not editing the command line.
3837 call assert_equal(1, 'foo'->setcmdline())
3838
3839 " Called in custom function
3840 func CustomComplete(A, L, P)
3841 call assert_equal(0, setcmdline("DoCmd "))
3842 return "January\nFebruary\nMars\n"
3843 endfunc
3844
3845 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3846 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3847 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003848 delcom DoCmd
3849 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003850
3851 " Called in <expr>
3852 cnoremap <expr>a setcmdline('let foo=')
3853 call feedkeys(":a\<CR>", 'tx')
3854 call assert_equal('let foo=0', @:)
3855 cunmap a
3856endfunc
3857
Sean Dewarfc8a6012023-04-17 16:41:20 +01003858func Test_rulerformat_position()
3859 CheckScreendump
3860
3861 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3862 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3863 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3864 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3865 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3866
3867 " clean up
3868 call StopVimInTerminal(buf)
3869endfunc
3870
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01003871" Test for using "%!" in 'rulerformat' to use a function
3872func Test_rulerformat_function()
3873 CheckScreendump
3874
3875 let lines =<< trim END
3876 func TestRulerFn()
3877 return '10,20%=30%%'
3878 endfunc
3879 END
3880 call writefile(lines, 'Xrulerformat_function', 'D')
3881
3882 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
3883 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
3884 call term_sendkeys(buf, ":redraw!\<CR>")
3885 call term_wait(buf)
3886 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
3887
3888 " clean up
3889 call StopVimInTerminal(buf)
3890endfunc
3891
zeertzjqe4c79d32023-08-15 22:41:53 +02003892func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003893 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003894
zeertzjqe4c79d32023-08-15 22:41:53 +02003895 call assert_equal(getcompletion('', 'cmdline'),
3896 \ getcompletion('TestCompletion ', 'cmdline'))
3897 call assert_equal(['<buffer>'],
3898 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3899
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003900 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003901endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003902
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003903func Test_custom_completion()
3904 func CustomComplete1(lead, line, pos)
3905 return "a\nb\nc"
3906 endfunc
3907 func CustomComplete2(lead, line, pos)
3908 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3909 endfunc
3910 func Check_custom_completion()
3911 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3912 return ''
3913 endfunc
3914 func Check_customlist_completion()
3915 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3916 return ''
3917 endfunc
3918
3919 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3920 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3921
3922 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3923 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3924
3925 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3926 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3927
zeertzjq757f3212024-04-15 19:01:04 +02003928 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
3929 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
3930 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003931
3932 delcom Test1
3933 delcom Test2
3934
3935 delfunc CustomComplete1
3936 delfunc CustomComplete2
3937 delfunc Check_custom_completion
3938 delfunc Check_customlist_completion
3939endfunc
3940
zeertzjq28a23602023-09-29 19:58:35 +02003941func Test_custom_completion_with_glob()
3942 func TestGlobComplete(A, L, P)
3943 return split(glob('Xglob*'), "\n")
3944 endfunc
3945
3946 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3947 call writefile([], 'Xglob1', 'D')
3948 call writefile([], 'Xglob2', 'D')
3949
3950 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3951 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3952
3953 delcommand TestGlobComplete
3954 delfunc TestGlobComplete
3955endfunc
3956
Christian Brabandt8610f742024-01-12 17:34:40 +01003957func Test_window_size_stays_same_after_changing_cmdheight()
3958 set laststatus=2
3959 let expected = winheight(0)
3960 function! Function_name() abort
3961 call feedkeys(":"..repeat('x', &columns), 'x')
3962 let &cmdheight=2
3963 let &cmdheight=1
3964 redraw
3965 endfunction
3966 call Function_name()
3967 call assert_equal(expected, winheight(0))
3968endfunc
3969
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01003970" verify that buffer-completion finds all buffer names matching a pattern
3971func Test_buffer_completion()
3972 " should return empty list
3973 call assert_equal([], getcompletion('', 'buffer'))
3974
3975 call mkdir('Xbuf_complete', 'R')
3976 e Xbuf_complete/Foobar.c
3977 e Xbuf_complete/MyFoobar.c
3978 e AFoobar.h
3979 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
3980
3981 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
3982 call assert_equal(expected, getcompletion('Foo', 'buffer'))
3983 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
3984 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
3985endfunc
3986
Anton Sharonov49528da2024-04-14 20:02:24 +02003987" :set t_??
3988func Test_term_option()
3989 set wildoptions&
3990 let _cpo = &cpo
3991 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003992 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02003993 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'
3994 \ .. ' 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'
3995 \ .. ' 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'
3996 \ .. ' 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'
3997 \ .. ' 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 +02003998 \ .. ' 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 +02003999 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02004000 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004001 let &cpo = _cpo
4002endfunc
4003
Christian Brabandt70a11a62024-07-26 19:13:55 +02004004func Test_ex_command_completion()
4005 " required for :*
4006 set cpo+=*
4007 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4008 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4009 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004010 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004011 call assert_equal(0, exists(':ke'))
4012 call assert_equal(1, exists(':kee'))
4013 call assert_equal(1, exists(':keep'))
4014 call assert_equal(1, exists(':keepm'))
4015 call assert_equal(1, exists(':keepma'))
4016 call assert_equal(1, exists(':keepmar'))
4017 call assert_equal(1, exists(':keepmark'))
4018 call assert_equal(2, exists(':keepmarks'))
4019 call assert_equal(2, exists(':keepalt'))
4020 call assert_equal(2, exists(':keepjumps'))
4021 call assert_equal(2, exists(':keeppatterns'))
4022 set cpo-=*
4023endfunc
4024
zeertzjq5df3cb22024-10-07 21:05:06 +02004025func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004026 CheckMSWindows
4027 let save_shellslash = &shellslash
4028 set noshellslash
4029 call system('mkdir XXXa\_b')
4030 defer delete('XXXa', 'rf')
4031 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4032 call assert_equal('"cd XXXa\_b\', @:)
4033 let &shellslash = save_shellslash
4034endfunc
4035
Bram Moolenaar309976e2019-12-05 18:16:33 +01004036" vim: shiftwidth=2 sts=2 expandtab