blob: 30ded35b8d90f3e8d6060a049c6cdb947a3d87d7 [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
Bram Moolenaar0816f472022-10-05 15:42:32 +0100273 func EchoTwo()
274 set laststatus=2
275 set cmdheight=5
276 echo 'foo'
277 echo 'bar'
278 set cmdheight=1
279 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100280 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100281 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100282
283 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
284 call term_sendkeys(buf, ":resize -3\<CR>")
285 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
286
287 " using the space available doesn't change the status line
288 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
289 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
290
291 " using more space moves the status line up
292 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
293 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
294
295 " reducing cmdheight moves status line down
296 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
297 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
298
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000299 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100300 call term_sendkeys(buf, ":resize -1\<CR>")
301 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
302 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
303
Bram Moolenaar0816f472022-10-05 15:42:32 +0100304 " setting 'cmdheight' works after outputting two messages
305 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
306 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
307
Bram Moolenaarf797e302022-08-11 13:17:30 +0100308 " clean up
309 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100310endfunc
311
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100312func Test_cmdheight_tabline()
313 CheckScreendump
314
315 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
316 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
317
318 " clean up
319 call StopVimInTerminal(buf)
320endfunc
321
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100322func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100323 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
324 call assert_equal('"map <unique> <silent>', getreg(':'))
325 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
326 call assert_equal('"map <script> <unique>', getreg(':'))
327 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
328 call assert_equal('"map <expr> <script>', getreg(':'))
329 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
330 call assert_equal('"map <buffer> <expr>', getreg(':'))
331 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
332 call assert_equal('"map <nowait> <buffer>', getreg(':'))
333 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
334 call assert_equal('"map <special> <nowait>', getreg(':'))
335 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
336 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200337
Bram Moolenaar1776a282019-05-03 16:05:41 +0200338 map <Middle>x middle
339
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200340 map ,f commaf
341 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200342 map <Left> left
343 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200344 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
345 call assert_equal('"map ,f', getreg(':'))
346 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
347 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200348 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
349 call assert_equal('"map <Left>', getreg(':'))
350 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200351 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000352 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
353 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 unmap ,f
355 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200356 unmap <Left>
357 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200358
zeertzjqc3a26c62023-02-17 16:40:20 +0000359 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200360 map <Left> left
361 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
362 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200363 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200364 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000365 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
366 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200367 unmap <Left>
368
369 set cpo+=<
370 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200371 exe "set t_k6=\<Esc>[17~"
372 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200373 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
374 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200375 if !has('gui_running')
376 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal("\"map <F6>x", getreg(':'))
378 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200379 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200380 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200381 set cpo-=<
382
383 set cpo+=B
384 map <Left> left
385 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
386 call assert_equal('"map <Left>', getreg(':'))
387 unmap <Left>
388 set cpo-=B
389
390 set cpo+=k
391 map <Left> left
392 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
393 call assert_equal('"map <Left>', getreg(':'))
394 unmap <Left>
395 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200396
Bram Moolenaar531be472020-09-23 22:38:05 +0200397 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
398
Bram Moolenaar1776a282019-05-03 16:05:41 +0200399 unmap <Middle>x
400 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100401endfunc
402
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100403func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100404 hi Aardig ctermfg=green
405 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000406 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100407 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000408 call assert_equal('"match none', @:)
409 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
410 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100411endfunc
412
413func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100414 hi Aardig ctermfg=green
415 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
416 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200417 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
418 call assert_equal('"hi default Aardig', getreg(':'))
419 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
420 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100421 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
422 call assert_equal('"hi link', getreg(':'))
423 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
424 call assert_equal('"hi default', getreg(':'))
425 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
426 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200427 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
428 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
429 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
430 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200431
432 " A cleared group does not show up in completions.
433 hi Anders ctermfg=green
434 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
435 hi clear Aardig
436 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
437 hi clear Anders
438 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100439endfunc
440
Bram Moolenaar75e15672020-06-28 13:10:22 +0200441" Test for command-line expansion of "hi Ni " (easter egg)
442func Test_highlight_easter_egg()
443 call test_override('ui_delay', 1)
444 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
445 call assert_equal("\"hi Ni \<Tab>", @:)
446 call test_override('ALL', 0)
447endfunc
448
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200449func Test_getcompletion()
450 let groupcount = len(getcompletion('', 'event'))
451 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200452 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200453 call assert_true(matchcount > 0)
454 call assert_true(groupcount > matchcount)
455
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200456 if has('menu')
457 source $VIMRUNTIME/menu.vim
458 let matchcount = len(getcompletion('', 'menu'))
459 call assert_true(matchcount > 0)
460 call assert_equal(['File.'], getcompletion('File', 'menu'))
461 call assert_true(matchcount > 0)
462 let matchcount = len(getcompletion('File.', 'menu'))
463 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000464 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200465 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200466
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467 let l = getcompletion('v:n', 'var')
468 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('v:notexists', 'var')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200472 args a.c b.c
473 let l = getcompletion('', 'arglist')
474 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000475 let l = getcompletion('a.', 'buffer')
476 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200477 %argdelete
478
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200479 let l = getcompletion('', 'augroup')
480 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200481 let l = getcompletion('blahblah', 'augroup')
482 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200483
484 let l = getcompletion('', 'behave')
485 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200486 let l = getcompletion('not', 'behave')
487 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200488
489 let l = getcompletion('', 'color')
490 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200491 let l = getcompletion('dirty', 'color')
492 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200493
494 let l = getcompletion('', 'command')
495 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200496 let l = getcompletion('awake', 'command')
497 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200498
499 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200500 call assert_true(index(l, 'samples/') >= 0)
501 let l = getcompletion('NoMatch', 'dir')
502 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100504 if glob('~/*') !=# ''
505 let l = getcompletion('~/', 'dir')
506 call assert_true(l[0][0] ==# '~')
507 endif
508
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509 let l = getcompletion('exe', 'expression')
510 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200511 let l = getcompletion('kill', 'expression')
512 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200513
514 let l = getcompletion('tag', 'function')
515 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200516 let l = getcompletion('paint', 'function')
517 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200518
Kota Kato90c23532023-01-18 15:27:38 +0000519 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000520 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000521 let l = getcompletion('ruby', 'function')
522 call assert_equal([], l)
523 endif
524
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200525 let Flambda = {-> 'hello'}
526 let l = getcompletion('', 'function')
527 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200529
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530 let l = getcompletion('run', 'file')
531 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200532 let l = getcompletion('walk', 'file')
533 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200534 set wildignore=*.vim
535 let l = getcompletion('run', 'file', 1)
536 call assert_true(index(l, 'runtest.vim') < 0)
537 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000538 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100539 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000540 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
541 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200542
543 let l = getcompletion('ha', 'filetype')
544 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200545 let l = getcompletion('horse', 'filetype')
546 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200547
Doug Kearns81642d92024-01-04 22:37:44 +0100548 if has('keymap')
549 let l = getcompletion('acc', 'keymap')
550 call assert_true(index(l, 'accents') >= 0)
551 let l = getcompletion('nullkeymap', 'keymap')
552 call assert_equal([], l)
553 endif
554
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200555 let l = getcompletion('z', 'syntax')
556 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200557 let l = getcompletion('emacs', 'syntax')
558 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200559
560 let l = getcompletion('jikes', 'compiler')
561 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200562 let l = getcompletion('break', 'compiler')
563 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200564
565 let l = getcompletion('last', 'help')
566 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200567 let l = getcompletion('giveup', 'help')
568 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200569
570 let l = getcompletion('time', 'option')
571 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200572 let l = getcompletion('space', 'option')
573 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200574
575 let l = getcompletion('er', 'highlight')
576 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200577 let l = getcompletion('dark', 'highlight')
578 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200579
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200580 let l = getcompletion('', 'messages')
581 call assert_true(index(l, 'clear') >= 0)
582 let l = getcompletion('not', 'messages')
583 call assert_equal([], l)
584
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200585 let l = getcompletion('', 'mapclear')
586 call assert_true(index(l, '<buffer>') >= 0)
587 let l = getcompletion('not', 'mapclear')
588 call assert_equal([], l)
589
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200590 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200591 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200592 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
593 let root = has('win32') ? 'C:\\' : '/'
594 let l = getcompletion(root, 'shellcmd')
595 let expected = map(filter(glob(root . '*', 0, 1),
596 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
597 call assert_equal(expected, l)
598
Bram Moolenaarb650b982016-08-05 20:35:13 +0200599 if has('cscope')
600 let l = getcompletion('', 'cscope')
601 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
602 call assert_equal(cmds, l)
603 " using cmdline completion must not change the result
604 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
605 let l = getcompletion('', 'cscope')
606 call assert_equal(cmds, l)
607 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
608 let l = getcompletion('find ', 'cscope')
609 call assert_equal(keys, l)
610 endif
611
Bram Moolenaar7522f692016-08-06 14:12:50 +0200612 if has('signs')
613 sign define Testing linehl=Comment
614 let l = getcompletion('', 'sign')
615 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
616 call assert_equal(cmds, l)
617 " using cmdline completion must not change the result
618 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
619 let l = getcompletion('', 'sign')
620 call assert_equal(cmds, l)
621 let l = getcompletion('list ', 'sign')
622 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000623 let l = getcompletion('de*', 'sign')
624 call assert_equal(['define'], l)
625 let l = getcompletion('p?', 'sign')
626 call assert_equal(['place'], l)
627 let l = getcompletion('j.', 'sign')
628 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200629 endif
630
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200631 " Command line completion tests
632 let l = getcompletion('cd ', 'cmdline')
633 call assert_true(index(l, 'samples/') >= 0)
634 let l = getcompletion('cd NoMatch', 'cmdline')
635 call assert_equal([], l)
636 let l = getcompletion('let v:n', 'cmdline')
637 call assert_true(index(l, 'v:null') >= 0)
638 let l = getcompletion('let v:notexists', 'cmdline')
639 call assert_equal([], l)
640 let l = getcompletion('call tag', 'cmdline')
641 call assert_true(index(l, 'taglist(') >= 0)
642 let l = getcompletion('call paint', 'cmdline')
643 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200644 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
645 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200646
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100647 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000648 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100649 return "oneA\noneB\noneC"
650 endfunc
651 command -nargs=1 -complete=custom,T MyCmd
652 let l = getcompletion('MyCmd ', 'cmdline')
653 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000654 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100655
656 delcommand MyCmd
657 delfunc T
ii144785fe02021-11-21 12:13:56 +0000658 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100659
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200660 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200661 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
662 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200663 if has('cmdline_hist')
664 call add(names, 'history')
665 endif
666 if has('gettext')
667 call add(names, 'locale')
668 endif
669 if has('profile')
670 call add(names, 'syntime')
671 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200672
673 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100674 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200675
676 for name in names
677 let matchcount = len(getcompletion('', name))
678 call assert_true(matchcount >= 0, 'No matches for ' . name)
679 endfor
680
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200681 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200682
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000683 edit a~b
684 enew
685 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
686 bw a~b
687
688 if has('unix')
689 edit Xtest\
690 enew
691 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
692 bw Xtest\
693 endif
694
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100695 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200696 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100697 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200698endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200699
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000700func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000701 " Get a dialog in the GUI
702 CheckNotGui
703
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000704 " This was using uninitialized memory.
705 let lines =<< trim END
706 set verbose=6
707 norm @=ٷ
708 qall!
709 END
710 call writefile(lines, 'XmultiScript', 'D')
711 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
712endfunc
713
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000714" Test for getcompletion() with "fuzzy" in 'wildoptions'
715func Test_getcompletion_wildoptions()
716 let save_wildoptions = &wildoptions
717 set wildoptions&
718 let l = getcompletion('space', 'option')
719 call assert_equal([], l)
720 let l = getcompletion('ier', 'command')
721 call assert_equal([], l)
722 set wildoptions=fuzzy
723 let l = getcompletion('space', 'option')
724 call assert_true(index(l, 'backspace') >= 0)
725 let l = getcompletion('ier', 'command')
726 call assert_true(index(l, 'compiler') >= 0)
727 let &wildoptions = save_wildoptions
728endfunc
729
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000730func Test_complete_autoload_error()
731 let save_rtp = &rtp
732 let lines =<< trim END
733 vim9script
734 export def Complete(..._): string
735 return 'match'
736 enddef
737 echo this will cause an error
738 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100739 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000740 call writefile(lines, 'Xdir/autoload/script.vim')
741 exe 'set rtp+=' .. getcwd() .. '/Xdir'
742
743 let lines =<< trim END
744 vim9script
745 import autoload 'script.vim'
746 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
747 &wildcharm = char2nr("\<Tab>")
748 feedkeys(":Cmd \<Tab>", 'xt')
749 END
750 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
751
752 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000753endfunc
754
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100755func Test_fullcommand()
756 let tests = {
757 \ '': '',
758 \ ':': '',
759 \ ':::': '',
760 \ ':::5': '',
761 \ 'not_a_cmd': '',
762 \ 'Check': '',
763 \ 'syntax': 'syntax',
764 \ ':syntax': 'syntax',
765 \ '::::syntax': 'syntax',
766 \ 'sy': 'syntax',
767 \ 'syn': 'syntax',
768 \ 'synt': 'syntax',
769 \ ':sy': 'syntax',
770 \ '::::sy': 'syntax',
771 \ 'match': 'match',
772 \ '2match': 'match',
773 \ '3match': 'match',
774 \ 'aboveleft': 'aboveleft',
775 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100776 \ 'en': 'endif',
777 \ 'end': 'endif',
778 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100779 \ 's': 'substitute',
780 \ '5s': 'substitute',
781 \ ':5s': 'substitute',
782 \ "'<,'>s": 'substitute',
783 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100784 \ 'CheckLin': 'CheckLinux',
785 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100786 \ }
787
788 for [in, want] in items(tests)
789 call assert_equal(want, fullcommand(in))
790 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200791 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100792
793 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200794
795 command -buffer BufferLocalCommand :
796 command GlobalCommand :
797 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
798 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
799 delcommand BufferLocalCommand
800 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100801endfunc
802
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200803func Test_shellcmd_completion()
804 let save_path = $PATH
805
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100806 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200807 call writefile([''], 'Xpathdir/Xfile.exe')
808 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
809
810 " Set PATH to example directory without trailing slash.
811 let $PATH = getcwd() . '/Xpathdir'
812
813 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
814 " dirs in the PATH, even though they won't be executed. We check that only
815 " subdirs of the PWD and executables from the PATH are included in the
816 " suggestions.
817 let actual = getcompletion('X', 'shellcmd')
818 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
819 call insert(expected, 'Xfile.exe')
820 call assert_equal(expected, actual)
821
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200822 let $PATH = save_path
823endfunc
824
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200825func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100826 call mkdir('a/b/c', 'pR')
827 call writefile(['asdfasdf'], 'a/b/c/fileXname')
828 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
829 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200830 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200831endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100832
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100833func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100834 let @a = "def"
835 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
836 call assert_equal('"abc def ghi', @:)
837
838 new
839 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
840
841 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
842 call assert_equal('"aaa asdf bbb', @:)
843
844 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
845 call assert_equal('"aaa /tmp/some bbb', @:)
846
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200847 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
848 call assert_equal('"aaa '.getline(1).' bbb', @:)
849
Bram Moolenaar21efc362016-12-03 14:05:49 +0100850 set incsearch
851 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
852 call assert_equal('"aaa verylongword bbb', @:)
853
854 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
855 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100856
857 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
858 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100859 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200860
861 " Error while typing a command used to cause that it was not executed
862 " in the end.
863 new
864 try
865 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
866 catch /^Vim\%((\a\+)\)\=:E32/
867 " ignore error E32
868 endtry
869 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100870
Bram Moolenaar578fe942020-02-27 21:32:51 +0100871 " Try to paste an invalid register using <C-R>
872 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
873 call assert_equal('"onetwo', @:)
874
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100875 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100876 let @a = "xy\<C-H>z"
877 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
878 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100879 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
880 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100881 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
882 call assert_equal("\"xy\<C-H>z", @:)
883
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100884 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
885 let @a = "xy\<C-V>z"
886 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
887 call assert_equal('"xyz', @:)
888 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
889 call assert_equal("\"xy\<C-V>z", @:)
890
Bram Moolenaar578fe942020-02-27 21:32:51 +0100891 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
892
Bram Moolenaar72532d32018-04-07 19:09:09 +0200893 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100894endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100895
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100896func Test_cmdline_remove_char()
897 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100898
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100899 for e in ['utf8', 'latin1']
900 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100901
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100902 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
903 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100904
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100905 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
906 call assert_equal('"abcdef', @:)
907
908 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
909 call assert_equal('"abc ghi', @:, e)
910
911 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
912 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100913
914 " This was going before the start in latin1.
915 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100916 endfor
917
918 let &encoding = encoding_save
919endfunc
920
zeertzjqff2b79d2024-02-26 20:38:36 +0100921func Test_cmdline_del_utf8()
922 let @s = '⒌'
923 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
924 call assert_equal('",,', @:)
925
926 let @s = 'a̳'
927 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
928 call assert_equal('",,', @:)
929
930 let @s = 'β̳'
931 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
932 call assert_equal('",,', @:)
933
934 if has('arabic')
935 let @s = 'لا'
936 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
937 call assert_equal('",,', @:)
938 endif
939endfunc
940
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100941func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200942 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100943
944 set keymap=esperanto
945 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
946 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
947 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100948endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100949
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100950func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100951 new
952 2;'(
953 2;')
954 quit
955endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100956
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100957func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100958 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100959 new
960 source Xtest.vim
961 " Trigger calling validate_cursor()
962 diffsp Xtest.vim
963 quit!
964 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100965endfunc
966
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100967func Test_mark_from_line_zero()
968 " this was reading past the end of the first (empty) line
969 new
970 norm oxxxx
971 call assert_fails("0;'(", 'E20:')
972 bwipe!
973endfunc
974
Bram Moolenaarba47b512017-01-24 21:18:19 +0100975func Test_cmdline_complete_wildoptions()
976 help
977 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
978 let a = join(sort(split(@:)),' ')
979 set wildoptions=tagfile
980 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
981 let b = join(sort(split(@:)),' ')
982 call assert_equal(a, b)
983 bw!
984endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100985
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200986func Test_cmdline_complete_user_cmd()
987 command! -complete=color -nargs=1 Foo :
988 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
989 call assert_equal('"Foo blue', @:)
990 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
991 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000992 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
993 call assert_equal('"Foo a blue', @:)
994 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
995 call assert_equal('"Foo b\', @:)
996 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
997 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200998 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100999
1000 redraw
1001 call assert_equal('~', Screenline(&lines - 1))
1002 command! FooOne :
1003 command! FooTwo :
1004
1005 set nowildmenu
1006 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1007 call assert_equal('"FooOne', @:)
1008 call assert_equal('~', Screenline(&lines - 1))
1009
1010 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1011 call assert_equal('"FooTwo', @:)
1012 call assert_equal('~', Screenline(&lines - 1))
1013
1014 delcommand FooOne
1015 delcommand FooTwo
1016 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001017endfunc
1018
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001019func Test_complete_user_cmd()
1020 command FooBar echo 'global'
1021 command -buffer FooBar echo 'local'
1022 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1023 call assert_equal('"FooBar', @:)
1024
1025 delcommand -buffer FooBar
1026 delcommand FooBar
1027endfunc
1028
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001029func s:ScriptLocalFunction()
1030 echo 'yes'
1031endfunc
1032
1033func Test_cmdline_complete_user_func()
1034 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001035 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001036 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1037 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001038
1039 " g: prefix also works
1040 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1041 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001042
1043 " using g: prefix does not result in just "g:" matches from a lambda
1044 let Fx = { a -> a }
1045 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1046 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001047
1048 " existence of script-local dict function does not break user function name
1049 " completion
1050 function s:a_dict_func() dict
1051 endfunction
1052 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1053 call assert_match('"call Test_cmdline_complete_user_', @:)
1054 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001055endfunc
1056
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001057func Test_cmdline_complete_user_names()
1058 if has('unix') && executable('whoami')
1059 let whoami = systemlist('whoami')[0]
1060 let first_letter = whoami[0]
1061 if len(first_letter) > 0
1062 " Trying completion of :e ~x where x is the first letter of
1063 " the user name should complete to at least the user name.
1064 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1065 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1066 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001067 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001068 " Just in case: check that the system has an Administrator account.
1069 let names = system('net user')
1070 if names =~ 'Administrator'
1071 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001072 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001073 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001074 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001075 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001076 else
1077 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001078 endif
1079endfunc
1080
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001081func Test_cmdline_complete_shellcmdline()
1082 CheckExecutable whoami
1083 command -nargs=1 -complete=shellcmdline MyCmd
1084
1085 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1086 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001087 let l = getcompletion('whoam', 'shellcmdline')
1088 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001089
1090 delcommand MyCmd
1091endfunc
1092
Bram Moolenaar297610b2019-12-27 17:20:55 +01001093func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001094 CheckExecutable whoami
1095 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1096 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001097endfunc
1098
Bram Moolenaar8b633132020-03-20 18:20:51 +01001099func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001100 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1101 call assert_equal(lang, v:lc_time)
1102
1103 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1104 call assert_equal(lang, v:ctype)
1105
1106 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1107 call assert_equal(lang, v:collate)
1108
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001109 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001110 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001111
1112 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001113 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001114
Bram Moolenaarec680282020-06-12 19:35:32 +02001115 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001116
Bram Moolenaarec680282020-06-12 19:35:32 +02001117 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1118 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001119
Bram Moolenaarec680282020-06-12 19:35:32 +02001120 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1121 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001122
Bram Moolenaarec680282020-06-12 19:35:32 +02001123 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1124 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001125
1126 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1127 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001128endfunc
1129
Bram Moolenaar297610b2019-12-27 17:20:55 +01001130func Test_cmdline_complete_env_variable()
1131 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001132 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1133 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001134 unlet $X_VIM_TEST_COMPLETE_ENV
1135endfunc
1136
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001137func Test_cmdline_complete_expression()
1138 let g:SomeVar = 'blah'
1139 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1140 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1141 call assert_match('"' .. cmd .. ' SomeVar', @:)
1142 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1143 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1144 endfor
1145 unlet g:SomeVar
1146endfunc
1147
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001148func Test_cmdline_complete_argopt()
1149 " completion for ++opt=arg for file commands
1150 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1151 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1152 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1153
1154 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001155 " Test ++ff in the middle of the cmdline
1156 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001158
1159 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1160 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1161 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1162 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1163 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1164
1165 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1166
1167 " completion should skip the ++opt and continue
1168 call writefile([], 'Xaaaaa.txt', 'D')
1169 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1171
1172 if has('terminal')
1173 " completion for terminal's [options]
1174 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1175 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1176 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1177
1178 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1179
1180 " :terminal completion should skip the ++opt when considering what is the
1181 " first option, which is a list of shell commands, unlike second option
1182 " onwards.
1183 let first_param = getcompletion('terminal ', 'cmdline')
1184 let second_param = getcompletion('terminal foo ', 'cmdline')
1185 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1186 call assert_equal(first_param, skipped_opt_param)
1187 call assert_notequal(first_param, second_param)
1188 endif
1189endfunc
1190
Bram Moolenaar47016f52021-08-26 16:39:58 +02001191" Unique function name for completion below
1192func s:WeirdFunc()
1193 echo 'weird'
1194endfunc
1195
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001196" Test for various command-line completion
1197func Test_cmdline_complete_various()
1198 " completion for a command starting with a comment
1199 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1200 call assert_equal("\" :|\"\<C-A>", @:)
1201
1202 " completion for a range followed by a comment
1203 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1204 call assert_equal("\"1,2\"\<C-A>", @:)
1205
1206 " completion for :k command
1207 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1208 call assert_equal("\"ka\<C-A>", @:)
1209
Doug Kearnsea842022024-09-29 17:17:41 +02001210 " completion for :keepmarks command
1211 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"kee edit", @:)
1213
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001214 " completion for short version of the :s command
1215 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1216 call assert_equal("\"sI \<C-A>", @:)
1217
1218 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001219 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001220 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001221 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001222 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001223 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal("\"w >> Xfile1", @:)
1225 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001226
1227 " completion for :w ! and :r ! commands
1228 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1229 call assert_equal("\"w !invalid_xyz_cmd", @:)
1230 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1231 call assert_equal("\"r !invalid_xyz_cmd", @:)
1232
1233 " completion for :>> and :<< commands
1234 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1235 call assert_equal("\">>>\<C-A>", @:)
1236 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1237 call assert_equal("\"<<<\<C-A>", @:)
1238
1239 " completion for command with +cmd argument
1240 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1241 call assert_equal("\"buffer +/pat Xabc", @:)
1242 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1243 call assert_equal("\"buffer +/pat\<C-A>", @:)
1244
1245 " completion for a command with a trailing comment
1246 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1247 call assert_equal("\"ls \" comment\<C-A>", @:)
1248
1249 " completion for a command with a trailing command
1250 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1251 call assert_equal("\"ls | ls", @:)
1252
1253 " completion for a command with an CTRL-V escaped argument
1254 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1255 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1256
1257 " completion for a command that doesn't take additional arguments
1258 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1259 call assert_equal("\"all abc\<C-A>", @:)
1260
zeertzjqd3de1782022-09-01 12:58:52 +01001261 " completion for :wincmd with :horizontal modifier
1262 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1263 call assert_equal("\"horizontal wincmd", @:)
1264
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001265 " completion for a command with a command modifier
1266 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1267 call assert_equal("\"topleft new", @:)
1268
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001269 " completion for vim9 and legacy commands
1270 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1271 call assert_equal("\"vim9 call strlen(", @:)
1272 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1273 call assert_equal("\"legac call strlen(", @:)
1274
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001275 " completion for the :disassemble command
1276 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1277 call assert_equal("\"disas debug", @:)
1278 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1279 call assert_equal("\"disas profile", @:)
1280 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1282 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1283 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001284 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1285 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001286
Bram Moolenaar47016f52021-08-26 16:39:58 +02001287 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001288 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001289
naohiro onodfe04db2021-09-12 15:45:10 +02001290 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1291 call assert_match('"disas <SNR>\d\+_', @:)
1292 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1293 call assert_match('"disas debug <SNR>\d\+_', @:)
1294
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001295 " completion for the :match command
1296 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1297 call assert_equal("\"match Search /pat/\<C-A>", @:)
1298
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001299 " completion for the :doautocmd command
1300 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1301 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1302
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001303 " completion of autocmd group after comma
1304 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1305 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1306
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001307 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001308 call writefile([], 'Xvarfile1', 'D')
1309 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001310 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1311 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001312
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001313 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001314 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001315 augroup END
1316 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001317 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001318
1319 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001320 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1321 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001322 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1323 call assert_equal("\"au XTest.test", @:)
1324
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001325 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001326
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001327 " autocmd pattern completion
1328 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1329 call assert_equal("\"au BufEnter *.py\t", @:)
1330
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001331 " completion for the :unlet command
1332 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1333 call assert_equal("\"unlet one two", @:)
1334
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001335 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001336 " FIXME: what should happen on MS-Windows?
1337 if !has('win32')
1338 edit \{someFile}
1339 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1340 call assert_equal("\"buf {someFile}", @:)
1341 bwipe {someFile}
1342 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001343
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001344 " completion for the :bdelete command
1345 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1346 call assert_equal("\"bdel a b c", @:)
1347
1348 " completion for the :mapclear command
1349 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1350 call assert_equal("\"mapclear <buffer>", @:)
1351
1352 " completion for user defined commands with menu names
1353 menu Test.foo :ls<CR>
1354 com -nargs=* -complete=menu MyCmd
1355 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1356 call assert_equal('"MyCmd Test.', @:)
1357 delcom MyCmd
1358 unmenu Test
1359
1360 " completion for user defined commands with mappings
1361 mapclear
1362 map <F3> :ls<CR>
1363 com -nargs=* -complete=mapping MyCmd
1364 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001365 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001366 mapclear
1367 delcom MyCmd
1368
Yee Cheng Chin54844852023-10-09 18:12:31 +02001369 " Prepare for path completion
1370 call mkdir('Xa b c', 'D')
1371 defer delete('Xcomma,foobar.txt')
1372 call writefile([], 'Xcomma,foobar.txt')
1373
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001374 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001375 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1376 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1377 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001378
1379 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001380 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1381 call assert_equal('"set dir=Xa\ b\ c/', @:)
1382 set dir&
1383
1384 " completion for :set tags= / set dictionary= with escaped commas
1385 if has('win32')
1386 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1387 " '\,'
1388 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1389 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1390
1391 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1392 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1393
1394 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1395 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1396
1397 " completion for :set dictionary= with escaped commas (same behavior, but
1398 " different internal code path from 'set tags=' for escaping the output)
1399 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1400 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1401 else
1402 " In other platforms, backslashes are rounded down (since '\,' itself will
1403 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1404 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1405 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1406
1407 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1408 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1409
1410 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1411 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1412
1413 " completion for :set dictionary= with escaped commas (same behavior, but
1414 " different internal code path from 'set tags=' for escaping the output)
1415 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1416 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1417 endif
1418 set tags&
1419 set dictionary&
1420
1421 " completion for :set makeprg= with no escaped commas
1422 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1423 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1424
1425 if !has('win32')
1426 " Cannot create file with backslash in file name in Windows, so only test
1427 " this elsewhere.
1428 defer delete('Xcomma\,fooslash.txt')
1429 call writefile([], 'Xcomma\,fooslash.txt')
1430 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1431 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1432 endif
1433 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001434
1435 " completion for the :py3 commands
1436 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1437 call assert_equal('"py3 py3do py3file', @:)
1438
Bram Moolenaardf749a22021-03-28 15:29:43 +02001439 " completion for the :vim9 commands
1440 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1441 call assert_equal('"vim9cmd vim9script', @:)
1442
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001443 " redir @" is not the start of a comment. So complete after that
1444 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1445 call assert_equal('"redir @" | cwindow', @:)
1446
1447 " completion after a backtick
1448 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1449 call assert_equal('"e `a1b2c', @:)
1450
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001451 " completion for :language command with an invalid argument
1452 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1453 call assert_equal("\"language dummy \t", @:)
1454
1455 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001456 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1457 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001458
1459 " completion with ambiguous user defined commands
1460 com TCmd1 echo 'TCmd1'
1461 com TCmd2 echo 'TCmd2'
1462 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1463 call assert_equal('"TCmd ', @:)
1464 delcom TCmd1
1465 delcom TCmd2
1466
1467 " completion after a range followed by a pipe (|) character
1468 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1469 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001470
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001471 " completion after a :global command
1472 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1473 call assert_equal('"g/a/chistory', @:)
1474 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1475 call assert_equal("\"g/a\\/chist\t", @:)
1476
Bram Moolenaar9c929712020-09-07 22:05:28 +02001477 " use <Esc> as the 'wildchar' for completion
1478 set wildchar=<Esc>
1479 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1480 call assert_equal('"g/a\xb/clearjumps', @:)
1481 " pressing <esc> twice should cancel the command
1482 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1483 call assert_equal('"g/a\xb/clearjumps', @:)
1484 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001485
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001486 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001487 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001488 call writefile([], '~Xtest')
1489 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1490 call assert_equal('"e \~Xtest', @:)
1491 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001492
1493 " should be able to complete a file name that has a '*'
1494 call writefile([], 'Xx*Yy')
1495 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1496 call assert_equal('"e Xx\*Yy', @:)
1497 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001498
1499 " use a literal star
1500 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1501 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001502 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001503
1504 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1505 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001506endfunc
1507
zeertzjq094dd152023-06-15 22:51:57 +01001508" Test that expanding a pattern doesn't interfere with cmdline completion.
1509func Test_expand_during_cmdline_completion()
1510 func ExpandStuff()
1511 badd <script>:p:h/README.*
1512 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1513 $bwipe
1514 call assert_equal('README.txt', expand('README.*'))
1515 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1516 endfunc
1517 augroup test_CmdlineChanged
1518 autocmd!
1519 autocmd CmdlineChanged * call ExpandStuff()
1520 augroup END
1521
1522 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1523 call assert_equal('"sign place', @:)
1524
1525 augroup test_CmdlineChanged
1526 au!
1527 augroup END
1528 augroup! test_CmdlineChanged
1529 delfunc ExpandStuff
1530endfunc
1531
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001532" Test for 'wildignorecase'
1533func Test_cmdline_wildignorecase()
1534 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001535 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001536 set wildignorecase
1537 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1538 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001539 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001540 let g:Sline = ''
1541 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1542 call assert_equal('"e xt', @:)
1543 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001544 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001545endfunc
1546
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001547func Test_cmdline_write_alternatefile()
1548 new
1549 call setline('.', ['one', 'two'])
1550 f foo.txt
1551 new
1552 f #-A
1553 call assert_equal('foo.txt-A', expand('%'))
1554 f #<-B.txt
1555 call assert_equal('foo-B.txt', expand('%'))
1556 f %<
1557 call assert_equal('foo-B', expand('%'))
1558 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001559 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001560 bw!
1561 f foo-B.txt
1562 f %<-A
1563 call assert_equal('foo-B-A', expand('%'))
1564 bw!
1565 bw!
1566endfunc
1567
Bram Moolenaarf5724372022-09-02 19:45:15 +01001568func Test_cmdline_expand_cur_alt_file()
1569 enew
1570 file http://some.com/file.txt
1571 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1572 call assert_equal('"e http://some.com/file.txt', @:)
1573 edit another
1574 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1575 call assert_equal('"e http://some.com/file.txt', @:)
1576 bwipe
1577 bwipe http://some.com/file.txt
1578endfunc
1579
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001580" using a leading backslash here
1581set cpo+=C
1582
1583func Test_cmdline_search_range()
1584 new
1585 call setline(1, ['a', 'b', 'c', 'd'])
1586 /d
1587 1,\/s/b/B/
1588 call assert_equal('B', getline(2))
1589
1590 /a
1591 $
1592 \?,4s/c/C/
1593 call assert_equal('C', getline(3))
1594
1595 call setline(1, ['a', 'b', 'c', 'd'])
1596 %s/c/c/
1597 1,\&s/b/B/
1598 call assert_equal('B', getline(2))
1599
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001600 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001601 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001602
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001603 bwipe!
1604endfunc
1605
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001606" Test for the tick mark (') in an excmd range
1607func Test_tick_mark_in_range()
1608 " If only the tick is passed as a range and no command is specified, there
1609 " should not be an error
1610 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001611 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001612 call assert_fails("',print", 'E78:')
1613endfunc
1614
1615" Test for using a line number followed by a search pattern as range
1616func Test_lnum_and_pattern_as_range()
1617 new
1618 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1619 let @" = ''
1620 2/foo/yank
1621 call assert_equal("foo 3\n", @")
1622 call assert_equal(1, line('.'))
1623 close!
1624endfunc
1625
Bram Moolenaar65189a12017-02-06 22:22:17 +01001626" Tests for getcmdline(), getcmdpos() and getcmdtype()
1627func Check_cmdline(cmdtype)
1628 call assert_equal('MyCmd a', getcmdline())
1629 call assert_equal(8, getcmdpos())
1630 call assert_equal(a:cmdtype, getcmdtype())
1631 return ''
1632endfunc
1633
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001634set cpo&
1635
Shougo Matsushita69084282024-09-23 20:34:47 +02001636func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001637 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1638
1639 let cmdtype = ''
1640 debuggreedy
1641 call feedkeys(":debug echo 'test'\<CR>", "t")
1642 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1643 call feedkeys("cont\<CR>", "xt")
1644 0debuggreedy
1645 call assert_equal('>', cmdtype)
1646
1647 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1648 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1649
1650 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001651 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001652
1653 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1654
1655 cnoremap <expr> <F6> Check_cmdline('=')
1656 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1657 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001658
1659 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001660
1661 call assert_equal('', getcmdprompt())
1662 augroup test_CmdlineEnter
1663 autocmd!
1664 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1665 augroup END
1666 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1667 call assert_equal('Answer?', g:cmdprompt)
1668 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001669 call feedkeys(":\<CR>\<ESC>", "xt")
1670 call assert_equal('', g:cmdprompt)
1671 call assert_equal('', getcmdprompt())
1672
1673 let str = "C" .. repeat("c", 1023) .. "xyz"
1674 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1675 call assert_equal(str, g:cmdprompt)
1676
1677 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1678 call assert_equal('Ans?', g:cmdprompt)
1679 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001680
1681 augroup test_CmdlineEnter
1682 au!
1683 augroup END
1684 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001685endfunc
1686
Bram Moolenaar52604f22017-04-07 16:17:39 +02001687func Test_verbosefile()
1688 set verbosefile=Xlog
1689 echomsg 'foo'
1690 echomsg 'bar'
1691 set verbosefile=
1692 let log = readfile('Xlog')
1693 call assert_match("foo\nbar", join(log, "\n"))
1694 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001695
1696 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001697 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001698endfunc
1699
Bram Moolenaar4facea32019-10-12 20:17:40 +02001700func Test_verbose_option()
1701 CheckScreendump
1702
1703 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001704 " clear the TermResponse autocommand from defaults.vim
1705 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001706 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1707 call feedkeys("\r", 't') " for the hit-enter prompt
1708 set verbose=20
1709 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001710 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001711
1712 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001713 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001714 call term_sendkeys(buf, ":DoSomething\<CR>")
1715 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1716
1717 " clean up
1718 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001719endfunc
1720
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001721func Test_setcmdpos()
1722 func InsertTextAtPos(text, pos)
1723 call assert_equal(0, setcmdpos(a:pos))
1724 return a:text
1725 endfunc
1726
1727 " setcmdpos() with position in the middle of the command line.
1728 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1729 call assert_equal('"1ab2', @:)
1730
1731 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1732 call assert_equal('"1b2a', @:)
1733
1734 " setcmdpos() with position beyond the end of the command line.
1735 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1736 call assert_equal('"12ab', @:)
1737
1738 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001739 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001740endfunc
1741
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001742func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001743 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001744 let encoding_save = &encoding
1745
1746 for e in encodings
1747 exe 'set encoding=' . e
1748
1749 " Test overstrike in the middle of the command line.
1750 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001751 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001752
1753 " Test overstrike going beyond end of command line.
1754 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001755 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001756
1757 " Test toggling insert/overstrike a few times.
1758 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001759 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001760 endfor
1761
Bram Moolenaar30276f22019-01-24 17:59:39 +01001762 " Test overstrike with multi-byte characters.
1763 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001764 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001765
1766 let &encoding = encoding_save
1767endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001768
Bram Moolenaar52410572019-10-27 05:12:45 +01001769func Test_buffers_lastused()
1770 " check that buffers are sorted by time when wildmode has lastused
1771 call test_settime(1550020000) " middle
1772 edit bufa
1773 enew
1774 call test_settime(1550030000) " newest
1775 edit bufb
1776 enew
1777 call test_settime(1550010000) " oldest
1778 edit bufc
1779 enew
1780 call test_settime(0)
1781 enew
1782
1783 call assert_equal(['bufa', 'bufb', 'bufc'],
1784 \ getcompletion('', 'buffer'))
1785
1786 let save_wildmode = &wildmode
1787 set wildmode=full:lastused
1788
1789 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1790 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1791 call assert_equal('b bufb', X)
1792 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1793 call assert_equal('b bufa', X)
1794 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1795 call assert_equal('b bufc', X)
1796 enew
1797
1798 edit other
1799 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1800 call assert_equal('b bufb', X)
1801 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1802 call assert_equal('b bufa', X)
1803 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1804 call assert_equal('b bufc', X)
1805 enew
1806
1807 let &wildmode = save_wildmode
1808
1809 bwipeout bufa
1810 bwipeout bufb
1811 bwipeout bufc
1812endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001813
Bram Moolenaar479950f2020-01-19 15:45:17 +01001814func Test_cmdlineclear_tabenter()
1815 CheckScreendump
1816
1817 let lines =<< trim [SCRIPT]
1818 call setline(1, range(30))
1819 [SCRIPT]
1820
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001821 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001822 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001823 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001824 " in one tab make the command line higher with CTRL-W -
1825 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1826 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1827
1828 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001829endfunc
1830
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001831" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001832func Test_cmdline_expand_special()
1833 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001834 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001835 call assert_fails('e <afile>', 'E495:')
1836 call assert_fails('e <abuf>', 'E496:')
1837 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001838
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001839 call writefile([], 'Xfile.cpp', 'D')
1840 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001841 new Xfile.cpp
1842 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1843 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1844 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001845endfunc
1846
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001847" Test for backtick expression in the command line
1848func Test_cmd_backtick()
1849 %argd
1850 argadd `=['a', 'b', 'c']`
1851 call assert_equal(['a', 'b', 'c'], argv())
1852 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001853
1854 argadd `echo abc def`
1855 call assert_equal(['abc def'], argv())
1856 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001857endfunc
1858
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001859" Test for the :! command
1860func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001861 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001862
1863 let lines =<< trim [SCRIPT]
1864 " Test for no previous command
1865 call assert_fails('!!', 'E34:')
1866 set nomore
1867 " Test for cmdline expansion with :!
1868 call setline(1, 'foo!')
1869 silent !echo <cWORD> > Xfile.out
1870 call assert_equal(['foo!'], readfile('Xfile.out'))
1871 " Test for using previous command
1872 silent !echo \! !
1873 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1874 call writefile(v:errors, 'Xresult')
1875 call delete('Xfile.out')
1876 qall!
1877 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001878 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001879 if RunVim([], [], '--clean -S Xscript')
1880 call assert_equal([], readfile('Xresult'))
1881 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001882 call delete('Xresult')
1883endfunc
1884
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001885" Test error: "E135: *Filter* Autocommands must not change current buffer"
1886func Test_cmd_bang_E135()
1887 new
1888 call setline(1, ['a', 'b', 'c', 'd'])
1889 augroup test_cmd_filter_E135
1890 au!
1891 autocmd FilterReadPost * help
1892 augroup END
1893 call assert_fails('2,3!echo "x"', 'E135:')
1894
1895 augroup test_cmd_filter_E135
1896 au!
1897 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001898 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001899 %bwipe!
1900endfunc
1901
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001902func Test_cmd_bang_args()
1903 new
1904 :.!
1905 call assert_equal(0, v:shell_error)
1906
1907 " Note that below there is one space char after the '!'. This caused a
1908 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1909 :.!
1910 call assert_equal(0, v:shell_error)
1911 bwipe!
1912
1913 CheckUnix
1914 :.!pwd
1915 call assert_equal(0, v:shell_error)
1916 :.! pwd
1917 call assert_equal(0, v:shell_error)
1918
1919 " Note there is one space after 'pwd'.
1920 :.! pwd
1921 call assert_equal(0, v:shell_error)
1922
1923 " Note there are two spaces after 'pwd'.
1924 :.! pwd
1925 call assert_equal(0, v:shell_error)
1926 :.!ls ~
1927 call assert_equal(0, v:shell_error)
1928
1929 " Note there is one space char after '~'.
1930 :.!ls ~
1931 call assert_equal(0, v:shell_error)
1932
1933 " Note there are two spaces after '~'.
1934 :.!ls ~
1935 call assert_equal(0, v:shell_error)
1936
1937 :.!echo "foo"
1938 call assert_equal(getline('.'), "foo")
1939 :.!echo "foo "
1940 call assert_equal(getline('.'), "foo ")
1941 :.!echo " foo "
1942 call assert_equal(getline('.'), " foo ")
1943 :.!echo " foo "
1944 call assert_equal(getline('.'), " foo ")
1945
1946 %bwipe!
1947endfunc
1948
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001949" Test for using ~ for home directory in cmdline completion matches
1950func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001951 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001952 call writefile([], 'Xexpdir/Xfile1')
1953 call writefile([], 'Xexpdir/Xfile2')
1954 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001955 let save_HOME = $HOME
1956 let $HOME = getcwd()
1957 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1958 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1959 let $HOME = save_HOME
1960 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001961endfunc
1962
Bram Moolenaar578fe942020-02-27 21:32:51 +01001963" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1964" or insert mode (when 'insertmode' is set)
1965func Test_cmdline_ctrl_g()
1966 new
1967 call setline(1, 'abc')
1968 call cursor(1, 3)
1969 " If command line is entered from insert mode, using C-\ C-G should back to
1970 " insert mode
1971 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1972 call assert_equal('abxyc', getline(1))
1973 call assert_equal(4, col('.'))
1974
1975 " If command line is entered in 'insertmode', using C-\ C-G should back to
1976 " 'insertmode'
1977 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1978 call assert_equal('ab12xyc', getline(1))
1979 close!
1980endfunc
1981
Bram Moolenaar578fe942020-02-27 21:32:51 +01001982" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001983func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001984 func T(a, c, p)
1985 return "oneA\noneB\noneC"
1986 endfunc
1987 command -nargs=1 -complete=custom,T MyCmd
1988
Bram Moolenaar578fe942020-02-27 21:32:51 +01001989 set nowildmenu
1990 set wildmode=full,list
1991 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001992 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001993 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001994 call assert_equal('"MyCmd oneA', @:)
1995
1996 set wildmode=longest,full
1997 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1998 call assert_equal('"MyCmd one', @:)
1999 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2000 call assert_equal('"MyCmd oneC', @:)
2001
2002 set wildmode=longest
2003 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2004 call assert_equal('"MyCmd one', @:)
2005
2006 set wildmode=list:longest
2007 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002008 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002009 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002010 call assert_equal('"MyCmd one', @:)
2011
2012 set wildmode=""
2013 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2014 call assert_equal('"MyCmd oneA', @:)
2015
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002016 " Test for wildmode=longest with 'fileignorecase' set
2017 set wildmode=longest
2018 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002019 argadd AAA AAAA AAAAA
2020 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2021 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002022 set fileignorecase&
2023
2024 " Test for listing files with wildmode=list
2025 set wildmode=list
2026 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002027 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002028 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002029 call assert_equal('"b A', @:)
2030
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002031 " when using longest completion match, matches shorter than the argument
2032 " should be ignored (happens with :help)
2033 set wildmode=longest,full
2034 set wildmenu
2035 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2036 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002037 " non existing file
2038 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2039 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002040 set wildmenu&
2041
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002042 " Test for longest file name completion with 'fileignorecase'
2043 " On MS-Windows, file names are case insensitive.
2044 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002045 call writefile([], 'XTESTfoo', 'D')
2046 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002047 set nofileignorecase
2048 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2049 call assert_equal('"e XTESTfoo', @:)
2050 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2051 call assert_equal('"e Xtestbar', @:)
2052 set fileignorecase
2053 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2054 call assert_equal('"e Xtest', @:)
2055 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2056 call assert_equal('"e Xtest', @:)
2057 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002058 endif
2059
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002060 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002061 delcommand MyCmd
2062 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002063 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002064 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002065endfunc
2066
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002067func Test_wildmode()
2068 " Test with utf-8 encoding
2069 call Wildmode_tests()
2070
2071 " Test with latin1 encoding
2072 let save_encoding = &encoding
2073 set encoding=latin1
2074 call Wildmode_tests()
2075 let &encoding = save_encoding
2076endfunc
2077
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002078func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002079 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002080 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002081 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002082 let lines =<< trim END
2083 func vim8#Complete(a, c, p)
2084 return "oneA\noneB\noneC"
2085 endfunc
2086 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002087 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002088
2089 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2090 set nowildmenu
2091 set wildmode=full,list
2092 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2093 call assert_equal('"MyCmd oneA oneB oneC', @:)
2094
2095 let &rtp = save_rtp
2096 set wildmode& wildmenu&
2097 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002098endfunc
2099
Bram Moolenaar578fe942020-02-27 21:32:51 +01002100" Test for interrupting the command-line completion
2101func Test_interrupt_compl()
2102 func F(lead, cmdl, p)
2103 if a:lead =~ 'tw'
2104 call interrupt()
2105 return
2106 endif
2107 return "one\ntwo\nthree"
2108 endfunc
2109 command -nargs=1 -complete=custom,F Tcmd
2110
2111 set nowildmenu
2112 set wildmode=full
2113 let interrupted = 0
2114 try
2115 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2116 catch /^Vim:Interrupt$/
2117 let interrupted = 1
2118 endtry
2119 call assert_equal(1, interrupted)
2120
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002121 let interrupted = 0
2122 try
2123 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2124 catch /^Vim:Interrupt$/
2125 let interrupted = 1
2126 endtry
2127 call assert_equal(1, interrupted)
2128
Bram Moolenaar578fe942020-02-27 21:32:51 +01002129 delcommand Tcmd
2130 delfunc F
2131 set wildmode&
2132endfunc
2133
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002134" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002135func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002136 let str = ":one two\<C-U>"
2137 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002138 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002139 let str ..= "\<Left>five\<Right>"
2140 let str ..= "\<Home>two "
2141 let str ..= "\<C-Left>one "
2142 let str ..= "\<C-Right> three"
2143 let str ..= "\<End>\<S-Left>four "
2144 let str ..= "\<S-Right> six"
2145 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2146 call feedkeys(str, 'xt')
2147 call assert_equal("\"one two three four five six seven", @:)
2148endfunc
2149
2150" Test for moving the cursor on the / command line in 'rightleft' mode
2151func Test_cmdline_edit_rightleft()
2152 CheckFeature rightleft
2153 set rightleft
2154 set rightleftcmd=search
2155 let str = "/one two\<C-U>"
2156 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002157 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002158 let str ..= "\<Right>five\<Left>"
2159 let str ..= "\<Home>two "
2160 let str ..= "\<C-Right>one "
2161 let str ..= "\<C-Left> three"
2162 let str ..= "\<End>\<S-Right>four "
2163 let str ..= "\<S-Left> six"
2164 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2165 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2166 call assert_equal("\"one two three four five six seven", @/)
2167 set rightleftcmd&
2168 set rightleft&
2169endfunc
2170
2171" Test for using <C-\>e in the command line to evaluate an expression
2172func Test_cmdline_expr()
2173 " Evaluate an expression from the beginning of a command line
2174 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2175 call assert_equal('"hello', @:)
2176
2177 " Use an invalid expression for <C-\>e
2178 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2179
2180 " Insert literal <CTRL-\> in the command line
2181 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2182 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002183endfunc
2184
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002185" This was making the insert position negative
2186func Test_cmdline_expr_register()
2187 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2188endfunc
2189
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002190" Test for 'imcmdline' and 'imsearch'
2191" This test doesn't actually test the input method functionality.
2192func Test_cmdline_inputmethod()
2193 new
2194 call setline(1, ['', 'abc', ''])
2195 set imcmdline
2196
2197 call feedkeys(":\"abc\<CR>", 'xt')
2198 call assert_equal("\"abc", @:)
2199 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2200 call assert_equal("\"abc", @:)
2201 call feedkeys("/abc\<CR>", 'xt')
2202 call assert_equal([2, 1], [line('.'), col('.')])
2203 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2204 call assert_equal([2, 1], [line('.'), col('.')])
2205
2206 set imsearch=2
2207 call cursor(1, 1)
2208 call feedkeys("/abc\<CR>", 'xt')
2209 call assert_equal([2, 1], [line('.'), col('.')])
2210 call cursor(1, 1)
2211 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2212 call assert_equal([2, 1], [line('.'), col('.')])
2213 set imdisable
2214 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2215 call assert_equal([2, 1], [line('.'), col('.')])
2216 set imdisable&
2217 set imsearch&
2218
2219 set imcmdline&
2220 %bwipe!
2221endfunc
2222
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002223" Test for using CTRL-_ in the command line with 'allowrevins'
2224func Test_cmdline_revins()
2225 CheckNotMSWindows
2226 CheckFeature rightleft
2227 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2228 call assert_equal("\"abc\<c-_>", @:)
2229 set allowrevins
2230 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2231 call assert_equal('"abcñèæ', @:)
2232 set allowrevins&
2233endfunc
2234
2235" Test for typing UTF-8 composing characters in the command line
2236func Test_cmdline_composing_chars()
2237 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2238 call assert_equal('"ゔ', @:)
2239endfunc
2240
Bram Moolenaar0e717042020-04-27 19:29:01 +02002241" test that ";" works to find a match at the start of the first line
2242func Test_zero_line_search()
2243 new
2244 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2245 call cursor(1,1)
2246 0;/pattern/d
2247 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2248 q!
2249endfunc
2250
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002251func Test_read_shellcmd()
2252 CheckUnix
2253 if executable('ls')
2254 " There should be ls in the $PATH
2255 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2256 call assert_match('^"r! .*\<ls\>', @:)
2257 endif
2258
2259 if executable('rm')
2260 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2261 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2262 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002263
2264 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2265 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2266 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002267 endif
2268endfunc
2269
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002270" Test for going up and down the directory tree using 'wildmenu'
2271func Test_wildmenu_dirstack()
2272 CheckUnix
2273 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002274 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002275 call writefile([], 'Xwildmenu/file1_1.txt')
2276 call writefile([], 'Xwildmenu/file1_2.txt')
2277 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2278 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2279 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2280 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2281 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2282 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002283 set wildmenu
2284
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002285 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002286 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002287 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002288 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002289 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002290 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002291 call assert_equal('"e ../../dir3/', @:)
2292 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2293 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002294 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002295 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002296 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002297 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002298 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002299 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2300 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002301
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002302 set wildmenu&
2303endfunc
2304
obcat71c6f7a2021-05-13 20:23:10 +02002305" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002306" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2307" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002308func Test_recalling_cmdline()
2309 CheckFeature cmdline_hist
2310
2311 let g:cmdlines = []
2312 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2313
2314 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002315 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2316 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2317 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2318 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002319 "\ TODO: {'name': 'debug', ...}
2320 \]
2321 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002322 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2323 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2324 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2325 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2326 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002327 \]
2328 let prefix = 'vi'
2329 for h in histories
2330 call histadd(h.name, 'vim')
2331 call histadd(h.name, 'virtue')
2332 call histadd(h.name, 'Virgo')
2333 call histadd(h.name, 'vogue')
2334 call histadd(h.name, 'emacs')
2335 for k in keypairs
2336 let g:cmdlines = []
2337 let keyseqs = h.enter
2338 \ .. prefix
2339 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2340 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2341 \ .. h.exit
2342 call feedkeys(keyseqs, 'xt')
2343 call histdel(h.name, -1) " delete the history added by feedkeys above
2344 let expect = k.prefixmatch
2345 \ ? ['virtue', 'vim', 'virtue', prefix]
2346 \ : ['emacs', 'vogue', 'emacs', prefix]
2347 call assert_equal(expect, g:cmdlines)
2348 endfor
2349 endfor
2350
2351 unlet g:cmdlines
2352 cunmap <Plug>(save-cmdline)
2353endfunc
2354
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002355func Test_cmd_map_cmdlineChanged()
2356 let g:log = []
2357 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002358 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002359 autocmd!
2360 autocmd CmdlineChanged : let g:log += [getcmdline()]
2361 augroup END
2362
2363 call feedkeys(":\<F1>\<CR>", 'xt')
2364 call assert_equal(['l', 'ls'], g:log)
2365
Bram Moolenaar796139a2021-05-18 21:38:45 +02002366 let @b = 'b'
2367 cnoremap <F1> a<C-R>b
2368 let g:log = []
2369 call feedkeys(":\<F1>\<CR>", 'xt')
2370 call assert_equal(['a', 'ab'], g:log)
2371
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002372 unlet g:log
2373 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002374 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002375 autocmd!
2376 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002377 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002378endfunc
2379
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002380" Test for the 'suffixes' option
2381func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002382 call writefile([], 'Xsuffile', 'D')
2383 call writefile([], 'Xsuffile.c', 'D')
2384 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002385 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002386 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2387 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2388 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2389 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002390 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002391 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2392 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2393 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2394 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002395 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002396 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2397 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2398 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2399 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002400 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002401 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002402 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2403 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002404endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002405
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002406" Test for using a popup menu for the command line completion matches
2407" (wildoptions=pum)
2408func Test_wildmenu_pum()
2409 CheckRunVimInTerminal
2410
2411 let commands =<< trim [CODE]
2412 set wildmenu
2413 set wildoptions=pum
2414 set shm+=I
2415 set noruler
2416 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002417
2418 func CmdCompl(a, b, c)
2419 return repeat(['aaaa'], 120)
2420 endfunc
2421 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002422
2423 func MyStatusLine() abort
2424 return 'status'
2425 endfunc
2426 func SetupStatusline()
2427 set statusline=%!MyStatusLine()
2428 set laststatus=2
2429 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002430
2431 func MyTabLine()
2432 return 'my tab line'
2433 endfunc
2434 func SetupTabline()
2435 set statusline=
2436 set tabline=%!MyTabLine()
2437 set showtabline=2
2438 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002439
2440 func DoFeedKeys()
2441 let &wildcharm = char2nr("\t")
2442 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2443 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002444 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002445 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002446
2447 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2448
2449 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002450 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2451
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002452 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002453 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002454 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2455
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002456 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002457 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002458 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2459
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002460 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002461 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002462 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2463
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002464 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002465 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002466 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2467
2468 " pressing <C-E> should end completion and go back to the original match
2469 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002470 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2471
2472 " pressing <C-Y> should select the current match and end completion
2473 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002474 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2475
2476 " With 'wildmode' set to 'longest,full', completing a match should display
2477 " the longest match, the wildmenu should not be displayed.
2478 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2479 call TermWait(buf)
2480 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002481 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2482
2483 " pressing <Tab> should display the wildmenu
2484 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002485 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2486
2487 " pressing <Tab> second time should select the next entry in the menu
2488 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002489 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2490
2491 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002492 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002493 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002494 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2495
2496 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002497 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2498
2499 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002500 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2501
2502 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002503 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002504 call writefile([], 'Xnamedir/XfileA')
2505 call writefile([], 'Xnamedir/XdirA/XfileB')
2506 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002507
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002508 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002509 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2510
2511 " Pressing <Right> on a directory name should go into that directory
2512 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002513 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2514
2515 " Pressing <Left> on a directory name should go to the parent directory
2516 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002517 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2518
2519 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002520 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002521 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002522 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2523
2524 " Pressing <C-D> when the popup menu is displayed should remove the popup
2525 " menu
2526 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002527 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2528
2529 " Pressing <S-Tab> should open the popup menu with the last entry selected
2530 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002531 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2532
2533 " Pressing <Esc> should close the popup menu and cancel the cmd line
2534 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002535 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2536
2537 " Typing a character when the popup is open, should close the popup
2538 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002539 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2540
2541 " When the popup is open, entering the cmdline window should close the popup
2542 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002543 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2544 call term_sendkeys(buf, ":q\<CR>")
2545
2546 " After the last popup menu item, <C-N> should show the original string
2547 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002548 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2549
2550 " Use the popup menu for the command name
2551 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002552 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2553
2554 " Pressing the left arrow should remove the popup menu
2555 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002556 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2557
2558 " Pressing <BS> should remove the popup menu and erase the last character
2559 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002560 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2561
2562 " Pressing <C-W> should remove the popup menu and erase the previous word
2563 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002564 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2565
2566 " Pressing <C-U> should remove the popup menu and erase the entire line
2567 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002568 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2569
2570 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2571 " the cmdline from history
2572 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002573 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2574
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002575 " Check "list" still works
2576 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2577 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002578 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2579 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002580 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2581
rbtnn68cc2b82022-02-09 11:55:47 +00002582 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002583 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002584 call writefile([], 'Xnamedir/あいう/abc')
2585 call writefile([], 'Xnamedir/あいう/xyz')
2586 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002587
2588 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002589 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002590 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2591
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002592 " Pressing <C-A> when the popup menu is displayed should list all the
2593 " matches and pressing a key after that should remove the popup menu
2594 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2595 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2596 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2597
2598 " Pressing <C-A> when the popup menu is displayed should list all the
2599 " matches and pressing <Left> after that should move the cursor
2600 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2601 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2602 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2603
2604 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2605 " should be displayed correctly on the screen.
2606 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2607 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2608
2609 " After using <C-A> to expand all the filename matches, pressing <Up>
2610 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002611 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002612 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2613 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2614 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2615
2616 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2617 " crash Vim
2618 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2619 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2620
Bram Moolenaar414acd32022-02-10 21:09:45 +00002621 " After removing the pum the command line is redrawn
2622 call term_sendkeys(buf, ":edit foo\<CR>")
2623 call term_sendkeys(buf, ":edit bar\<CR>")
2624 call term_sendkeys(buf, ":ls\<CR>")
2625 call term_sendkeys(buf, ":com\<Tab> ")
2626 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002627 call term_sendkeys(buf, "\<C-U>\<CR>")
2628
2629 " Esc still works to abort the command when 'statusline' is set
2630 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2631 call term_sendkeys(buf, ":si\<Tab>")
2632 call term_sendkeys(buf, "\<Esc>")
2633 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002634
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002635 " Esc still works to abort the command when 'tabline' is set
2636 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2637 call term_sendkeys(buf, ":si\<Tab>")
2638 call term_sendkeys(buf, "\<Esc>")
2639 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2640
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002641 " popup is cleared also when 'lazyredraw' is set
2642 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2643 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2644 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2645 call term_sendkeys(buf, "\<Esc>")
2646
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002647 " Pressing <PageDown> should scroll the menu downward
2648 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2649 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2650 call term_sendkeys(buf, "\<PageDown>")
2651 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2652 call term_sendkeys(buf, "\<PageDown>")
2653 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2654 call term_sendkeys(buf, "\<PageDown>")
2655 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2656 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2657 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2658
2659 " Pressing <PageUp> should scroll the menu upward
2660 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2661 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2662 call term_sendkeys(buf, "\<PageUp>")
2663 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2664 call term_sendkeys(buf, "\<PageUp>")
2665 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2666 call term_sendkeys(buf, "\<PageUp>")
2667 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2668
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002669 " pressing <C-E> to end completion should work in middle of the line too
2670 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2671 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2672 call term_sendkeys(buf, "\<C-E>")
2673 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2674
2675 " pressing <C-Y> should select the current match and end completion
2676 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2677 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2678
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002679 call term_sendkeys(buf, "\<C-U>\<CR>")
2680 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002681endfunc
2682
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002683" Test for wildmenumode() with the cmdline popup menu
2684func Test_wildmenumode_with_pum()
2685 set wildmenu
2686 set wildoptions=pum
2687 cnoremap <expr> <F2> wildmenumode()
2688 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2689 call assert_equal('"sign define10', @:)
2690 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2691 call assert_equal('"sign define jump list place undefine unplace0', @:)
2692 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2693 call assert_equal('"sign 0', @:)
2694 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2695 call assert_equal('"sign define0', @:)
2696 set nowildmenu wildoptions&
2697 cunmap <F2>
2698endfunc
2699
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002700func Test_wildmenu_with_pum_foldexpr()
2701 CheckRunVimInTerminal
2702
2703 let lines =<< trim END
2704 call setline(1, ['folded one', 'folded two', 'some more text'])
2705 func MyFoldText()
2706 return 'foo'
2707 endfunc
2708 set foldtext=MyFoldText() wildoptions=pum
2709 normal ggzfj
2710 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002711 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002712 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2713 call term_sendkeys(buf, ":set\<Tab>")
2714 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2715
2716 call term_sendkeys(buf, "\<Esc>")
2717 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2718
2719 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002720endfunc
2721
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002722" Test for opening the cmdline completion popup menu from the terminal window.
2723" The popup menu should be positioned correctly over the status line of the
2724" bottom-most window.
2725func Test_wildmenu_pum_from_terminal()
2726 CheckRunVimInTerminal
2727 let python = PythonProg()
2728 call CheckPython(python)
2729
2730 %bw!
2731 let cmds = ['set wildmenu wildoptions=pum']
2732 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2733 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002734 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002735 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2736 call term_sendkeys(buf, "\r\r\r")
2737 call term_wait(buf)
2738 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2739 call term_wait(buf)
2740 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2741 call term_wait(buf)
2742 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002743endfunc
2744
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002745func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002746 CheckRunVimInTerminal
2747
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002748 " Test odd wildchar interactions with pum. Make sure they behave properly
2749 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002750 let lines =<< trim END
2751 set wildoptions=pum
2752 set wildchar=<C-E>
2753 END
2754 call writefile(lines, 'XwildmenuTest', 'D')
2755 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2756
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002757 call term_sendkeys(buf, ":\<C-E>")
2758 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002759
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002760 " <C-E> being a wildchar takes priority over its original functionality
2761 call term_sendkeys(buf, "\<C-E>")
2762 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2763
2764 call term_sendkeys(buf, "\<Esc>")
2765 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2766
2767 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2768 " command-line, and we need to make sure to clean up properly.
2769 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2770 call term_sendkeys(buf, ":\<Esc>")
2771 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2772
2773 call term_sendkeys(buf, "\<Esc>")
2774 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2775
2776 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2777 " and we again need to make sure we clean up properly.
2778 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2779 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2780 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2781
2782 call term_sendkeys(buf, "\<C-N>")
2783 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2784
2785 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002786endfunc
2787
zeertzjq883018f2024-06-15 15:37:11 +02002788" Test that 'rightleft' should not affect cmdline completion popup menu.
2789func Test_wildmenu_pum_rightleft()
2790 CheckFeature rightleft
2791 CheckScreendump
2792
2793 let lines =<< trim END
2794 set wildoptions=pum
2795 set rightleft
2796 END
2797 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2798 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2799
2800 call term_sendkeys(buf, ":sign \<Tab>")
2801 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2802
2803 call StopVimInTerminal(buf)
2804endfunc
2805
zeertzjqd8c93402024-06-17 18:25:32 +02002806" Test highlighting matched text in cmdline completion popup menu.
2807func Test_wildmenu_pum_hl_match()
2808 CheckScreendump
2809
2810 let lines =<< trim END
2811 set wildoptions=pum,fuzzy
2812 hi PmenuMatchSel ctermfg=6 ctermbg=7
2813 hi PmenuMatch ctermfg=4 ctermbg=225
2814 END
2815 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2816 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2817
2818 call term_sendkeys(buf, ":sign plc\<Tab>")
2819 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2820 call term_sendkeys(buf, "\<Tab>")
2821 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2822 call term_sendkeys(buf, "\<Tab>")
2823 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2824 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2825 call TermWait(buf)
2826 call term_sendkeys(buf, ":sign un\<Tab>")
2827 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2828 call term_sendkeys(buf, "\<Tab>")
2829 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2830 call term_sendkeys(buf, "\<Tab>")
2831 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2832 call term_sendkeys(buf, "\<Esc>")
2833
2834 call StopVimInTerminal(buf)
2835endfunc
2836
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002837" Test for completion after a :substitute command followed by a pipe (|)
2838" character
2839func Test_cmdline_complete_substitute()
2840 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2841 call assert_equal("\"s | \t", @:)
2842 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2843 call assert_equal("\"s/ | \t", @:)
2844 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2845 call assert_equal("\"s/one | \t", @:)
2846 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2847 call assert_equal("\"s/one/ | \t", @:)
2848 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2849 call assert_equal("\"s/one/two | \t", @:)
2850 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2851 call assert_equal('"s/one/two/ | chistory', @:)
2852 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2853 call assert_equal("\"s/one/two/g \t", @:)
2854 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2855 call assert_equal("\"s/one/two/g | chistory", @:)
2856 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2857 call assert_equal("\"s/one/t\\/ | \t", @:)
2858 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2859 call assert_equal('"s/one/t"o/ | chistory', @:)
2860 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2861 call assert_equal('"s/one/t|o/ | chistory', @:)
2862 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2863 call assert_equal("\"&\t", @:)
2864endfunc
2865
2866" Test for the :dlist command completion
2867func Test_cmdline_complete_dlist()
2868 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2869 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2870 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2871 call assert_equal("\"dlist 10 /pat/ \t", @:)
2872 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2873 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2874 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2875 call assert_equal("\"dlist 10 /pat\\\t", @:)
2876 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2877 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2878endfunc
2879
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002880" argument list (only for :argdel) fuzzy completion
2881func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002882 argadd change.py count.py charge.py
2883 set wildoptions&
2884 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2885 call assert_equal('"argdel cge', @:)
2886 set wildoptions=fuzzy
2887 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal('"argdel change.py charge.py', @:)
2889 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890 set wildoptions&
2891endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002892
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002893" autocmd group name fuzzy completion
2894func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002895 set wildoptions&
2896 augroup MyFuzzyGroup
2897 augroup END
2898 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"augroup mfg', @:)
2900 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2901 call assert_equal('"augroup MyFuzzyGroup', @:)
2902 set wildoptions=fuzzy
2903 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2904 call assert_equal('"augroup MyFuzzyGroup', @:)
2905 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal('"augroup My*p', @:)
2907 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002908 set wildoptions&
2909endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002910
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002911" buffer name fuzzy completion
2912func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002913 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002914 " Use a long name to reduce the risk of matching a random directory name
2915 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002916 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002917 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2918 call assert_equal('"b SRFWL', @:)
2919 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002921 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002922 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2923 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2924 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2925 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002927 set wildoptions&
2928endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" buffer name (full path) fuzzy completion
2931func Test_fuzzy_completion_bufname_fullpath()
2932 CheckUnix
2933 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002934 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002935 edit Xcmd/Xstate/Xfile.js
2936 cd Xcmd/Xstate
2937 enew
2938 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal('"b CmdStateFile', @:)
2940 set wildoptions=fuzzy
2941 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2942 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2943 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002944 set wildoptions&
2945endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002946
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947" :behave suboptions fuzzy completion
2948func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949 set wildoptions&
2950 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"behave xm', @:)
2952 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2953 call assert_equal('"behave xterm', @:)
2954 set wildoptions=fuzzy
2955 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2956 call assert_equal('"behave xterm', @:)
2957 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2958 call assert_equal('"behave xt*m', @:)
2959 let g:Sline = ''
2960 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('mswin', g:Sline)
2962 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002963 set wildoptions&
2964endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002965
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002966" " colorscheme name fuzzy completion - NOT supported
2967" func Test_fuzzy_completion_colorscheme()
2968" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002969
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002970" built-in command name fuzzy completion
2971func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002972 set wildoptions&
2973 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2974 call assert_equal('"sbwin', @:)
2975 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2976 call assert_equal('"sbrewind', @:)
2977 set wildoptions=fuzzy
2978 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2979 call assert_equal('"sbrewind', @:)
2980 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2981 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002982 set wildoptions&
2983endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002984
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002985" " compiler name fuzzy completion - NOT supported
2986" func Test_fuzzy_completion_compiler()
2987" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002988
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002989" :cscope suboptions fuzzy completion
2990func Test_fuzzy_completion_cscope()
2991 CheckFeature cscope
2992 set wildoptions&
2993 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal('"cscope ret', @:)
2995 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal('"cscope reset', @:)
2997 set wildoptions=fuzzy
2998 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2999 call assert_equal('"cscope reset', @:)
3000 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3001 call assert_equal('"cscope re*t', @:)
3002 set wildoptions&
3003endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003004
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003005" :diffget/:diffput buffer name fuzzy completion
3006func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003007 new SomeBuffer
3008 diffthis
3009 new OtherBuffer
3010 diffthis
3011 set wildoptions&
3012 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"diffget sbuf', @:)
3014 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3015 call assert_equal('"diffput sbuf', @:)
3016 set wildoptions=fuzzy
3017 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal('"diffget SomeBuffer', @:)
3019 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3020 call assert_equal('"diffput SomeBuffer', @:)
3021 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003022 set wildoptions&
3023endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003024
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003025" " directory name fuzzy completion - NOT supported
3026" func Test_fuzzy_completion_dirname()
3027" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003028
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003029" environment variable name fuzzy completion
3030func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003031 set wildoptions&
3032 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal('"echo $VUT', @:)
3034 set wildoptions=fuzzy
3035 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003037 set wildoptions&
3038endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003039
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003040" autocmd event fuzzy completion
3041func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003042 set wildoptions&
3043 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3044 call assert_equal('"autocmd BWout', @:)
3045 set wildoptions=fuzzy
3046 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal('"autocmd BufWipeout', @:)
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" vim expression fuzzy completion
3052func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003053 let g:PerPlaceCount = 10
3054 set wildoptions&
3055 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3056 call assert_equal('"let c = ppc', @:)
3057 set wildoptions=fuzzy
3058 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3059 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003060 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003061endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003062
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003063" " file name fuzzy completion - NOT supported
3064" func Test_fuzzy_completion_filename()
3065" endfunc
3066
3067" " files in path fuzzy completion - NOT supported
3068" func Test_fuzzy_completion_filesinpath()
3069" endfunc
3070
3071" " filetype name fuzzy completion - NOT supported
3072" func Test_fuzzy_completion_filetype()
3073" endfunc
3074
3075" user defined function name completion
3076func Test_fuzzy_completion_userdefined_func()
3077 set wildoptions&
3078 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal('"call Test_f_u_f', @:)
3080 set wildoptions=fuzzy
3081 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3083 set wildoptions&
3084endfunc
3085
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003086" <SNR> functions should be sorted to the end
3087func Test_fuzzy_completion_userdefined_snr_func()
3088 func s:Sendmail()
3089 endfunc
3090 func SendSomemail()
3091 endfunc
3092 func S1e2n3dmail()
3093 endfunc
3094 set wildoptions=fuzzy
3095 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003096 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003097 set wildoptions&
3098 delfunc s:Sendmail
3099 delfunc SendSomemail
3100 delfunc S1e2n3dmail
3101endfunc
3102
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003103" user defined command name completion
3104func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003105 set wildoptions&
3106 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3107 call assert_equal('"MsFeat', @:)
3108 set wildoptions=fuzzy
3109 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003111 set wildoptions&
3112endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003113
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003114" " :help tag fuzzy completion - NOT supported
3115" func Test_fuzzy_completion_helptag()
3116" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003117
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003118" highlight group name fuzzy completion
3119func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003120 set wildoptions&
3121 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal('"highlight SKey', @:)
3123 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal('"highlight SpecialKey', @:)
3125 set wildoptions=fuzzy
3126 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3127 call assert_equal('"highlight SpecialKey', @:)
3128 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3129 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003130 set wildoptions&
3131endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003132
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003133" :history suboptions fuzzy completion
3134func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003135 set wildoptions&
3136 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal('"history dg', @:)
3138 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal('"history search', @:)
3140 set wildoptions=fuzzy
3141 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal('"history debug', @:)
3143 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003145 set wildoptions&
3146endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003147
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003148" :language locale name fuzzy completion
3149func Test_fuzzy_completion_lang()
3150 CheckUnix
3151 set wildoptions&
3152 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal('"lang psx', @:)
3154 set wildoptions=fuzzy
3155 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal('"lang POSIX', @:)
3157 set wildoptions&
3158endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003159
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003160" :mapclear buffer argument fuzzy completion
3161func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003162 set wildoptions&
3163 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal('"mapclear buf', @:)
3165 set wildoptions=fuzzy
3166 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003168 set wildoptions&
3169endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003170
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003171" map name fuzzy completion
3172func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003173 " test regex completion works
3174 set wildoptions=fuzzy
3175 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003177 nmap <plug>MyLongMap :p<CR>
3178 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3180 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"nmap MLM \t", @:)
3182 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3183 call assert_equal("\"nmap <F2> one two \t", @:)
3184 " duplicate entries should be removed
3185 vmap <plug>MyLongMap :<C-U>#<CR>
3186 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3187 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3188 nunmap <plug>MyLongMap
3189 vunmap <plug>MyLongMap
3190 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal("\"nmap ABC\t", @:)
3192 " results should be sorted by best match
3193 nmap <Plug>format :
3194 nmap <Plug>goformat :
3195 nmap <Plug>TestFOrmat :
3196 nmap <Plug>fendoff :
3197 nmap <Plug>state :
3198 nmap <Plug>FendingOff :
3199 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3200 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3201 nunmap <Plug>format
3202 nunmap <Plug>goformat
3203 nunmap <Plug>TestFOrmat
3204 nunmap <Plug>fendoff
3205 nunmap <Plug>state
3206 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003207 set wildoptions&
3208endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003209
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003210" abbreviation fuzzy completion
3211func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003212 set wildoptions=fuzzy
3213 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3214 call assert_equal("\"iabbr <nowait>", @:)
3215 iabbr WaitForCompletion WFC
3216 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3217 call assert_equal("\"iabbr WaitForCompletion", @:)
3218 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3219 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003220
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003221 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003222 set wildoptions&
3223endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003224
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003225" menu name fuzzy completion
3226func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003227 CheckFeature menu
3228
3229 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003230 set wildoptions&
3231 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal('"menu pup', @:)
3233 set wildoptions=fuzzy
3234 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3235 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003236
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003237 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003238 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003239endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003240
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003241" :messages suboptions fuzzy completion
3242func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003243 set wildoptions&
3244 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal('"messages clr', @:)
3246 set wildoptions=fuzzy
3247 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003249 set wildoptions&
3250endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003251
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003252" :set option name fuzzy completion
3253func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003254 set wildoptions&
3255 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal('"set brkopt', @:)
3257 set wildoptions=fuzzy
3258 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3259 call assert_equal('"set breakindentopt', @:)
3260 set wildoptions&
3261 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal('"set fixendofline', @:)
3263 set wildoptions=fuzzy
3264 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3265 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003266 set wildoptions&
3267endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003268
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003269" :set <term_option>
3270func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003271 set wildoptions&
3272 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal('"set t_EC', @:)
3274 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3275 call assert_equal('"set <t_EC>', @:)
3276 set wildoptions=fuzzy
3277 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_equal('"set t_EC', @:)
3279 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003281 set wildoptions&
3282endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003283
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003284" " :packadd directory name fuzzy completion - NOT supported
3285" func Test_fuzzy_completion_packadd()
3286" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003287
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003288" " shell command name fuzzy completion - NOT supported
3289" func Test_fuzzy_completion_shellcmd()
3290" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003291
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003292" :sign suboptions fuzzy completion
3293func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003294 set wildoptions&
3295 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3296 call assert_equal('"sign ufe', @:)
3297 set wildoptions=fuzzy
3298 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3299 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003300 set wildoptions&
3301endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003302
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003303" :syntax suboptions fuzzy completion
3304func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003305 set wildoptions&
3306 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3307 call assert_equal('"syntax kwd', @:)
3308 set wildoptions=fuzzy
3309 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal('"syntax keyword', @:)
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 group name fuzzy completion
3315func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003316 set wildoptions&
3317 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_equal('"syntax list mpar', @:)
3319 set wildoptions=fuzzy
3320 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal('"syntax list MatchParen', @:)
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" :syntime suboptions fuzzy completion
3326func Test_fuzzy_completion_syntime()
3327 CheckFeature profile
3328 set wildoptions&
3329 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3330 call assert_equal('"syntime clr', @:)
3331 set wildoptions=fuzzy
3332 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3333 call assert_equal('"syntime clear', @:)
3334 set wildoptions&
3335endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003336
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003337" " tag name fuzzy completion - NOT supported
3338" func Test_fuzzy_completion_tagname()
3339" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003340
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003341" " tag name and file fuzzy completion - NOT supported
3342" func Test_fuzzy_completion_tagfile()
3343" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003344
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003345" " user names fuzzy completion - how to test this functionality?
3346" func Test_fuzzy_completion_username()
3347" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003348
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003349" user defined variable name fuzzy completion
3350func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003351 let g:SomeVariable=10
3352 set wildoptions&
3353 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3354 call assert_equal('"let SVar', @:)
3355 set wildoptions=fuzzy
3356 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3357 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003358 set wildoptions&
3359endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003360
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003361" Test for sorting the results by the best match
3362func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003363 %bw!
3364 command T123format :
3365 command T123goformat :
3366 command T123TestFOrmat :
3367 command T123fendoff :
3368 command T123state :
3369 command T123FendingOff :
3370 set wildoptions=fuzzy
3371 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3372 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3373 delcommand T123format
3374 delcommand T123goformat
3375 delcommand T123TestFOrmat
3376 delcommand T123fendoff
3377 delcommand T123state
3378 delcommand T123FendingOff
3379 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003380 set wildoptions&
3381endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003382
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003383" Test for fuzzy completion of a command with lower case letters and a number
3384func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003385 command Foo2Bar :
3386 set wildoptions=fuzzy
3387 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3388 call assert_equal('"Foo2Bar', @:)
3389 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3390 call assert_equal('"Foo2Bar', @:)
3391 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3392 call assert_equal('"Foo2Bar', @:)
3393 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003394 set wildoptions&
3395endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003396
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003397" Test for command completion for a command starting with 'k'
3398func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003399 command KillKillKill :
3400 set wildoptions&
3401 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal("\"killkill\<Tab>", @:)
3403 set wildoptions=fuzzy
3404 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3405 call assert_equal('"KillKillKill', @:)
3406 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003407 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003408endfunc
3409
3410" Test for fuzzy completion for user defined custom completion function
3411func Test_fuzzy_completion_custom_func()
3412 func Tcompl(a, c, p)
3413 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3414 endfunc
3415 command -nargs=* -complete=custom,Tcompl Fuzzy :
3416 set wildoptions&
3417 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3418 call assert_equal("\"Fuzzy format", @:)
3419 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3420 call assert_equal("\"Fuzzy xy", @:)
3421 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3422 call assert_equal("\"Fuzzy ttt", @:)
3423 set wildoptions=fuzzy
3424 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3425 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3426 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3427 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3428 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3429 call assert_equal("\"Fuzzy xy", @:)
3430 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3431 call assert_equal("\"Fuzzy TestFOrmat", @:)
3432 delcom Fuzzy
3433 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003434endfunc
3435
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003436" Test for fuzzy completion in the middle of a cmdline instead of at the end
3437func Test_fuzzy_completion_in_middle()
3438 set wildoptions=fuzzy
3439 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3440 call assert_equal("\"set wildchar wildcharm wrap", @:)
3441
3442 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3443 call assert_equal("\"args ++encoding= zz", @:)
3444 set wildoptions&
3445endfunc
3446
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003447" Test for :breakadd argument completion
3448func Test_cmdline_complete_breakadd()
3449 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3450 call assert_equal("\"breakadd expr file func here", @:)
3451 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3452 call assert_equal("\"breakadd expr", @:)
3453 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3454 call assert_equal("\"breakadd expr", @:)
3455 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3456 call assert_equal("\"breakadd here", @:)
3457 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3458 call assert_equal("\"breakadd here", @:)
3459 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal("\"breakadd abc", @:)
3461 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3462 let l = getcompletion('not', 'breakpoint')
3463 call assert_equal([], l)
3464
3465 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003466 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003467 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3468 call assert_equal("\"breakadd file Xscript", @:)
3469 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3470 call assert_equal("\"breakadd file Xscript", @:)
3471 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3472 call assert_equal("\"breakadd file 20 Xscript", @:)
3473 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3474 call assert_equal("\"breakadd file 20 Xscript", @:)
3475 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3476 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3477 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3478 call assert_equal("\"breakadd file 20\t", @:)
3479 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3480 call assert_equal("\"breakadd file 20x\t", @:)
3481 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3482 call assert_equal("\"breakadd file Xscript ", @:)
3483 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3484 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003485
3486 " Test for :breakadd func [lnum] <function>
3487 func Xbreak_func()
3488 endfunc
3489 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal("\"breakadd func Xbreak_func", @:)
3491 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3492 call assert_equal("\"breakadd func Xbreak_func", @:)
3493 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3494 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3495 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3496 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3497 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3498 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3499 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3500 call assert_equal("\"breakadd func 20\t", @:)
3501 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3502 call assert_equal("\"breakadd func 20x\t", @:)
3503 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3504 call assert_equal("\"breakadd func Xbreak_func ", @:)
3505 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3506 call assert_equal("\"breakadd func X1B2C3", @:)
3507 delfunc Xbreak_func
3508
3509 " Test for :breakadd expr <expression>
3510 let g:Xtest_var = 10
3511 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3512 call assert_equal("\"breakadd expr Xtest_var", @:)
3513 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3514 call assert_equal("\"breakadd expr Xtest_var", @:)
3515 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3516 call assert_equal("\"breakadd expr Xtest_var ", @:)
3517 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3518 call assert_equal("\"breakadd expr X1B2C3", @:)
3519 unlet g:Xtest_var
3520
3521 " Test for :breakadd here
3522 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3523 call assert_equal("\"breakadd here Xtest", @:)
3524 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3525 call assert_equal("\"breakadd here Xtest", @:)
3526 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3527 call assert_equal("\"breakadd here ", @:)
3528endfunc
3529
3530" Test for :breakdel argument completion
3531func Test_cmdline_complete_breakdel()
3532 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3533 call assert_equal("\"breakdel file func here", @:)
3534 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3535 call assert_equal("\"breakdel file", @:)
3536 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3537 call assert_equal("\"breakdel file", @:)
3538 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3539 call assert_equal("\"breakdel here", @:)
3540 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3541 call assert_equal("\"breakdel here", @:)
3542 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3543 call assert_equal("\"breakdel abc", @:)
3544
3545 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003546 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003547 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3548 call assert_equal("\"breakdel file Xscript", @:)
3549 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3550 call assert_equal("\"breakdel file Xscript", @:)
3551 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3552 call assert_equal("\"breakdel file 20 Xscript", @:)
3553 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3554 call assert_equal("\"breakdel file 20 Xscript", @:)
3555 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3556 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3557 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3558 call assert_equal("\"breakdel file 20\t", @:)
3559 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3560 call assert_equal("\"breakdel file 20x\t", @:)
3561 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3562 call assert_equal("\"breakdel file Xscript ", @:)
3563 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3564 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003565
3566 " Test for :breakdel func [lnum] <function>
3567 func Xbreak_func()
3568 endfunc
3569 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal("\"breakdel func Xbreak_func", @:)
3571 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal("\"breakdel func Xbreak_func", @:)
3573 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3574 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3575 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3576 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3577 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3578 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3579 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3580 call assert_equal("\"breakdel func 20\t", @:)
3581 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3582 call assert_equal("\"breakdel func 20x\t", @:)
3583 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3584 call assert_equal("\"breakdel func Xbreak_func ", @:)
3585 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3586 call assert_equal("\"breakdel func X1B2C3", @:)
3587 delfunc Xbreak_func
3588
3589 " Test for :breakdel here
3590 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3591 call assert_equal("\"breakdel here Xtest", @:)
3592 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3593 call assert_equal("\"breakdel here Xtest", @:)
3594 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3595 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003596endfunc
3597
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003598" Test for :scriptnames argument completion
3599func Test_cmdline_complete_scriptnames()
3600 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003601 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003602 source Xa1b2c3.vim
3603 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3604 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3605 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3606 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3607 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3608 call assert_equal("\"script b2c3", @:)
3609 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3610 call assert_match("\"script 2\<Tab>$", @:)
3611 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3612 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3613 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3614 call assert_equal("\"script ", @:)
3615 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3616 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3617 new
3618 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3619 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3620 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003621 set wildmenu&
3622endfunc
3623
Bram Moolenaard8893442022-05-06 20:38:47 +01003624" this was going over the end of IObuff
3625func Test_report_error_with_composing()
3626 let caught = 'no'
3627 try
3628 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3629 catch /E492:/
3630 let caught = 'yes'
3631 endtry
3632 call assert_equal('yes', caught)
3633endfunc
3634
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003635" Test for expanding 2-letter and 3-letter :substitute command arguments.
3636" These commands don't accept an argument.
3637func Test_cmdline_complete_substitute_short()
3638 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3639 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3640 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3641 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3642 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3643 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3644 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3645 endfor
3646endfunc
3647
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003648" Test for shellcmdline command argument completion
3649func Test_cmdline_complete_shellcmdline_argument()
3650 command -nargs=+ -complete=shellcmdline MyCmd
3651
3652 set wildoptions=fuzzy
3653
3654 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3655 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003656 call assert_equal(['test_cmdline.vim'],
3657 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003658
3659 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3660 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003661 call assert_equal([],
3662 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003663
3664 let compl1 = getcompletion('', 'file')[0]
3665 let compl2 = getcompletion('', 'file')[1]
3666 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3667 call assert_equal('"MyCmd vim ' .. compl1, @:)
3668
3669 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3670 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3671
3672 let compl = getcompletion('', 'file')[1]
3673 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3674 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3675
3676 set wildoptions&
3677 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3678 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003679 call assert_equal(['test_cmdline.vim'],
3680 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003681
3682 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3683 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003684 call assert_equal([],
3685 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003686
3687 let compl1 = getcompletion('', 'file')[0]
3688 let compl2 = getcompletion('', 'file')[1]
3689 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3690 call assert_equal('"MyCmd vim ' .. compl1, @:)
3691
3692 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3693 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3694
3695 let compl = getcompletion('', 'file')[1]
3696 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3697 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3698
3699 delcommand MyCmd
3700endfunc
3701
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003702" Test for :! shell command argument completion
3703func Test_cmdline_complete_bang_cmd_argument()
3704 set wildoptions=fuzzy
3705 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3706 call assert_equal('"!vim test_cmdline.vim', @:)
3707 set wildoptions&
3708 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3709 call assert_equal('"!vim test_cmdline.vim', @:)
3710endfunc
3711
zeertzjq961b2e52023-04-17 15:53:24 +01003712func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003713 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003714endfunc
3715
3716func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003717 call assert_equal(0, getcmdpos())
3718 call assert_equal(0, getcmdscreenpos())
3719 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003720 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003721
zeertzjqa821b602024-06-18 20:31:08 +02003722 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003723 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003724 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003725 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003726 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003727 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003728 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003729
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003730 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3731 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003732 let g:results = []
3733 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3734 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3735 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003736 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3737 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3738 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003739
3740 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003741 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003742endfunc
3743
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003744func Test_recursive_register()
3745 let @= = ''
3746 silent! ?e/
3747 let caught = 'no'
3748 try
3749 normal //
3750 catch /E169:/
3751 let caught = 'yes'
3752 endtry
3753 call assert_equal('yes', caught)
3754endfunc
3755
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003756func Test_long_error_message()
3757 " the error should be truncated, not overrun IObuff
3758 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3759endfunc
3760
zeertzjq6791adc2022-07-26 20:42:25 +01003761func Test_cmdline_redraw_tabline()
3762 CheckRunVimInTerminal
3763
3764 let lines =<< trim END
3765 set showtabline=2
3766 autocmd CmdlineEnter * set tabline=foo
3767 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003768 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003769 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3770 call term_sendkeys(buf, ':')
3771 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3772
3773 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003774endfunc
3775
zeertzjqb82a2ab2022-08-21 14:33:57 +01003776func Test_wildmenu_pum_disable_while_shown()
3777 set wildoptions=pum
3778 set wildmenu
3779 cnoremap <F2> <Cmd>set nowildmenu<CR>
3780 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3781 call assert_equal(0, pumvisible())
3782 cunmap <F2>
3783 set wildoptions& wildmenu&
3784endfunc
3785
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003786func Test_setcmdline()
3787 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003788 call assert_equal(0, setcmdline(test_null_string()))
3789 call assert_equal('', getcmdline())
3790 call assert_equal(1, getcmdpos())
3791
3792 call assert_equal(0, setcmdline(''[: -1]))
3793 call assert_equal('', getcmdline())
3794 call assert_equal(1, getcmdpos())
3795
zeertzjq54acb902022-08-29 16:21:25 +01003796 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003797 call assert_equal(0, setcmdline(a:text))
3798 call assert_equal(a:text, getcmdline())
3799 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003800 call assert_equal(getcmdtype(), g:cmdtype)
3801 unlet g:cmdtype
3802 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003803
3804 call assert_equal(0, setcmdline(a:text, a:pos))
3805 call assert_equal(a:text, getcmdline())
3806 call assert_equal(a:pos, getcmdpos())
3807
3808 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003809 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3810 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003811
3812 return ''
3813 endfunc
3814
3815 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3816 call assert_equal('set rtp?', @:)
3817
zeertzjq54acb902022-08-29 16:21:25 +01003818 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3819 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3820 call assert_equal('foo', g:str)
3821 unlet g:str
3822
3823 delfunc SetText
3824
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003825 " setcmdline() returns 1 when not editing the command line.
3826 call assert_equal(1, 'foo'->setcmdline())
3827
3828 " Called in custom function
3829 func CustomComplete(A, L, P)
3830 call assert_equal(0, setcmdline("DoCmd "))
3831 return "January\nFebruary\nMars\n"
3832 endfunc
3833
3834 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3835 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3836 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003837 delcom DoCmd
3838 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003839
3840 " Called in <expr>
3841 cnoremap <expr>a setcmdline('let foo=')
3842 call feedkeys(":a\<CR>", 'tx')
3843 call assert_equal('let foo=0', @:)
3844 cunmap a
3845endfunc
3846
Sean Dewarfc8a6012023-04-17 16:41:20 +01003847func Test_rulerformat_position()
3848 CheckScreendump
3849
3850 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3851 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3852 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3853 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3854 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3855
3856 " clean up
3857 call StopVimInTerminal(buf)
3858endfunc
3859
zeertzjqe4c79d32023-08-15 22:41:53 +02003860func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003861 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003862
zeertzjqe4c79d32023-08-15 22:41:53 +02003863 call assert_equal(getcompletion('', 'cmdline'),
3864 \ getcompletion('TestCompletion ', 'cmdline'))
3865 call assert_equal(['<buffer>'],
3866 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3867
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003868 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003869endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003870
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003871func Test_custom_completion()
3872 func CustomComplete1(lead, line, pos)
3873 return "a\nb\nc"
3874 endfunc
3875 func CustomComplete2(lead, line, pos)
3876 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3877 endfunc
3878 func Check_custom_completion()
3879 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3880 return ''
3881 endfunc
3882 func Check_customlist_completion()
3883 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3884 return ''
3885 endfunc
3886
3887 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3888 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3889
3890 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3891 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3892
3893 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3894 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3895
zeertzjq757f3212024-04-15 19:01:04 +02003896 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
3897 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
3898 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003899
3900 delcom Test1
3901 delcom Test2
3902
3903 delfunc CustomComplete1
3904 delfunc CustomComplete2
3905 delfunc Check_custom_completion
3906 delfunc Check_customlist_completion
3907endfunc
3908
zeertzjq28a23602023-09-29 19:58:35 +02003909func Test_custom_completion_with_glob()
3910 func TestGlobComplete(A, L, P)
3911 return split(glob('Xglob*'), "\n")
3912 endfunc
3913
3914 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3915 call writefile([], 'Xglob1', 'D')
3916 call writefile([], 'Xglob2', 'D')
3917
3918 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3919 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3920
3921 delcommand TestGlobComplete
3922 delfunc TestGlobComplete
3923endfunc
3924
Christian Brabandt8610f742024-01-12 17:34:40 +01003925func Test_window_size_stays_same_after_changing_cmdheight()
3926 set laststatus=2
3927 let expected = winheight(0)
3928 function! Function_name() abort
3929 call feedkeys(":"..repeat('x', &columns), 'x')
3930 let &cmdheight=2
3931 let &cmdheight=1
3932 redraw
3933 endfunction
3934 call Function_name()
3935 call assert_equal(expected, winheight(0))
3936endfunc
3937
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01003938" verify that buffer-completion finds all buffer names matching a pattern
3939func Test_buffer_completion()
3940 " should return empty list
3941 call assert_equal([], getcompletion('', 'buffer'))
3942
3943 call mkdir('Xbuf_complete', 'R')
3944 e Xbuf_complete/Foobar.c
3945 e Xbuf_complete/MyFoobar.c
3946 e AFoobar.h
3947 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
3948
3949 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
3950 call assert_equal(expected, getcompletion('Foo', 'buffer'))
3951 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
3952 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
3953endfunc
3954
Anton Sharonov49528da2024-04-14 20:02:24 +02003955" :set t_??
3956func Test_term_option()
3957 set wildoptions&
3958 let _cpo = &cpo
3959 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003960 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02003961 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'
3962 \ .. ' 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'
3963 \ .. ' 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'
3964 \ .. ' 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'
3965 \ .. ' 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 +02003966 \ .. ' 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 +02003967 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003968 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02003969 let &cpo = _cpo
3970endfunc
3971
Christian Brabandt70a11a62024-07-26 19:13:55 +02003972func Test_ex_command_completion()
3973 " required for :*
3974 set cpo+=*
3975 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
3976 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
3977 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02003978 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02003979 call assert_equal(0, exists(':ke'))
3980 call assert_equal(1, exists(':kee'))
3981 call assert_equal(1, exists(':keep'))
3982 call assert_equal(1, exists(':keepm'))
3983 call assert_equal(1, exists(':keepma'))
3984 call assert_equal(1, exists(':keepmar'))
3985 call assert_equal(1, exists(':keepmark'))
3986 call assert_equal(2, exists(':keepmarks'))
3987 call assert_equal(2, exists(':keepalt'))
3988 call assert_equal(2, exists(':keepjumps'))
3989 call assert_equal(2, exists(':keeppatterns'))
3990 set cpo-=*
3991endfunc
3992
zeertzjq5df3cb22024-10-07 21:05:06 +02003993func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02003994 CheckMSWindows
3995 let save_shellslash = &shellslash
3996 set noshellslash
3997 call system('mkdir XXXa\_b')
3998 defer delete('XXXa', 'rf')
3999 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4000 call assert_equal('"cd XXXa\_b\', @:)
4001 let &shellslash = save_shellslash
4002endfunc
4003
Bram Moolenaar309976e2019-12-05 18:16:33 +01004004" vim: shiftwidth=2 sts=2 expandtab