blob: f81cec930c31deb4b4a15d4d5c7d2ea3ae18f005 [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
Bram Moolenaar37db6422019-03-28 21:26:23 +0100161 " cleanup
162 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200163 set nowildmenu
164endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100165
Bram Moolenaara60053b2020-09-03 16:50:13 +0200166func Test_wildmenu_screendump()
167 CheckScreendump
168
169 let lines =<< trim [SCRIPT]
170 set wildmenu hlsearch
171 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100172 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173
174 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
175 call term_sendkeys(buf, ":vim\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
177
178 call term_sendkeys(buf, "\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
183
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100184 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200185 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
186 call term_sendkeys(buf, "\<Esc>")
187
188 " clean up
189 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200190endfunc
191
Bram Moolenaara653e532022-04-19 11:38:24 +0100192func Test_redraw_in_autocmd()
193 CheckScreendump
194
195 let lines =<< trim END
196 set cmdheight=2
197 autocmd CmdlineChanged * redraw
198 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100199 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100200
201 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
202 call term_sendkeys(buf, ":for i in range(3)\<CR>")
203 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
204
205 call term_sendkeys(buf, "let i =")
206 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
207
208 " clean up
209 call term_sendkeys(buf, "\<CR>")
210 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100211endfunc
212
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100213func Test_redrawstatus_in_autocmd()
214 CheckScreendump
215
216 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100217 set laststatus=2
218 set statusline=%=:%{getcmdline()}
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100219 autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif
220 END
221 call writefile(lines, 'XTest_redrawstatus', 'D')
222
223 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100224 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100225 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
226 call term_sendkeys(buf, ":foobar")
227 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100228 " it is not postponed if messages have not scrolled
229 call term_sendkeys(buf, "\<Esc>:foobar")
230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100231
232 " clean up
233 call term_sendkeys(buf, "\<CR>")
234 call StopVimInTerminal(buf)
235endfunc
236
Bram Moolenaarf797e302022-08-11 13:17:30 +0100237func Test_changing_cmdheight()
238 CheckScreendump
239
240 let lines =<< trim END
241 set cmdheight=1 laststatus=2
242 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100243 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100244
245 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
246 call term_sendkeys(buf, ":resize -3\<CR>")
247 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
248
249 " using the space available doesn't change the status line
250 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
251 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
252
253 " using more space moves the status line up
254 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
255 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
256
257 " reducing cmdheight moves status line down
258 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
259 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
260
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100261 " reducing window size and then setting cmdheight
262 call term_sendkeys(buf, ":resize -1\<CR>")
263 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
264 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
265
Bram Moolenaarf797e302022-08-11 13:17:30 +0100266 " clean up
267 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100268endfunc
269
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100270func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100271 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
272 call assert_equal('"map <unique> <silent>', getreg(':'))
273 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
274 call assert_equal('"map <script> <unique>', getreg(':'))
275 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
276 call assert_equal('"map <expr> <script>', getreg(':'))
277 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
278 call assert_equal('"map <buffer> <expr>', getreg(':'))
279 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
280 call assert_equal('"map <nowait> <buffer>', getreg(':'))
281 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
282 call assert_equal('"map <special> <nowait>', getreg(':'))
283 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
284 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200285
Bram Moolenaar1776a282019-05-03 16:05:41 +0200286 map <Middle>x middle
287
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200288 map ,f commaf
289 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200290 map <Left> left
291 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200292 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
293 call assert_equal('"map ,f', getreg(':'))
294 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
295 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200296 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
297 call assert_equal('"map <Left>', getreg(':'))
298 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200299 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200300 unmap ,f
301 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200302 unmap <Left>
303 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200304
305 set cpo-=< cpo-=B cpo-=k
306 map <Left> left
307 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200309 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200310 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200311 unmap <Left>
312
313 set cpo+=<
314 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200315 exe "set t_k6=\<Esc>[17~"
316 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200317 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
318 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200319 if !has('gui_running')
320 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
321 call assert_equal("\"map <F6>x", getreg(':'))
322 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200323 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200324 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200325 set cpo-=<
326
327 set cpo+=B
328 map <Left> left
329 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
330 call assert_equal('"map <Left>', getreg(':'))
331 unmap <Left>
332 set cpo-=B
333
334 set cpo+=k
335 map <Left> left
336 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
337 call assert_equal('"map <Left>', getreg(':'))
338 unmap <Left>
339 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200340
Bram Moolenaar531be472020-09-23 22:38:05 +0200341 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
342
Bram Moolenaar1776a282019-05-03 16:05:41 +0200343 unmap <Middle>x
344 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100345endfunc
346
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100347func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100348 hi Aardig ctermfg=green
349 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000350 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100351 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000352 call assert_equal('"match none', @:)
353 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
354 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100355endfunc
356
357func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100358 hi Aardig ctermfg=green
359 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200361 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
362 call assert_equal('"hi default Aardig', getreg(':'))
363 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
364 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100365 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
366 call assert_equal('"hi link', getreg(':'))
367 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
368 call assert_equal('"hi default', getreg(':'))
369 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
370 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200371 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
372 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
373 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
374 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200375
376 " A cleared group does not show up in completions.
377 hi Anders ctermfg=green
378 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
379 hi clear Aardig
380 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
381 hi clear Anders
382 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100383endfunc
384
Bram Moolenaar75e15672020-06-28 13:10:22 +0200385" Test for command-line expansion of "hi Ni " (easter egg)
386func Test_highlight_easter_egg()
387 call test_override('ui_delay', 1)
388 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
389 call assert_equal("\"hi Ni \<Tab>", @:)
390 call test_override('ALL', 0)
391endfunc
392
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200393func Test_getcompletion()
394 let groupcount = len(getcompletion('', 'event'))
395 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200396 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200397 call assert_true(matchcount > 0)
398 call assert_true(groupcount > matchcount)
399
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200400 if has('menu')
401 source $VIMRUNTIME/menu.vim
402 let matchcount = len(getcompletion('', 'menu'))
403 call assert_true(matchcount > 0)
404 call assert_equal(['File.'], getcompletion('File', 'menu'))
405 call assert_true(matchcount > 0)
406 let matchcount = len(getcompletion('File.', 'menu'))
407 call assert_true(matchcount > 0)
408 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200409
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200410 let l = getcompletion('v:n', 'var')
411 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200412 let l = getcompletion('v:notexists', 'var')
413 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200414
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200415 args a.c b.c
416 let l = getcompletion('', 'arglist')
417 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000418 let l = getcompletion('a.', 'buffer')
419 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200420 %argdelete
421
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200422 let l = getcompletion('', 'augroup')
423 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200424 let l = getcompletion('blahblah', 'augroup')
425 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200426
427 let l = getcompletion('', 'behave')
428 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200429 let l = getcompletion('not', 'behave')
430 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200431
432 let l = getcompletion('', 'color')
433 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200434 let l = getcompletion('dirty', 'color')
435 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200436
437 let l = getcompletion('', 'command')
438 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200439 let l = getcompletion('awake', 'command')
440 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200441
442 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200443 call assert_true(index(l, 'samples/') >= 0)
444 let l = getcompletion('NoMatch', 'dir')
445 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200446
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100447 if glob('~/*') !=# ''
448 let l = getcompletion('~/', 'dir')
449 call assert_true(l[0][0] ==# '~')
450 endif
451
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200452 let l = getcompletion('exe', 'expression')
453 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200454 let l = getcompletion('kill', 'expression')
455 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200456
457 let l = getcompletion('tag', 'function')
458 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('paint', 'function')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200462 let Flambda = {-> 'hello'}
463 let l = getcompletion('', 'function')
464 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200465 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200466
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467 let l = getcompletion('run', 'file')
468 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('walk', 'file')
470 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200471 set wildignore=*.vim
472 let l = getcompletion('run', 'file', 1)
473 call assert_true(index(l, 'runtest.vim') < 0)
474 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000475 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100476 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000477 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
478 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200479
480 let l = getcompletion('ha', 'filetype')
481 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200482 let l = getcompletion('horse', 'filetype')
483 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200484
485 let l = getcompletion('z', 'syntax')
486 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200487 let l = getcompletion('emacs', 'syntax')
488 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200489
490 let l = getcompletion('jikes', 'compiler')
491 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200492 let l = getcompletion('break', 'compiler')
493 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200494
495 let l = getcompletion('last', 'help')
496 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200497 let l = getcompletion('giveup', 'help')
498 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200499
500 let l = getcompletion('time', 'option')
501 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200502 let l = getcompletion('space', 'option')
503 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200504
505 let l = getcompletion('er', 'highlight')
506 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200507 let l = getcompletion('dark', 'highlight')
508 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200509
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200510 let l = getcompletion('', 'messages')
511 call assert_true(index(l, 'clear') >= 0)
512 let l = getcompletion('not', 'messages')
513 call assert_equal([], l)
514
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200515 let l = getcompletion('', 'mapclear')
516 call assert_true(index(l, '<buffer>') >= 0)
517 let l = getcompletion('not', 'mapclear')
518 call assert_equal([], l)
519
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200520 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200521 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200522 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
523 let root = has('win32') ? 'C:\\' : '/'
524 let l = getcompletion(root, 'shellcmd')
525 let expected = map(filter(glob(root . '*', 0, 1),
526 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
527 call assert_equal(expected, l)
528
Bram Moolenaarb650b982016-08-05 20:35:13 +0200529 if has('cscope')
530 let l = getcompletion('', 'cscope')
531 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
532 call assert_equal(cmds, l)
533 " using cmdline completion must not change the result
534 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
535 let l = getcompletion('', 'cscope')
536 call assert_equal(cmds, l)
537 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
538 let l = getcompletion('find ', 'cscope')
539 call assert_equal(keys, l)
540 endif
541
Bram Moolenaar7522f692016-08-06 14:12:50 +0200542 if has('signs')
543 sign define Testing linehl=Comment
544 let l = getcompletion('', 'sign')
545 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
546 call assert_equal(cmds, l)
547 " using cmdline completion must not change the result
548 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
549 let l = getcompletion('', 'sign')
550 call assert_equal(cmds, l)
551 let l = getcompletion('list ', 'sign')
552 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000553 let l = getcompletion('de*', 'sign')
554 call assert_equal(['define'], l)
555 let l = getcompletion('p?', 'sign')
556 call assert_equal(['place'], l)
557 let l = getcompletion('j.', 'sign')
558 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200559 endif
560
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200561 " Command line completion tests
562 let l = getcompletion('cd ', 'cmdline')
563 call assert_true(index(l, 'samples/') >= 0)
564 let l = getcompletion('cd NoMatch', 'cmdline')
565 call assert_equal([], l)
566 let l = getcompletion('let v:n', 'cmdline')
567 call assert_true(index(l, 'v:null') >= 0)
568 let l = getcompletion('let v:notexists', 'cmdline')
569 call assert_equal([], l)
570 let l = getcompletion('call tag', 'cmdline')
571 call assert_true(index(l, 'taglist(') >= 0)
572 let l = getcompletion('call paint', 'cmdline')
573 call assert_equal([], l)
574
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100575 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000576 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100577 return "oneA\noneB\noneC"
578 endfunc
579 command -nargs=1 -complete=custom,T MyCmd
580 let l = getcompletion('MyCmd ', 'cmdline')
581 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000582 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100583
584 delcommand MyCmd
585 delfunc T
ii144785fe02021-11-21 12:13:56 +0000586 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100587
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200588 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200589 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200590 if has('cmdline_hist')
591 call add(names, 'history')
592 endif
593 if has('gettext')
594 call add(names, 'locale')
595 endif
596 if has('profile')
597 call add(names, 'syntime')
598 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200599
600 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100601 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200602
603 for name in names
604 let matchcount = len(getcompletion('', name))
605 call assert_true(matchcount >= 0, 'No matches for ' . name)
606 endfor
607
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200608 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200609
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000610 edit a~b
611 enew
612 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
613 bw a~b
614
615 if has('unix')
616 edit Xtest\
617 enew
618 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
619 bw Xtest\
620 endif
621
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200622 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200623 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100624 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200625endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200626
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000627" Test for getcompletion() with "fuzzy" in 'wildoptions'
628func Test_getcompletion_wildoptions()
629 let save_wildoptions = &wildoptions
630 set wildoptions&
631 let l = getcompletion('space', 'option')
632 call assert_equal([], l)
633 let l = getcompletion('ier', 'command')
634 call assert_equal([], l)
635 set wildoptions=fuzzy
636 let l = getcompletion('space', 'option')
637 call assert_true(index(l, 'backspace') >= 0)
638 let l = getcompletion('ier', 'command')
639 call assert_true(index(l, 'compiler') >= 0)
640 let &wildoptions = save_wildoptions
641endfunc
642
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000643func Test_complete_autoload_error()
644 let save_rtp = &rtp
645 let lines =<< trim END
646 vim9script
647 export def Complete(..._): string
648 return 'match'
649 enddef
650 echo this will cause an error
651 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100652 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000653 call writefile(lines, 'Xdir/autoload/script.vim')
654 exe 'set rtp+=' .. getcwd() .. '/Xdir'
655
656 let lines =<< trim END
657 vim9script
658 import autoload 'script.vim'
659 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
660 &wildcharm = char2nr("\<Tab>")
661 feedkeys(":Cmd \<Tab>", 'xt')
662 END
663 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
664
665 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000666endfunc
667
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100668func Test_fullcommand()
669 let tests = {
670 \ '': '',
671 \ ':': '',
672 \ ':::': '',
673 \ ':::5': '',
674 \ 'not_a_cmd': '',
675 \ 'Check': '',
676 \ 'syntax': 'syntax',
677 \ ':syntax': 'syntax',
678 \ '::::syntax': 'syntax',
679 \ 'sy': 'syntax',
680 \ 'syn': 'syntax',
681 \ 'synt': 'syntax',
682 \ ':sy': 'syntax',
683 \ '::::sy': 'syntax',
684 \ 'match': 'match',
685 \ '2match': 'match',
686 \ '3match': 'match',
687 \ 'aboveleft': 'aboveleft',
688 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100689 \ 'en': 'endif',
690 \ 'end': 'endif',
691 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100692 \ 's': 'substitute',
693 \ '5s': 'substitute',
694 \ ':5s': 'substitute',
695 \ "'<,'>s": 'substitute',
696 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100697 \ 'CheckLin': 'CheckLinux',
698 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100699 \ }
700
701 for [in, want] in items(tests)
702 call assert_equal(want, fullcommand(in))
703 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200704 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100705
706 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200707
708 command -buffer BufferLocalCommand :
709 command GlobalCommand :
710 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
711 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
712 delcommand BufferLocalCommand
713 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100714endfunc
715
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200716func Test_shellcmd_completion()
717 let save_path = $PATH
718
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100719 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200720 call writefile([''], 'Xpathdir/Xfile.exe')
721 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
722
723 " Set PATH to example directory without trailing slash.
724 let $PATH = getcwd() . '/Xpathdir'
725
726 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
727 " dirs in the PATH, even though they won't be executed. We check that only
728 " subdirs of the PWD and executables from the PATH are included in the
729 " suggestions.
730 let actual = getcompletion('X', 'shellcmd')
731 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
732 call insert(expected, 'Xfile.exe')
733 call assert_equal(expected, actual)
734
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200735 let $PATH = save_path
736endfunc
737
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200738func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100739 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200740 call writefile(['asdfasdf'], 'a/b/fileXname')
741 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000742 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200743 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200744endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100745
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100746func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100747 let @a = "def"
748 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
749 call assert_equal('"abc def ghi', @:)
750
751 new
752 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
753
754 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
755 call assert_equal('"aaa asdf bbb', @:)
756
757 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
758 call assert_equal('"aaa /tmp/some bbb', @:)
759
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200760 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
761 call assert_equal('"aaa '.getline(1).' bbb', @:)
762
Bram Moolenaar21efc362016-12-03 14:05:49 +0100763 set incsearch
764 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
765 call assert_equal('"aaa verylongword bbb', @:)
766
767 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
768 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100769
770 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
771 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100772 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200773
774 " Error while typing a command used to cause that it was not executed
775 " in the end.
776 new
777 try
778 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
779 catch /^Vim\%((\a\+)\)\=:E32/
780 " ignore error E32
781 endtry
782 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100783
Bram Moolenaar578fe942020-02-27 21:32:51 +0100784 " Try to paste an invalid register using <C-R>
785 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
786 call assert_equal('"onetwo', @:)
787
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100788 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100789 let @a = "xy\<C-H>z"
790 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
791 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100792 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
793 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100794 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
795 call assert_equal("\"xy\<C-H>z", @:)
796
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100797 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
798 let @a = "xy\<C-V>z"
799 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
800 call assert_equal('"xyz', @:)
801 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
802 call assert_equal("\"xy\<C-V>z", @:)
803
Bram Moolenaar578fe942020-02-27 21:32:51 +0100804 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
805
Bram Moolenaar72532d32018-04-07 19:09:09 +0200806 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100807endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100808
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100809func Test_cmdline_remove_char()
810 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100811
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100812 for e in ['utf8', 'latin1']
813 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100814
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100815 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
816 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100817
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100818 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
819 call assert_equal('"abcdef', @:)
820
821 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
822 call assert_equal('"abc ghi', @:, e)
823
824 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
825 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100826
827 " This was going before the start in latin1.
828 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100829 endfor
830
831 let &encoding = encoding_save
832endfunc
833
834func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200835 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100836
837 set keymap=esperanto
838 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
839 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
840 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100841endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100842
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100843func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100844 new
845 2;'(
846 2;')
847 quit
848endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100849
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100850func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100851 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100852 new
853 source Xtest.vim
854 " Trigger calling validate_cursor()
855 diffsp Xtest.vim
856 quit!
857 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100858endfunc
859
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100860func Test_mark_from_line_zero()
861 " this was reading past the end of the first (empty) line
862 new
863 norm oxxxx
864 call assert_fails("0;'(", 'E20:')
865 bwipe!
866endfunc
867
Bram Moolenaarba47b512017-01-24 21:18:19 +0100868func Test_cmdline_complete_wildoptions()
869 help
870 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
871 let a = join(sort(split(@:)),' ')
872 set wildoptions=tagfile
873 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
874 let b = join(sort(split(@:)),' ')
875 call assert_equal(a, b)
876 bw!
877endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100878
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200879func Test_cmdline_complete_user_cmd()
880 command! -complete=color -nargs=1 Foo :
881 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
882 call assert_equal('"Foo blue', @:)
883 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
884 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000885 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
886 call assert_equal('"Foo a blue', @:)
887 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
888 call assert_equal('"Foo b\', @:)
889 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
890 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200891 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100892
893 redraw
894 call assert_equal('~', Screenline(&lines - 1))
895 command! FooOne :
896 command! FooTwo :
897
898 set nowildmenu
899 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
900 call assert_equal('"FooOne', @:)
901 call assert_equal('~', Screenline(&lines - 1))
902
903 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
904 call assert_equal('"FooTwo', @:)
905 call assert_equal('~', Screenline(&lines - 1))
906
907 delcommand FooOne
908 delcommand FooTwo
909 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200910endfunc
911
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100912func Test_complete_user_cmd()
913 command FooBar echo 'global'
914 command -buffer FooBar echo 'local'
915 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
916 call assert_equal('"FooBar', @:)
917
918 delcommand -buffer FooBar
919 delcommand FooBar
920endfunc
921
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100922func s:ScriptLocalFunction()
923 echo 'yes'
924endfunc
925
926func Test_cmdline_complete_user_func()
927 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200928 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100929 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
930 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100931
932 " g: prefix also works
933 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
934 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200935
936 " using g: prefix does not result in just "g:" matches from a lambda
937 let Fx = { a -> a }
938 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
939 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200940
941 " existence of script-local dict function does not break user function name
942 " completion
943 function s:a_dict_func() dict
944 endfunction
945 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
946 call assert_match('"call Test_cmdline_complete_user_', @:)
947 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100948endfunc
949
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200950func Test_cmdline_complete_user_names()
951 if has('unix') && executable('whoami')
952 let whoami = systemlist('whoami')[0]
953 let first_letter = whoami[0]
954 if len(first_letter) > 0
955 " Trying completion of :e ~x where x is the first letter of
956 " the user name should complete to at least the user name.
957 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
958 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
959 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200960 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200961 " Just in case: check that the system has an Administrator account.
962 let names = system('net user')
963 if names =~ 'Administrator'
964 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100965 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200966 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100967 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200968 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200969 else
970 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200971 endif
972endfunc
973
Bram Moolenaar297610b2019-12-27 17:20:55 +0100974func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200975 CheckExecutable whoami
976 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
977 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100978endfunc
979
Bram Moolenaar8b633132020-03-20 18:20:51 +0100980func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200981 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
982 call assert_equal(lang, v:lc_time)
983
984 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
985 call assert_equal(lang, v:ctype)
986
987 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
988 call assert_equal(lang, v:collate)
989
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200990 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200991 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200992
993 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200994 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200995
Bram Moolenaarec680282020-06-12 19:35:32 +0200996 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200997
Bram Moolenaarec680282020-06-12 19:35:32 +0200998 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
999 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001000
Bram Moolenaarec680282020-06-12 19:35:32 +02001001 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1002 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001003
Bram Moolenaarec680282020-06-12 19:35:32 +02001004 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1005 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001006
1007 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1008 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001009endfunc
1010
Bram Moolenaar297610b2019-12-27 17:20:55 +01001011func Test_cmdline_complete_env_variable()
1012 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001013 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1014 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001015 unlet $X_VIM_TEST_COMPLETE_ENV
1016endfunc
1017
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001018func Test_cmdline_complete_expression()
1019 let g:SomeVar = 'blah'
1020 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1021 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1022 call assert_match('"' .. cmd .. ' SomeVar', @:)
1023 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1024 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1025 endfor
1026 unlet g:SomeVar
1027endfunc
1028
Bram Moolenaar47016f52021-08-26 16:39:58 +02001029" Unique function name for completion below
1030func s:WeirdFunc()
1031 echo 'weird'
1032endfunc
1033
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001034" Test for various command-line completion
1035func Test_cmdline_complete_various()
1036 " completion for a command starting with a comment
1037 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1038 call assert_equal("\" :|\"\<C-A>", @:)
1039
1040 " completion for a range followed by a comment
1041 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1042 call assert_equal("\"1,2\"\<C-A>", @:)
1043
1044 " completion for :k command
1045 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1046 call assert_equal("\"ka\<C-A>", @:)
1047
1048 " completion for short version of the :s command
1049 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1050 call assert_equal("\"sI \<C-A>", @:)
1051
1052 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001053 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001054 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001055 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001056 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001057 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1058 call assert_equal("\"w >> Xfile1", @:)
1059 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001060
1061 " completion for :w ! and :r ! commands
1062 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1063 call assert_equal("\"w !invalid_xyz_cmd", @:)
1064 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1065 call assert_equal("\"r !invalid_xyz_cmd", @:)
1066
1067 " completion for :>> and :<< commands
1068 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1069 call assert_equal("\">>>\<C-A>", @:)
1070 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1071 call assert_equal("\"<<<\<C-A>", @:)
1072
1073 " completion for command with +cmd argument
1074 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1075 call assert_equal("\"buffer +/pat Xabc", @:)
1076 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1077 call assert_equal("\"buffer +/pat\<C-A>", @:)
1078
1079 " completion for a command with a trailing comment
1080 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1081 call assert_equal("\"ls \" comment\<C-A>", @:)
1082
1083 " completion for a command with a trailing command
1084 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1085 call assert_equal("\"ls | ls", @:)
1086
1087 " completion for a command with an CTRL-V escaped argument
1088 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1090
1091 " completion for a command that doesn't take additional arguments
1092 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"all abc\<C-A>", @:)
1094
zeertzjqd3de1782022-09-01 12:58:52 +01001095 " completion for :wincmd with :horizontal modifier
1096 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\"horizontal wincmd", @:)
1098
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001099 " completion for a command with a command modifier
1100 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"topleft new", @:)
1102
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001103 " completion for vim9 and legacy commands
1104 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal("\"vim9 call strlen(", @:)
1106 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"legac call strlen(", @:)
1108
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001109 " completion for the :disassemble command
1110 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1111 call assert_equal("\"disas debug", @:)
1112 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1113 call assert_equal("\"disas profile", @:)
1114 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1116 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1117 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001118 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1119 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001120
Bram Moolenaar47016f52021-08-26 16:39:58 +02001121 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001122 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001123
naohiro onodfe04db2021-09-12 15:45:10 +02001124 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1125 call assert_match('"disas <SNR>\d\+_', @:)
1126 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1127 call assert_match('"disas debug <SNR>\d\+_', @:)
1128
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001129 " completion for the :match command
1130 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"match Search /pat/\<C-A>", @:)
1132
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001133 " completion for the :doautocmd command
1134 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1136
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001137 " completion of autocmd group after comma
1138 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1140
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001141 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001142 call writefile([], 'Xvarfile1', 'D')
1143 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001144 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1145 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001146
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001147 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001148 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001149 augroup END
1150 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001151 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001152
1153 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001154 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001156 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal("\"au XTest.test", @:)
1158
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001159 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001160
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001161 " autocmd pattern completion
1162 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1163 call assert_equal("\"au BufEnter *.py\t", @:)
1164
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001165 " completion for the :unlet command
1166 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1167 call assert_equal("\"unlet one two", @:)
1168
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001169 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001170 " FIXME: what should happen on MS-Windows?
1171 if !has('win32')
1172 edit \{someFile}
1173 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal("\"buf {someFile}", @:)
1175 bwipe {someFile}
1176 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001177
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001178 " completion for the :bdelete command
1179 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1180 call assert_equal("\"bdel a b c", @:)
1181
1182 " completion for the :mapclear command
1183 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1184 call assert_equal("\"mapclear <buffer>", @:)
1185
1186 " completion for user defined commands with menu names
1187 menu Test.foo :ls<CR>
1188 com -nargs=* -complete=menu MyCmd
1189 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1190 call assert_equal('"MyCmd Test.', @:)
1191 delcom MyCmd
1192 unmenu Test
1193
1194 " completion for user defined commands with mappings
1195 mapclear
1196 map <F3> :ls<CR>
1197 com -nargs=* -complete=mapping MyCmd
1198 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001199 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001200 mapclear
1201 delcom MyCmd
1202
1203 " completion for :set path= with multiple backslashes
1204 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1205 call assert_equal('"set path=a\\\ b', @:)
1206
1207 " completion for :set dir= with a backslash
1208 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1209 call assert_equal('"set dir=a\ b', @:)
1210
1211 " completion for the :py3 commands
1212 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1213 call assert_equal('"py3 py3do py3file', @:)
1214
Bram Moolenaardf749a22021-03-28 15:29:43 +02001215 " completion for the :vim9 commands
1216 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1217 call assert_equal('"vim9cmd vim9script', @:)
1218
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001219 " redir @" is not the start of a comment. So complete after that
1220 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1221 call assert_equal('"redir @" | cwindow', @:)
1222
1223 " completion after a backtick
1224 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1225 call assert_equal('"e `a1b2c', @:)
1226
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001227 " completion for :language command with an invalid argument
1228 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1229 call assert_equal("\"language dummy \t", @:)
1230
1231 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001232 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1233 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001234
1235 " completion with ambiguous user defined commands
1236 com TCmd1 echo 'TCmd1'
1237 com TCmd2 echo 'TCmd2'
1238 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1239 call assert_equal('"TCmd ', @:)
1240 delcom TCmd1
1241 delcom TCmd2
1242
1243 " completion after a range followed by a pipe (|) character
1244 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1245 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001246
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001247 " completion after a :global command
1248 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1249 call assert_equal('"g/a/chistory', @:)
1250 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1251 call assert_equal("\"g/a\\/chist\t", @:)
1252
Bram Moolenaar9c929712020-09-07 22:05:28 +02001253 " use <Esc> as the 'wildchar' for completion
1254 set wildchar=<Esc>
1255 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1256 call assert_equal('"g/a\xb/clearjumps', @:)
1257 " pressing <esc> twice should cancel the command
1258 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1259 call assert_equal('"g/a\xb/clearjumps', @:)
1260 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001261
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001262 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001263 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001264 call writefile([], '~Xtest')
1265 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1266 call assert_equal('"e \~Xtest', @:)
1267 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001268
1269 " should be able to complete a file name that has a '*'
1270 call writefile([], 'Xx*Yy')
1271 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1272 call assert_equal('"e Xx\*Yy', @:)
1273 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001274
1275 " use a literal star
1276 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1277 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001278 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001279
1280 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001282endfunc
1283
1284" Test for 'wildignorecase'
1285func Test_cmdline_wildignorecase()
1286 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001287 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001288 set wildignorecase
1289 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1290 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001291 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001292 let g:Sline = ''
1293 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1294 call assert_equal('"e xt', @:)
1295 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001296 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001297endfunc
1298
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001299func Test_cmdline_write_alternatefile()
1300 new
1301 call setline('.', ['one', 'two'])
1302 f foo.txt
1303 new
1304 f #-A
1305 call assert_equal('foo.txt-A', expand('%'))
1306 f #<-B.txt
1307 call assert_equal('foo-B.txt', expand('%'))
1308 f %<
1309 call assert_equal('foo-B', expand('%'))
1310 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001311 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001312 bw!
1313 f foo-B.txt
1314 f %<-A
1315 call assert_equal('foo-B-A', expand('%'))
1316 bw!
1317 bw!
1318endfunc
1319
Bram Moolenaarf5724372022-09-02 19:45:15 +01001320func Test_cmdline_expand_cur_alt_file()
1321 enew
1322 file http://some.com/file.txt
1323 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1324 call assert_equal('"e http://some.com/file.txt', @:)
1325 edit another
1326 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1327 call assert_equal('"e http://some.com/file.txt', @:)
1328 bwipe
1329 bwipe http://some.com/file.txt
1330endfunc
1331
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001332" using a leading backslash here
1333set cpo+=C
1334
1335func Test_cmdline_search_range()
1336 new
1337 call setline(1, ['a', 'b', 'c', 'd'])
1338 /d
1339 1,\/s/b/B/
1340 call assert_equal('B', getline(2))
1341
1342 /a
1343 $
1344 \?,4s/c/C/
1345 call assert_equal('C', getline(3))
1346
1347 call setline(1, ['a', 'b', 'c', 'd'])
1348 %s/c/c/
1349 1,\&s/b/B/
1350 call assert_equal('B', getline(2))
1351
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001352 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001353 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001354
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001355 bwipe!
1356endfunc
1357
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001358" Test for the tick mark (') in an excmd range
1359func Test_tick_mark_in_range()
1360 " If only the tick is passed as a range and no command is specified, there
1361 " should not be an error
1362 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001363 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001364 call assert_fails("',print", 'E78:')
1365endfunc
1366
1367" Test for using a line number followed by a search pattern as range
1368func Test_lnum_and_pattern_as_range()
1369 new
1370 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1371 let @" = ''
1372 2/foo/yank
1373 call assert_equal("foo 3\n", @")
1374 call assert_equal(1, line('.'))
1375 close!
1376endfunc
1377
Bram Moolenaar65189a12017-02-06 22:22:17 +01001378" Tests for getcmdline(), getcmdpos() and getcmdtype()
1379func Check_cmdline(cmdtype)
1380 call assert_equal('MyCmd a', getcmdline())
1381 call assert_equal(8, getcmdpos())
1382 call assert_equal(a:cmdtype, getcmdtype())
1383 return ''
1384endfunc
1385
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001386set cpo&
1387
Bram Moolenaar65189a12017-02-06 22:22:17 +01001388func Test_getcmdtype()
1389 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1390
1391 let cmdtype = ''
1392 debuggreedy
1393 call feedkeys(":debug echo 'test'\<CR>", "t")
1394 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1395 call feedkeys("cont\<CR>", "xt")
1396 0debuggreedy
1397 call assert_equal('>', cmdtype)
1398
1399 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1400 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1401
1402 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001403 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001404
1405 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1406
1407 cnoremap <expr> <F6> Check_cmdline('=')
1408 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1409 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001410
1411 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001412endfunc
1413
Bram Moolenaar52604f22017-04-07 16:17:39 +02001414func Test_verbosefile()
1415 set verbosefile=Xlog
1416 echomsg 'foo'
1417 echomsg 'bar'
1418 set verbosefile=
1419 let log = readfile('Xlog')
1420 call assert_match("foo\nbar", join(log, "\n"))
1421 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001422
1423 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001424 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001425endfunc
1426
Bram Moolenaar4facea32019-10-12 20:17:40 +02001427func Test_verbose_option()
1428 CheckScreendump
1429
1430 let lines =<< trim [SCRIPT]
1431 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1432 call feedkeys("\r", 't') " for the hit-enter prompt
1433 set verbose=20
1434 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001435 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001436
1437 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001438 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001439 call term_sendkeys(buf, ":DoSomething\<CR>")
1440 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1441
1442 " clean up
1443 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001444endfunc
1445
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001446func Test_setcmdpos()
1447 func InsertTextAtPos(text, pos)
1448 call assert_equal(0, setcmdpos(a:pos))
1449 return a:text
1450 endfunc
1451
1452 " setcmdpos() with position in the middle of the command line.
1453 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1454 call assert_equal('"1ab2', @:)
1455
1456 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1457 call assert_equal('"1b2a', @:)
1458
1459 " setcmdpos() with position beyond the end of the command line.
1460 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1461 call assert_equal('"12ab', @:)
1462
1463 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001464 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001465endfunc
1466
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001467func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001468 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001469 let encoding_save = &encoding
1470
1471 for e in encodings
1472 exe 'set encoding=' . e
1473
1474 " Test overstrike in the middle of the command line.
1475 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001476 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001477
1478 " Test overstrike going beyond end of command line.
1479 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001480 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001481
1482 " Test toggling insert/overstrike a few times.
1483 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001484 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001485 endfor
1486
Bram Moolenaar30276f22019-01-24 17:59:39 +01001487 " Test overstrike with multi-byte characters.
1488 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001489 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001490
1491 let &encoding = encoding_save
1492endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001493
Bram Moolenaar52410572019-10-27 05:12:45 +01001494func Test_buffers_lastused()
1495 " check that buffers are sorted by time when wildmode has lastused
1496 call test_settime(1550020000) " middle
1497 edit bufa
1498 enew
1499 call test_settime(1550030000) " newest
1500 edit bufb
1501 enew
1502 call test_settime(1550010000) " oldest
1503 edit bufc
1504 enew
1505 call test_settime(0)
1506 enew
1507
1508 call assert_equal(['bufa', 'bufb', 'bufc'],
1509 \ getcompletion('', 'buffer'))
1510
1511 let save_wildmode = &wildmode
1512 set wildmode=full:lastused
1513
1514 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1515 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1516 call assert_equal('b bufb', X)
1517 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1518 call assert_equal('b bufa', X)
1519 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1520 call assert_equal('b bufc', X)
1521 enew
1522
1523 edit other
1524 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1525 call assert_equal('b bufb', X)
1526 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1527 call assert_equal('b bufa', X)
1528 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1529 call assert_equal('b bufc', X)
1530 enew
1531
1532 let &wildmode = save_wildmode
1533
1534 bwipeout bufa
1535 bwipeout bufb
1536 bwipeout bufc
1537endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001538
Bram Moolenaar479950f2020-01-19 15:45:17 +01001539func Test_cmdlineclear_tabenter()
1540 CheckScreendump
1541
1542 let lines =<< trim [SCRIPT]
1543 call setline(1, range(30))
1544 [SCRIPT]
1545
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001546 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001547 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001548 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001549 " in one tab make the command line higher with CTRL-W -
1550 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1551 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1552
1553 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001554endfunc
1555
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001556" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001557func Test_cmdline_expand_special()
1558 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001559 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001560 call assert_fails('e <afile>', 'E495:')
1561 call assert_fails('e <abuf>', 'E496:')
1562 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001563
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001564 call writefile([], 'Xfile.cpp', 'D')
1565 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001566 new Xfile.cpp
1567 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1568 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1569 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001570endfunc
1571
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001572" Test for backtick expression in the command line
1573func Test_cmd_backtick()
1574 %argd
1575 argadd `=['a', 'b', 'c']`
1576 call assert_equal(['a', 'b', 'c'], argv())
1577 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001578
1579 argadd `echo abc def`
1580 call assert_equal(['abc def'], argv())
1581 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001582endfunc
1583
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001584" Test for the :! command
1585func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001586 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001587
1588 let lines =<< trim [SCRIPT]
1589 " Test for no previous command
1590 call assert_fails('!!', 'E34:')
1591 set nomore
1592 " Test for cmdline expansion with :!
1593 call setline(1, 'foo!')
1594 silent !echo <cWORD> > Xfile.out
1595 call assert_equal(['foo!'], readfile('Xfile.out'))
1596 " Test for using previous command
1597 silent !echo \! !
1598 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1599 call writefile(v:errors, 'Xresult')
1600 call delete('Xfile.out')
1601 qall!
1602 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001603 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001604 if RunVim([], [], '--clean -S Xscript')
1605 call assert_equal([], readfile('Xresult'))
1606 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001607 call delete('Xresult')
1608endfunc
1609
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001610" Test error: "E135: *Filter* Autocommands must not change current buffer"
1611func Test_cmd_bang_E135()
1612 new
1613 call setline(1, ['a', 'b', 'c', 'd'])
1614 augroup test_cmd_filter_E135
1615 au!
1616 autocmd FilterReadPost * help
1617 augroup END
1618 call assert_fails('2,3!echo "x"', 'E135:')
1619
1620 augroup test_cmd_filter_E135
1621 au!
1622 augroup END
1623 %bwipe!
1624endfunc
1625
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001626" Test for using ~ for home directory in cmdline completion matches
1627func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001628 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001629 call writefile([], 'Xexpdir/Xfile1')
1630 call writefile([], 'Xexpdir/Xfile2')
1631 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001632 let save_HOME = $HOME
1633 let $HOME = getcwd()
1634 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1635 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1636 let $HOME = save_HOME
1637 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001638endfunc
1639
Bram Moolenaar578fe942020-02-27 21:32:51 +01001640" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1641" or insert mode (when 'insertmode' is set)
1642func Test_cmdline_ctrl_g()
1643 new
1644 call setline(1, 'abc')
1645 call cursor(1, 3)
1646 " If command line is entered from insert mode, using C-\ C-G should back to
1647 " insert mode
1648 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1649 call assert_equal('abxyc', getline(1))
1650 call assert_equal(4, col('.'))
1651
1652 " If command line is entered in 'insertmode', using C-\ C-G should back to
1653 " 'insertmode'
1654 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1655 call assert_equal('ab12xyc', getline(1))
1656 close!
1657endfunc
1658
Bram Moolenaar578fe942020-02-27 21:32:51 +01001659" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001660func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001661 func T(a, c, p)
1662 return "oneA\noneB\noneC"
1663 endfunc
1664 command -nargs=1 -complete=custom,T MyCmd
1665
Bram Moolenaar578fe942020-02-27 21:32:51 +01001666 set nowildmenu
1667 set wildmode=full,list
1668 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001669 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001670 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001671 call assert_equal('"MyCmd oneA', @:)
1672
1673 set wildmode=longest,full
1674 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1675 call assert_equal('"MyCmd one', @:)
1676 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1677 call assert_equal('"MyCmd oneC', @:)
1678
1679 set wildmode=longest
1680 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1681 call assert_equal('"MyCmd one', @:)
1682
1683 set wildmode=list:longest
1684 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001685 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001686 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001687 call assert_equal('"MyCmd one', @:)
1688
1689 set wildmode=""
1690 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1691 call assert_equal('"MyCmd oneA', @:)
1692
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001693 " Test for wildmode=longest with 'fileignorecase' set
1694 set wildmode=longest
1695 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001696 argadd AAA AAAA AAAAA
1697 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1698 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001699 set fileignorecase&
1700
1701 " Test for listing files with wildmode=list
1702 set wildmode=list
1703 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001704 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001705 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001706 call assert_equal('"b A', @:)
1707
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001708 " when using longest completion match, matches shorter than the argument
1709 " should be ignored (happens with :help)
1710 set wildmode=longest,full
1711 set wildmenu
1712 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1713 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001714 " non existing file
1715 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1716 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001717 set wildmenu&
1718
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001719 " Test for longest file name completion with 'fileignorecase'
1720 " On MS-Windows, file names are case insensitive.
1721 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001722 call writefile([], 'XTESTfoo', 'D')
1723 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001724 set nofileignorecase
1725 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1726 call assert_equal('"e XTESTfoo', @:)
1727 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1728 call assert_equal('"e Xtestbar', @:)
1729 set fileignorecase
1730 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1731 call assert_equal('"e Xtest', @:)
1732 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1733 call assert_equal('"e Xtest', @:)
1734 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001735 endif
1736
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001737 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001738 delcommand MyCmd
1739 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001740 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001741 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001742endfunc
1743
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001744func Test_wildmode()
1745 " Test with utf-8 encoding
1746 call Wildmode_tests()
1747
1748 " Test with latin1 encoding
1749 let save_encoding = &encoding
1750 set encoding=latin1
1751 call Wildmode_tests()
1752 let &encoding = save_encoding
1753endfunc
1754
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001755func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001756 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001757 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001758 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001759 let lines =<< trim END
1760 func vim8#Complete(a, c, p)
1761 return "oneA\noneB\noneC"
1762 endfunc
1763 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001764 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001765
1766 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1767 set nowildmenu
1768 set wildmode=full,list
1769 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1770 call assert_equal('"MyCmd oneA oneB oneC', @:)
1771
1772 let &rtp = save_rtp
1773 set wildmode& wildmenu&
1774 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001775endfunc
1776
Bram Moolenaar578fe942020-02-27 21:32:51 +01001777" Test for interrupting the command-line completion
1778func Test_interrupt_compl()
1779 func F(lead, cmdl, p)
1780 if a:lead =~ 'tw'
1781 call interrupt()
1782 return
1783 endif
1784 return "one\ntwo\nthree"
1785 endfunc
1786 command -nargs=1 -complete=custom,F Tcmd
1787
1788 set nowildmenu
1789 set wildmode=full
1790 let interrupted = 0
1791 try
1792 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1793 catch /^Vim:Interrupt$/
1794 let interrupted = 1
1795 endtry
1796 call assert_equal(1, interrupted)
1797
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001798 let interrupted = 0
1799 try
1800 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1801 catch /^Vim:Interrupt$/
1802 let interrupted = 1
1803 endtry
1804 call assert_equal(1, interrupted)
1805
Bram Moolenaar578fe942020-02-27 21:32:51 +01001806 delcommand Tcmd
1807 delfunc F
1808 set wildmode&
1809endfunc
1810
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001811" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001812func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001813 let str = ":one two\<C-U>"
1814 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001815 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001816 let str ..= "\<Left>five\<Right>"
1817 let str ..= "\<Home>two "
1818 let str ..= "\<C-Left>one "
1819 let str ..= "\<C-Right> three"
1820 let str ..= "\<End>\<S-Left>four "
1821 let str ..= "\<S-Right> six"
1822 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1823 call feedkeys(str, 'xt')
1824 call assert_equal("\"one two three four five six seven", @:)
1825endfunc
1826
1827" Test for moving the cursor on the / command line in 'rightleft' mode
1828func Test_cmdline_edit_rightleft()
1829 CheckFeature rightleft
1830 set rightleft
1831 set rightleftcmd=search
1832 let str = "/one two\<C-U>"
1833 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001834 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001835 let str ..= "\<Right>five\<Left>"
1836 let str ..= "\<Home>two "
1837 let str ..= "\<C-Right>one "
1838 let str ..= "\<C-Left> three"
1839 let str ..= "\<End>\<S-Right>four "
1840 let str ..= "\<S-Left> six"
1841 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1842 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1843 call assert_equal("\"one two three four five six seven", @/)
1844 set rightleftcmd&
1845 set rightleft&
1846endfunc
1847
1848" Test for using <C-\>e in the command line to evaluate an expression
1849func Test_cmdline_expr()
1850 " Evaluate an expression from the beginning of a command line
1851 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1852 call assert_equal('"hello', @:)
1853
1854 " Use an invalid expression for <C-\>e
1855 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1856
1857 " Insert literal <CTRL-\> in the command line
1858 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1859 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001860endfunc
1861
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001862" This was making the insert position negative
1863func Test_cmdline_expr_register()
1864 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1865endfunc
1866
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001867" Test for 'imcmdline' and 'imsearch'
1868" This test doesn't actually test the input method functionality.
1869func Test_cmdline_inputmethod()
1870 new
1871 call setline(1, ['', 'abc', ''])
1872 set imcmdline
1873
1874 call feedkeys(":\"abc\<CR>", 'xt')
1875 call assert_equal("\"abc", @:)
1876 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1877 call assert_equal("\"abc", @:)
1878 call feedkeys("/abc\<CR>", 'xt')
1879 call assert_equal([2, 1], [line('.'), col('.')])
1880 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1881 call assert_equal([2, 1], [line('.'), col('.')])
1882
1883 set imsearch=2
1884 call cursor(1, 1)
1885 call feedkeys("/abc\<CR>", 'xt')
1886 call assert_equal([2, 1], [line('.'), col('.')])
1887 call cursor(1, 1)
1888 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1889 call assert_equal([2, 1], [line('.'), col('.')])
1890 set imdisable
1891 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1892 call assert_equal([2, 1], [line('.'), col('.')])
1893 set imdisable&
1894 set imsearch&
1895
1896 set imcmdline&
1897 %bwipe!
1898endfunc
1899
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001900" Test for using CTRL-_ in the command line with 'allowrevins'
1901func Test_cmdline_revins()
1902 CheckNotMSWindows
1903 CheckFeature rightleft
1904 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1905 call assert_equal("\"abc\<c-_>", @:)
1906 set allowrevins
1907 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1908 call assert_equal('"abcñèæ', @:)
1909 set allowrevins&
1910endfunc
1911
1912" Test for typing UTF-8 composing characters in the command line
1913func Test_cmdline_composing_chars()
1914 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1915 call assert_equal('"ゔ', @:)
1916endfunc
1917
Bram Moolenaar0e717042020-04-27 19:29:01 +02001918" test that ";" works to find a match at the start of the first line
1919func Test_zero_line_search()
1920 new
1921 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1922 call cursor(1,1)
1923 0;/pattern/d
1924 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1925 q!
1926endfunc
1927
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001928func Test_read_shellcmd()
1929 CheckUnix
1930 if executable('ls')
1931 " There should be ls in the $PATH
1932 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1933 call assert_match('^"r! .*\<ls\>', @:)
1934 endif
1935
1936 if executable('rm')
1937 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1938 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1939 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001940
1941 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1942 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1943 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001944 endif
1945endfunc
1946
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001947" Test for going up and down the directory tree using 'wildmenu'
1948func Test_wildmenu_dirstack()
1949 CheckUnix
1950 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001951 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001952 call writefile([], 'Xwildmenu/file1_1.txt')
1953 call writefile([], 'Xwildmenu/file1_2.txt')
1954 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
1955 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
1956 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
1957 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
1958 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
1959 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001960 set wildmenu
1961
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001962 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001963 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001964 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001965 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001966 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001967 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001968 call assert_equal('"e ../../dir3/', @:)
1969 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1970 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001971 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001972 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001973 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001974 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001975 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001976 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1977 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001978
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001979 set wildmenu&
1980endfunc
1981
obcat71c6f7a2021-05-13 20:23:10 +02001982" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001983" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
1984" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02001985func Test_recalling_cmdline()
1986 CheckFeature cmdline_hist
1987
1988 let g:cmdlines = []
1989 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1990
1991 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001992 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
1993 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
1994 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
1995 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02001996 "\ TODO: {'name': 'debug', ...}
1997 \]
1998 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001999 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2000 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2001 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2002 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2003 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002004 \]
2005 let prefix = 'vi'
2006 for h in histories
2007 call histadd(h.name, 'vim')
2008 call histadd(h.name, 'virtue')
2009 call histadd(h.name, 'Virgo')
2010 call histadd(h.name, 'vogue')
2011 call histadd(h.name, 'emacs')
2012 for k in keypairs
2013 let g:cmdlines = []
2014 let keyseqs = h.enter
2015 \ .. prefix
2016 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2017 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2018 \ .. h.exit
2019 call feedkeys(keyseqs, 'xt')
2020 call histdel(h.name, -1) " delete the history added by feedkeys above
2021 let expect = k.prefixmatch
2022 \ ? ['virtue', 'vim', 'virtue', prefix]
2023 \ : ['emacs', 'vogue', 'emacs', prefix]
2024 call assert_equal(expect, g:cmdlines)
2025 endfor
2026 endfor
2027
2028 unlet g:cmdlines
2029 cunmap <Plug>(save-cmdline)
2030endfunc
2031
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002032func Test_cmd_map_cmdlineChanged()
2033 let g:log = []
2034 cnoremap <F1> l<Cmd><CR>s
2035 augroup test
2036 autocmd!
2037 autocmd CmdlineChanged : let g:log += [getcmdline()]
2038 augroup END
2039
2040 call feedkeys(":\<F1>\<CR>", 'xt')
2041 call assert_equal(['l', 'ls'], g:log)
2042
Bram Moolenaar796139a2021-05-18 21:38:45 +02002043 let @b = 'b'
2044 cnoremap <F1> a<C-R>b
2045 let g:log = []
2046 call feedkeys(":\<F1>\<CR>", 'xt')
2047 call assert_equal(['a', 'ab'], g:log)
2048
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002049 unlet g:log
2050 cunmap <F1>
2051 augroup test
2052 autocmd!
2053 augroup END
2054endfunc
2055
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002056" Test for the 'suffixes' option
2057func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002058 call writefile([], 'Xsuffile', 'D')
2059 call writefile([], 'Xsuffile.c', 'D')
2060 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002061 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002062 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2063 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2064 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2065 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002066 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002067 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2068 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2069 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2070 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002071 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002072 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2073 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2074 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2075 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002076 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002077 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002078 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2079 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002080endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002081
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002082" Test for using a popup menu for the command line completion matches
2083" (wildoptions=pum)
2084func Test_wildmenu_pum()
2085 CheckRunVimInTerminal
2086
2087 let commands =<< trim [CODE]
2088 set wildmenu
2089 set wildoptions=pum
2090 set shm+=I
2091 set noruler
2092 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002093
2094 func CmdCompl(a, b, c)
2095 return repeat(['aaaa'], 120)
2096 endfunc
2097 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002098
2099 func MyStatusLine() abort
2100 return 'status'
2101 endfunc
2102 func SetupStatusline()
2103 set statusline=%!MyStatusLine()
2104 set laststatus=2
2105 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002106
2107 func MyTabLine()
2108 return 'my tab line'
2109 endfunc
2110 func SetupTabline()
2111 set statusline=
2112 set tabline=%!MyTabLine()
2113 set showtabline=2
2114 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002115
2116 func DoFeedKeys()
2117 let &wildcharm = char2nr("\t")
2118 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2119 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002120 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002121 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002122
2123 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2124
2125 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002126 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2127
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002128 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002129 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002130 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2131
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002132 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002133 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002134 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2135
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002136 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002137 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002138 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2139
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002140 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002141 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002142 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2143
2144 " pressing <C-E> should end completion and go back to the original match
2145 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002146 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2147
2148 " pressing <C-Y> should select the current match and end completion
2149 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002150 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2151
2152 " With 'wildmode' set to 'longest,full', completing a match should display
2153 " the longest match, the wildmenu should not be displayed.
2154 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2155 call TermWait(buf)
2156 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002157 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2158
2159 " pressing <Tab> should display the wildmenu
2160 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002161 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2162
2163 " pressing <Tab> second time should select the next entry in the menu
2164 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002165 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2166
2167 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002168 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002169 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002170 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2171
2172 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002173 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2174
2175 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002176 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2177
2178 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002179 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002180 call writefile([], 'Xnamedir/XfileA')
2181 call writefile([], 'Xnamedir/XdirA/XfileB')
2182 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002183
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002184 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002185 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2186
2187 " Pressing <Right> on a directory name should go into that directory
2188 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002189 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2190
2191 " Pressing <Left> on a directory name should go to the parent directory
2192 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002193 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2194
2195 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002196 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002197 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002198 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2199
2200 " Pressing <C-D> when the popup menu is displayed should remove the popup
2201 " menu
2202 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002203 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2204
2205 " Pressing <S-Tab> should open the popup menu with the last entry selected
2206 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002207 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2208
2209 " Pressing <Esc> should close the popup menu and cancel the cmd line
2210 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002211 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2212
2213 " Typing a character when the popup is open, should close the popup
2214 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002215 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2216
2217 " When the popup is open, entering the cmdline window should close the popup
2218 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002219 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2220 call term_sendkeys(buf, ":q\<CR>")
2221
2222 " After the last popup menu item, <C-N> should show the original string
2223 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002224 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2225
2226 " Use the popup menu for the command name
2227 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2229
2230 " Pressing the left arrow should remove the popup menu
2231 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002232 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2233
2234 " Pressing <BS> should remove the popup menu and erase the last character
2235 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002236 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2237
2238 " Pressing <C-W> should remove the popup menu and erase the previous word
2239 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002240 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2241
2242 " Pressing <C-U> should remove the popup menu and erase the entire line
2243 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002244 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2245
2246 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2247 " the cmdline from history
2248 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002249 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2250
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002251 " Check "list" still works
2252 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2253 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002254 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2255 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002256 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2257
rbtnn68cc2b82022-02-09 11:55:47 +00002258 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002259 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002260 call writefile([], 'Xnamedir/あいう/abc')
2261 call writefile([], 'Xnamedir/あいう/xyz')
2262 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002263
2264 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002265 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002266 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2267
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002268 " Pressing <C-A> when the popup menu is displayed should list all the
2269 " matches and pressing a key after that should remove the popup menu
2270 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2271 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2272 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2273
2274 " Pressing <C-A> when the popup menu is displayed should list all the
2275 " matches and pressing <Left> after that should move the cursor
2276 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2277 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2278 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2279
2280 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2281 " should be displayed correctly on the screen.
2282 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2283 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2284
2285 " After using <C-A> to expand all the filename matches, pressing <Up>
2286 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002287 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002288 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2289 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2290 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2291
2292 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2293 " crash Vim
2294 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2295 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2296
Bram Moolenaar414acd32022-02-10 21:09:45 +00002297 " After removing the pum the command line is redrawn
2298 call term_sendkeys(buf, ":edit foo\<CR>")
2299 call term_sendkeys(buf, ":edit bar\<CR>")
2300 call term_sendkeys(buf, ":ls\<CR>")
2301 call term_sendkeys(buf, ":com\<Tab> ")
2302 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002303 call term_sendkeys(buf, "\<C-U>\<CR>")
2304
2305 " Esc still works to abort the command when 'statusline' is set
2306 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2307 call term_sendkeys(buf, ":si\<Tab>")
2308 call term_sendkeys(buf, "\<Esc>")
2309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002310
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002311 " Esc still works to abort the command when 'tabline' is set
2312 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2313 call term_sendkeys(buf, ":si\<Tab>")
2314 call term_sendkeys(buf, "\<Esc>")
2315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2316
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002317 " popup is cleared also when 'lazyredraw' is set
2318 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2319 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2320 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2321 call term_sendkeys(buf, "\<Esc>")
2322
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002323 " Pressing <PageDown> should scroll the menu downward
2324 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2325 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2326 call term_sendkeys(buf, "\<PageDown>")
2327 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2328 call term_sendkeys(buf, "\<PageDown>")
2329 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2330 call term_sendkeys(buf, "\<PageDown>")
2331 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2332 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2333 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2334
2335 " Pressing <PageUp> should scroll the menu upward
2336 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2337 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2338 call term_sendkeys(buf, "\<PageUp>")
2339 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2340 call term_sendkeys(buf, "\<PageUp>")
2341 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2342 call term_sendkeys(buf, "\<PageUp>")
2343 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2344
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002345 call term_sendkeys(buf, "\<C-U>\<CR>")
2346 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002347endfunc
2348
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002349" Test for wildmenumode() with the cmdline popup menu
2350func Test_wildmenumode_with_pum()
2351 set wildmenu
2352 set wildoptions=pum
2353 cnoremap <expr> <F2> wildmenumode()
2354 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2355 call assert_equal('"sign define10', @:)
2356 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2357 call assert_equal('"sign define jump list place undefine unplace0', @:)
2358 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2359 call assert_equal('"sign 0', @:)
2360 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2361 call assert_equal('"sign define0', @:)
2362 set nowildmenu wildoptions&
2363 cunmap <F2>
2364endfunc
2365
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002366func Test_wildmenu_with_pum_foldexpr()
2367 CheckRunVimInTerminal
2368
2369 let lines =<< trim END
2370 call setline(1, ['folded one', 'folded two', 'some more text'])
2371 func MyFoldText()
2372 return 'foo'
2373 endfunc
2374 set foldtext=MyFoldText() wildoptions=pum
2375 normal ggzfj
2376 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002377 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002378 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2379 call term_sendkeys(buf, ":set\<Tab>")
2380 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2381
2382 call term_sendkeys(buf, "\<Esc>")
2383 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2384
2385 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002386endfunc
2387
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002388" Test for opening the cmdline completion popup menu from the terminal window.
2389" The popup menu should be positioned correctly over the status line of the
2390" bottom-most window.
2391func Test_wildmenu_pum_from_terminal()
2392 CheckRunVimInTerminal
2393 let python = PythonProg()
2394 call CheckPython(python)
2395
2396 %bw!
2397 let cmds = ['set wildmenu wildoptions=pum']
2398 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2399 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002400 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002401 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2402 call term_sendkeys(buf, "\r\r\r")
2403 call term_wait(buf)
2404 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2405 call term_wait(buf)
2406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2407 call term_wait(buf)
2408 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002409endfunc
2410
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002411" Test for completion after a :substitute command followed by a pipe (|)
2412" character
2413func Test_cmdline_complete_substitute()
2414 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2415 call assert_equal("\"s | \t", @:)
2416 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2417 call assert_equal("\"s/ | \t", @:)
2418 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2419 call assert_equal("\"s/one | \t", @:)
2420 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2421 call assert_equal("\"s/one/ | \t", @:)
2422 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2423 call assert_equal("\"s/one/two | \t", @:)
2424 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2425 call assert_equal('"s/one/two/ | chistory', @:)
2426 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2427 call assert_equal("\"s/one/two/g \t", @:)
2428 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2429 call assert_equal("\"s/one/two/g | chistory", @:)
2430 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2431 call assert_equal("\"s/one/t\\/ | \t", @:)
2432 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2433 call assert_equal('"s/one/t"o/ | chistory', @:)
2434 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2435 call assert_equal('"s/one/t|o/ | chistory', @:)
2436 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2437 call assert_equal("\"&\t", @:)
2438endfunc
2439
2440" Test for the :dlist command completion
2441func Test_cmdline_complete_dlist()
2442 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2443 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2444 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2445 call assert_equal("\"dlist 10 /pat/ \t", @:)
2446 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2447 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2448 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2449 call assert_equal("\"dlist 10 /pat\\\t", @:)
2450 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2451 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2452endfunc
2453
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002454" argument list (only for :argdel) fuzzy completion
2455func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002456 argadd change.py count.py charge.py
2457 set wildoptions&
2458 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2459 call assert_equal('"argdel cge', @:)
2460 set wildoptions=fuzzy
2461 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2462 call assert_equal('"argdel change.py charge.py', @:)
2463 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002464 set wildoptions&
2465endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002466
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002467" autocmd group name fuzzy completion
2468func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002469 set wildoptions&
2470 augroup MyFuzzyGroup
2471 augroup END
2472 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2473 call assert_equal('"augroup mfg', @:)
2474 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2475 call assert_equal('"augroup MyFuzzyGroup', @:)
2476 set wildoptions=fuzzy
2477 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2478 call assert_equal('"augroup MyFuzzyGroup', @:)
2479 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2480 call assert_equal('"augroup My*p', @:)
2481 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002482 set wildoptions&
2483endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002484
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002485" buffer name fuzzy completion
2486func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002487 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002488 " Use a long name to reduce the risk of matching a random directory name
2489 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002490 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002491 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2492 call assert_equal('"b SRFWL', @:)
2493 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2494 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002495 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002496 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2497 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2498 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2499 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002500 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002501 set wildoptions&
2502endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002503
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002504" buffer name (full path) fuzzy completion
2505func Test_fuzzy_completion_bufname_fullpath()
2506 CheckUnix
2507 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002508 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002509 edit Xcmd/Xstate/Xfile.js
2510 cd Xcmd/Xstate
2511 enew
2512 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2513 call assert_equal('"b CmdStateFile', @:)
2514 set wildoptions=fuzzy
2515 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2516 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2517 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002518 set wildoptions&
2519endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002520
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002521" :behave suboptions fuzzy completion
2522func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002523 set wildoptions&
2524 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2525 call assert_equal('"behave xm', @:)
2526 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2527 call assert_equal('"behave xterm', @:)
2528 set wildoptions=fuzzy
2529 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2530 call assert_equal('"behave xterm', @:)
2531 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2532 call assert_equal('"behave xt*m', @:)
2533 let g:Sline = ''
2534 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2535 call assert_equal('mswin', g:Sline)
2536 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002537 set wildoptions&
2538endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002539
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002540" " colorscheme name fuzzy completion - NOT supported
2541" func Test_fuzzy_completion_colorscheme()
2542" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002543
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002544" built-in command name fuzzy completion
2545func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002546 set wildoptions&
2547 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2548 call assert_equal('"sbwin', @:)
2549 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2550 call assert_equal('"sbrewind', @:)
2551 set wildoptions=fuzzy
2552 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2553 call assert_equal('"sbrewind', @:)
2554 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2555 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002556 set wildoptions&
2557endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002558
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002559" " compiler name fuzzy completion - NOT supported
2560" func Test_fuzzy_completion_compiler()
2561" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002562
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002563" :cscope suboptions fuzzy completion
2564func Test_fuzzy_completion_cscope()
2565 CheckFeature cscope
2566 set wildoptions&
2567 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2568 call assert_equal('"cscope ret', @:)
2569 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2570 call assert_equal('"cscope reset', @:)
2571 set wildoptions=fuzzy
2572 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2573 call assert_equal('"cscope reset', @:)
2574 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2575 call assert_equal('"cscope re*t', @:)
2576 set wildoptions&
2577endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002578
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002579" :diffget/:diffput buffer name fuzzy completion
2580func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002581 new SomeBuffer
2582 diffthis
2583 new OtherBuffer
2584 diffthis
2585 set wildoptions&
2586 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2587 call assert_equal('"diffget sbuf', @:)
2588 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2589 call assert_equal('"diffput sbuf', @:)
2590 set wildoptions=fuzzy
2591 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2592 call assert_equal('"diffget SomeBuffer', @:)
2593 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2594 call assert_equal('"diffput SomeBuffer', @:)
2595 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002596 set wildoptions&
2597endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002598
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002599" " directory name fuzzy completion - NOT supported
2600" func Test_fuzzy_completion_dirname()
2601" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002602
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002603" environment variable name fuzzy completion
2604func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002605 set wildoptions&
2606 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2607 call assert_equal('"echo $VUT', @:)
2608 set wildoptions=fuzzy
2609 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2610 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002611 set wildoptions&
2612endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002613
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002614" autocmd event fuzzy completion
2615func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002616 set wildoptions&
2617 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2618 call assert_equal('"autocmd BWout', @:)
2619 set wildoptions=fuzzy
2620 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2621 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002622 set wildoptions&
2623endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002624
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002625" vim expression fuzzy completion
2626func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002627 let g:PerPlaceCount = 10
2628 set wildoptions&
2629 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2630 call assert_equal('"let c = ppc', @:)
2631 set wildoptions=fuzzy
2632 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2633 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002634 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002635endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002636
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002637" " file name fuzzy completion - NOT supported
2638" func Test_fuzzy_completion_filename()
2639" endfunc
2640
2641" " files in path fuzzy completion - NOT supported
2642" func Test_fuzzy_completion_filesinpath()
2643" endfunc
2644
2645" " filetype name fuzzy completion - NOT supported
2646" func Test_fuzzy_completion_filetype()
2647" endfunc
2648
2649" user defined function name completion
2650func Test_fuzzy_completion_userdefined_func()
2651 set wildoptions&
2652 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2653 call assert_equal('"call Test_f_u_f', @:)
2654 set wildoptions=fuzzy
2655 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2656 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2657 set wildoptions&
2658endfunc
2659
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002660" <SNR> functions should be sorted to the end
2661func Test_fuzzy_completion_userdefined_snr_func()
2662 func s:Sendmail()
2663 endfunc
2664 func SendSomemail()
2665 endfunc
2666 func S1e2n3dmail()
2667 endfunc
2668 set wildoptions=fuzzy
2669 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002670 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002671 set wildoptions&
2672 delfunc s:Sendmail
2673 delfunc SendSomemail
2674 delfunc S1e2n3dmail
2675endfunc
2676
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002677" user defined command name completion
2678func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002679 set wildoptions&
2680 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2681 call assert_equal('"MsFeat', @:)
2682 set wildoptions=fuzzy
2683 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2684 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002685 set wildoptions&
2686endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002687
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002688" " :help tag fuzzy completion - NOT supported
2689" func Test_fuzzy_completion_helptag()
2690" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002691
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002692" highlight group name fuzzy completion
2693func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002694 set wildoptions&
2695 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2696 call assert_equal('"highlight SKey', @:)
2697 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2698 call assert_equal('"highlight SpecialKey', @:)
2699 set wildoptions=fuzzy
2700 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2701 call assert_equal('"highlight SpecialKey', @:)
2702 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2703 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002704 set wildoptions&
2705endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002706
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002707" :history suboptions fuzzy completion
2708func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002709 set wildoptions&
2710 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2711 call assert_equal('"history dg', @:)
2712 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2713 call assert_equal('"history search', @:)
2714 set wildoptions=fuzzy
2715 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2716 call assert_equal('"history debug', @:)
2717 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002719 set wildoptions&
2720endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002721
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002722" :language locale name fuzzy completion
2723func Test_fuzzy_completion_lang()
2724 CheckUnix
2725 set wildoptions&
2726 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2727 call assert_equal('"lang psx', @:)
2728 set wildoptions=fuzzy
2729 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2730 call assert_equal('"lang POSIX', @:)
2731 set wildoptions&
2732endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002733
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002734" :mapclear buffer argument fuzzy completion
2735func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002736 set wildoptions&
2737 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2738 call assert_equal('"mapclear buf', @:)
2739 set wildoptions=fuzzy
2740 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2741 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002742 set wildoptions&
2743endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002744
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002745" map name fuzzy completion
2746func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002747 " test regex completion works
2748 set wildoptions=fuzzy
2749 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2750 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002751 nmap <plug>MyLongMap :p<CR>
2752 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2753 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2754 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2755 call assert_equal("\"nmap MLM \t", @:)
2756 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2757 call assert_equal("\"nmap <F2> one two \t", @:)
2758 " duplicate entries should be removed
2759 vmap <plug>MyLongMap :<C-U>#<CR>
2760 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2762 nunmap <plug>MyLongMap
2763 vunmap <plug>MyLongMap
2764 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2765 call assert_equal("\"nmap ABC\t", @:)
2766 " results should be sorted by best match
2767 nmap <Plug>format :
2768 nmap <Plug>goformat :
2769 nmap <Plug>TestFOrmat :
2770 nmap <Plug>fendoff :
2771 nmap <Plug>state :
2772 nmap <Plug>FendingOff :
2773 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2774 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2775 nunmap <Plug>format
2776 nunmap <Plug>goformat
2777 nunmap <Plug>TestFOrmat
2778 nunmap <Plug>fendoff
2779 nunmap <Plug>state
2780 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002781 set wildoptions&
2782endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002783
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002784" abbreviation fuzzy completion
2785func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002786 set wildoptions=fuzzy
2787 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2788 call assert_equal("\"iabbr <nowait>", @:)
2789 iabbr WaitForCompletion WFC
2790 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2791 call assert_equal("\"iabbr WaitForCompletion", @:)
2792 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2793 call assert_equal("\"iabbr a1z\t", @:)
2794 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002795 set wildoptions&
2796endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002797
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002798" menu name fuzzy completion
2799func Test_fuzzy_completion_menu()
2800 CheckGui
2801 set wildoptions&
2802 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2803 call assert_equal('"menu pup', @:)
2804 set wildoptions=fuzzy
2805 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2806 call assert_equal('"menu PopUp.', @:)
2807 set wildoptions&
2808endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002809
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002810" :messages suboptions fuzzy completion
2811func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002812 set wildoptions&
2813 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2814 call assert_equal('"messages clr', @:)
2815 set wildoptions=fuzzy
2816 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2817 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818 set wildoptions&
2819endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002821" :set option name fuzzy completion
2822func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002823 set wildoptions&
2824 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2825 call assert_equal('"set brkopt', @:)
2826 set wildoptions=fuzzy
2827 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2828 call assert_equal('"set breakindentopt', @:)
2829 set wildoptions&
2830 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2831 call assert_equal('"set fixendofline', @:)
2832 set wildoptions=fuzzy
2833 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002835 set wildoptions&
2836endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002837
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002838" :set <term_option>
2839func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002840 set wildoptions&
2841 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2842 call assert_equal('"set t_EC', @:)
2843 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"set <t_EC>', @:)
2845 set wildoptions=fuzzy
2846 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2847 call assert_equal('"set t_EC', @:)
2848 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2849 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002850 set wildoptions&
2851endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002852
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002853" " :packadd directory name fuzzy completion - NOT supported
2854" func Test_fuzzy_completion_packadd()
2855" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002856
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002857" " shell command name fuzzy completion - NOT supported
2858" func Test_fuzzy_completion_shellcmd()
2859" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002860
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002861" :sign suboptions fuzzy completion
2862func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002863 set wildoptions&
2864 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2865 call assert_equal('"sign ufe', @:)
2866 set wildoptions=fuzzy
2867 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2868 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002869 set wildoptions&
2870endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002871
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002872" :syntax suboptions fuzzy completion
2873func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002874 set wildoptions&
2875 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2876 call assert_equal('"syntax kwd', @:)
2877 set wildoptions=fuzzy
2878 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2879 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002880 set wildoptions&
2881endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002882
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002883" syntax group name fuzzy completion
2884func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002885 set wildoptions&
2886 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2887 call assert_equal('"syntax list mpar', @:)
2888 set wildoptions=fuzzy
2889 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2890 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002891 set wildoptions&
2892endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002893
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002894" :syntime suboptions fuzzy completion
2895func Test_fuzzy_completion_syntime()
2896 CheckFeature profile
2897 set wildoptions&
2898 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"syntime clr', @:)
2900 set wildoptions=fuzzy
2901 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2902 call assert_equal('"syntime clear', @:)
2903 set wildoptions&
2904endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002906" " tag name fuzzy completion - NOT supported
2907" func Test_fuzzy_completion_tagname()
2908" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002909
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002910" " tag name and file fuzzy completion - NOT supported
2911" func Test_fuzzy_completion_tagfile()
2912" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002913
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002914" " user names fuzzy completion - how to test this functionality?
2915" func Test_fuzzy_completion_username()
2916" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002917
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002918" user defined variable name fuzzy completion
2919func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002920 let g:SomeVariable=10
2921 set wildoptions&
2922 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2923 call assert_equal('"let SVar', @:)
2924 set wildoptions=fuzzy
2925 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2926 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002927 set wildoptions&
2928endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" Test for sorting the results by the best match
2931func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002932 %bw!
2933 command T123format :
2934 command T123goformat :
2935 command T123TestFOrmat :
2936 command T123fendoff :
2937 command T123state :
2938 command T123FendingOff :
2939 set wildoptions=fuzzy
2940 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2941 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2942 delcommand T123format
2943 delcommand T123goformat
2944 delcommand T123TestFOrmat
2945 delcommand T123fendoff
2946 delcommand T123state
2947 delcommand T123FendingOff
2948 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949 set wildoptions&
2950endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002951
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002952" Test for fuzzy completion of a command with lower case letters and a number
2953func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002954 command Foo2Bar :
2955 set wildoptions=fuzzy
2956 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2957 call assert_equal('"Foo2Bar', @:)
2958 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2959 call assert_equal('"Foo2Bar', @:)
2960 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('"Foo2Bar', @:)
2962 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002963 set wildoptions&
2964endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002965
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002966" Test for command completion for a command starting with 'k'
2967func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002968 command KillKillKill :
2969 set wildoptions&
2970 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2971 call assert_equal("\"killkill\<Tab>", @:)
2972 set wildoptions=fuzzy
2973 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2974 call assert_equal('"KillKillKill', @:)
2975 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002976 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977endfunc
2978
2979" Test for fuzzy completion for user defined custom completion function
2980func Test_fuzzy_completion_custom_func()
2981 func Tcompl(a, c, p)
2982 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
2983 endfunc
2984 command -nargs=* -complete=custom,Tcompl Fuzzy :
2985 set wildoptions&
2986 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2987 call assert_equal("\"Fuzzy format", @:)
2988 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2989 call assert_equal("\"Fuzzy xy", @:)
2990 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2991 call assert_equal("\"Fuzzy ttt", @:)
2992 set wildoptions=fuzzy
2993 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
2995 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
2997 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal("\"Fuzzy xy", @:)
2999 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3000 call assert_equal("\"Fuzzy TestFOrmat", @:)
3001 delcom Fuzzy
3002 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003003endfunc
3004
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003005" Test for :breakadd argument completion
3006func Test_cmdline_complete_breakadd()
3007 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3008 call assert_equal("\"breakadd expr file func here", @:)
3009 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal("\"breakadd expr", @:)
3011 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3012 call assert_equal("\"breakadd expr", @:)
3013 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3014 call assert_equal("\"breakadd here", @:)
3015 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3016 call assert_equal("\"breakadd here", @:)
3017 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal("\"breakadd abc", @:)
3019 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3020 let l = getcompletion('not', 'breakpoint')
3021 call assert_equal([], l)
3022
3023 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003024 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003025 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3026 call assert_equal("\"breakadd file Xscript", @:)
3027 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal("\"breakadd file Xscript", @:)
3029 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal("\"breakadd file 20 Xscript", @:)
3031 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3032 call assert_equal("\"breakadd file 20 Xscript", @:)
3033 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3035 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal("\"breakadd file 20\t", @:)
3037 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal("\"breakadd file 20x\t", @:)
3039 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3040 call assert_equal("\"breakadd file Xscript ", @:)
3041 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3042 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003043
3044 " Test for :breakadd func [lnum] <function>
3045 func Xbreak_func()
3046 endfunc
3047 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3048 call assert_equal("\"breakadd func Xbreak_func", @:)
3049 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal("\"breakadd func Xbreak_func", @:)
3051 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3053 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3055 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3056 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3057 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3058 call assert_equal("\"breakadd func 20\t", @:)
3059 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3060 call assert_equal("\"breakadd func 20x\t", @:)
3061 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3062 call assert_equal("\"breakadd func Xbreak_func ", @:)
3063 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal("\"breakadd func X1B2C3", @:)
3065 delfunc Xbreak_func
3066
3067 " Test for :breakadd expr <expression>
3068 let g:Xtest_var = 10
3069 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3070 call assert_equal("\"breakadd expr Xtest_var", @:)
3071 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3072 call assert_equal("\"breakadd expr Xtest_var", @:)
3073 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3074 call assert_equal("\"breakadd expr Xtest_var ", @:)
3075 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3076 call assert_equal("\"breakadd expr X1B2C3", @:)
3077 unlet g:Xtest_var
3078
3079 " Test for :breakadd here
3080 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal("\"breakadd here Xtest", @:)
3082 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal("\"breakadd here Xtest", @:)
3084 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal("\"breakadd here ", @:)
3086endfunc
3087
3088" Test for :breakdel argument completion
3089func Test_cmdline_complete_breakdel()
3090 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3091 call assert_equal("\"breakdel file func here", @:)
3092 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3093 call assert_equal("\"breakdel file", @:)
3094 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3095 call assert_equal("\"breakdel file", @:)
3096 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal("\"breakdel here", @:)
3098 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3099 call assert_equal("\"breakdel here", @:)
3100 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3101 call assert_equal("\"breakdel abc", @:)
3102
3103 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003104 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003105 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakdel file Xscript", @:)
3107 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakdel file Xscript", @:)
3109 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"breakdel file 20 Xscript", @:)
3111 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"breakdel file 20 Xscript", @:)
3113 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3115 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"breakdel file 20\t", @:)
3117 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakdel file 20x\t", @:)
3119 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakdel file Xscript ", @:)
3121 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003123
3124 " Test for :breakdel func [lnum] <function>
3125 func Xbreak_func()
3126 endfunc
3127 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakdel func Xbreak_func", @:)
3129 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakdel func Xbreak_func", @:)
3131 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3133 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3135 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3137 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakdel func 20\t", @:)
3139 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakdel func 20x\t", @:)
3141 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakdel func Xbreak_func ", @:)
3143 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakdel func X1B2C3", @:)
3145 delfunc Xbreak_func
3146
3147 " Test for :breakdel here
3148 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal("\"breakdel here Xtest", @:)
3150 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal("\"breakdel here Xtest", @:)
3152 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003154endfunc
3155
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003156" Test for :scriptnames argument completion
3157func Test_cmdline_complete_scriptnames()
3158 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003159 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003160 source Xa1b2c3.vim
3161 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3162 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3163 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3164 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3165 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"script b2c3", @:)
3167 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_match("\"script 2\<Tab>$", @:)
3169 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3171 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal("\"script ", @:)
3173 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3174 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3175 new
3176 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3177 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3178 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003179 set wildmenu&
3180endfunc
3181
Bram Moolenaard8893442022-05-06 20:38:47 +01003182" this was going over the end of IObuff
3183func Test_report_error_with_composing()
3184 let caught = 'no'
3185 try
3186 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3187 catch /E492:/
3188 let caught = 'yes'
3189 endtry
3190 call assert_equal('yes', caught)
3191endfunc
3192
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003193" Test for expanding 2-letter and 3-letter :substitute command arguments.
3194" These commands don't accept an argument.
3195func Test_cmdline_complete_substitute_short()
3196 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3197 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3198 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3199 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3200 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3201 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3202 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3203 endfor
3204endfunc
3205
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003206" Test for :! shell command argument completion
3207func Test_cmdline_complete_bang_cmd_argument()
3208 set wildoptions=fuzzy
3209 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3210 call assert_equal('"!vim test_cmdline.vim', @:)
3211 set wildoptions&
3212 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3213 call assert_equal('"!vim test_cmdline.vim', @:)
3214endfunc
3215
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003216func Check_completion()
3217 call assert_equal('let a', getcmdline())
3218 call assert_equal(6, getcmdpos())
3219 call assert_equal(7, getcmdscreenpos())
3220 call assert_equal('var', getcmdcompltype())
3221 return ''
3222endfunc
3223
3224func Test_screenpos_and_completion()
3225 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3226endfunc
3227
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003228func Test_recursive_register()
3229 let @= = ''
3230 silent! ?e/
3231 let caught = 'no'
3232 try
3233 normal //
3234 catch /E169:/
3235 let caught = 'yes'
3236 endtry
3237 call assert_equal('yes', caught)
3238endfunc
3239
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003240func Test_long_error_message()
3241 " the error should be truncated, not overrun IObuff
3242 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3243endfunc
3244
zeertzjq6791adc2022-07-26 20:42:25 +01003245func Test_cmdline_redraw_tabline()
3246 CheckRunVimInTerminal
3247
3248 let lines =<< trim END
3249 set showtabline=2
3250 autocmd CmdlineEnter * set tabline=foo
3251 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003252 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003253 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3254 call term_sendkeys(buf, ':')
3255 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3256
3257 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003258endfunc
3259
zeertzjqb82a2ab2022-08-21 14:33:57 +01003260func Test_wildmenu_pum_disable_while_shown()
3261 set wildoptions=pum
3262 set wildmenu
3263 cnoremap <F2> <Cmd>set nowildmenu<CR>
3264 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3265 call assert_equal(0, pumvisible())
3266 cunmap <F2>
3267 set wildoptions& wildmenu&
3268endfunc
3269
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003270func Test_setcmdline()
3271 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003272 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003273 call assert_equal(0, setcmdline(a:text))
3274 call assert_equal(a:text, getcmdline())
3275 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003276 call assert_equal(getcmdtype(), g:cmdtype)
3277 unlet g:cmdtype
3278 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003279
3280 call assert_equal(0, setcmdline(a:text, a:pos))
3281 call assert_equal(a:text, getcmdline())
3282 call assert_equal(a:pos, getcmdpos())
3283
3284 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003285 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3286 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003287
3288 return ''
3289 endfunc
3290
3291 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3292 call assert_equal('set rtp?', @:)
3293
zeertzjq54acb902022-08-29 16:21:25 +01003294 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3295 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3296 call assert_equal('foo', g:str)
3297 unlet g:str
3298
3299 delfunc SetText
3300
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003301 " setcmdline() returns 1 when not editing the command line.
3302 call assert_equal(1, 'foo'->setcmdline())
3303
3304 " Called in custom function
3305 func CustomComplete(A, L, P)
3306 call assert_equal(0, setcmdline("DoCmd "))
3307 return "January\nFebruary\nMars\n"
3308 endfunc
3309
3310 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3311 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3312 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003313 delcom DoCmd
3314 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003315
3316 " Called in <expr>
3317 cnoremap <expr>a setcmdline('let foo=')
3318 call feedkeys(":a\<CR>", 'tx')
3319 call assert_equal('let foo=0', @:)
3320 cunmap a
3321endfunc
3322
Bram Moolenaar309976e2019-12-05 18:16:33 +01003323" vim: shiftwidth=2 sts=2 expandtab