blob: 6d4fdd781167f3e2ed04e095da23e2d11d0ec936 [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200161 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
162 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"sign un yy zz', @:)
164
165 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"sign unplace yy zz', @:)
167
Bram Moolenaar37db6422019-03-28 21:26:23 +0100168 " cleanup
169 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200170 set nowildmenu
171endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100172
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173func Test_wildmenu_screendump()
174 CheckScreendump
175
176 let lines =<< trim [SCRIPT]
177 set wildmenu hlsearch
178 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100179 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200180
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200181 " Test simple wildmenu
Bram Moolenaara60053b2020-09-03 16:50:13 +0200182 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
183 call term_sendkeys(buf, ":vim\<Tab>")
184 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
185
186 call term_sendkeys(buf, "\<Tab>")
187 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
188
189 call term_sendkeys(buf, "\<Tab>")
190 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
191
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200192 " Looped back to the original value
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100193 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200194 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200195
196 " Test that the wild menu is cleared properly
197 call term_sendkeys(buf, " ")
198 call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
199
200 " Test that a different wildchar still works
201 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
202 call term_sendkeys(buf, ":vim\<Esc>")
203 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
204
205 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
206 " sure clean up is properly done in edge case like this.
Bram Moolenaara60053b2020-09-03 16:50:13 +0200207 call term_sendkeys(buf, "\<Esc>")
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200208 call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
Bram Moolenaara60053b2020-09-03 16:50:13 +0200209
210 " clean up
211 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200212endfunc
213
Bram Moolenaara653e532022-04-19 11:38:24 +0100214func Test_redraw_in_autocmd()
215 CheckScreendump
216
217 let lines =<< trim END
218 set cmdheight=2
219 autocmd CmdlineChanged * redraw
220 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100221 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100222
223 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
224 call term_sendkeys(buf, ":for i in range(3)\<CR>")
225 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
226
227 call term_sendkeys(buf, "let i =")
228 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
229
230 " clean up
231 call term_sendkeys(buf, "\<CR>")
232 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100233endfunc
234
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100235func Test_redrawstatus_in_autocmd()
236 CheckScreendump
237
238 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100239 set laststatus=2
240 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100241 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100242 END
243 call writefile(lines, 'XTest_redrawstatus', 'D')
244
245 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100246 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100247 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
248 call term_sendkeys(buf, ":foobar")
249 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100250 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100251 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100252 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100253 " with cmdheight=1 messages have scrolled when typing :endfor
254 call term_sendkeys(buf, "\<CR>:endfor")
255 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
256 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
257 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
258 call term_sendkeys(buf, ":for in in range(3)")
259 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
260 call term_sendkeys(buf, "\<CR>:endfor")
261 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100262
263 " clean up
264 call term_sendkeys(buf, "\<CR>")
265 call StopVimInTerminal(buf)
266endfunc
267
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268func Test_changing_cmdheight()
269 CheckScreendump
270
271 let lines =<< trim END
272 set cmdheight=1 laststatus=2
nwounkn2e485672024-11-11 21:48:30 +0100273 func EchoOne()
274 set laststatus=2 cmdheight=1
275 echo 'foo'
276 echo 'bar'
277 set cmdheight=2
278 endfunc
Bram Moolenaar0816f472022-10-05 15:42:32 +0100279 func EchoTwo()
280 set laststatus=2
281 set cmdheight=5
282 echo 'foo'
283 echo 'bar'
284 set cmdheight=1
285 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100287 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288
289 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
290 call term_sendkeys(buf, ":resize -3\<CR>")
291 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
292
293 " using the space available doesn't change the status line
294 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
295 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
296
297 " using more space moves the status line up
298 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
299 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
300
301 " reducing cmdheight moves status line down
302 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
303 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
304
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000305 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100306 call term_sendkeys(buf, ":resize -1\<CR>")
307 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
308 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
309
Bram Moolenaar0816f472022-10-05 15:42:32 +0100310 " setting 'cmdheight' works after outputting two messages
311 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
312 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
313
nwounkn2e485672024-11-11 21:48:30 +0100314 " increasing 'cmdheight' doesn't clear the messages that need hit-enter
315 call term_sendkeys(buf, ":call EchoOne()\<CR>")
316 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
317
Bram Moolenaarf797e302022-08-11 13:17:30 +0100318 " clean up
319 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100320endfunc
321
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100322func Test_cmdheight_tabline()
323 CheckScreendump
324
325 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
326 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
327
328 " clean up
329 call StopVimInTerminal(buf)
330endfunc
331
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100332func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100333 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
334 call assert_equal('"map <unique> <silent>', getreg(':'))
335 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
336 call assert_equal('"map <script> <unique>', getreg(':'))
337 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <expr> <script>', getreg(':'))
339 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <buffer> <expr>', getreg(':'))
341 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"map <nowait> <buffer>', getreg(':'))
343 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"map <special> <nowait>', getreg(':'))
345 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200347
Bram Moolenaar1776a282019-05-03 16:05:41 +0200348 map <Middle>x middle
349
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200350 map ,f commaf
351 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200352 map <Left> left
353 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200354 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
355 call assert_equal('"map ,f', getreg(':'))
356 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
357 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200358 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
359 call assert_equal('"map <Left>', getreg(':'))
360 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200361 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000362 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
363 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200364 unmap ,f
365 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200366 unmap <Left>
367 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200368
zeertzjqc3a26c62023-02-17 16:40:20 +0000369 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200370 map <Left> left
371 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
372 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200373 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200374 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000375 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
376 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200377 unmap <Left>
378
379 set cpo+=<
380 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200381 exe "set t_k6=\<Esc>[17~"
382 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200383 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
384 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200385 if !has('gui_running')
386 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
387 call assert_equal("\"map <F6>x", getreg(':'))
388 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200389 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200390 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200391 set cpo-=<
392
393 set cpo+=B
394 map <Left> left
395 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"map <Left>', getreg(':'))
397 unmap <Left>
398 set cpo-=B
399
400 set cpo+=k
401 map <Left> left
402 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
403 call assert_equal('"map <Left>', getreg(':'))
404 unmap <Left>
405 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200406
Bram Moolenaar531be472020-09-23 22:38:05 +0200407 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
408
Bram Moolenaar1776a282019-05-03 16:05:41 +0200409 unmap <Middle>x
410 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100411endfunc
412
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100413func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100414 hi Aardig ctermfg=green
415 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000416 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000418 call assert_equal('"match none', @:)
419 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
420 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100421endfunc
422
423func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100424 hi Aardig ctermfg=green
425 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
426 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200427 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
428 call assert_equal('"hi default Aardig', getreg(':'))
429 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
430 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100431 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
432 call assert_equal('"hi link', getreg(':'))
433 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
434 call assert_equal('"hi default', getreg(':'))
435 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
436 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200437 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
438 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
439 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
440 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200441
442 " A cleared group does not show up in completions.
443 hi Anders ctermfg=green
444 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
445 hi clear Aardig
446 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
447 hi clear Anders
448 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100449endfunc
450
Bram Moolenaar75e15672020-06-28 13:10:22 +0200451" Test for command-line expansion of "hi Ni " (easter egg)
452func Test_highlight_easter_egg()
453 call test_override('ui_delay', 1)
454 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
455 call assert_equal("\"hi Ni \<Tab>", @:)
456 call test_override('ALL', 0)
457endfunc
458
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200459func Test_getcompletion()
460 let groupcount = len(getcompletion('', 'event'))
461 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200462 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200463 call assert_true(matchcount > 0)
464 call assert_true(groupcount > matchcount)
465
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200466 if has('menu')
467 source $VIMRUNTIME/menu.vim
468 let matchcount = len(getcompletion('', 'menu'))
469 call assert_true(matchcount > 0)
470 call assert_equal(['File.'], getcompletion('File', 'menu'))
471 call assert_true(matchcount > 0)
472 let matchcount = len(getcompletion('File.', 'menu'))
473 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000474 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200475 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200476
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200477 let l = getcompletion('v:n', 'var')
478 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200479 let l = getcompletion('v:notexists', 'var')
480 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200481
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200482 args a.c b.c
483 let l = getcompletion('', 'arglist')
484 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000485 let l = getcompletion('a.', 'buffer')
486 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200487 %argdelete
488
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200489 let l = getcompletion('', 'augroup')
490 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200491 let l = getcompletion('blahblah', 'augroup')
492 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200493
494 let l = getcompletion('', 'behave')
495 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200496 let l = getcompletion('not', 'behave')
497 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200498
499 let l = getcompletion('', 'color')
500 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200501 let l = getcompletion('dirty', 'color')
502 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503
504 let l = getcompletion('', 'command')
505 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200506 let l = getcompletion('awake', 'command')
507 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200508
509 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200510 call assert_true(index(l, 'samples/') >= 0)
511 let l = getcompletion('NoMatch', 'dir')
512 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200513
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100514 if glob('~/*') !=# ''
515 let l = getcompletion('~/', 'dir')
516 call assert_true(l[0][0] ==# '~')
517 endif
518
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200519 let l = getcompletion('exe', 'expression')
520 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200521 let l = getcompletion('kill', 'expression')
522 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200523
524 let l = getcompletion('tag', 'function')
525 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200526 let l = getcompletion('paint', 'function')
527 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200528
Kota Kato90c23532023-01-18 15:27:38 +0000529 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000530 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000531 let l = getcompletion('ruby', 'function')
532 call assert_equal([], l)
533 endif
534
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200535 let Flambda = {-> 'hello'}
536 let l = getcompletion('', 'function')
537 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200538 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200539
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200540 let l = getcompletion('run', 'file')
541 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200542 let l = getcompletion('walk', 'file')
543 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200544 set wildignore=*.vim
545 let l = getcompletion('run', 'file', 1)
546 call assert_true(index(l, 'runtest.vim') < 0)
547 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000548 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100549 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000550 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
551 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200552
553 let l = getcompletion('ha', 'filetype')
554 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200555 let l = getcompletion('horse', 'filetype')
556 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200557
Doug Kearns81642d92024-01-04 22:37:44 +0100558 if has('keymap')
559 let l = getcompletion('acc', 'keymap')
560 call assert_true(index(l, 'accents') >= 0)
561 let l = getcompletion('nullkeymap', 'keymap')
562 call assert_equal([], l)
563 endif
564
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200565 let l = getcompletion('z', 'syntax')
566 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200567 let l = getcompletion('emacs', 'syntax')
568 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200569
570 let l = getcompletion('jikes', 'compiler')
571 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200572 let l = getcompletion('break', 'compiler')
573 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200574
575 let l = getcompletion('last', 'help')
576 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200577 let l = getcompletion('giveup', 'help')
578 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200579
580 let l = getcompletion('time', 'option')
581 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200582 let l = getcompletion('space', 'option')
583 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200584
585 let l = getcompletion('er', 'highlight')
586 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200587 let l = getcompletion('dark', 'highlight')
588 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200589
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200590 let l = getcompletion('', 'messages')
591 call assert_true(index(l, 'clear') >= 0)
592 let l = getcompletion('not', 'messages')
593 call assert_equal([], l)
594
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200595 let l = getcompletion('', 'mapclear')
596 call assert_true(index(l, '<buffer>') >= 0)
597 let l = getcompletion('not', 'mapclear')
598 call assert_equal([], l)
599
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200600 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200601 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200602 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
603 let root = has('win32') ? 'C:\\' : '/'
604 let l = getcompletion(root, 'shellcmd')
605 let expected = map(filter(glob(root . '*', 0, 1),
606 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
607 call assert_equal(expected, l)
608
Bram Moolenaarb650b982016-08-05 20:35:13 +0200609 if has('cscope')
610 let l = getcompletion('', 'cscope')
611 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
612 call assert_equal(cmds, l)
613 " using cmdline completion must not change the result
614 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
615 let l = getcompletion('', 'cscope')
616 call assert_equal(cmds, l)
617 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
618 let l = getcompletion('find ', 'cscope')
619 call assert_equal(keys, l)
620 endif
621
Bram Moolenaar7522f692016-08-06 14:12:50 +0200622 if has('signs')
623 sign define Testing linehl=Comment
624 let l = getcompletion('', 'sign')
625 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
626 call assert_equal(cmds, l)
627 " using cmdline completion must not change the result
628 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
629 let l = getcompletion('', 'sign')
630 call assert_equal(cmds, l)
631 let l = getcompletion('list ', 'sign')
632 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000633 let l = getcompletion('de*', 'sign')
634 call assert_equal(['define'], l)
635 let l = getcompletion('p?', 'sign')
636 call assert_equal(['place'], l)
637 let l = getcompletion('j.', 'sign')
638 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200639 endif
640
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200641 " Command line completion tests
642 let l = getcompletion('cd ', 'cmdline')
643 call assert_true(index(l, 'samples/') >= 0)
644 let l = getcompletion('cd NoMatch', 'cmdline')
645 call assert_equal([], l)
646 let l = getcompletion('let v:n', 'cmdline')
647 call assert_true(index(l, 'v:null') >= 0)
648 let l = getcompletion('let v:notexists', 'cmdline')
649 call assert_equal([], l)
650 let l = getcompletion('call tag', 'cmdline')
651 call assert_true(index(l, 'taglist(') >= 0)
652 let l = getcompletion('call paint', 'cmdline')
653 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200654 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
655 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200656
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100657 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000658 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100659 return "oneA\noneB\noneC"
660 endfunc
661 command -nargs=1 -complete=custom,T MyCmd
662 let l = getcompletion('MyCmd ', 'cmdline')
663 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000664 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100665
666 delcommand MyCmd
667 delfunc T
ii144785fe02021-11-21 12:13:56 +0000668 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100669
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200670 " For others test if the name is recognized.
LemonBoya20bf692024-07-11 22:35:53 +0200671 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
672 \ 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200673 if has('cmdline_hist')
674 call add(names, 'history')
675 endif
676 if has('gettext')
677 call add(names, 'locale')
678 endif
679 if has('profile')
680 call add(names, 'syntime')
681 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200682
683 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100684 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200685
686 for name in names
687 let matchcount = len(getcompletion('', name))
688 call assert_true(matchcount >= 0, 'No matches for ' . name)
689 endfor
690
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200691 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200692
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000693 edit a~b
694 enew
695 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
696 bw a~b
697
698 if has('unix')
699 edit Xtest\
700 enew
701 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
702 bw Xtest\
703 endif
704
Christian Brabandt0dc0bff2024-02-24 14:12:13 +0100705 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200706 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100707 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200708endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200709
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000710func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000711 " Get a dialog in the GUI
712 CheckNotGui
713
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000714 " This was using uninitialized memory.
715 let lines =<< trim END
716 set verbose=6
717 norm @=ٷ
718 qall!
719 END
720 call writefile(lines, 'XmultiScript', 'D')
721 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
722endfunc
723
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000724" Test for getcompletion() with "fuzzy" in 'wildoptions'
725func Test_getcompletion_wildoptions()
726 let save_wildoptions = &wildoptions
727 set wildoptions&
728 let l = getcompletion('space', 'option')
729 call assert_equal([], l)
730 let l = getcompletion('ier', 'command')
731 call assert_equal([], l)
732 set wildoptions=fuzzy
733 let l = getcompletion('space', 'option')
734 call assert_true(index(l, 'backspace') >= 0)
735 let l = getcompletion('ier', 'command')
736 call assert_true(index(l, 'compiler') >= 0)
737 let &wildoptions = save_wildoptions
738endfunc
739
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000740func Test_complete_autoload_error()
741 let save_rtp = &rtp
742 let lines =<< trim END
743 vim9script
744 export def Complete(..._): string
745 return 'match'
746 enddef
747 echo this will cause an error
748 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100749 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000750 call writefile(lines, 'Xdir/autoload/script.vim')
751 exe 'set rtp+=' .. getcwd() .. '/Xdir'
752
753 let lines =<< trim END
754 vim9script
755 import autoload 'script.vim'
756 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
757 &wildcharm = char2nr("\<Tab>")
758 feedkeys(":Cmd \<Tab>", 'xt')
759 END
760 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
761
762 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000763endfunc
764
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100765func Test_fullcommand()
766 let tests = {
767 \ '': '',
768 \ ':': '',
769 \ ':::': '',
770 \ ':::5': '',
771 \ 'not_a_cmd': '',
772 \ 'Check': '',
773 \ 'syntax': 'syntax',
774 \ ':syntax': 'syntax',
775 \ '::::syntax': 'syntax',
776 \ 'sy': 'syntax',
777 \ 'syn': 'syntax',
778 \ 'synt': 'syntax',
779 \ ':sy': 'syntax',
780 \ '::::sy': 'syntax',
781 \ 'match': 'match',
782 \ '2match': 'match',
783 \ '3match': 'match',
784 \ 'aboveleft': 'aboveleft',
785 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100786 \ 'en': 'endif',
787 \ 'end': 'endif',
788 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100789 \ 's': 'substitute',
790 \ '5s': 'substitute',
791 \ ':5s': 'substitute',
792 \ "'<,'>s": 'substitute',
793 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100794 \ 'CheckLin': 'CheckLinux',
795 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100796 \ }
797
798 for [in, want] in items(tests)
799 call assert_equal(want, fullcommand(in))
800 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200801 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100802
803 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200804
805 command -buffer BufferLocalCommand :
806 command GlobalCommand :
807 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
808 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
809 delcommand BufferLocalCommand
810 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100811endfunc
812
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200813func Test_shellcmd_completion()
814 let save_path = $PATH
815
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100816 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200817 call writefile([''], 'Xpathdir/Xfile.exe')
818 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
819
820 " Set PATH to example directory without trailing slash.
821 let $PATH = getcwd() . '/Xpathdir'
822
823 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
824 " dirs in the PATH, even though they won't be executed. We check that only
825 " subdirs of the PWD and executables from the PATH are included in the
826 " suggestions.
827 let actual = getcompletion('X', 'shellcmd')
828 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
829 call insert(expected, 'Xfile.exe')
830 call assert_equal(expected, actual)
831
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200832 let $PATH = save_path
833endfunc
834
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200835func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100836 call mkdir('a/b/c', 'pR')
837 call writefile(['asdfasdf'], 'a/b/c/fileXname')
838 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
839 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200840 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200841endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100842
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100843func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100844 let @a = "def"
845 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
846 call assert_equal('"abc def ghi', @:)
847
848 new
849 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
850
851 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
852 call assert_equal('"aaa asdf bbb', @:)
853
854 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
855 call assert_equal('"aaa /tmp/some bbb', @:)
856
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200857 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
858 call assert_equal('"aaa '.getline(1).' bbb', @:)
859
Bram Moolenaar21efc362016-12-03 14:05:49 +0100860 set incsearch
861 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
862 call assert_equal('"aaa verylongword bbb', @:)
863
864 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
865 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100866
867 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
868 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100869 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200870
871 " Error while typing a command used to cause that it was not executed
872 " in the end.
873 new
874 try
875 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
876 catch /^Vim\%((\a\+)\)\=:E32/
877 " ignore error E32
878 endtry
879 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100880
Bram Moolenaar578fe942020-02-27 21:32:51 +0100881 " Try to paste an invalid register using <C-R>
882 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
883 call assert_equal('"onetwo', @:)
884
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100885 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100886 let @a = "xy\<C-H>z"
887 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
888 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100889 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
890 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100891 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
892 call assert_equal("\"xy\<C-H>z", @:)
893
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100894 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
895 let @a = "xy\<C-V>z"
896 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
897 call assert_equal('"xyz', @:)
898 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
899 call assert_equal("\"xy\<C-V>z", @:)
900
Bram Moolenaar578fe942020-02-27 21:32:51 +0100901 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
902
Bram Moolenaar72532d32018-04-07 19:09:09 +0200903 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100904endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100905
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100906func Test_cmdline_remove_char()
907 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100908
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100909 for e in ['utf8', 'latin1']
910 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100911
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100912 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
913 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100914
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100915 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
916 call assert_equal('"abcdef', @:)
917
918 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
919 call assert_equal('"abc ghi', @:, e)
920
921 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
922 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100923
924 " This was going before the start in latin1.
925 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100926 endfor
927
928 let &encoding = encoding_save
929endfunc
930
zeertzjqff2b79d2024-02-26 20:38:36 +0100931func Test_cmdline_del_utf8()
932 let @s = '⒌'
933 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
934 call assert_equal('",,', @:)
935
936 let @s = 'a̳'
937 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
938 call assert_equal('",,', @:)
939
940 let @s = 'β̳'
941 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
942 call assert_equal('",,', @:)
943
944 if has('arabic')
945 let @s = 'لا'
946 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
947 call assert_equal('",,', @:)
948 endif
949endfunc
950
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100951func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200952 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100953
954 set keymap=esperanto
955 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
956 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
957 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100958endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100959
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100960func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100961 new
962 2;'(
963 2;')
964 quit
965endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100966
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100967func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100968 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100969 new
970 source Xtest.vim
971 " Trigger calling validate_cursor()
972 diffsp Xtest.vim
973 quit!
974 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100975endfunc
976
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100977func Test_mark_from_line_zero()
978 " this was reading past the end of the first (empty) line
979 new
980 norm oxxxx
981 call assert_fails("0;'(", 'E20:')
982 bwipe!
983endfunc
984
Bram Moolenaarba47b512017-01-24 21:18:19 +0100985func Test_cmdline_complete_wildoptions()
986 help
987 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
988 let a = join(sort(split(@:)),' ')
989 set wildoptions=tagfile
990 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
991 let b = join(sort(split(@:)),' ')
992 call assert_equal(a, b)
993 bw!
994endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100995
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200996func Test_cmdline_complete_user_cmd()
997 command! -complete=color -nargs=1 Foo :
998 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
999 call assert_equal('"Foo blue', @:)
1000 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
1001 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001002 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
1003 call assert_equal('"Foo a blue', @:)
1004 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
1005 call assert_equal('"Foo b\', @:)
1006 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
1007 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001008 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +01001009
1010 redraw
1011 call assert_equal('~', Screenline(&lines - 1))
1012 command! FooOne :
1013 command! FooTwo :
1014
1015 set nowildmenu
1016 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
1017 call assert_equal('"FooOne', @:)
1018 call assert_equal('~', Screenline(&lines - 1))
1019
1020 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
1021 call assert_equal('"FooTwo', @:)
1022 call assert_equal('~', Screenline(&lines - 1))
1023
1024 delcommand FooOne
1025 delcommand FooTwo
1026 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +02001027endfunc
1028
Bram Moolenaarc2842ad2022-07-26 17:23:47 +01001029func Test_complete_user_cmd()
1030 command FooBar echo 'global'
1031 command -buffer FooBar echo 'local'
1032 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
1033 call assert_equal('"FooBar', @:)
1034
1035 delcommand -buffer FooBar
1036 delcommand FooBar
1037endfunc
1038
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001039func s:ScriptLocalFunction()
1040 echo 'yes'
1041endfunc
1042
1043func Test_cmdline_complete_user_func()
1044 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +02001045 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001046 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
1047 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +01001048
1049 " g: prefix also works
1050 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
1051 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +02001052
1053 " using g: prefix does not result in just "g:" matches from a lambda
1054 let Fx = { a -> a }
1055 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
1056 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +02001057
1058 " existence of script-local dict function does not break user function name
1059 " completion
1060 function s:a_dict_func() dict
1061 endfunction
1062 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1063 call assert_match('"call Test_cmdline_complete_user_', @:)
1064 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001065endfunc
1066
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001067func Test_cmdline_complete_user_names()
1068 if has('unix') && executable('whoami')
1069 let whoami = systemlist('whoami')[0]
1070 let first_letter = whoami[0]
1071 if len(first_letter) > 0
1072 " Trying completion of :e ~x where x is the first letter of
1073 " the user name should complete to at least the user name.
1074 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1075 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1076 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001077 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001078 " Just in case: check that the system has an Administrator account.
1079 let names = system('net user')
1080 if names =~ 'Administrator'
1081 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001082 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001083 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001084 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001085 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001086 else
1087 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001088 endif
1089endfunc
1090
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001091func Test_cmdline_complete_shellcmdline()
1092 CheckExecutable whoami
1093 command -nargs=1 -complete=shellcmdline MyCmd
1094
1095 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1096 call assert_match('^".*\<whoami\>', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02001097 let l = getcompletion('whoam', 'shellcmdline')
1098 call assert_match('\<whoami\>', join(l, ' '))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001099
1100 delcommand MyCmd
1101endfunc
1102
Bram Moolenaar297610b2019-12-27 17:20:55 +01001103func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001104 CheckExecutable whoami
1105 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1106 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001107endfunc
1108
Bram Moolenaar8b633132020-03-20 18:20:51 +01001109func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001110 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1111 call assert_equal(lang, v:lc_time)
1112
1113 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1114 call assert_equal(lang, v:ctype)
1115
1116 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1117 call assert_equal(lang, v:collate)
1118
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001119 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001120 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001121
1122 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001123 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001124
Bram Moolenaarec680282020-06-12 19:35:32 +02001125 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001126
Bram Moolenaarec680282020-06-12 19:35:32 +02001127 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1128 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001129
Bram Moolenaarec680282020-06-12 19:35:32 +02001130 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1131 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001132
Bram Moolenaarec680282020-06-12 19:35:32 +02001133 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1134 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001135
1136 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1137 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001138endfunc
1139
Bram Moolenaar297610b2019-12-27 17:20:55 +01001140func Test_cmdline_complete_env_variable()
1141 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001142 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1143 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001144 unlet $X_VIM_TEST_COMPLETE_ENV
1145endfunc
1146
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001147func Test_cmdline_complete_expression()
1148 let g:SomeVar = 'blah'
1149 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1150 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1151 call assert_match('"' .. cmd .. ' SomeVar', @:)
1152 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1153 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1154 endfor
1155 unlet g:SomeVar
1156endfunc
1157
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001158func Test_cmdline_complete_argopt()
1159 " completion for ++opt=arg for file commands
1160 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1161 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1162 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1163
1164 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +02001165 " Test ++ff in the middle of the cmdline
1166 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
1167 call assert_equal("\"edit ++fileformat= zz", @:)
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001168
1169 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1170 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1171 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1172 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1173 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1174
1175 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1176
1177 " completion should skip the ++opt and continue
1178 call writefile([], 'Xaaaaa.txt', 'D')
1179 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1180 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1181
1182 if has('terminal')
1183 " completion for terminal's [options]
1184 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1185 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1186 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1187
1188 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1189
1190 " :terminal completion should skip the ++opt when considering what is the
1191 " first option, which is a list of shell commands, unlike second option
1192 " onwards.
1193 let first_param = getcompletion('terminal ', 'cmdline')
1194 let second_param = getcompletion('terminal foo ', 'cmdline')
1195 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1196 call assert_equal(first_param, skipped_opt_param)
1197 call assert_notequal(first_param, second_param)
1198 endif
1199endfunc
1200
Bram Moolenaar47016f52021-08-26 16:39:58 +02001201" Unique function name for completion below
1202func s:WeirdFunc()
1203 echo 'weird'
1204endfunc
1205
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001206" Test for various command-line completion
1207func Test_cmdline_complete_various()
1208 " completion for a command starting with a comment
1209 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1210 call assert_equal("\" :|\"\<C-A>", @:)
1211
1212 " completion for a range followed by a comment
1213 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"1,2\"\<C-A>", @:)
1215
1216 " completion for :k command
1217 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\"ka\<C-A>", @:)
1219
Doug Kearnsea842022024-09-29 17:17:41 +02001220 " completion for :keepmarks command
1221 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
1222 call assert_equal("\"kee edit", @:)
1223
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001224 " completion for short version of the :s command
1225 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1226 call assert_equal("\"sI \<C-A>", @:)
1227
1228 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001229 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001230 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001231 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001232 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001233 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1234 call assert_equal("\"w >> Xfile1", @:)
1235 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001236
1237 " completion for :w ! and :r ! commands
1238 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1239 call assert_equal("\"w !invalid_xyz_cmd", @:)
1240 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1241 call assert_equal("\"r !invalid_xyz_cmd", @:)
1242
1243 " completion for :>> and :<< commands
1244 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1245 call assert_equal("\">>>\<C-A>", @:)
1246 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1247 call assert_equal("\"<<<\<C-A>", @:)
1248
1249 " completion for command with +cmd argument
1250 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1251 call assert_equal("\"buffer +/pat Xabc", @:)
1252 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1253 call assert_equal("\"buffer +/pat\<C-A>", @:)
1254
1255 " completion for a command with a trailing comment
1256 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1257 call assert_equal("\"ls \" comment\<C-A>", @:)
1258
1259 " completion for a command with a trailing command
1260 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1261 call assert_equal("\"ls | ls", @:)
1262
1263 " completion for a command with an CTRL-V escaped argument
1264 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1265 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1266
1267 " completion for a command that doesn't take additional arguments
1268 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1269 call assert_equal("\"all abc\<C-A>", @:)
1270
zeertzjqd3de1782022-09-01 12:58:52 +01001271 " completion for :wincmd with :horizontal modifier
1272 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1273 call assert_equal("\"horizontal wincmd", @:)
1274
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001275 " completion for a command with a command modifier
1276 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1277 call assert_equal("\"topleft new", @:)
1278
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001279 " completion for vim9 and legacy commands
1280 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal("\"vim9 call strlen(", @:)
1282 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1283 call assert_equal("\"legac call strlen(", @:)
1284
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001285 " completion for the :disassemble command
1286 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1287 call assert_equal("\"disas debug", @:)
1288 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1289 call assert_equal("\"disas profile", @:)
1290 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1291 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1292 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1293 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001294 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1295 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001296
Bram Moolenaar47016f52021-08-26 16:39:58 +02001297 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001298 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001299
naohiro onodfe04db2021-09-12 15:45:10 +02001300 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1301 call assert_match('"disas <SNR>\d\+_', @:)
1302 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1303 call assert_match('"disas debug <SNR>\d\+_', @:)
1304
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001305 " completion for the :match command
1306 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1307 call assert_equal("\"match Search /pat/\<C-A>", @:)
1308
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001309 " completion for the :doautocmd command
1310 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1311 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1312
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001313 " completion of autocmd group after comma
1314 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1315 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1316
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001317 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001318 call writefile([], 'Xvarfile1', 'D')
1319 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001320 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1321 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001322
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001323 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001324 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001325 augroup END
1326 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001327 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001328
1329 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001330 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1331 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001332 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1333 call assert_equal("\"au XTest.test", @:)
1334
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001335 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001336
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001337 " autocmd pattern completion
1338 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1339 call assert_equal("\"au BufEnter *.py\t", @:)
1340
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001341 " completion for the :unlet command
1342 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1343 call assert_equal("\"unlet one two", @:)
1344
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001345 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001346 " FIXME: what should happen on MS-Windows?
1347 if !has('win32')
1348 edit \{someFile}
1349 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1350 call assert_equal("\"buf {someFile}", @:)
1351 bwipe {someFile}
1352 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001353
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001354 " completion for the :bdelete command
1355 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1356 call assert_equal("\"bdel a b c", @:)
1357
1358 " completion for the :mapclear command
1359 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1360 call assert_equal("\"mapclear <buffer>", @:)
1361
1362 " completion for user defined commands with menu names
1363 menu Test.foo :ls<CR>
1364 com -nargs=* -complete=menu MyCmd
1365 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1366 call assert_equal('"MyCmd Test.', @:)
1367 delcom MyCmd
1368 unmenu Test
1369
1370 " completion for user defined commands with mappings
1371 mapclear
1372 map <F3> :ls<CR>
1373 com -nargs=* -complete=mapping MyCmd
1374 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001375 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001376 mapclear
1377 delcom MyCmd
1378
Yee Cheng Chin54844852023-10-09 18:12:31 +02001379 " Prepare for path completion
1380 call mkdir('Xa b c', 'D')
1381 defer delete('Xcomma,foobar.txt')
1382 call writefile([], 'Xcomma,foobar.txt')
1383
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001384 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001385 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1386 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1387 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001388
1389 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001390 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1391 call assert_equal('"set dir=Xa\ b\ c/', @:)
1392 set dir&
1393
1394 " completion for :set tags= / set dictionary= with escaped commas
1395 if has('win32')
1396 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1397 " '\,'
1398 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1399 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1400
1401 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1402 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1403
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 " completion for :set dictionary= with escaped commas (same behavior, but
1408 " different internal code path from 'set tags=' for escaping the output)
1409 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1410 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1411 else
1412 " In other platforms, backslashes are rounded down (since '\,' itself will
1413 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1414 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1415 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1416
1417 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1418 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1419
1420 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1422
1423 " completion for :set dictionary= with escaped commas (same behavior, but
1424 " different internal code path from 'set tags=' for escaping the output)
1425 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1426 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1427 endif
1428 set tags&
1429 set dictionary&
1430
1431 " completion for :set makeprg= with no escaped commas
1432 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1433 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1434
1435 if !has('win32')
1436 " Cannot create file with backslash in file name in Windows, so only test
1437 " this elsewhere.
1438 defer delete('Xcomma\,fooslash.txt')
1439 call writefile([], 'Xcomma\,fooslash.txt')
1440 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1441 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1442 endif
1443 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001444
1445 " completion for the :py3 commands
1446 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1447 call assert_equal('"py3 py3do py3file', @:)
1448
Bram Moolenaardf749a22021-03-28 15:29:43 +02001449 " completion for the :vim9 commands
1450 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1451 call assert_equal('"vim9cmd vim9script', @:)
1452
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001453 " redir @" is not the start of a comment. So complete after that
1454 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1455 call assert_equal('"redir @" | cwindow', @:)
1456
1457 " completion after a backtick
1458 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1459 call assert_equal('"e `a1b2c', @:)
1460
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001461 " completion for :language command with an invalid argument
1462 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1463 call assert_equal("\"language dummy \t", @:)
1464
1465 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001466 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1467 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001468
1469 " completion with ambiguous user defined commands
1470 com TCmd1 echo 'TCmd1'
1471 com TCmd2 echo 'TCmd2'
1472 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1473 call assert_equal('"TCmd ', @:)
1474 delcom TCmd1
1475 delcom TCmd2
1476
1477 " completion after a range followed by a pipe (|) character
1478 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1479 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001480
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001481 " completion after a :global command
1482 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1483 call assert_equal('"g/a/chistory', @:)
1484 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1485 call assert_equal("\"g/a\\/chist\t", @:)
1486
Bram Moolenaar9c929712020-09-07 22:05:28 +02001487 " use <Esc> as the 'wildchar' for completion
1488 set wildchar=<Esc>
1489 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1490 call assert_equal('"g/a\xb/clearjumps', @:)
1491 " pressing <esc> twice should cancel the command
1492 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1493 call assert_equal('"g/a\xb/clearjumps', @:)
1494 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001495
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001496 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001497 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001498 call writefile([], '~Xtest')
1499 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1500 call assert_equal('"e \~Xtest', @:)
1501 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001502
1503 " should be able to complete a file name that has a '*'
1504 call writefile([], 'Xx*Yy')
1505 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1506 call assert_equal('"e Xx\*Yy', @:)
1507 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001508
1509 " use a literal star
1510 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1511 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001512 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001513
1514 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1515 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001516endfunc
1517
zeertzjq094dd152023-06-15 22:51:57 +01001518" Test that expanding a pattern doesn't interfere with cmdline completion.
1519func Test_expand_during_cmdline_completion()
1520 func ExpandStuff()
1521 badd <script>:p:h/README.*
1522 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1523 $bwipe
1524 call assert_equal('README.txt', expand('README.*'))
1525 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1526 endfunc
1527 augroup test_CmdlineChanged
1528 autocmd!
1529 autocmd CmdlineChanged * call ExpandStuff()
1530 augroup END
1531
1532 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1533 call assert_equal('"sign place', @:)
1534
1535 augroup test_CmdlineChanged
1536 au!
1537 augroup END
1538 augroup! test_CmdlineChanged
1539 delfunc ExpandStuff
1540endfunc
1541
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001542" Test for 'wildignorecase'
1543func Test_cmdline_wildignorecase()
1544 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001545 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001546 set wildignorecase
1547 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1548 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001549 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001550 let g:Sline = ''
1551 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1552 call assert_equal('"e xt', @:)
1553 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001554 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001555endfunc
1556
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001557func Test_cmdline_write_alternatefile()
1558 new
1559 call setline('.', ['one', 'two'])
1560 f foo.txt
1561 new
1562 f #-A
1563 call assert_equal('foo.txt-A', expand('%'))
1564 f #<-B.txt
1565 call assert_equal('foo-B.txt', expand('%'))
1566 f %<
1567 call assert_equal('foo-B', expand('%'))
1568 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001569 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001570 bw!
1571 f foo-B.txt
1572 f %<-A
1573 call assert_equal('foo-B-A', expand('%'))
1574 bw!
1575 bw!
1576endfunc
1577
Bram Moolenaarf5724372022-09-02 19:45:15 +01001578func Test_cmdline_expand_cur_alt_file()
1579 enew
1580 file http://some.com/file.txt
1581 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1582 call assert_equal('"e http://some.com/file.txt', @:)
1583 edit another
1584 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1585 call assert_equal('"e http://some.com/file.txt', @:)
1586 bwipe
1587 bwipe http://some.com/file.txt
1588endfunc
1589
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001590" using a leading backslash here
1591set cpo+=C
1592
1593func Test_cmdline_search_range()
1594 new
1595 call setline(1, ['a', 'b', 'c', 'd'])
1596 /d
1597 1,\/s/b/B/
1598 call assert_equal('B', getline(2))
1599
1600 /a
1601 $
1602 \?,4s/c/C/
1603 call assert_equal('C', getline(3))
1604
1605 call setline(1, ['a', 'b', 'c', 'd'])
1606 %s/c/c/
1607 1,\&s/b/B/
1608 call assert_equal('B', getline(2))
1609
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001610 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001611 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001612
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001613 bwipe!
1614endfunc
1615
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001616" Test for the tick mark (') in an excmd range
1617func Test_tick_mark_in_range()
1618 " If only the tick is passed as a range and no command is specified, there
1619 " should not be an error
1620 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001621 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001622 call assert_fails("',print", 'E78:')
1623endfunc
1624
1625" Test for using a line number followed by a search pattern as range
1626func Test_lnum_and_pattern_as_range()
1627 new
1628 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1629 let @" = ''
1630 2/foo/yank
1631 call assert_equal("foo 3\n", @")
1632 call assert_equal(1, line('.'))
1633 close!
1634endfunc
1635
Bram Moolenaar65189a12017-02-06 22:22:17 +01001636" Tests for getcmdline(), getcmdpos() and getcmdtype()
1637func Check_cmdline(cmdtype)
1638 call assert_equal('MyCmd a', getcmdline())
1639 call assert_equal(8, getcmdpos())
1640 call assert_equal(a:cmdtype, getcmdtype())
1641 return ''
1642endfunc
1643
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001644set cpo&
1645
Shougo Matsushita69084282024-09-23 20:34:47 +02001646func Test_getcmdtype_getcmdprompt()
Bram Moolenaar65189a12017-02-06 22:22:17 +01001647 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1648
1649 let cmdtype = ''
1650 debuggreedy
1651 call feedkeys(":debug echo 'test'\<CR>", "t")
1652 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1653 call feedkeys("cont\<CR>", "xt")
1654 0debuggreedy
1655 call assert_equal('>', cmdtype)
1656
1657 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1658 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1659
1660 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001661 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001662
1663 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1664
1665 cnoremap <expr> <F6> Check_cmdline('=')
1666 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1667 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001668
1669 call assert_equal('', getcmdline())
Shougo Matsushita69084282024-09-23 20:34:47 +02001670
1671 call assert_equal('', getcmdprompt())
1672 augroup test_CmdlineEnter
1673 autocmd!
1674 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
1675 augroup END
1676 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
1677 call assert_equal('Answer?', g:cmdprompt)
1678 call assert_equal('', getcmdprompt())
h-east25876a62024-09-26 16:01:57 +02001679 call feedkeys(":\<CR>\<ESC>", "xt")
1680 call assert_equal('', g:cmdprompt)
1681 call assert_equal('', getcmdprompt())
1682
1683 let str = "C" .. repeat("c", 1023) .. "xyz"
1684 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
1685 call assert_equal(str, g:cmdprompt)
1686
1687 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
1688 call assert_equal('Ans?', g:cmdprompt)
1689 call assert_equal('', getcmdprompt())
Shougo Matsushita69084282024-09-23 20:34:47 +02001690
1691 augroup test_CmdlineEnter
1692 au!
1693 augroup END
1694 augroup! test_CmdlineEnter
Bram Moolenaar65189a12017-02-06 22:22:17 +01001695endfunc
1696
Bram Moolenaar52604f22017-04-07 16:17:39 +02001697func Test_verbosefile()
1698 set verbosefile=Xlog
1699 echomsg 'foo'
1700 echomsg 'bar'
1701 set verbosefile=
1702 let log = readfile('Xlog')
1703 call assert_match("foo\nbar", join(log, "\n"))
1704 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001705
1706 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001707 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001708endfunc
1709
Bram Moolenaar4facea32019-10-12 20:17:40 +02001710func Test_verbose_option()
1711 CheckScreendump
1712
1713 let lines =<< trim [SCRIPT]
Christian Brabandt2abec432024-10-27 21:33:09 +01001714 " clear the TermResponse autocommand from defaults.vim
1715 au! vimStartup TermResponse
Bram Moolenaar4facea32019-10-12 20:17:40 +02001716 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1717 call feedkeys("\r", 't') " for the hit-enter prompt
1718 set verbose=20
1719 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001720 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001721
1722 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001723 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001724 call term_sendkeys(buf, ":DoSomething\<CR>")
1725 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1726
1727 " clean up
1728 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001729endfunc
1730
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001731func Test_setcmdpos()
1732 func InsertTextAtPos(text, pos)
1733 call assert_equal(0, setcmdpos(a:pos))
1734 return a:text
1735 endfunc
1736
1737 " setcmdpos() with position in the middle of the command line.
1738 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1739 call assert_equal('"1ab2', @:)
1740
1741 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1742 call assert_equal('"1b2a', @:)
1743
1744 " setcmdpos() with position beyond the end of the command line.
1745 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1746 call assert_equal('"12ab', @:)
1747
1748 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001749 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001750endfunc
1751
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001752func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001753 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001754 let encoding_save = &encoding
1755
1756 for e in encodings
1757 exe 'set encoding=' . e
1758
1759 " Test overstrike in the middle of the command line.
1760 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001761 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001762
1763 " Test overstrike going beyond end of command line.
1764 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001765 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001766
1767 " Test toggling insert/overstrike a few times.
1768 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001769 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001770 endfor
1771
Bram Moolenaar30276f22019-01-24 17:59:39 +01001772 " Test overstrike with multi-byte characters.
1773 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001774 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001775
1776 let &encoding = encoding_save
1777endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001778
Bram Moolenaar52410572019-10-27 05:12:45 +01001779func Test_buffers_lastused()
1780 " check that buffers are sorted by time when wildmode has lastused
1781 call test_settime(1550020000) " middle
1782 edit bufa
1783 enew
1784 call test_settime(1550030000) " newest
1785 edit bufb
1786 enew
1787 call test_settime(1550010000) " oldest
1788 edit bufc
1789 enew
1790 call test_settime(0)
1791 enew
1792
1793 call assert_equal(['bufa', 'bufb', 'bufc'],
1794 \ getcompletion('', 'buffer'))
1795
1796 let save_wildmode = &wildmode
1797 set wildmode=full:lastused
1798
1799 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1800 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1801 call assert_equal('b bufb', X)
1802 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1803 call assert_equal('b bufa', X)
1804 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1805 call assert_equal('b bufc', X)
1806 enew
1807
1808 edit other
1809 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1810 call assert_equal('b bufb', X)
1811 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1812 call assert_equal('b bufa', X)
1813 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1814 call assert_equal('b bufc', X)
1815 enew
1816
1817 let &wildmode = save_wildmode
1818
1819 bwipeout bufa
1820 bwipeout bufb
1821 bwipeout bufc
1822endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001823
Bram Moolenaar479950f2020-01-19 15:45:17 +01001824func Test_cmdlineclear_tabenter()
1825 CheckScreendump
1826
1827 let lines =<< trim [SCRIPT]
1828 call setline(1, range(30))
1829 [SCRIPT]
1830
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001831 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001832 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001833 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001834 " in one tab make the command line higher with CTRL-W -
1835 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1836 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1837
1838 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001839endfunc
1840
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001841" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001842func Test_cmdline_expand_special()
1843 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001844 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001845 call assert_fails('e <afile>', 'E495:')
1846 call assert_fails('e <abuf>', 'E496:')
1847 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001848
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001849 call writefile([], 'Xfile.cpp', 'D')
1850 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001851 new Xfile.cpp
1852 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1853 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1854 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001855endfunc
1856
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001857" Test for backtick expression in the command line
1858func Test_cmd_backtick()
1859 %argd
1860 argadd `=['a', 'b', 'c']`
1861 call assert_equal(['a', 'b', 'c'], argv())
1862 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001863
1864 argadd `echo abc def`
1865 call assert_equal(['abc def'], argv())
1866 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001867endfunc
1868
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001869" Test for the :! command
1870func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001871 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001872
1873 let lines =<< trim [SCRIPT]
1874 " Test for no previous command
1875 call assert_fails('!!', 'E34:')
1876 set nomore
1877 " Test for cmdline expansion with :!
1878 call setline(1, 'foo!')
1879 silent !echo <cWORD> > Xfile.out
1880 call assert_equal(['foo!'], readfile('Xfile.out'))
1881 " Test for using previous command
1882 silent !echo \! !
1883 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1884 call writefile(v:errors, 'Xresult')
1885 call delete('Xfile.out')
1886 qall!
1887 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001888 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001889 if RunVim([], [], '--clean -S Xscript')
1890 call assert_equal([], readfile('Xresult'))
1891 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001892 call delete('Xresult')
1893endfunc
1894
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001895" Test error: "E135: *Filter* Autocommands must not change current buffer"
1896func Test_cmd_bang_E135()
1897 new
1898 call setline(1, ['a', 'b', 'c', 'd'])
1899 augroup test_cmd_filter_E135
1900 au!
1901 autocmd FilterReadPost * help
1902 augroup END
1903 call assert_fails('2,3!echo "x"', 'E135:')
1904
1905 augroup test_cmd_filter_E135
1906 au!
1907 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001908 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001909 %bwipe!
1910endfunc
1911
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001912func Test_cmd_bang_args()
1913 new
1914 :.!
1915 call assert_equal(0, v:shell_error)
1916
1917 " Note that below there is one space char after the '!'. This caused a
1918 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1919 :.!
1920 call assert_equal(0, v:shell_error)
1921 bwipe!
1922
1923 CheckUnix
1924 :.!pwd
1925 call assert_equal(0, v:shell_error)
1926 :.! pwd
1927 call assert_equal(0, v:shell_error)
1928
1929 " Note there is one space after 'pwd'.
1930 :.! pwd
1931 call assert_equal(0, v:shell_error)
1932
1933 " Note there are two spaces after 'pwd'.
1934 :.! pwd
1935 call assert_equal(0, v:shell_error)
1936 :.!ls ~
1937 call assert_equal(0, v:shell_error)
1938
1939 " Note there is one space char after '~'.
1940 :.!ls ~
1941 call assert_equal(0, v:shell_error)
1942
1943 " Note there are two spaces after '~'.
1944 :.!ls ~
1945 call assert_equal(0, v:shell_error)
1946
1947 :.!echo "foo"
1948 call assert_equal(getline('.'), "foo")
1949 :.!echo "foo "
1950 call assert_equal(getline('.'), "foo ")
1951 :.!echo " foo "
1952 call assert_equal(getline('.'), " foo ")
1953 :.!echo " foo "
1954 call assert_equal(getline('.'), " foo ")
1955
1956 %bwipe!
1957endfunc
1958
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001959" Test for using ~ for home directory in cmdline completion matches
1960func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001961 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001962 call writefile([], 'Xexpdir/Xfile1')
1963 call writefile([], 'Xexpdir/Xfile2')
1964 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001965 let save_HOME = $HOME
1966 let $HOME = getcwd()
1967 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1968 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1969 let $HOME = save_HOME
1970 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001971endfunc
1972
Bram Moolenaar578fe942020-02-27 21:32:51 +01001973" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1974" or insert mode (when 'insertmode' is set)
1975func Test_cmdline_ctrl_g()
1976 new
1977 call setline(1, 'abc')
1978 call cursor(1, 3)
1979 " If command line is entered from insert mode, using C-\ C-G should back to
1980 " insert mode
1981 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1982 call assert_equal('abxyc', getline(1))
1983 call assert_equal(4, col('.'))
1984
1985 " If command line is entered in 'insertmode', using C-\ C-G should back to
1986 " 'insertmode'
1987 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1988 call assert_equal('ab12xyc', getline(1))
1989 close!
1990endfunc
1991
Bram Moolenaar578fe942020-02-27 21:32:51 +01001992" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001993func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001994 func T(a, c, p)
1995 return "oneA\noneB\noneC"
1996 endfunc
1997 command -nargs=1 -complete=custom,T MyCmd
1998
Bram Moolenaar578fe942020-02-27 21:32:51 +01001999 set nowildmenu
2000 set wildmode=full,list
2001 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002002 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002003 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002004 call assert_equal('"MyCmd oneA', @:)
2005
2006 set wildmode=longest,full
2007 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
2008 call assert_equal('"MyCmd one', @:)
2009 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
2010 call assert_equal('"MyCmd oneC', @:)
2011
2012 set wildmode=longest
2013 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
2014 call assert_equal('"MyCmd one', @:)
2015
2016 set wildmode=list:longest
2017 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002018 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002019 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002020 call assert_equal('"MyCmd one', @:)
2021
2022 set wildmode=""
2023 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
2024 call assert_equal('"MyCmd oneA', @:)
2025
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002026 " Test for wildmode=longest with 'fileignorecase' set
2027 set wildmode=longest
2028 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002029 argadd AAA AAAA AAAAA
2030 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
2031 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002032 set fileignorecase&
2033
2034 " Test for listing files with wildmode=list
2035 set wildmode=list
2036 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002037 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002038 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002039 call assert_equal('"b A', @:)
2040
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002041 " when using longest completion match, matches shorter than the argument
2042 " should be ignored (happens with :help)
2043 set wildmode=longest,full
2044 set wildmenu
2045 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2046 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002047 " non existing file
2048 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
2049 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00002050 set wildmenu&
2051
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002052 " Test for longest file name completion with 'fileignorecase'
2053 " On MS-Windows, file names are case insensitive.
2054 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002055 call writefile([], 'XTESTfoo', 'D')
2056 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002057 set nofileignorecase
2058 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2059 call assert_equal('"e XTESTfoo', @:)
2060 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2061 call assert_equal('"e Xtestbar', @:)
2062 set fileignorecase
2063 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
2064 call assert_equal('"e Xtest', @:)
2065 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
2066 call assert_equal('"e Xtest', @:)
2067 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002068 endif
2069
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002070 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01002071 delcommand MyCmd
2072 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01002073 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01002074 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01002075endfunc
2076
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002077func Test_wildmode()
2078 " Test with utf-8 encoding
2079 call Wildmode_tests()
2080
2081 " Test with latin1 encoding
2082 let save_encoding = &encoding
2083 set encoding=latin1
2084 call Wildmode_tests()
2085 let &encoding = save_encoding
2086endfunc
2087
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002088func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002089 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002090 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002091 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002092 let lines =<< trim END
2093 func vim8#Complete(a, c, p)
2094 return "oneA\noneB\noneC"
2095 endfunc
2096 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002097 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002098
2099 command -nargs=1 -complete=custom,vim8#Complete MyCmd
2100 set nowildmenu
2101 set wildmode=full,list
2102 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
2103 call assert_equal('"MyCmd oneA oneB oneC', @:)
2104
2105 let &rtp = save_rtp
2106 set wildmode& wildmenu&
2107 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002108endfunc
2109
Bram Moolenaar578fe942020-02-27 21:32:51 +01002110" Test for interrupting the command-line completion
2111func Test_interrupt_compl()
2112 func F(lead, cmdl, p)
2113 if a:lead =~ 'tw'
2114 call interrupt()
2115 return
2116 endif
2117 return "one\ntwo\nthree"
2118 endfunc
2119 command -nargs=1 -complete=custom,F Tcmd
2120
2121 set nowildmenu
2122 set wildmode=full
2123 let interrupted = 0
2124 try
2125 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2126 catch /^Vim:Interrupt$/
2127 let interrupted = 1
2128 endtry
2129 call assert_equal(1, interrupted)
2130
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002131 let interrupted = 0
2132 try
2133 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2134 catch /^Vim:Interrupt$/
2135 let interrupted = 1
2136 endtry
2137 call assert_equal(1, interrupted)
2138
Bram Moolenaar578fe942020-02-27 21:32:51 +01002139 delcommand Tcmd
2140 delfunc F
2141 set wildmode&
2142endfunc
2143
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002144" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002145func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002146 let str = ":one two\<C-U>"
2147 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002148 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002149 let str ..= "\<Left>five\<Right>"
2150 let str ..= "\<Home>two "
2151 let str ..= "\<C-Left>one "
2152 let str ..= "\<C-Right> three"
2153 let str ..= "\<End>\<S-Left>four "
2154 let str ..= "\<S-Right> six"
2155 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2156 call feedkeys(str, 'xt')
2157 call assert_equal("\"one two three four five six seven", @:)
2158endfunc
2159
2160" Test for moving the cursor on the / command line in 'rightleft' mode
2161func Test_cmdline_edit_rightleft()
2162 CheckFeature rightleft
2163 set rightleft
2164 set rightleftcmd=search
2165 let str = "/one two\<C-U>"
2166 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002167 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002168 let str ..= "\<Right>five\<Left>"
2169 let str ..= "\<Home>two "
2170 let str ..= "\<C-Right>one "
2171 let str ..= "\<C-Left> three"
2172 let str ..= "\<End>\<S-Right>four "
2173 let str ..= "\<S-Left> six"
2174 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2175 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2176 call assert_equal("\"one two three four five six seven", @/)
2177 set rightleftcmd&
2178 set rightleft&
2179endfunc
2180
2181" Test for using <C-\>e in the command line to evaluate an expression
2182func Test_cmdline_expr()
2183 " Evaluate an expression from the beginning of a command line
2184 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2185 call assert_equal('"hello', @:)
2186
2187 " Use an invalid expression for <C-\>e
2188 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2189
2190 " Insert literal <CTRL-\> in the command line
2191 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2192 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002193endfunc
2194
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002195" This was making the insert position negative
2196func Test_cmdline_expr_register()
2197 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2198endfunc
2199
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002200" Test for 'imcmdline' and 'imsearch'
2201" This test doesn't actually test the input method functionality.
2202func Test_cmdline_inputmethod()
2203 new
2204 call setline(1, ['', 'abc', ''])
2205 set imcmdline
2206
2207 call feedkeys(":\"abc\<CR>", 'xt')
2208 call assert_equal("\"abc", @:)
2209 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2210 call assert_equal("\"abc", @:)
2211 call feedkeys("/abc\<CR>", 'xt')
2212 call assert_equal([2, 1], [line('.'), col('.')])
2213 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2214 call assert_equal([2, 1], [line('.'), col('.')])
2215
2216 set imsearch=2
2217 call cursor(1, 1)
2218 call feedkeys("/abc\<CR>", 'xt')
2219 call assert_equal([2, 1], [line('.'), col('.')])
2220 call cursor(1, 1)
2221 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2222 call assert_equal([2, 1], [line('.'), col('.')])
2223 set imdisable
2224 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2225 call assert_equal([2, 1], [line('.'), col('.')])
2226 set imdisable&
2227 set imsearch&
2228
2229 set imcmdline&
2230 %bwipe!
2231endfunc
2232
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002233" Test for using CTRL-_ in the command line with 'allowrevins'
2234func Test_cmdline_revins()
2235 CheckNotMSWindows
2236 CheckFeature rightleft
2237 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2238 call assert_equal("\"abc\<c-_>", @:)
2239 set allowrevins
2240 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2241 call assert_equal('"abcñèæ', @:)
2242 set allowrevins&
2243endfunc
2244
2245" Test for typing UTF-8 composing characters in the command line
2246func Test_cmdline_composing_chars()
2247 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2248 call assert_equal('"ゔ', @:)
2249endfunc
2250
Bram Moolenaar0e717042020-04-27 19:29:01 +02002251" test that ";" works to find a match at the start of the first line
2252func Test_zero_line_search()
2253 new
2254 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2255 call cursor(1,1)
2256 0;/pattern/d
2257 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2258 q!
2259endfunc
2260
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002261func Test_read_shellcmd()
2262 CheckUnix
2263 if executable('ls')
2264 " There should be ls in the $PATH
2265 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2266 call assert_match('^"r! .*\<ls\>', @:)
2267 endif
2268
2269 if executable('rm')
2270 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2271 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2272 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002273
2274 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2275 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2276 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002277 endif
2278endfunc
2279
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002280" Test for going up and down the directory tree using 'wildmenu'
2281func Test_wildmenu_dirstack()
2282 CheckUnix
2283 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002284 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002285 call writefile([], 'Xwildmenu/file1_1.txt')
2286 call writefile([], 'Xwildmenu/file1_2.txt')
2287 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2288 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2289 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2290 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2291 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2292 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002293 set wildmenu
2294
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002295 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002296 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002297 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002298 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002299 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002300 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002301 call assert_equal('"e ../../dir3/', @:)
2302 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2303 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002304 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002305 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002306 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002307 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002308 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002309 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2310 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002311
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002312 set wildmenu&
2313endfunc
2314
obcat71c6f7a2021-05-13 20:23:10 +02002315" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002316" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2317" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002318func Test_recalling_cmdline()
2319 CheckFeature cmdline_hist
2320
2321 let g:cmdlines = []
2322 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2323
2324 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002325 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2326 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2327 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2328 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002329 "\ TODO: {'name': 'debug', ...}
2330 \]
2331 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002332 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2333 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2334 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2335 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2336 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002337 \]
2338 let prefix = 'vi'
2339 for h in histories
2340 call histadd(h.name, 'vim')
2341 call histadd(h.name, 'virtue')
2342 call histadd(h.name, 'Virgo')
2343 call histadd(h.name, 'vogue')
2344 call histadd(h.name, 'emacs')
2345 for k in keypairs
2346 let g:cmdlines = []
2347 let keyseqs = h.enter
2348 \ .. prefix
2349 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2350 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2351 \ .. h.exit
2352 call feedkeys(keyseqs, 'xt')
2353 call histdel(h.name, -1) " delete the history added by feedkeys above
2354 let expect = k.prefixmatch
2355 \ ? ['virtue', 'vim', 'virtue', prefix]
2356 \ : ['emacs', 'vogue', 'emacs', prefix]
2357 call assert_equal(expect, g:cmdlines)
2358 endfor
2359 endfor
2360
2361 unlet g:cmdlines
2362 cunmap <Plug>(save-cmdline)
2363endfunc
2364
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002365func Test_cmd_map_cmdlineChanged()
2366 let g:log = []
2367 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002368 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002369 autocmd!
2370 autocmd CmdlineChanged : let g:log += [getcmdline()]
2371 augroup END
2372
2373 call feedkeys(":\<F1>\<CR>", 'xt')
2374 call assert_equal(['l', 'ls'], g:log)
2375
Bram Moolenaar796139a2021-05-18 21:38:45 +02002376 let @b = 'b'
2377 cnoremap <F1> a<C-R>b
2378 let g:log = []
2379 call feedkeys(":\<F1>\<CR>", 'xt')
2380 call assert_equal(['a', 'ab'], g:log)
2381
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002382 unlet g:log
2383 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002384 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002385 autocmd!
2386 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002387 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002388endfunc
2389
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002390" Test for the 'suffixes' option
2391func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002392 call writefile([], 'Xsuffile', 'D')
2393 call writefile([], 'Xsuffile.c', 'D')
2394 call writefile([], 'Xsuffile.o', 'D')
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 Xsuffile.c Xsuffile.o', @:)
2398 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2399 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002400 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002401 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2402 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2403 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2404 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002405 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002406 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2407 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2408 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2409 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002410 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002411 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002412 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2413 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002414endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002415
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002416" Test for using a popup menu for the command line completion matches
2417" (wildoptions=pum)
2418func Test_wildmenu_pum()
2419 CheckRunVimInTerminal
2420
2421 let commands =<< trim [CODE]
2422 set wildmenu
2423 set wildoptions=pum
2424 set shm+=I
2425 set noruler
2426 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002427
2428 func CmdCompl(a, b, c)
2429 return repeat(['aaaa'], 120)
2430 endfunc
2431 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002432
2433 func MyStatusLine() abort
2434 return 'status'
2435 endfunc
2436 func SetupStatusline()
2437 set statusline=%!MyStatusLine()
2438 set laststatus=2
2439 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002440
2441 func MyTabLine()
2442 return 'my tab line'
2443 endfunc
2444 func SetupTabline()
2445 set statusline=
2446 set tabline=%!MyTabLine()
2447 set showtabline=2
2448 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002449
2450 func DoFeedKeys()
2451 let &wildcharm = char2nr("\t")
2452 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2453 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002454 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002455 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002456
2457 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2458
2459 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002460 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2461
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002462 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002463 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002464 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2465
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002466 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002467 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002468 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2469
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002470 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002471 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002472 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2473
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002474 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002475 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002476 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2477
2478 " pressing <C-E> should end completion and go back to the original match
2479 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002480 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2481
2482 " pressing <C-Y> should select the current match and end completion
2483 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002484 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2485
2486 " With 'wildmode' set to 'longest,full', completing a match should display
2487 " the longest match, the wildmenu should not be displayed.
2488 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2489 call TermWait(buf)
2490 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002491 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2492
2493 " pressing <Tab> should display the wildmenu
2494 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002495 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2496
2497 " pressing <Tab> second time should select the next entry in the menu
2498 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002499 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2500
2501 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002502 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002503 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002504 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2505
2506 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002507 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2508
2509 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002510 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2511
2512 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002513 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002514 call writefile([], 'Xnamedir/XfileA')
2515 call writefile([], 'Xnamedir/XdirA/XfileB')
2516 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002517
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002518 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002519 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2520
2521 " Pressing <Right> on a directory name should go into that directory
2522 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002523 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2524
2525 " Pressing <Left> on a directory name should go to the parent directory
2526 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002527 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2528
2529 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002530 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002531 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002532 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2533
2534 " Pressing <C-D> when the popup menu is displayed should remove the popup
2535 " menu
2536 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002537 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2538
2539 " Pressing <S-Tab> should open the popup menu with the last entry selected
2540 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002541 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2542
2543 " Pressing <Esc> should close the popup menu and cancel the cmd line
2544 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002545 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2546
2547 " Typing a character when the popup is open, should close the popup
2548 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002549 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2550
2551 " When the popup is open, entering the cmdline window should close the popup
2552 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002553 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2554 call term_sendkeys(buf, ":q\<CR>")
2555
2556 " After the last popup menu item, <C-N> should show the original string
2557 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002558 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2559
2560 " Use the popup menu for the command name
2561 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002562 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2563
2564 " Pressing the left arrow should remove the popup menu
2565 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002566 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2567
2568 " Pressing <BS> should remove the popup menu and erase the last character
2569 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002570 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2571
2572 " Pressing <C-W> should remove the popup menu and erase the previous word
2573 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002574 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2575
2576 " Pressing <C-U> should remove the popup menu and erase the entire line
2577 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002578 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2579
2580 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2581 " the cmdline from history
2582 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002583 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2584
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002585 " Check "list" still works
2586 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2587 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002588 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2589 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002590 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2591
rbtnn68cc2b82022-02-09 11:55:47 +00002592 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002593 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002594 call writefile([], 'Xnamedir/あいう/abc')
2595 call writefile([], 'Xnamedir/あいう/xyz')
2596 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002597
2598 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002599 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002600 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2601
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002602 " Pressing <C-A> when the popup menu is displayed should list all the
2603 " matches and pressing a key after that should remove the popup menu
2604 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2605 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2606 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2607
2608 " Pressing <C-A> when the popup menu is displayed should list all the
2609 " matches and pressing <Left> after that should move the cursor
2610 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2611 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2612 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2613
2614 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2615 " should be displayed correctly on the screen.
2616 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2617 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2618
2619 " After using <C-A> to expand all the filename matches, pressing <Up>
2620 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002621 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002622 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2623 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2624 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2625
2626 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2627 " crash Vim
2628 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2629 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2630
Bram Moolenaar414acd32022-02-10 21:09:45 +00002631 " After removing the pum the command line is redrawn
2632 call term_sendkeys(buf, ":edit foo\<CR>")
2633 call term_sendkeys(buf, ":edit bar\<CR>")
2634 call term_sendkeys(buf, ":ls\<CR>")
2635 call term_sendkeys(buf, ":com\<Tab> ")
2636 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002637 call term_sendkeys(buf, "\<C-U>\<CR>")
2638
2639 " Esc still works to abort the command when 'statusline' is set
2640 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2641 call term_sendkeys(buf, ":si\<Tab>")
2642 call term_sendkeys(buf, "\<Esc>")
2643 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002644
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002645 " Esc still works to abort the command when 'tabline' is set
2646 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2647 call term_sendkeys(buf, ":si\<Tab>")
2648 call term_sendkeys(buf, "\<Esc>")
2649 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2650
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002651 " popup is cleared also when 'lazyredraw' is set
2652 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2653 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2654 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2655 call term_sendkeys(buf, "\<Esc>")
2656
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002657 " Pressing <PageDown> should scroll the menu downward
2658 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2659 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2660 call term_sendkeys(buf, "\<PageDown>")
2661 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2662 call term_sendkeys(buf, "\<PageDown>")
2663 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2664 call term_sendkeys(buf, "\<PageDown>")
2665 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2666 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2667 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2668
2669 " Pressing <PageUp> should scroll the menu upward
2670 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2671 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2672 call term_sendkeys(buf, "\<PageUp>")
2673 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2674 call term_sendkeys(buf, "\<PageUp>")
2675 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2676 call term_sendkeys(buf, "\<PageUp>")
2677 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2678
Yee Cheng Chin209ec902023-10-17 10:56:25 +02002679 " pressing <C-E> to end completion should work in middle of the line too
2680 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
2681 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
2682 call term_sendkeys(buf, "\<C-E>")
2683 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
2684
2685 " pressing <C-Y> should select the current match and end completion
2686 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
2687 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
2688
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002689 call term_sendkeys(buf, "\<C-U>\<CR>")
2690 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002691endfunc
2692
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002693" Test for wildmenumode() with the cmdline popup menu
2694func Test_wildmenumode_with_pum()
2695 set wildmenu
2696 set wildoptions=pum
2697 cnoremap <expr> <F2> wildmenumode()
2698 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2699 call assert_equal('"sign define10', @:)
2700 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2701 call assert_equal('"sign define jump list place undefine unplace0', @:)
2702 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2703 call assert_equal('"sign 0', @:)
2704 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2705 call assert_equal('"sign define0', @:)
2706 set nowildmenu wildoptions&
2707 cunmap <F2>
2708endfunc
2709
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002710func Test_wildmenu_with_pum_foldexpr()
2711 CheckRunVimInTerminal
2712
2713 let lines =<< trim END
2714 call setline(1, ['folded one', 'folded two', 'some more text'])
2715 func MyFoldText()
2716 return 'foo'
2717 endfunc
2718 set foldtext=MyFoldText() wildoptions=pum
2719 normal ggzfj
2720 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002721 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002722 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2723 call term_sendkeys(buf, ":set\<Tab>")
2724 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2725
2726 call term_sendkeys(buf, "\<Esc>")
2727 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2728
2729 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002730endfunc
2731
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002732" Test for opening the cmdline completion popup menu from the terminal window.
2733" The popup menu should be positioned correctly over the status line of the
2734" bottom-most window.
2735func Test_wildmenu_pum_from_terminal()
2736 CheckRunVimInTerminal
2737 let python = PythonProg()
2738 call CheckPython(python)
2739
2740 %bw!
2741 let cmds = ['set wildmenu wildoptions=pum']
2742 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2743 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002744 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002745 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2746 call term_sendkeys(buf, "\r\r\r")
2747 call term_wait(buf)
2748 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2749 call term_wait(buf)
2750 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2751 call term_wait(buf)
2752 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002753endfunc
2754
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002755func Test_wildmenu_pum_odd_wildchar()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002756 CheckRunVimInTerminal
2757
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002758 " Test odd wildchar interactions with pum. Make sure they behave properly
2759 " and don't lead to memory corruption due to improperly cleaned up memory.
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002760 let lines =<< trim END
2761 set wildoptions=pum
2762 set wildchar=<C-E>
2763 END
2764 call writefile(lines, 'XwildmenuTest', 'D')
2765 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2766
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002767 call term_sendkeys(buf, ":\<C-E>")
2768 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002769
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +02002770 " <C-E> being a wildchar takes priority over its original functionality
2771 call term_sendkeys(buf, "\<C-E>")
2772 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
2773
2774 call term_sendkeys(buf, "\<Esc>")
2775 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2776
2777 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
2778 " command-line, and we need to make sure to clean up properly.
2779 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
2780 call term_sendkeys(buf, ":\<Esc>")
2781 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2782
2783 call term_sendkeys(buf, "\<Esc>")
2784 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2785
2786 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
2787 " and we again need to make sure we clean up properly.
2788 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
2789 call term_sendkeys(buf, ":\<C-\>\<C-\>")
2790 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
2791
2792 call term_sendkeys(buf, "\<C-N>")
2793 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
2794
2795 call StopVimInTerminal(buf)
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002796endfunc
2797
zeertzjq883018f2024-06-15 15:37:11 +02002798" Test that 'rightleft' should not affect cmdline completion popup menu.
2799func Test_wildmenu_pum_rightleft()
2800 CheckFeature rightleft
2801 CheckScreendump
2802
2803 let lines =<< trim END
2804 set wildoptions=pum
2805 set rightleft
2806 END
2807 call writefile(lines, 'Xwildmenu_pum_rl', 'D')
2808 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
2809
2810 call term_sendkeys(buf, ":sign \<Tab>")
2811 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
2812
2813 call StopVimInTerminal(buf)
2814endfunc
2815
zeertzjqd8c93402024-06-17 18:25:32 +02002816" Test highlighting matched text in cmdline completion popup menu.
2817func Test_wildmenu_pum_hl_match()
2818 CheckScreendump
2819
2820 let lines =<< trim END
2821 set wildoptions=pum,fuzzy
2822 hi PmenuMatchSel ctermfg=6 ctermbg=7
2823 hi PmenuMatch ctermfg=4 ctermbg=225
2824 END
2825 call writefile(lines, 'Xwildmenu_pum_hl', 'D')
2826 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
2827
2828 call term_sendkeys(buf, ":sign plc\<Tab>")
2829 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
2830 call term_sendkeys(buf, "\<Tab>")
2831 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
2832 call term_sendkeys(buf, "\<Tab>")
2833 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
2834 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
2835 call TermWait(buf)
2836 call term_sendkeys(buf, ":sign un\<Tab>")
2837 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
2838 call term_sendkeys(buf, "\<Tab>")
2839 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
2840 call term_sendkeys(buf, "\<Tab>")
2841 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
2842 call term_sendkeys(buf, "\<Esc>")
2843
2844 call StopVimInTerminal(buf)
2845endfunc
2846
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002847" Test for completion after a :substitute command followed by a pipe (|)
2848" character
2849func Test_cmdline_complete_substitute()
2850 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2851 call assert_equal("\"s | \t", @:)
2852 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2853 call assert_equal("\"s/ | \t", @:)
2854 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2855 call assert_equal("\"s/one | \t", @:)
2856 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2857 call assert_equal("\"s/one/ | \t", @:)
2858 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2859 call assert_equal("\"s/one/two | \t", @:)
2860 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2861 call assert_equal('"s/one/two/ | chistory', @:)
2862 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2863 call assert_equal("\"s/one/two/g \t", @:)
2864 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2865 call assert_equal("\"s/one/two/g | chistory", @:)
2866 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2867 call assert_equal("\"s/one/t\\/ | \t", @:)
2868 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2869 call assert_equal('"s/one/t"o/ | chistory', @:)
2870 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2871 call assert_equal('"s/one/t|o/ | chistory', @:)
2872 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2873 call assert_equal("\"&\t", @:)
2874endfunc
2875
2876" Test for the :dlist command completion
2877func Test_cmdline_complete_dlist()
2878 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2879 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2880 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2881 call assert_equal("\"dlist 10 /pat/ \t", @:)
2882 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2883 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2884 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2885 call assert_equal("\"dlist 10 /pat\\\t", @:)
2886 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2887 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2888endfunc
2889
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890" argument list (only for :argdel) fuzzy completion
2891func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002892 argadd change.py count.py charge.py
2893 set wildoptions&
2894 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2895 call assert_equal('"argdel cge', @:)
2896 set wildoptions=fuzzy
2897 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2898 call assert_equal('"argdel change.py charge.py', @:)
2899 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002900 set wildoptions&
2901endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002902
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903" autocmd group name fuzzy completion
2904func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905 set wildoptions&
2906 augroup MyFuzzyGroup
2907 augroup END
2908 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2909 call assert_equal('"augroup mfg', @:)
2910 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2911 call assert_equal('"augroup MyFuzzyGroup', @:)
2912 set wildoptions=fuzzy
2913 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2914 call assert_equal('"augroup MyFuzzyGroup', @:)
2915 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2916 call assert_equal('"augroup My*p', @:)
2917 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002918 set wildoptions&
2919endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002920
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002921" buffer name fuzzy completion
2922func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002923 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002924 " Use a long name to reduce the risk of matching a random directory name
2925 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002927 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2928 call assert_equal('"b SRFWL', @:)
2929 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2930 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002931 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002932 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2934 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2935 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002936 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002937 set wildoptions&
2938endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002939
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002940" buffer name (full path) fuzzy completion
2941func Test_fuzzy_completion_bufname_fullpath()
2942 CheckUnix
2943 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002944 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002945 edit Xcmd/Xstate/Xfile.js
2946 cd Xcmd/Xstate
2947 enew
2948 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2949 call assert_equal('"b CmdStateFile', @:)
2950 set wildoptions=fuzzy
2951 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2952 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2953 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002954 set wildoptions&
2955endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002956
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002957" :behave suboptions fuzzy completion
2958func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002959 set wildoptions&
2960 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('"behave xm', @:)
2962 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2963 call assert_equal('"behave xterm', @:)
2964 set wildoptions=fuzzy
2965 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal('"behave xterm', @:)
2967 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal('"behave xt*m', @:)
2969 let g:Sline = ''
2970 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2971 call assert_equal('mswin', g:Sline)
2972 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002973 set wildoptions&
2974endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002975
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002976" " colorscheme name fuzzy completion - NOT supported
2977" func Test_fuzzy_completion_colorscheme()
2978" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002980" built-in command name fuzzy completion
2981func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002982 set wildoptions&
2983 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal('"sbwin', @:)
2985 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2986 call assert_equal('"sbrewind', @:)
2987 set wildoptions=fuzzy
2988 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2989 call assert_equal('"sbrewind', @:)
2990 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002992 set wildoptions&
2993endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002994
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002995" " compiler name fuzzy completion - NOT supported
2996" func Test_fuzzy_completion_compiler()
2997" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002998
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002999" :cscope suboptions fuzzy completion
3000func Test_fuzzy_completion_cscope()
3001 CheckFeature cscope
3002 set wildoptions&
3003 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3004 call assert_equal('"cscope ret', @:)
3005 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3006 call assert_equal('"cscope reset', @:)
3007 set wildoptions=fuzzy
3008 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
3009 call assert_equal('"cscope reset', @:)
3010 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
3011 call assert_equal('"cscope re*t', @:)
3012 set wildoptions&
3013endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003014
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003015" :diffget/:diffput buffer name fuzzy completion
3016func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003017 new SomeBuffer
3018 diffthis
3019 new OtherBuffer
3020 diffthis
3021 set wildoptions&
3022 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3023 call assert_equal('"diffget sbuf', @:)
3024 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal('"diffput sbuf', @:)
3026 set wildoptions=fuzzy
3027 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal('"diffget SomeBuffer', @:)
3029 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal('"diffput SomeBuffer', @:)
3031 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003032 set wildoptions&
3033endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003034
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003035" " directory name fuzzy completion - NOT supported
3036" func Test_fuzzy_completion_dirname()
3037" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003038
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003039" environment variable name fuzzy completion
3040func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003041 set wildoptions&
3042 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal('"echo $VUT', @:)
3044 set wildoptions=fuzzy
3045 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003047 set wildoptions&
3048endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003049
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003050" autocmd event fuzzy completion
3051func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003052 set wildoptions&
3053 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal('"autocmd BWout', @:)
3055 set wildoptions=fuzzy
3056 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003058 set wildoptions&
3059endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003060
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003061" vim expression fuzzy completion
3062func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003063 let g:PerPlaceCount = 10
3064 set wildoptions&
3065 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3066 call assert_equal('"let c = ppc', @:)
3067 set wildoptions=fuzzy
3068 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003070 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003071endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003072
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003073" " file name fuzzy completion - NOT supported
3074" func Test_fuzzy_completion_filename()
3075" endfunc
3076
3077" " files in path fuzzy completion - NOT supported
3078" func Test_fuzzy_completion_filesinpath()
3079" endfunc
3080
3081" " filetype name fuzzy completion - NOT supported
3082" func Test_fuzzy_completion_filetype()
3083" endfunc
3084
3085" user defined function name completion
3086func Test_fuzzy_completion_userdefined_func()
3087 set wildoptions&
3088 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3089 call assert_equal('"call Test_f_u_f', @:)
3090 set wildoptions=fuzzy
3091 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
3093 set wildoptions&
3094endfunc
3095
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003096" <SNR> functions should be sorted to the end
3097func Test_fuzzy_completion_userdefined_snr_func()
3098 func s:Sendmail()
3099 endfunc
3100 func SendSomemail()
3101 endfunc
3102 func S1e2n3dmail()
3103 endfunc
3104 set wildoptions=fuzzy
3105 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00003106 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00003107 set wildoptions&
3108 delfunc s:Sendmail
3109 delfunc SendSomemail
3110 delfunc S1e2n3dmail
3111endfunc
3112
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003113" user defined command name completion
3114func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003115 set wildoptions&
3116 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal('"MsFeat', @:)
3118 set wildoptions=fuzzy
3119 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003121 set wildoptions&
3122endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003123
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003124" " :help tag fuzzy completion - NOT supported
3125" func Test_fuzzy_completion_helptag()
3126" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003127
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003128" highlight group name fuzzy completion
3129func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003130 set wildoptions&
3131 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal('"highlight SKey', @:)
3133 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal('"highlight SpecialKey', @:)
3135 set wildoptions=fuzzy
3136 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal('"highlight SpecialKey', @:)
3138 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003140 set wildoptions&
3141endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003142
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003143" :history suboptions fuzzy completion
3144func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003145 set wildoptions&
3146 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal('"history dg', @:)
3148 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal('"history search', @:)
3150 set wildoptions=fuzzy
3151 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal('"history debug', @:)
3153 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003155 set wildoptions&
3156endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003157
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003158" :language locale name fuzzy completion
3159func Test_fuzzy_completion_lang()
3160 CheckUnix
3161 set wildoptions&
3162 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3163 call assert_equal('"lang psx', @:)
3164 set wildoptions=fuzzy
3165 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal('"lang POSIX', @:)
3167 set wildoptions&
3168endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003169
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003170" :mapclear buffer argument fuzzy completion
3171func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003172 set wildoptions&
3173 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal('"mapclear buf', @:)
3175 set wildoptions=fuzzy
3176 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003178 set wildoptions&
3179endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003180
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003181" map name fuzzy completion
3182func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00003183 " test regex completion works
3184 set wildoptions=fuzzy
3185 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003187 nmap <plug>MyLongMap :p<CR>
3188 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3189 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3190 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal("\"nmap MLM \t", @:)
3192 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3193 call assert_equal("\"nmap <F2> one two \t", @:)
3194 " duplicate entries should be removed
3195 vmap <plug>MyLongMap :<C-U>#<CR>
3196 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3198 nunmap <plug>MyLongMap
3199 vunmap <plug>MyLongMap
3200 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"nmap ABC\t", @:)
3202 " results should be sorted by best match
3203 nmap <Plug>format :
3204 nmap <Plug>goformat :
3205 nmap <Plug>TestFOrmat :
3206 nmap <Plug>fendoff :
3207 nmap <Plug>state :
3208 nmap <Plug>FendingOff :
3209 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3211 nunmap <Plug>format
3212 nunmap <Plug>goformat
3213 nunmap <Plug>TestFOrmat
3214 nunmap <Plug>fendoff
3215 nunmap <Plug>state
3216 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003217 set wildoptions&
3218endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003219
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003220" abbreviation fuzzy completion
3221func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003222 set wildoptions=fuzzy
3223 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"iabbr <nowait>", @:)
3225 iabbr WaitForCompletion WFC
3226 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3227 call assert_equal("\"iabbr WaitForCompletion", @:)
3228 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3229 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003230
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003231 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003232 set wildoptions&
3233endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003234
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003235" menu name fuzzy completion
3236func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003237 CheckFeature menu
3238
3239 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003240 set wildoptions&
3241 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal('"menu pup', @:)
3243 set wildoptions=fuzzy
3244 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3245 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003246
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003247 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003248 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003249endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003250
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003251" :messages suboptions fuzzy completion
3252func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003253 set wildoptions&
3254 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3255 call assert_equal('"messages clr', @:)
3256 set wildoptions=fuzzy
3257 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003259 set wildoptions&
3260endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003261
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003262" :set option name fuzzy completion
3263func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003264 set wildoptions&
3265 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal('"set brkopt', @:)
3267 set wildoptions=fuzzy
3268 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal('"set breakindentopt', @:)
3270 set wildoptions&
3271 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal('"set fixendofline', @:)
3273 set wildoptions=fuzzy
3274 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3275 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003276 set wildoptions&
3277endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003278
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003279" :set <term_option>
3280func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003281 set wildoptions&
3282 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3283 call assert_equal('"set t_EC', @:)
3284 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3285 call assert_equal('"set <t_EC>', @:)
3286 set wildoptions=fuzzy
3287 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal('"set t_EC', @:)
3289 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003291 set wildoptions&
3292endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003293
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003294" " :packadd directory name fuzzy completion - NOT supported
3295" func Test_fuzzy_completion_packadd()
3296" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003297
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003298" " shell command name fuzzy completion - NOT supported
3299" func Test_fuzzy_completion_shellcmd()
3300" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003301
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003302" :sign suboptions fuzzy completion
3303func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003304 set wildoptions&
3305 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal('"sign ufe', @:)
3307 set wildoptions=fuzzy
3308 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003310 set wildoptions&
3311endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003312
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003313" :syntax suboptions fuzzy completion
3314func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003315 set wildoptions&
3316 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3317 call assert_equal('"syntax kwd', @:)
3318 set wildoptions=fuzzy
3319 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003321 set wildoptions&
3322endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003323
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003324" syntax group name fuzzy completion
3325func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003326 set wildoptions&
3327 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3328 call assert_equal('"syntax list mpar', @:)
3329 set wildoptions=fuzzy
3330 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3331 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003332 set wildoptions&
3333endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003334
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003335" :syntime suboptions fuzzy completion
3336func Test_fuzzy_completion_syntime()
3337 CheckFeature profile
3338 set wildoptions&
3339 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3340 call assert_equal('"syntime clr', @:)
3341 set wildoptions=fuzzy
3342 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3343 call assert_equal('"syntime clear', @:)
3344 set wildoptions&
3345endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003346
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003347" " tag name fuzzy completion - NOT supported
3348" func Test_fuzzy_completion_tagname()
3349" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003350
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003351" " tag name and file fuzzy completion - NOT supported
3352" func Test_fuzzy_completion_tagfile()
3353" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003354
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003355" " user names fuzzy completion - how to test this functionality?
3356" func Test_fuzzy_completion_username()
3357" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003358
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003359" user defined variable name fuzzy completion
3360func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003361 let g:SomeVariable=10
3362 set wildoptions&
3363 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3364 call assert_equal('"let SVar', @:)
3365 set wildoptions=fuzzy
3366 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3367 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003368 set wildoptions&
3369endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003370
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003371" Test for sorting the results by the best match
3372func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003373 %bw!
3374 command T123format :
3375 command T123goformat :
3376 command T123TestFOrmat :
3377 command T123fendoff :
3378 command T123state :
3379 command T123FendingOff :
3380 set wildoptions=fuzzy
3381 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3382 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3383 delcommand T123format
3384 delcommand T123goformat
3385 delcommand T123TestFOrmat
3386 delcommand T123fendoff
3387 delcommand T123state
3388 delcommand T123FendingOff
3389 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003390 set wildoptions&
3391endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003392
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003393" Test for fuzzy completion of a command with lower case letters and a number
3394func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003395 command Foo2Bar :
3396 set wildoptions=fuzzy
3397 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3398 call assert_equal('"Foo2Bar', @:)
3399 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3400 call assert_equal('"Foo2Bar', @:)
3401 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3402 call assert_equal('"Foo2Bar', @:)
3403 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003404 set wildoptions&
3405endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003406
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003407" Test for command completion for a command starting with 'k'
3408func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003409 command KillKillKill :
3410 set wildoptions&
3411 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3412 call assert_equal("\"killkill\<Tab>", @:)
3413 set wildoptions=fuzzy
3414 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3415 call assert_equal('"KillKillKill', @:)
3416 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003417 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003418endfunc
3419
3420" Test for fuzzy completion for user defined custom completion function
3421func Test_fuzzy_completion_custom_func()
3422 func Tcompl(a, c, p)
3423 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3424 endfunc
3425 command -nargs=* -complete=custom,Tcompl Fuzzy :
3426 set wildoptions&
3427 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3428 call assert_equal("\"Fuzzy format", @:)
3429 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3430 call assert_equal("\"Fuzzy xy", @:)
3431 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal("\"Fuzzy ttt", @:)
3433 set wildoptions=fuzzy
3434 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3435 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3436 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3437 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3438 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3439 call assert_equal("\"Fuzzy xy", @:)
3440 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3441 call assert_equal("\"Fuzzy TestFOrmat", @:)
3442 delcom Fuzzy
3443 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003444endfunc
3445
Yee Cheng Chin209ec902023-10-17 10:56:25 +02003446" Test for fuzzy completion in the middle of a cmdline instead of at the end
3447func Test_fuzzy_completion_in_middle()
3448 set wildoptions=fuzzy
3449 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3450 call assert_equal("\"set wildchar wildcharm wrap", @:)
3451
3452 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
3453 call assert_equal("\"args ++encoding= zz", @:)
3454 set wildoptions&
3455endfunc
3456
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003457" Test for :breakadd argument completion
3458func Test_cmdline_complete_breakadd()
3459 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3460 call assert_equal("\"breakadd expr file func here", @:)
3461 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3462 call assert_equal("\"breakadd expr", @:)
3463 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3464 call assert_equal("\"breakadd expr", @:)
3465 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3466 call assert_equal("\"breakadd here", @:)
3467 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3468 call assert_equal("\"breakadd here", @:)
3469 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3470 call assert_equal("\"breakadd abc", @:)
3471 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3472 let l = getcompletion('not', 'breakpoint')
3473 call assert_equal([], l)
3474
3475 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003476 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003477 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3478 call assert_equal("\"breakadd file Xscript", @:)
3479 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3480 call assert_equal("\"breakadd file Xscript", @:)
3481 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3482 call assert_equal("\"breakadd file 20 Xscript", @:)
3483 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3484 call assert_equal("\"breakadd file 20 Xscript", @:)
3485 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3486 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3487 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3488 call assert_equal("\"breakadd file 20\t", @:)
3489 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3490 call assert_equal("\"breakadd file 20x\t", @:)
3491 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3492 call assert_equal("\"breakadd file Xscript ", @:)
3493 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3494 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003495
3496 " Test for :breakadd func [lnum] <function>
3497 func Xbreak_func()
3498 endfunc
3499 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3500 call assert_equal("\"breakadd func Xbreak_func", @:)
3501 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3502 call assert_equal("\"breakadd func Xbreak_func", @:)
3503 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3504 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3505 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3506 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3507 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3508 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3509 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3510 call assert_equal("\"breakadd func 20\t", @:)
3511 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3512 call assert_equal("\"breakadd func 20x\t", @:)
3513 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3514 call assert_equal("\"breakadd func Xbreak_func ", @:)
3515 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3516 call assert_equal("\"breakadd func X1B2C3", @:)
3517 delfunc Xbreak_func
3518
3519 " Test for :breakadd expr <expression>
3520 let g:Xtest_var = 10
3521 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3522 call assert_equal("\"breakadd expr Xtest_var", @:)
3523 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3524 call assert_equal("\"breakadd expr Xtest_var", @:)
3525 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3526 call assert_equal("\"breakadd expr Xtest_var ", @:)
3527 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3528 call assert_equal("\"breakadd expr X1B2C3", @:)
3529 unlet g:Xtest_var
3530
3531 " Test for :breakadd here
3532 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3533 call assert_equal("\"breakadd here Xtest", @:)
3534 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3535 call assert_equal("\"breakadd here Xtest", @:)
3536 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3537 call assert_equal("\"breakadd here ", @:)
3538endfunc
3539
3540" Test for :breakdel argument completion
3541func Test_cmdline_complete_breakdel()
3542 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3543 call assert_equal("\"breakdel file func here", @:)
3544 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3545 call assert_equal("\"breakdel file", @:)
3546 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3547 call assert_equal("\"breakdel file", @:)
3548 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3549 call assert_equal("\"breakdel here", @:)
3550 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3551 call assert_equal("\"breakdel here", @:)
3552 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3553 call assert_equal("\"breakdel abc", @:)
3554
3555 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003556 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003557 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3558 call assert_equal("\"breakdel file Xscript", @:)
3559 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3560 call assert_equal("\"breakdel file Xscript", @:)
3561 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3562 call assert_equal("\"breakdel file 20 Xscript", @:)
3563 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3564 call assert_equal("\"breakdel file 20 Xscript", @:)
3565 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3566 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3567 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3568 call assert_equal("\"breakdel file 20\t", @:)
3569 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3570 call assert_equal("\"breakdel file 20x\t", @:)
3571 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3572 call assert_equal("\"breakdel file Xscript ", @:)
3573 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3574 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003575
3576 " Test for :breakdel func [lnum] <function>
3577 func Xbreak_func()
3578 endfunc
3579 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3580 call assert_equal("\"breakdel func Xbreak_func", @:)
3581 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3582 call assert_equal("\"breakdel func Xbreak_func", @:)
3583 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3584 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3585 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3586 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3587 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3588 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3589 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3590 call assert_equal("\"breakdel func 20\t", @:)
3591 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3592 call assert_equal("\"breakdel func 20x\t", @:)
3593 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3594 call assert_equal("\"breakdel func Xbreak_func ", @:)
3595 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3596 call assert_equal("\"breakdel func X1B2C3", @:)
3597 delfunc Xbreak_func
3598
3599 " Test for :breakdel here
3600 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3601 call assert_equal("\"breakdel here Xtest", @:)
3602 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3603 call assert_equal("\"breakdel here Xtest", @:)
3604 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3605 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003606endfunc
3607
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003608" Test for :scriptnames argument completion
3609func Test_cmdline_complete_scriptnames()
3610 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003611 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003612 source Xa1b2c3.vim
3613 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3614 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3615 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3616 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3617 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3618 call assert_equal("\"script b2c3", @:)
3619 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3620 call assert_match("\"script 2\<Tab>$", @:)
3621 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3622 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3623 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3624 call assert_equal("\"script ", @:)
3625 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3626 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3627 new
3628 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3629 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3630 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003631 set wildmenu&
3632endfunc
3633
Bram Moolenaard8893442022-05-06 20:38:47 +01003634" this was going over the end of IObuff
3635func Test_report_error_with_composing()
3636 let caught = 'no'
3637 try
3638 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3639 catch /E492:/
3640 let caught = 'yes'
3641 endtry
3642 call assert_equal('yes', caught)
3643endfunc
3644
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003645" Test for expanding 2-letter and 3-letter :substitute command arguments.
3646" These commands don't accept an argument.
3647func Test_cmdline_complete_substitute_short()
3648 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3649 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3650 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3651 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3652 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3653 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3654 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3655 endfor
3656endfunc
3657
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003658" Test for shellcmdline command argument completion
3659func Test_cmdline_complete_shellcmdline_argument()
3660 command -nargs=+ -complete=shellcmdline MyCmd
3661
3662 set wildoptions=fuzzy
3663
3664 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3665 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003666 call assert_equal(['test_cmdline.vim'],
3667 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003668
3669 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3670 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003671 call assert_equal([],
3672 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003673
3674 let compl1 = getcompletion('', 'file')[0]
3675 let compl2 = getcompletion('', 'file')[1]
3676 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3677 call assert_equal('"MyCmd vim ' .. compl1, @:)
3678
3679 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3680 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3681
3682 let compl = getcompletion('', 'file')[1]
3683 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3684 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3685
3686 set wildoptions&
3687 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3688 call assert_equal('"MyCmd vim test_cmdline.vim', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003689 call assert_equal(['test_cmdline.vim'],
3690 \ getcompletion('vim test_cmdline.', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003691
3692 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
3693 call assert_equal('"MyCmd vim nonexistentfile', @:)
zeertzjq85f36d62024-10-10 19:14:13 +02003694 call assert_equal([],
3695 \ getcompletion('vim nonexistentfile', 'shellcmdline'))
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003696
3697 let compl1 = getcompletion('', 'file')[0]
3698 let compl2 = getcompletion('', 'file')[1]
3699 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
3700 call assert_equal('"MyCmd vim ' .. compl1, @:)
3701
3702 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
3703 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
3704
3705 let compl = getcompletion('', 'file')[1]
3706 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
3707 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
3708
3709 delcommand MyCmd
3710endfunc
3711
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003712" Test for :! shell command argument completion
3713func Test_cmdline_complete_bang_cmd_argument()
3714 set wildoptions=fuzzy
3715 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3716 call assert_equal('"!vim test_cmdline.vim', @:)
3717 set wildoptions&
3718 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3719 call assert_equal('"!vim test_cmdline.vim', @:)
3720endfunc
3721
zeertzjq961b2e52023-04-17 15:53:24 +01003722func Call_cmd_funcs()
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003723 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003724endfunc
3725
3726func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003727 call assert_equal(0, getcmdpos())
3728 call assert_equal(0, getcmdscreenpos())
3729 call assert_equal('', getcmdcompltype())
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003730 call assert_equal('', getcmdcomplpat())
zeertzjq961b2e52023-04-17 15:53:24 +01003731
zeertzjqa821b602024-06-18 20:31:08 +02003732 cnoremap <expr> <F2> string(Call_cmd_funcs())
zeertzjq961b2e52023-04-17 15:53:24 +01003733 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003734 call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003735 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003736 call assert_equal("\"quit [6, 7, '', '']", @:)
zeertzjq961b2e52023-04-17 15:53:24 +01003737 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003738 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
zeertzjqa821b602024-06-18 20:31:08 +02003739
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003740 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
3741 " cmdline completion.
zeertzjqa821b602024-06-18 20:31:08 +02003742 let g:results = []
3743 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
3744 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
3745 call assert_equal([
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003746 \ ['sign undefine', 14, 15, 'sign', 'undefine'],
3747 \ ['sign unplace', 13, 14, 'sign', 'unplace'],
3748 \ ['sign un', 8, 9, 'sign', 'un']], g:results)
zeertzjqa821b602024-06-18 20:31:08 +02003749
3750 unlet g:results
zeertzjq961b2e52023-04-17 15:53:24 +01003751 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003752endfunc
3753
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003754func Test_recursive_register()
3755 let @= = ''
3756 silent! ?e/
3757 let caught = 'no'
3758 try
3759 normal //
3760 catch /E169:/
3761 let caught = 'yes'
3762 endtry
3763 call assert_equal('yes', caught)
3764endfunc
3765
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003766func Test_long_error_message()
3767 " the error should be truncated, not overrun IObuff
3768 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3769endfunc
3770
zeertzjq6791adc2022-07-26 20:42:25 +01003771func Test_cmdline_redraw_tabline()
3772 CheckRunVimInTerminal
3773
3774 let lines =<< trim END
3775 set showtabline=2
3776 autocmd CmdlineEnter * set tabline=foo
3777 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003778 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003779 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3780 call term_sendkeys(buf, ':')
3781 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3782
3783 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003784endfunc
3785
zeertzjqb82a2ab2022-08-21 14:33:57 +01003786func Test_wildmenu_pum_disable_while_shown()
3787 set wildoptions=pum
3788 set wildmenu
3789 cnoremap <F2> <Cmd>set nowildmenu<CR>
3790 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3791 call assert_equal(0, pumvisible())
3792 cunmap <F2>
3793 set wildoptions& wildmenu&
3794endfunc
3795
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003796func Test_setcmdline()
3797 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003798 call assert_equal(0, setcmdline(test_null_string()))
3799 call assert_equal('', getcmdline())
3800 call assert_equal(1, getcmdpos())
3801
3802 call assert_equal(0, setcmdline(''[: -1]))
3803 call assert_equal('', getcmdline())
3804 call assert_equal(1, getcmdpos())
3805
zeertzjq54acb902022-08-29 16:21:25 +01003806 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003807 call assert_equal(0, setcmdline(a:text))
3808 call assert_equal(a:text, getcmdline())
3809 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003810 call assert_equal(getcmdtype(), g:cmdtype)
3811 unlet g:cmdtype
3812 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003813
3814 call assert_equal(0, setcmdline(a:text, a:pos))
3815 call assert_equal(a:text, getcmdline())
3816 call assert_equal(a:pos, getcmdpos())
3817
3818 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003819 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3820 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003821
3822 return ''
3823 endfunc
3824
3825 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3826 call assert_equal('set rtp?', @:)
3827
zeertzjq54acb902022-08-29 16:21:25 +01003828 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3829 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3830 call assert_equal('foo', g:str)
3831 unlet g:str
3832
3833 delfunc SetText
3834
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003835 " setcmdline() returns 1 when not editing the command line.
3836 call assert_equal(1, 'foo'->setcmdline())
3837
3838 " Called in custom function
3839 func CustomComplete(A, L, P)
3840 call assert_equal(0, setcmdline("DoCmd "))
3841 return "January\nFebruary\nMars\n"
3842 endfunc
3843
3844 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3845 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3846 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003847 delcom DoCmd
3848 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003849
3850 " Called in <expr>
3851 cnoremap <expr>a setcmdline('let foo=')
3852 call feedkeys(":a\<CR>", 'tx')
3853 call assert_equal('let foo=0', @:)
3854 cunmap a
3855endfunc
3856
Sean Dewarfc8a6012023-04-17 16:41:20 +01003857func Test_rulerformat_position()
3858 CheckScreendump
3859
3860 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3861 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3862 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3863 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3864 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3865
3866 " clean up
3867 call StopVimInTerminal(buf)
3868endfunc
3869
Yegappan Lakshmananac023e82024-11-27 20:55:45 +01003870" Test for using "%!" in 'rulerformat' to use a function
3871func Test_rulerformat_function()
3872 CheckScreendump
3873
3874 let lines =<< trim END
3875 func TestRulerFn()
3876 return '10,20%=30%%'
3877 endfunc
3878 END
3879 call writefile(lines, 'Xrulerformat_function', 'D')
3880
3881 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
3882 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
3883 call term_sendkeys(buf, ":redraw!\<CR>")
3884 call term_wait(buf)
3885 call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
3886
3887 " clean up
3888 call StopVimInTerminal(buf)
3889endfunc
3890
zeertzjqe4c79d32023-08-15 22:41:53 +02003891func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003892 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003893
zeertzjqe4c79d32023-08-15 22:41:53 +02003894 call assert_equal(getcompletion('', 'cmdline'),
3895 \ getcompletion('TestCompletion ', 'cmdline'))
3896 call assert_equal(['<buffer>'],
3897 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3898
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003899 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003900endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003901
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003902func Test_custom_completion()
3903 func CustomComplete1(lead, line, pos)
3904 return "a\nb\nc"
3905 endfunc
3906 func CustomComplete2(lead, line, pos)
3907 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3908 endfunc
3909 func Check_custom_completion()
3910 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3911 return ''
3912 endfunc
3913 func Check_customlist_completion()
3914 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3915 return ''
3916 endfunc
3917
3918 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3919 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3920
3921 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3922 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3923
3924 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3925 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3926
zeertzjq757f3212024-04-15 19:01:04 +02003927 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
3928 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
3929 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003930
3931 delcom Test1
3932 delcom Test2
3933
3934 delfunc CustomComplete1
3935 delfunc CustomComplete2
3936 delfunc Check_custom_completion
3937 delfunc Check_customlist_completion
3938endfunc
3939
zeertzjq28a23602023-09-29 19:58:35 +02003940func Test_custom_completion_with_glob()
3941 func TestGlobComplete(A, L, P)
3942 return split(glob('Xglob*'), "\n")
3943 endfunc
3944
3945 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3946 call writefile([], 'Xglob1', 'D')
3947 call writefile([], 'Xglob2', 'D')
3948
3949 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3950 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3951
3952 delcommand TestGlobComplete
3953 delfunc TestGlobComplete
3954endfunc
3955
Christian Brabandt8610f742024-01-12 17:34:40 +01003956func Test_window_size_stays_same_after_changing_cmdheight()
3957 set laststatus=2
3958 let expected = winheight(0)
3959 function! Function_name() abort
3960 call feedkeys(":"..repeat('x', &columns), 'x')
3961 let &cmdheight=2
3962 let &cmdheight=1
3963 redraw
3964 endfunction
3965 call Function_name()
3966 call assert_equal(expected, winheight(0))
3967endfunc
3968
Christian Brabandt0dc0bff2024-02-24 14:12:13 +01003969" verify that buffer-completion finds all buffer names matching a pattern
3970func Test_buffer_completion()
3971 " should return empty list
3972 call assert_equal([], getcompletion('', 'buffer'))
3973
3974 call mkdir('Xbuf_complete', 'R')
3975 e Xbuf_complete/Foobar.c
3976 e Xbuf_complete/MyFoobar.c
3977 e AFoobar.h
3978 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
3979
3980 call assert_equal(3, len(getcompletion('Foo', 'buffer')))
3981 call assert_equal(expected, getcompletion('Foo', 'buffer'))
3982 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
3983 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
3984endfunc
3985
Anton Sharonov49528da2024-04-14 20:02:24 +02003986" :set t_??
3987func Test_term_option()
3988 set wildoptions&
3989 let _cpo = &cpo
3990 set cpo-=C
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003991 " There may be more, test only until t_xo
Anton Sharonov49528da2024-04-14 20:02:24 +02003992 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'
3993 \ .. ' 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'
3994 \ .. ' 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'
3995 \ .. ' 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'
3996 \ .. ' 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 +02003997 \ .. ' 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 +02003998 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandt0d87e3c2024-04-14 23:14:50 +02003999 call assert_match(expected, @:)
Anton Sharonov49528da2024-04-14 20:02:24 +02004000 let &cpo = _cpo
4001endfunc
4002
Christian Brabandt70a11a62024-07-26 19:13:55 +02004003func Test_ex_command_completion()
4004 " required for :*
4005 set cpo+=*
4006 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
4007 " :++ and :-- are only valid in Vim9 Script context, so they can be ignored
4008 call assert_equal(['++', '--'], sort(list))
Doug Kearnsea842022024-09-29 17:17:41 +02004009 call assert_equal(2, exists(':k'))
Christian Brabandt70a11a62024-07-26 19:13:55 +02004010 call assert_equal(0, exists(':ke'))
4011 call assert_equal(1, exists(':kee'))
4012 call assert_equal(1, exists(':keep'))
4013 call assert_equal(1, exists(':keepm'))
4014 call assert_equal(1, exists(':keepma'))
4015 call assert_equal(1, exists(':keepmar'))
4016 call assert_equal(1, exists(':keepmark'))
4017 call assert_equal(2, exists(':keepmarks'))
4018 call assert_equal(2, exists(':keepalt'))
4019 call assert_equal(2, exists(':keepjumps'))
4020 call assert_equal(2, exists(':keeppatterns'))
4021 set cpo-=*
4022endfunc
4023
zeertzjq5df3cb22024-10-07 21:05:06 +02004024func Test_cd_bslash_completion_windows()
Christian Brabandt1a31c432024-10-06 16:34:20 +02004025 CheckMSWindows
4026 let save_shellslash = &shellslash
4027 set noshellslash
4028 call system('mkdir XXXa\_b')
4029 defer delete('XXXa', 'rf')
4030 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
4031 call assert_equal('"cd XXXa\_b\', @:)
4032 let &shellslash = save_shellslash
4033endfunc
4034
Bram Moolenaar309976e2019-12-05 18:16:33 +01004035" vim: shiftwidth=2 sts=2 expandtab