blob: 00939f9105f8ec0432fd0d094af355756fa3e050 [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()}
zeertzjq320d9102022-09-20 17:12:13 +0100219 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100220 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
zeertzjq320d9102022-09-20 17:12:13 +0100229 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100231 " with cmdheight=1 messages have scrolled when typing :endfor
232 call term_sendkeys(buf, "\<CR>:endfor")
233 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
234 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
235 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
236 call term_sendkeys(buf, ":for in in range(3)")
237 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
238 call term_sendkeys(buf, "\<CR>:endfor")
239 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100240
241 " clean up
242 call term_sendkeys(buf, "\<CR>")
243 call StopVimInTerminal(buf)
244endfunc
245
Bram Moolenaarf797e302022-08-11 13:17:30 +0100246func Test_changing_cmdheight()
247 CheckScreendump
248
249 let lines =<< trim END
250 set cmdheight=1 laststatus=2
251 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100252 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100253
254 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
255 call term_sendkeys(buf, ":resize -3\<CR>")
256 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
257
258 " using the space available doesn't change the status line
259 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
260 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
261
262 " using more space moves the status line up
263 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
264 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
265
266 " reducing cmdheight moves status line down
267 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
268 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
269
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100270 " reducing window size and then setting cmdheight
271 call term_sendkeys(buf, ":resize -1\<CR>")
272 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
273 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
274
Bram Moolenaarf797e302022-08-11 13:17:30 +0100275 " clean up
276 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100277endfunc
278
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100279func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100280 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
281 call assert_equal('"map <unique> <silent>', getreg(':'))
282 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
283 call assert_equal('"map <script> <unique>', getreg(':'))
284 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
285 call assert_equal('"map <expr> <script>', getreg(':'))
286 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
287 call assert_equal('"map <buffer> <expr>', getreg(':'))
288 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
289 call assert_equal('"map <nowait> <buffer>', getreg(':'))
290 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
291 call assert_equal('"map <special> <nowait>', getreg(':'))
292 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
293 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200294
Bram Moolenaar1776a282019-05-03 16:05:41 +0200295 map <Middle>x middle
296
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200297 map ,f commaf
298 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200299 map <Left> left
300 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200301 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map ,f', getreg(':'))
303 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200305 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <Left>', getreg(':'))
307 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200308 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200309 unmap ,f
310 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200311 unmap <Left>
312 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200313
314 set cpo-=< cpo-=B cpo-=k
315 map <Left> left
316 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
317 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200318 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200319 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200320 unmap <Left>
321
322 set cpo+=<
323 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200324 exe "set t_k6=\<Esc>[17~"
325 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200328 if !has('gui_running')
329 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
330 call assert_equal("\"map <F6>x", getreg(':'))
331 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200332 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200333 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200334 set cpo-=<
335
336 set cpo+=B
337 map <Left> left
338 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
339 call assert_equal('"map <Left>', getreg(':'))
340 unmap <Left>
341 set cpo-=B
342
343 set cpo+=k
344 map <Left> left
345 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"map <Left>', getreg(':'))
347 unmap <Left>
348 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200349
Bram Moolenaar531be472020-09-23 22:38:05 +0200350 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
351
Bram Moolenaar1776a282019-05-03 16:05:41 +0200352 unmap <Middle>x
353 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100354endfunc
355
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100356func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100357 hi Aardig ctermfg=green
358 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000359 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100360 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000361 call assert_equal('"match none', @:)
362 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
363 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100364endfunc
365
366func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100367 hi Aardig ctermfg=green
368 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
369 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200370 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
371 call assert_equal('"hi default Aardig', getreg(':'))
372 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
373 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100374 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
375 call assert_equal('"hi link', getreg(':'))
376 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
377 call assert_equal('"hi default', getreg(':'))
378 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
379 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200380 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
381 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
382 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
383 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200384
385 " A cleared group does not show up in completions.
386 hi Anders ctermfg=green
387 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
388 hi clear Aardig
389 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
390 hi clear Anders
391 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100392endfunc
393
Bram Moolenaar75e15672020-06-28 13:10:22 +0200394" Test for command-line expansion of "hi Ni " (easter egg)
395func Test_highlight_easter_egg()
396 call test_override('ui_delay', 1)
397 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
398 call assert_equal("\"hi Ni \<Tab>", @:)
399 call test_override('ALL', 0)
400endfunc
401
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200402func Test_getcompletion()
403 let groupcount = len(getcompletion('', 'event'))
404 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200405 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200406 call assert_true(matchcount > 0)
407 call assert_true(groupcount > matchcount)
408
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200409 if has('menu')
410 source $VIMRUNTIME/menu.vim
411 let matchcount = len(getcompletion('', 'menu'))
412 call assert_true(matchcount > 0)
413 call assert_equal(['File.'], getcompletion('File', 'menu'))
414 call assert_true(matchcount > 0)
415 let matchcount = len(getcompletion('File.', 'menu'))
416 call assert_true(matchcount > 0)
417 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200418
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200419 let l = getcompletion('v:n', 'var')
420 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200421 let l = getcompletion('v:notexists', 'var')
422 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200423
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200424 args a.c b.c
425 let l = getcompletion('', 'arglist')
426 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000427 let l = getcompletion('a.', 'buffer')
428 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200429 %argdelete
430
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200431 let l = getcompletion('', 'augroup')
432 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200433 let l = getcompletion('blahblah', 'augroup')
434 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200435
436 let l = getcompletion('', 'behave')
437 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200438 let l = getcompletion('not', 'behave')
439 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200440
441 let l = getcompletion('', 'color')
442 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200443 let l = getcompletion('dirty', 'color')
444 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200445
446 let l = getcompletion('', 'command')
447 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200448 let l = getcompletion('awake', 'command')
449 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200450
451 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200452 call assert_true(index(l, 'samples/') >= 0)
453 let l = getcompletion('NoMatch', 'dir')
454 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200455
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100456 if glob('~/*') !=# ''
457 let l = getcompletion('~/', 'dir')
458 call assert_true(l[0][0] ==# '~')
459 endif
460
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461 let l = getcompletion('exe', 'expression')
462 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200463 let l = getcompletion('kill', 'expression')
464 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200465
466 let l = getcompletion('tag', 'function')
467 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200468 let l = getcompletion('paint', 'function')
469 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200470
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200471 let Flambda = {-> 'hello'}
472 let l = getcompletion('', 'function')
473 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200474 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200475
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476 let l = getcompletion('run', 'file')
477 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200478 let l = getcompletion('walk', 'file')
479 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200480 set wildignore=*.vim
481 let l = getcompletion('run', 'file', 1)
482 call assert_true(index(l, 'runtest.vim') < 0)
483 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000484 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100485 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000486 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
487 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200488
489 let l = getcompletion('ha', 'filetype')
490 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200491 let l = getcompletion('horse', 'filetype')
492 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200493
494 let l = getcompletion('z', 'syntax')
495 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200496 let l = getcompletion('emacs', 'syntax')
497 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200498
499 let l = getcompletion('jikes', 'compiler')
500 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200501 let l = getcompletion('break', 'compiler')
502 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503
504 let l = getcompletion('last', 'help')
505 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200506 let l = getcompletion('giveup', 'help')
507 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200508
509 let l = getcompletion('time', 'option')
510 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200511 let l = getcompletion('space', 'option')
512 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200513
514 let l = getcompletion('er', 'highlight')
515 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200516 let l = getcompletion('dark', 'highlight')
517 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200518
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200519 let l = getcompletion('', 'messages')
520 call assert_true(index(l, 'clear') >= 0)
521 let l = getcompletion('not', 'messages')
522 call assert_equal([], l)
523
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200524 let l = getcompletion('', 'mapclear')
525 call assert_true(index(l, '<buffer>') >= 0)
526 let l = getcompletion('not', 'mapclear')
527 call assert_equal([], l)
528
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200529 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200530 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200531 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
532 let root = has('win32') ? 'C:\\' : '/'
533 let l = getcompletion(root, 'shellcmd')
534 let expected = map(filter(glob(root . '*', 0, 1),
535 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
536 call assert_equal(expected, l)
537
Bram Moolenaarb650b982016-08-05 20:35:13 +0200538 if has('cscope')
539 let l = getcompletion('', 'cscope')
540 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
541 call assert_equal(cmds, l)
542 " using cmdline completion must not change the result
543 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
544 let l = getcompletion('', 'cscope')
545 call assert_equal(cmds, l)
546 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
547 let l = getcompletion('find ', 'cscope')
548 call assert_equal(keys, l)
549 endif
550
Bram Moolenaar7522f692016-08-06 14:12:50 +0200551 if has('signs')
552 sign define Testing linehl=Comment
553 let l = getcompletion('', 'sign')
554 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
555 call assert_equal(cmds, l)
556 " using cmdline completion must not change the result
557 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
558 let l = getcompletion('', 'sign')
559 call assert_equal(cmds, l)
560 let l = getcompletion('list ', 'sign')
561 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000562 let l = getcompletion('de*', 'sign')
563 call assert_equal(['define'], l)
564 let l = getcompletion('p?', 'sign')
565 call assert_equal(['place'], l)
566 let l = getcompletion('j.', 'sign')
567 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200568 endif
569
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200570 " Command line completion tests
571 let l = getcompletion('cd ', 'cmdline')
572 call assert_true(index(l, 'samples/') >= 0)
573 let l = getcompletion('cd NoMatch', 'cmdline')
574 call assert_equal([], l)
575 let l = getcompletion('let v:n', 'cmdline')
576 call assert_true(index(l, 'v:null') >= 0)
577 let l = getcompletion('let v:notexists', 'cmdline')
578 call assert_equal([], l)
579 let l = getcompletion('call tag', 'cmdline')
580 call assert_true(index(l, 'taglist(') >= 0)
581 let l = getcompletion('call paint', 'cmdline')
582 call assert_equal([], l)
583
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100584 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000585 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100586 return "oneA\noneB\noneC"
587 endfunc
588 command -nargs=1 -complete=custom,T MyCmd
589 let l = getcompletion('MyCmd ', 'cmdline')
590 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000591 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100592
593 delcommand MyCmd
594 delfunc T
ii144785fe02021-11-21 12:13:56 +0000595 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100596
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200597 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200598 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200599 if has('cmdline_hist')
600 call add(names, 'history')
601 endif
602 if has('gettext')
603 call add(names, 'locale')
604 endif
605 if has('profile')
606 call add(names, 'syntime')
607 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200608
609 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100610 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200611
612 for name in names
613 let matchcount = len(getcompletion('', name))
614 call assert_true(matchcount >= 0, 'No matches for ' . name)
615 endfor
616
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200617 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200618
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000619 edit a~b
620 enew
621 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
622 bw a~b
623
624 if has('unix')
625 edit Xtest\
626 enew
627 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
628 bw Xtest\
629 endif
630
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200631 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200632 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100633 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200634endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200635
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000636" Test for getcompletion() with "fuzzy" in 'wildoptions'
637func Test_getcompletion_wildoptions()
638 let save_wildoptions = &wildoptions
639 set wildoptions&
640 let l = getcompletion('space', 'option')
641 call assert_equal([], l)
642 let l = getcompletion('ier', 'command')
643 call assert_equal([], l)
644 set wildoptions=fuzzy
645 let l = getcompletion('space', 'option')
646 call assert_true(index(l, 'backspace') >= 0)
647 let l = getcompletion('ier', 'command')
648 call assert_true(index(l, 'compiler') >= 0)
649 let &wildoptions = save_wildoptions
650endfunc
651
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000652func Test_complete_autoload_error()
653 let save_rtp = &rtp
654 let lines =<< trim END
655 vim9script
656 export def Complete(..._): string
657 return 'match'
658 enddef
659 echo this will cause an error
660 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100661 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000662 call writefile(lines, 'Xdir/autoload/script.vim')
663 exe 'set rtp+=' .. getcwd() .. '/Xdir'
664
665 let lines =<< trim END
666 vim9script
667 import autoload 'script.vim'
668 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
669 &wildcharm = char2nr("\<Tab>")
670 feedkeys(":Cmd \<Tab>", 'xt')
671 END
672 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
673
674 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000675endfunc
676
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100677func Test_fullcommand()
678 let tests = {
679 \ '': '',
680 \ ':': '',
681 \ ':::': '',
682 \ ':::5': '',
683 \ 'not_a_cmd': '',
684 \ 'Check': '',
685 \ 'syntax': 'syntax',
686 \ ':syntax': 'syntax',
687 \ '::::syntax': 'syntax',
688 \ 'sy': 'syntax',
689 \ 'syn': 'syntax',
690 \ 'synt': 'syntax',
691 \ ':sy': 'syntax',
692 \ '::::sy': 'syntax',
693 \ 'match': 'match',
694 \ '2match': 'match',
695 \ '3match': 'match',
696 \ 'aboveleft': 'aboveleft',
697 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100698 \ 'en': 'endif',
699 \ 'end': 'endif',
700 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100701 \ 's': 'substitute',
702 \ '5s': 'substitute',
703 \ ':5s': 'substitute',
704 \ "'<,'>s": 'substitute',
705 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100706 \ 'CheckLin': 'CheckLinux',
707 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100708 \ }
709
710 for [in, want] in items(tests)
711 call assert_equal(want, fullcommand(in))
712 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200713 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100714
715 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200716
717 command -buffer BufferLocalCommand :
718 command GlobalCommand :
719 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
720 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
721 delcommand BufferLocalCommand
722 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100723endfunc
724
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200725func Test_shellcmd_completion()
726 let save_path = $PATH
727
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100728 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200729 call writefile([''], 'Xpathdir/Xfile.exe')
730 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
731
732 " Set PATH to example directory without trailing slash.
733 let $PATH = getcwd() . '/Xpathdir'
734
735 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
736 " dirs in the PATH, even though they won't be executed. We check that only
737 " subdirs of the PWD and executables from the PATH are included in the
738 " suggestions.
739 let actual = getcompletion('X', 'shellcmd')
740 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
741 call insert(expected, 'Xfile.exe')
742 call assert_equal(expected, actual)
743
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200744 let $PATH = save_path
745endfunc
746
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200747func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100748 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200749 call writefile(['asdfasdf'], 'a/b/fileXname')
750 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000751 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200752 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200753endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100754
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100755func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100756 let @a = "def"
757 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
758 call assert_equal('"abc def ghi', @:)
759
760 new
761 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
762
763 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
764 call assert_equal('"aaa asdf bbb', @:)
765
766 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
767 call assert_equal('"aaa /tmp/some bbb', @:)
768
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200769 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
770 call assert_equal('"aaa '.getline(1).' bbb', @:)
771
Bram Moolenaar21efc362016-12-03 14:05:49 +0100772 set incsearch
773 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
774 call assert_equal('"aaa verylongword bbb', @:)
775
776 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
777 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100778
779 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
780 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100781 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200782
783 " Error while typing a command used to cause that it was not executed
784 " in the end.
785 new
786 try
787 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
788 catch /^Vim\%((\a\+)\)\=:E32/
789 " ignore error E32
790 endtry
791 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100792
Bram Moolenaar578fe942020-02-27 21:32:51 +0100793 " Try to paste an invalid register using <C-R>
794 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
795 call assert_equal('"onetwo', @:)
796
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100797 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100798 let @a = "xy\<C-H>z"
799 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
800 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100801 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
802 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100803 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
804 call assert_equal("\"xy\<C-H>z", @:)
805
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100806 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
807 let @a = "xy\<C-V>z"
808 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
809 call assert_equal('"xyz', @:)
810 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
811 call assert_equal("\"xy\<C-V>z", @:)
812
Bram Moolenaar578fe942020-02-27 21:32:51 +0100813 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
814
Bram Moolenaar72532d32018-04-07 19:09:09 +0200815 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100816endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100817
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100818func Test_cmdline_remove_char()
819 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100820
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100821 for e in ['utf8', 'latin1']
822 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100823
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100824 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
825 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100826
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100827 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
828 call assert_equal('"abcdef', @:)
829
830 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
831 call assert_equal('"abc ghi', @:, e)
832
833 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
834 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100835
836 " This was going before the start in latin1.
837 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100838 endfor
839
840 let &encoding = encoding_save
841endfunc
842
843func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200844 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100845
846 set keymap=esperanto
847 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
848 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
849 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100850endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100851
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100852func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100853 new
854 2;'(
855 2;')
856 quit
857endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100858
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100859func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100860 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100861 new
862 source Xtest.vim
863 " Trigger calling validate_cursor()
864 diffsp Xtest.vim
865 quit!
866 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100867endfunc
868
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100869func Test_mark_from_line_zero()
870 " this was reading past the end of the first (empty) line
871 new
872 norm oxxxx
873 call assert_fails("0;'(", 'E20:')
874 bwipe!
875endfunc
876
Bram Moolenaarba47b512017-01-24 21:18:19 +0100877func Test_cmdline_complete_wildoptions()
878 help
879 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
880 let a = join(sort(split(@:)),' ')
881 set wildoptions=tagfile
882 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
883 let b = join(sort(split(@:)),' ')
884 call assert_equal(a, b)
885 bw!
886endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100887
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200888func Test_cmdline_complete_user_cmd()
889 command! -complete=color -nargs=1 Foo :
890 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
891 call assert_equal('"Foo blue', @:)
892 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
893 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000894 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
895 call assert_equal('"Foo a blue', @:)
896 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
897 call assert_equal('"Foo b\', @:)
898 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
899 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200900 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100901
902 redraw
903 call assert_equal('~', Screenline(&lines - 1))
904 command! FooOne :
905 command! FooTwo :
906
907 set nowildmenu
908 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
909 call assert_equal('"FooOne', @:)
910 call assert_equal('~', Screenline(&lines - 1))
911
912 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
913 call assert_equal('"FooTwo', @:)
914 call assert_equal('~', Screenline(&lines - 1))
915
916 delcommand FooOne
917 delcommand FooTwo
918 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200919endfunc
920
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100921func Test_complete_user_cmd()
922 command FooBar echo 'global'
923 command -buffer FooBar echo 'local'
924 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
925 call assert_equal('"FooBar', @:)
926
927 delcommand -buffer FooBar
928 delcommand FooBar
929endfunc
930
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100931func s:ScriptLocalFunction()
932 echo 'yes'
933endfunc
934
935func Test_cmdline_complete_user_func()
936 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200937 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100938 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
939 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100940
941 " g: prefix also works
942 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
943 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200944
945 " using g: prefix does not result in just "g:" matches from a lambda
946 let Fx = { a -> a }
947 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
948 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200949
950 " existence of script-local dict function does not break user function name
951 " completion
952 function s:a_dict_func() dict
953 endfunction
954 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
955 call assert_match('"call Test_cmdline_complete_user_', @:)
956 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100957endfunc
958
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200959func Test_cmdline_complete_user_names()
960 if has('unix') && executable('whoami')
961 let whoami = systemlist('whoami')[0]
962 let first_letter = whoami[0]
963 if len(first_letter) > 0
964 " Trying completion of :e ~x where x is the first letter of
965 " the user name should complete to at least the user name.
966 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
967 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
968 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200969 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200970 " Just in case: check that the system has an Administrator account.
971 let names = system('net user')
972 if names =~ 'Administrator'
973 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100974 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200975 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100976 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200977 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200978 else
979 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200980 endif
981endfunc
982
Bram Moolenaar297610b2019-12-27 17:20:55 +0100983func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200984 CheckExecutable whoami
985 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
986 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100987endfunc
988
Bram Moolenaar8b633132020-03-20 18:20:51 +0100989func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200990 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
991 call assert_equal(lang, v:lc_time)
992
993 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
994 call assert_equal(lang, v:ctype)
995
996 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
997 call assert_equal(lang, v:collate)
998
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200999 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001000 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001001
1002 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001003 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001004
Bram Moolenaarec680282020-06-12 19:35:32 +02001005 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001006
Bram Moolenaarec680282020-06-12 19:35:32 +02001007 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1008 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001009
Bram Moolenaarec680282020-06-12 19:35:32 +02001010 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1011 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001012
Bram Moolenaarec680282020-06-12 19:35:32 +02001013 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1014 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001015
1016 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1017 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001018endfunc
1019
Bram Moolenaar297610b2019-12-27 17:20:55 +01001020func Test_cmdline_complete_env_variable()
1021 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001022 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1023 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001024 unlet $X_VIM_TEST_COMPLETE_ENV
1025endfunc
1026
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001027func Test_cmdline_complete_expression()
1028 let g:SomeVar = 'blah'
1029 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1030 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1031 call assert_match('"' .. cmd .. ' SomeVar', @:)
1032 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1033 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1034 endfor
1035 unlet g:SomeVar
1036endfunc
1037
Bram Moolenaar47016f52021-08-26 16:39:58 +02001038" Unique function name for completion below
1039func s:WeirdFunc()
1040 echo 'weird'
1041endfunc
1042
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001043" Test for various command-line completion
1044func Test_cmdline_complete_various()
1045 " completion for a command starting with a comment
1046 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1047 call assert_equal("\" :|\"\<C-A>", @:)
1048
1049 " completion for a range followed by a comment
1050 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1051 call assert_equal("\"1,2\"\<C-A>", @:)
1052
1053 " completion for :k command
1054 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1055 call assert_equal("\"ka\<C-A>", @:)
1056
1057 " completion for short version of the :s command
1058 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1059 call assert_equal("\"sI \<C-A>", @:)
1060
1061 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001062 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001063 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001064 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001065 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001066 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1067 call assert_equal("\"w >> Xfile1", @:)
1068 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001069
1070 " completion for :w ! and :r ! commands
1071 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1072 call assert_equal("\"w !invalid_xyz_cmd", @:)
1073 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1074 call assert_equal("\"r !invalid_xyz_cmd", @:)
1075
1076 " completion for :>> and :<< commands
1077 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1078 call assert_equal("\">>>\<C-A>", @:)
1079 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1080 call assert_equal("\"<<<\<C-A>", @:)
1081
1082 " completion for command with +cmd argument
1083 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1084 call assert_equal("\"buffer +/pat Xabc", @:)
1085 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1086 call assert_equal("\"buffer +/pat\<C-A>", @:)
1087
1088 " completion for a command with a trailing comment
1089 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1090 call assert_equal("\"ls \" comment\<C-A>", @:)
1091
1092 " completion for a command with a trailing command
1093 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1094 call assert_equal("\"ls | ls", @:)
1095
1096 " completion for a command with an CTRL-V escaped argument
1097 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1098 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1099
1100 " completion for a command that doesn't take additional arguments
1101 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1102 call assert_equal("\"all abc\<C-A>", @:)
1103
zeertzjqd3de1782022-09-01 12:58:52 +01001104 " completion for :wincmd with :horizontal modifier
1105 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1106 call assert_equal("\"horizontal wincmd", @:)
1107
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001108 " completion for a command with a command modifier
1109 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1110 call assert_equal("\"topleft new", @:)
1111
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001112 " completion for vim9 and legacy commands
1113 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1114 call assert_equal("\"vim9 call strlen(", @:)
1115 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1116 call assert_equal("\"legac call strlen(", @:)
1117
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001118 " completion for the :disassemble command
1119 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1120 call assert_equal("\"disas debug", @:)
1121 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1122 call assert_equal("\"disas profile", @:)
1123 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1124 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1125 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1126 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001127 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001129
Bram Moolenaar47016f52021-08-26 16:39:58 +02001130 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001131 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001132
naohiro onodfe04db2021-09-12 15:45:10 +02001133 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1134 call assert_match('"disas <SNR>\d\+_', @:)
1135 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1136 call assert_match('"disas debug <SNR>\d\+_', @:)
1137
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001138 " completion for the :match command
1139 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1140 call assert_equal("\"match Search /pat/\<C-A>", @:)
1141
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001142 " completion for the :doautocmd command
1143 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1144 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1145
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001146 " completion of autocmd group after comma
1147 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1148 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1149
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001150 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001151 call writefile([], 'Xvarfile1', 'D')
1152 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001153 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1154 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001155
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001156 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001157 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001158 augroup END
1159 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001160 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001161
1162 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001163 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1164 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001165 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal("\"au XTest.test", @:)
1167
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001168 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001169
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001170 " autocmd pattern completion
1171 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"au BufEnter *.py\t", @:)
1173
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001174 " completion for the :unlet command
1175 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1176 call assert_equal("\"unlet one two", @:)
1177
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001178 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001179 " FIXME: what should happen on MS-Windows?
1180 if !has('win32')
1181 edit \{someFile}
1182 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1183 call assert_equal("\"buf {someFile}", @:)
1184 bwipe {someFile}
1185 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001186
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001187 " completion for the :bdelete command
1188 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1189 call assert_equal("\"bdel a b c", @:)
1190
1191 " completion for the :mapclear command
1192 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1193 call assert_equal("\"mapclear <buffer>", @:)
1194
1195 " completion for user defined commands with menu names
1196 menu Test.foo :ls<CR>
1197 com -nargs=* -complete=menu MyCmd
1198 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1199 call assert_equal('"MyCmd Test.', @:)
1200 delcom MyCmd
1201 unmenu Test
1202
1203 " completion for user defined commands with mappings
1204 mapclear
1205 map <F3> :ls<CR>
1206 com -nargs=* -complete=mapping MyCmd
1207 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001208 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001209 mapclear
1210 delcom MyCmd
1211
1212 " completion for :set path= with multiple backslashes
1213 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal('"set path=a\\\ b', @:)
1215
1216 " completion for :set dir= with a backslash
1217 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal('"set dir=a\ b', @:)
1219
1220 " completion for the :py3 commands
1221 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1222 call assert_equal('"py3 py3do py3file', @:)
1223
Bram Moolenaardf749a22021-03-28 15:29:43 +02001224 " completion for the :vim9 commands
1225 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1226 call assert_equal('"vim9cmd vim9script', @:)
1227
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001228 " redir @" is not the start of a comment. So complete after that
1229 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1230 call assert_equal('"redir @" | cwindow', @:)
1231
1232 " completion after a backtick
1233 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1234 call assert_equal('"e `a1b2c', @:)
1235
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001236 " completion for :language command with an invalid argument
1237 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1238 call assert_equal("\"language dummy \t", @:)
1239
1240 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001241 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1242 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001243
1244 " completion with ambiguous user defined commands
1245 com TCmd1 echo 'TCmd1'
1246 com TCmd2 echo 'TCmd2'
1247 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1248 call assert_equal('"TCmd ', @:)
1249 delcom TCmd1
1250 delcom TCmd2
1251
1252 " completion after a range followed by a pipe (|) character
1253 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1254 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001255
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001256 " completion after a :global command
1257 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1258 call assert_equal('"g/a/chistory', @:)
1259 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1260 call assert_equal("\"g/a\\/chist\t", @:)
1261
Bram Moolenaar9c929712020-09-07 22:05:28 +02001262 " use <Esc> as the 'wildchar' for completion
1263 set wildchar=<Esc>
1264 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1265 call assert_equal('"g/a\xb/clearjumps', @:)
1266 " pressing <esc> twice should cancel the command
1267 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1268 call assert_equal('"g/a\xb/clearjumps', @:)
1269 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001270
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001271 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001272 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001273 call writefile([], '~Xtest')
1274 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1275 call assert_equal('"e \~Xtest', @:)
1276 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001277
1278 " should be able to complete a file name that has a '*'
1279 call writefile([], 'Xx*Yy')
1280 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal('"e Xx\*Yy', @:)
1282 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001283
1284 " use a literal star
1285 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1286 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001287 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001288
1289 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1290 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001291endfunc
1292
1293" Test for 'wildignorecase'
1294func Test_cmdline_wildignorecase()
1295 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001296 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001297 set wildignorecase
1298 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1299 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001300 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001301 let g:Sline = ''
1302 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1303 call assert_equal('"e xt', @:)
1304 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001305 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001306endfunc
1307
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001308func Test_cmdline_write_alternatefile()
1309 new
1310 call setline('.', ['one', 'two'])
1311 f foo.txt
1312 new
1313 f #-A
1314 call assert_equal('foo.txt-A', expand('%'))
1315 f #<-B.txt
1316 call assert_equal('foo-B.txt', expand('%'))
1317 f %<
1318 call assert_equal('foo-B', expand('%'))
1319 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001320 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001321 bw!
1322 f foo-B.txt
1323 f %<-A
1324 call assert_equal('foo-B-A', expand('%'))
1325 bw!
1326 bw!
1327endfunc
1328
Bram Moolenaarf5724372022-09-02 19:45:15 +01001329func Test_cmdline_expand_cur_alt_file()
1330 enew
1331 file http://some.com/file.txt
1332 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1333 call assert_equal('"e http://some.com/file.txt', @:)
1334 edit another
1335 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1336 call assert_equal('"e http://some.com/file.txt', @:)
1337 bwipe
1338 bwipe http://some.com/file.txt
1339endfunc
1340
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001341" using a leading backslash here
1342set cpo+=C
1343
1344func Test_cmdline_search_range()
1345 new
1346 call setline(1, ['a', 'b', 'c', 'd'])
1347 /d
1348 1,\/s/b/B/
1349 call assert_equal('B', getline(2))
1350
1351 /a
1352 $
1353 \?,4s/c/C/
1354 call assert_equal('C', getline(3))
1355
1356 call setline(1, ['a', 'b', 'c', 'd'])
1357 %s/c/c/
1358 1,\&s/b/B/
1359 call assert_equal('B', getline(2))
1360
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001361 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001362 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001363
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001364 bwipe!
1365endfunc
1366
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001367" Test for the tick mark (') in an excmd range
1368func Test_tick_mark_in_range()
1369 " If only the tick is passed as a range and no command is specified, there
1370 " should not be an error
1371 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001372 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001373 call assert_fails("',print", 'E78:')
1374endfunc
1375
1376" Test for using a line number followed by a search pattern as range
1377func Test_lnum_and_pattern_as_range()
1378 new
1379 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1380 let @" = ''
1381 2/foo/yank
1382 call assert_equal("foo 3\n", @")
1383 call assert_equal(1, line('.'))
1384 close!
1385endfunc
1386
Bram Moolenaar65189a12017-02-06 22:22:17 +01001387" Tests for getcmdline(), getcmdpos() and getcmdtype()
1388func Check_cmdline(cmdtype)
1389 call assert_equal('MyCmd a', getcmdline())
1390 call assert_equal(8, getcmdpos())
1391 call assert_equal(a:cmdtype, getcmdtype())
1392 return ''
1393endfunc
1394
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001395set cpo&
1396
Bram Moolenaar65189a12017-02-06 22:22:17 +01001397func Test_getcmdtype()
1398 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1399
1400 let cmdtype = ''
1401 debuggreedy
1402 call feedkeys(":debug echo 'test'\<CR>", "t")
1403 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1404 call feedkeys("cont\<CR>", "xt")
1405 0debuggreedy
1406 call assert_equal('>', cmdtype)
1407
1408 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1409 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1410
1411 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001412 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001413
1414 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1415
1416 cnoremap <expr> <F6> Check_cmdline('=')
1417 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1418 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001419
1420 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001421endfunc
1422
Bram Moolenaar52604f22017-04-07 16:17:39 +02001423func Test_verbosefile()
1424 set verbosefile=Xlog
1425 echomsg 'foo'
1426 echomsg 'bar'
1427 set verbosefile=
1428 let log = readfile('Xlog')
1429 call assert_match("foo\nbar", join(log, "\n"))
1430 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001431
1432 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001433 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001434endfunc
1435
Bram Moolenaar4facea32019-10-12 20:17:40 +02001436func Test_verbose_option()
1437 CheckScreendump
1438
1439 let lines =<< trim [SCRIPT]
1440 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1441 call feedkeys("\r", 't') " for the hit-enter prompt
1442 set verbose=20
1443 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001444 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001445
1446 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001447 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001448 call term_sendkeys(buf, ":DoSomething\<CR>")
1449 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1450
1451 " clean up
1452 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001453endfunc
1454
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001455func Test_setcmdpos()
1456 func InsertTextAtPos(text, pos)
1457 call assert_equal(0, setcmdpos(a:pos))
1458 return a:text
1459 endfunc
1460
1461 " setcmdpos() with position in the middle of the command line.
1462 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1463 call assert_equal('"1ab2', @:)
1464
1465 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1466 call assert_equal('"1b2a', @:)
1467
1468 " setcmdpos() with position beyond the end of the command line.
1469 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1470 call assert_equal('"12ab', @:)
1471
1472 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001473 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001474endfunc
1475
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001476func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001477 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001478 let encoding_save = &encoding
1479
1480 for e in encodings
1481 exe 'set encoding=' . e
1482
1483 " Test overstrike in the middle of the command line.
1484 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001485 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001486
1487 " Test overstrike going beyond end of command line.
1488 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001489 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001490
1491 " Test toggling insert/overstrike a few times.
1492 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001493 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001494 endfor
1495
Bram Moolenaar30276f22019-01-24 17:59:39 +01001496 " Test overstrike with multi-byte characters.
1497 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001498 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001499
1500 let &encoding = encoding_save
1501endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001502
Bram Moolenaar52410572019-10-27 05:12:45 +01001503func Test_buffers_lastused()
1504 " check that buffers are sorted by time when wildmode has lastused
1505 call test_settime(1550020000) " middle
1506 edit bufa
1507 enew
1508 call test_settime(1550030000) " newest
1509 edit bufb
1510 enew
1511 call test_settime(1550010000) " oldest
1512 edit bufc
1513 enew
1514 call test_settime(0)
1515 enew
1516
1517 call assert_equal(['bufa', 'bufb', 'bufc'],
1518 \ getcompletion('', 'buffer'))
1519
1520 let save_wildmode = &wildmode
1521 set wildmode=full:lastused
1522
1523 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
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 edit other
1533 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1534 call assert_equal('b bufb', X)
1535 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1536 call assert_equal('b bufa', X)
1537 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1538 call assert_equal('b bufc', X)
1539 enew
1540
1541 let &wildmode = save_wildmode
1542
1543 bwipeout bufa
1544 bwipeout bufb
1545 bwipeout bufc
1546endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001547
Bram Moolenaar479950f2020-01-19 15:45:17 +01001548func Test_cmdlineclear_tabenter()
1549 CheckScreendump
1550
1551 let lines =<< trim [SCRIPT]
1552 call setline(1, range(30))
1553 [SCRIPT]
1554
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001555 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001556 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001557 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001558 " in one tab make the command line higher with CTRL-W -
1559 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1560 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1561
1562 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001563endfunc
1564
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001565" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001566func Test_cmdline_expand_special()
1567 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001568 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001569 call assert_fails('e <afile>', 'E495:')
1570 call assert_fails('e <abuf>', 'E496:')
1571 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001572
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001573 call writefile([], 'Xfile.cpp', 'D')
1574 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001575 new Xfile.cpp
1576 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1577 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1578 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001579endfunc
1580
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001581" Test for backtick expression in the command line
1582func Test_cmd_backtick()
1583 %argd
1584 argadd `=['a', 'b', 'c']`
1585 call assert_equal(['a', 'b', 'c'], argv())
1586 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001587
1588 argadd `echo abc def`
1589 call assert_equal(['abc def'], argv())
1590 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001591endfunc
1592
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001593" Test for the :! command
1594func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001595 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001596
1597 let lines =<< trim [SCRIPT]
1598 " Test for no previous command
1599 call assert_fails('!!', 'E34:')
1600 set nomore
1601 " Test for cmdline expansion with :!
1602 call setline(1, 'foo!')
1603 silent !echo <cWORD> > Xfile.out
1604 call assert_equal(['foo!'], readfile('Xfile.out'))
1605 " Test for using previous command
1606 silent !echo \! !
1607 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1608 call writefile(v:errors, 'Xresult')
1609 call delete('Xfile.out')
1610 qall!
1611 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001612 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001613 if RunVim([], [], '--clean -S Xscript')
1614 call assert_equal([], readfile('Xresult'))
1615 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001616 call delete('Xresult')
1617endfunc
1618
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001619" Test error: "E135: *Filter* Autocommands must not change current buffer"
1620func Test_cmd_bang_E135()
1621 new
1622 call setline(1, ['a', 'b', 'c', 'd'])
1623 augroup test_cmd_filter_E135
1624 au!
1625 autocmd FilterReadPost * help
1626 augroup END
1627 call assert_fails('2,3!echo "x"', 'E135:')
1628
1629 augroup test_cmd_filter_E135
1630 au!
1631 augroup END
1632 %bwipe!
1633endfunc
1634
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001635" Test for using ~ for home directory in cmdline completion matches
1636func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001637 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001638 call writefile([], 'Xexpdir/Xfile1')
1639 call writefile([], 'Xexpdir/Xfile2')
1640 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001641 let save_HOME = $HOME
1642 let $HOME = getcwd()
1643 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1644 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1645 let $HOME = save_HOME
1646 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001647endfunc
1648
Bram Moolenaar578fe942020-02-27 21:32:51 +01001649" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1650" or insert mode (when 'insertmode' is set)
1651func Test_cmdline_ctrl_g()
1652 new
1653 call setline(1, 'abc')
1654 call cursor(1, 3)
1655 " If command line is entered from insert mode, using C-\ C-G should back to
1656 " insert mode
1657 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1658 call assert_equal('abxyc', getline(1))
1659 call assert_equal(4, col('.'))
1660
1661 " If command line is entered in 'insertmode', using C-\ C-G should back to
1662 " 'insertmode'
1663 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1664 call assert_equal('ab12xyc', getline(1))
1665 close!
1666endfunc
1667
Bram Moolenaar578fe942020-02-27 21:32:51 +01001668" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001669func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001670 func T(a, c, p)
1671 return "oneA\noneB\noneC"
1672 endfunc
1673 command -nargs=1 -complete=custom,T MyCmd
1674
Bram Moolenaar578fe942020-02-27 21:32:51 +01001675 set nowildmenu
1676 set wildmode=full,list
1677 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001678 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001679 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001680 call assert_equal('"MyCmd oneA', @:)
1681
1682 set wildmode=longest,full
1683 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1684 call assert_equal('"MyCmd one', @:)
1685 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1686 call assert_equal('"MyCmd oneC', @:)
1687
1688 set wildmode=longest
1689 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1690 call assert_equal('"MyCmd one', @:)
1691
1692 set wildmode=list:longest
1693 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001694 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001695 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001696 call assert_equal('"MyCmd one', @:)
1697
1698 set wildmode=""
1699 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1700 call assert_equal('"MyCmd oneA', @:)
1701
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001702 " Test for wildmode=longest with 'fileignorecase' set
1703 set wildmode=longest
1704 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001705 argadd AAA AAAA AAAAA
1706 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1707 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001708 set fileignorecase&
1709
1710 " Test for listing files with wildmode=list
1711 set wildmode=list
1712 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001713 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001714 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001715 call assert_equal('"b A', @:)
1716
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001717 " when using longest completion match, matches shorter than the argument
1718 " should be ignored (happens with :help)
1719 set wildmode=longest,full
1720 set wildmenu
1721 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1722 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001723 " non existing file
1724 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1725 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001726 set wildmenu&
1727
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001728 " Test for longest file name completion with 'fileignorecase'
1729 " On MS-Windows, file names are case insensitive.
1730 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001731 call writefile([], 'XTESTfoo', 'D')
1732 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001733 set nofileignorecase
1734 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1735 call assert_equal('"e XTESTfoo', @:)
1736 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1737 call assert_equal('"e Xtestbar', @:)
1738 set fileignorecase
1739 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1740 call assert_equal('"e Xtest', @:)
1741 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1742 call assert_equal('"e Xtest', @:)
1743 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001744 endif
1745
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001746 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001747 delcommand MyCmd
1748 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001749 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001750 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001751endfunc
1752
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001753func Test_wildmode()
1754 " Test with utf-8 encoding
1755 call Wildmode_tests()
1756
1757 " Test with latin1 encoding
1758 let save_encoding = &encoding
1759 set encoding=latin1
1760 call Wildmode_tests()
1761 let &encoding = save_encoding
1762endfunc
1763
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001764func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001765 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001766 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001767 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001768 let lines =<< trim END
1769 func vim8#Complete(a, c, p)
1770 return "oneA\noneB\noneC"
1771 endfunc
1772 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001773 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001774
1775 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1776 set nowildmenu
1777 set wildmode=full,list
1778 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1779 call assert_equal('"MyCmd oneA oneB oneC', @:)
1780
1781 let &rtp = save_rtp
1782 set wildmode& wildmenu&
1783 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001784endfunc
1785
Bram Moolenaar578fe942020-02-27 21:32:51 +01001786" Test for interrupting the command-line completion
1787func Test_interrupt_compl()
1788 func F(lead, cmdl, p)
1789 if a:lead =~ 'tw'
1790 call interrupt()
1791 return
1792 endif
1793 return "one\ntwo\nthree"
1794 endfunc
1795 command -nargs=1 -complete=custom,F Tcmd
1796
1797 set nowildmenu
1798 set wildmode=full
1799 let interrupted = 0
1800 try
1801 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1802 catch /^Vim:Interrupt$/
1803 let interrupted = 1
1804 endtry
1805 call assert_equal(1, interrupted)
1806
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001807 let interrupted = 0
1808 try
1809 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1810 catch /^Vim:Interrupt$/
1811 let interrupted = 1
1812 endtry
1813 call assert_equal(1, interrupted)
1814
Bram Moolenaar578fe942020-02-27 21:32:51 +01001815 delcommand Tcmd
1816 delfunc F
1817 set wildmode&
1818endfunc
1819
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001820" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001821func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001822 let str = ":one two\<C-U>"
1823 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001824 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001825 let str ..= "\<Left>five\<Right>"
1826 let str ..= "\<Home>two "
1827 let str ..= "\<C-Left>one "
1828 let str ..= "\<C-Right> three"
1829 let str ..= "\<End>\<S-Left>four "
1830 let str ..= "\<S-Right> six"
1831 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1832 call feedkeys(str, 'xt')
1833 call assert_equal("\"one two three four five six seven", @:)
1834endfunc
1835
1836" Test for moving the cursor on the / command line in 'rightleft' mode
1837func Test_cmdline_edit_rightleft()
1838 CheckFeature rightleft
1839 set rightleft
1840 set rightleftcmd=search
1841 let str = "/one two\<C-U>"
1842 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001843 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001844 let str ..= "\<Right>five\<Left>"
1845 let str ..= "\<Home>two "
1846 let str ..= "\<C-Right>one "
1847 let str ..= "\<C-Left> three"
1848 let str ..= "\<End>\<S-Right>four "
1849 let str ..= "\<S-Left> six"
1850 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1851 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1852 call assert_equal("\"one two three four five six seven", @/)
1853 set rightleftcmd&
1854 set rightleft&
1855endfunc
1856
1857" Test for using <C-\>e in the command line to evaluate an expression
1858func Test_cmdline_expr()
1859 " Evaluate an expression from the beginning of a command line
1860 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1861 call assert_equal('"hello', @:)
1862
1863 " Use an invalid expression for <C-\>e
1864 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1865
1866 " Insert literal <CTRL-\> in the command line
1867 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1868 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001869endfunc
1870
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001871" This was making the insert position negative
1872func Test_cmdline_expr_register()
1873 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1874endfunc
1875
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001876" Test for 'imcmdline' and 'imsearch'
1877" This test doesn't actually test the input method functionality.
1878func Test_cmdline_inputmethod()
1879 new
1880 call setline(1, ['', 'abc', ''])
1881 set imcmdline
1882
1883 call feedkeys(":\"abc\<CR>", 'xt')
1884 call assert_equal("\"abc", @:)
1885 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1886 call assert_equal("\"abc", @:)
1887 call feedkeys("/abc\<CR>", 'xt')
1888 call assert_equal([2, 1], [line('.'), col('.')])
1889 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1890 call assert_equal([2, 1], [line('.'), col('.')])
1891
1892 set imsearch=2
1893 call cursor(1, 1)
1894 call feedkeys("/abc\<CR>", 'xt')
1895 call assert_equal([2, 1], [line('.'), col('.')])
1896 call cursor(1, 1)
1897 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1898 call assert_equal([2, 1], [line('.'), col('.')])
1899 set imdisable
1900 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1901 call assert_equal([2, 1], [line('.'), col('.')])
1902 set imdisable&
1903 set imsearch&
1904
1905 set imcmdline&
1906 %bwipe!
1907endfunc
1908
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001909" Test for using CTRL-_ in the command line with 'allowrevins'
1910func Test_cmdline_revins()
1911 CheckNotMSWindows
1912 CheckFeature rightleft
1913 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1914 call assert_equal("\"abc\<c-_>", @:)
1915 set allowrevins
1916 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1917 call assert_equal('"abcñèæ', @:)
1918 set allowrevins&
1919endfunc
1920
1921" Test for typing UTF-8 composing characters in the command line
1922func Test_cmdline_composing_chars()
1923 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1924 call assert_equal('"ゔ', @:)
1925endfunc
1926
Bram Moolenaar0e717042020-04-27 19:29:01 +02001927" test that ";" works to find a match at the start of the first line
1928func Test_zero_line_search()
1929 new
1930 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1931 call cursor(1,1)
1932 0;/pattern/d
1933 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1934 q!
1935endfunc
1936
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001937func Test_read_shellcmd()
1938 CheckUnix
1939 if executable('ls')
1940 " There should be ls in the $PATH
1941 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1942 call assert_match('^"r! .*\<ls\>', @:)
1943 endif
1944
1945 if executable('rm')
1946 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1947 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1948 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001949
1950 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1951 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1952 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001953 endif
1954endfunc
1955
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001956" Test for going up and down the directory tree using 'wildmenu'
1957func Test_wildmenu_dirstack()
1958 CheckUnix
1959 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001960 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001961 call writefile([], 'Xwildmenu/file1_1.txt')
1962 call writefile([], 'Xwildmenu/file1_2.txt')
1963 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
1964 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
1965 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
1966 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
1967 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
1968 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001969 set wildmenu
1970
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001971 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001972 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001973 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001974 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001975 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001976 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001977 call assert_equal('"e ../../dir3/', @:)
1978 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1979 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001980 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001981 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001982 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001983 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001984 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001985 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1986 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001987
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001988 set wildmenu&
1989endfunc
1990
obcat71c6f7a2021-05-13 20:23:10 +02001991" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001992" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
1993" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02001994func Test_recalling_cmdline()
1995 CheckFeature cmdline_hist
1996
1997 let g:cmdlines = []
1998 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1999
2000 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002001 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2002 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2003 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2004 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002005 "\ TODO: {'name': 'debug', ...}
2006 \]
2007 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002008 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2009 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2010 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2011 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2012 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002013 \]
2014 let prefix = 'vi'
2015 for h in histories
2016 call histadd(h.name, 'vim')
2017 call histadd(h.name, 'virtue')
2018 call histadd(h.name, 'Virgo')
2019 call histadd(h.name, 'vogue')
2020 call histadd(h.name, 'emacs')
2021 for k in keypairs
2022 let g:cmdlines = []
2023 let keyseqs = h.enter
2024 \ .. prefix
2025 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2026 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2027 \ .. h.exit
2028 call feedkeys(keyseqs, 'xt')
2029 call histdel(h.name, -1) " delete the history added by feedkeys above
2030 let expect = k.prefixmatch
2031 \ ? ['virtue', 'vim', 'virtue', prefix]
2032 \ : ['emacs', 'vogue', 'emacs', prefix]
2033 call assert_equal(expect, g:cmdlines)
2034 endfor
2035 endfor
2036
2037 unlet g:cmdlines
2038 cunmap <Plug>(save-cmdline)
2039endfunc
2040
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002041func Test_cmd_map_cmdlineChanged()
2042 let g:log = []
2043 cnoremap <F1> l<Cmd><CR>s
2044 augroup test
2045 autocmd!
2046 autocmd CmdlineChanged : let g:log += [getcmdline()]
2047 augroup END
2048
2049 call feedkeys(":\<F1>\<CR>", 'xt')
2050 call assert_equal(['l', 'ls'], g:log)
2051
Bram Moolenaar796139a2021-05-18 21:38:45 +02002052 let @b = 'b'
2053 cnoremap <F1> a<C-R>b
2054 let g:log = []
2055 call feedkeys(":\<F1>\<CR>", 'xt')
2056 call assert_equal(['a', 'ab'], g:log)
2057
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002058 unlet g:log
2059 cunmap <F1>
2060 augroup test
2061 autocmd!
2062 augroup END
2063endfunc
2064
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002065" Test for the 'suffixes' option
2066func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002067 call writefile([], 'Xsuffile', 'D')
2068 call writefile([], 'Xsuffile.c', 'D')
2069 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002070 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002071 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2072 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2073 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2074 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002075 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002076 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2077 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2078 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2079 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002080 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002081 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2082 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2083 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2084 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002085 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002086 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002087 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2088 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002089endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002090
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002091" Test for using a popup menu for the command line completion matches
2092" (wildoptions=pum)
2093func Test_wildmenu_pum()
2094 CheckRunVimInTerminal
2095
2096 let commands =<< trim [CODE]
2097 set wildmenu
2098 set wildoptions=pum
2099 set shm+=I
2100 set noruler
2101 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002102
2103 func CmdCompl(a, b, c)
2104 return repeat(['aaaa'], 120)
2105 endfunc
2106 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002107
2108 func MyStatusLine() abort
2109 return 'status'
2110 endfunc
2111 func SetupStatusline()
2112 set statusline=%!MyStatusLine()
2113 set laststatus=2
2114 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002115
2116 func MyTabLine()
2117 return 'my tab line'
2118 endfunc
2119 func SetupTabline()
2120 set statusline=
2121 set tabline=%!MyTabLine()
2122 set showtabline=2
2123 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002124
2125 func DoFeedKeys()
2126 let &wildcharm = char2nr("\t")
2127 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2128 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002129 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002130 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002131
2132 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2133
2134 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002135 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2136
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002137 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002138 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002139 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2140
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002141 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002142 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002143 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2144
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002145 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002146 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002147 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2148
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002149 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002150 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002151 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2152
2153 " pressing <C-E> should end completion and go back to the original match
2154 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002155 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2156
2157 " pressing <C-Y> should select the current match and end completion
2158 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002159 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2160
2161 " With 'wildmode' set to 'longest,full', completing a match should display
2162 " the longest match, the wildmenu should not be displayed.
2163 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2164 call TermWait(buf)
2165 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002166 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2167
2168 " pressing <Tab> should display the wildmenu
2169 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002170 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2171
2172 " pressing <Tab> second time should select the next entry in the menu
2173 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002174 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2175
2176 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002177 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002178 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002179 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2180
2181 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002182 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2183
2184 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002185 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2186
2187 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002188 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002189 call writefile([], 'Xnamedir/XfileA')
2190 call writefile([], 'Xnamedir/XdirA/XfileB')
2191 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002192
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002193 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002194 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2195
2196 " Pressing <Right> on a directory name should go into that directory
2197 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002198 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2199
2200 " Pressing <Left> on a directory name should go to the parent directory
2201 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002202 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2203
2204 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002205 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002206 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002207 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2208
2209 " Pressing <C-D> when the popup menu is displayed should remove the popup
2210 " menu
2211 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002212 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2213
2214 " Pressing <S-Tab> should open the popup menu with the last entry selected
2215 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002216 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2217
2218 " Pressing <Esc> should close the popup menu and cancel the cmd line
2219 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002220 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2221
2222 " Typing a character when the popup is open, should close the popup
2223 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002224 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2225
2226 " When the popup is open, entering the cmdline window should close the popup
2227 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2229 call term_sendkeys(buf, ":q\<CR>")
2230
2231 " After the last popup menu item, <C-N> should show the original string
2232 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002233 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2234
2235 " Use the popup menu for the command name
2236 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002237 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2238
2239 " Pressing the left arrow should remove the popup menu
2240 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002241 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2242
2243 " Pressing <BS> should remove the popup menu and erase the last character
2244 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002245 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2246
2247 " Pressing <C-W> should remove the popup menu and erase the previous word
2248 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002249 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2250
2251 " Pressing <C-U> should remove the popup menu and erase the entire line
2252 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002253 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2254
2255 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2256 " the cmdline from history
2257 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2259
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002260 " Check "list" still works
2261 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2262 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002263 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2264 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002265 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2266
rbtnn68cc2b82022-02-09 11:55:47 +00002267 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002268 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002269 call writefile([], 'Xnamedir/あいう/abc')
2270 call writefile([], 'Xnamedir/あいう/xyz')
2271 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002272
2273 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002274 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002275 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2276
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002277 " Pressing <C-A> when the popup menu is displayed should list all the
2278 " matches and pressing a key after that should remove the popup menu
2279 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2280 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2281 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2282
2283 " Pressing <C-A> when the popup menu is displayed should list all the
2284 " matches and pressing <Left> after that should move the cursor
2285 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2286 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2287 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2288
2289 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2290 " should be displayed correctly on the screen.
2291 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2292 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2293
2294 " After using <C-A> to expand all the filename matches, pressing <Up>
2295 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002296 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002297 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2298 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2299 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2300
2301 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2302 " crash Vim
2303 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2305
Bram Moolenaar414acd32022-02-10 21:09:45 +00002306 " After removing the pum the command line is redrawn
2307 call term_sendkeys(buf, ":edit foo\<CR>")
2308 call term_sendkeys(buf, ":edit bar\<CR>")
2309 call term_sendkeys(buf, ":ls\<CR>")
2310 call term_sendkeys(buf, ":com\<Tab> ")
2311 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002312 call term_sendkeys(buf, "\<C-U>\<CR>")
2313
2314 " Esc still works to abort the command when 'statusline' is set
2315 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2316 call term_sendkeys(buf, ":si\<Tab>")
2317 call term_sendkeys(buf, "\<Esc>")
2318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002319
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002320 " Esc still works to abort the command when 'tabline' is set
2321 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2322 call term_sendkeys(buf, ":si\<Tab>")
2323 call term_sendkeys(buf, "\<Esc>")
2324 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2325
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002326 " popup is cleared also when 'lazyredraw' is set
2327 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2328 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2329 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2330 call term_sendkeys(buf, "\<Esc>")
2331
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002332 " Pressing <PageDown> should scroll the menu downward
2333 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2335 call term_sendkeys(buf, "\<PageDown>")
2336 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2337 call term_sendkeys(buf, "\<PageDown>")
2338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2339 call term_sendkeys(buf, "\<PageDown>")
2340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2341 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2342 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2343
2344 " Pressing <PageUp> should scroll the menu upward
2345 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2346 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2347 call term_sendkeys(buf, "\<PageUp>")
2348 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2349 call term_sendkeys(buf, "\<PageUp>")
2350 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2351 call term_sendkeys(buf, "\<PageUp>")
2352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2353
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002354 call term_sendkeys(buf, "\<C-U>\<CR>")
2355 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002356endfunc
2357
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002358" Test for wildmenumode() with the cmdline popup menu
2359func Test_wildmenumode_with_pum()
2360 set wildmenu
2361 set wildoptions=pum
2362 cnoremap <expr> <F2> wildmenumode()
2363 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2364 call assert_equal('"sign define10', @:)
2365 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2366 call assert_equal('"sign define jump list place undefine unplace0', @:)
2367 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2368 call assert_equal('"sign 0', @:)
2369 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2370 call assert_equal('"sign define0', @:)
2371 set nowildmenu wildoptions&
2372 cunmap <F2>
2373endfunc
2374
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002375func Test_wildmenu_with_pum_foldexpr()
2376 CheckRunVimInTerminal
2377
2378 let lines =<< trim END
2379 call setline(1, ['folded one', 'folded two', 'some more text'])
2380 func MyFoldText()
2381 return 'foo'
2382 endfunc
2383 set foldtext=MyFoldText() wildoptions=pum
2384 normal ggzfj
2385 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002386 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002387 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2388 call term_sendkeys(buf, ":set\<Tab>")
2389 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2390
2391 call term_sendkeys(buf, "\<Esc>")
2392 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2393
2394 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002395endfunc
2396
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002397" Test for opening the cmdline completion popup menu from the terminal window.
2398" The popup menu should be positioned correctly over the status line of the
2399" bottom-most window.
2400func Test_wildmenu_pum_from_terminal()
2401 CheckRunVimInTerminal
2402 let python = PythonProg()
2403 call CheckPython(python)
2404
2405 %bw!
2406 let cmds = ['set wildmenu wildoptions=pum']
2407 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2408 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002409 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002410 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2411 call term_sendkeys(buf, "\r\r\r")
2412 call term_wait(buf)
2413 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2414 call term_wait(buf)
2415 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2416 call term_wait(buf)
2417 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002418endfunc
2419
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002420" Test for completion after a :substitute command followed by a pipe (|)
2421" character
2422func Test_cmdline_complete_substitute()
2423 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2424 call assert_equal("\"s | \t", @:)
2425 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2426 call assert_equal("\"s/ | \t", @:)
2427 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2428 call assert_equal("\"s/one | \t", @:)
2429 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2430 call assert_equal("\"s/one/ | \t", @:)
2431 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2432 call assert_equal("\"s/one/two | \t", @:)
2433 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2434 call assert_equal('"s/one/two/ | chistory', @:)
2435 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2436 call assert_equal("\"s/one/two/g \t", @:)
2437 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2438 call assert_equal("\"s/one/two/g | chistory", @:)
2439 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2440 call assert_equal("\"s/one/t\\/ | \t", @:)
2441 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2442 call assert_equal('"s/one/t"o/ | chistory', @:)
2443 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2444 call assert_equal('"s/one/t|o/ | chistory', @:)
2445 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2446 call assert_equal("\"&\t", @:)
2447endfunc
2448
2449" Test for the :dlist command completion
2450func Test_cmdline_complete_dlist()
2451 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2452 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2453 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2454 call assert_equal("\"dlist 10 /pat/ \t", @:)
2455 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2456 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2457 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2458 call assert_equal("\"dlist 10 /pat\\\t", @:)
2459 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2460 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2461endfunc
2462
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002463" argument list (only for :argdel) fuzzy completion
2464func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002465 argadd change.py count.py charge.py
2466 set wildoptions&
2467 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2468 call assert_equal('"argdel cge', @:)
2469 set wildoptions=fuzzy
2470 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2471 call assert_equal('"argdel change.py charge.py', @:)
2472 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002473 set wildoptions&
2474endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002475
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002476" autocmd group name fuzzy completion
2477func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002478 set wildoptions&
2479 augroup MyFuzzyGroup
2480 augroup END
2481 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2482 call assert_equal('"augroup mfg', @:)
2483 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2484 call assert_equal('"augroup MyFuzzyGroup', @:)
2485 set wildoptions=fuzzy
2486 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2487 call assert_equal('"augroup MyFuzzyGroup', @:)
2488 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2489 call assert_equal('"augroup My*p', @:)
2490 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002491 set wildoptions&
2492endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002493
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002494" buffer name fuzzy completion
2495func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002496 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002497 " Use a long name to reduce the risk of matching a random directory name
2498 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002499 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002500 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2501 call assert_equal('"b SRFWL', @:)
2502 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2503 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002504 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002505 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2506 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2507 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2508 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002509 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002510 set wildoptions&
2511endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002512
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002513" buffer name (full path) fuzzy completion
2514func Test_fuzzy_completion_bufname_fullpath()
2515 CheckUnix
2516 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002517 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002518 edit Xcmd/Xstate/Xfile.js
2519 cd Xcmd/Xstate
2520 enew
2521 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2522 call assert_equal('"b CmdStateFile', @:)
2523 set wildoptions=fuzzy
2524 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2525 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2526 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002527 set wildoptions&
2528endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002529
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002530" :behave suboptions fuzzy completion
2531func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002532 set wildoptions&
2533 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2534 call assert_equal('"behave xm', @:)
2535 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2536 call assert_equal('"behave xterm', @:)
2537 set wildoptions=fuzzy
2538 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2539 call assert_equal('"behave xterm', @:)
2540 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2541 call assert_equal('"behave xt*m', @:)
2542 let g:Sline = ''
2543 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2544 call assert_equal('mswin', g:Sline)
2545 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002546 set wildoptions&
2547endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002548
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002549" " colorscheme name fuzzy completion - NOT supported
2550" func Test_fuzzy_completion_colorscheme()
2551" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002552
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002553" built-in command name fuzzy completion
2554func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002555 set wildoptions&
2556 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2557 call assert_equal('"sbwin', @:)
2558 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2559 call assert_equal('"sbrewind', @:)
2560 set wildoptions=fuzzy
2561 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2562 call assert_equal('"sbrewind', @:)
2563 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2564 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002565 set wildoptions&
2566endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002567
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002568" " compiler name fuzzy completion - NOT supported
2569" func Test_fuzzy_completion_compiler()
2570" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002571
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002572" :cscope suboptions fuzzy completion
2573func Test_fuzzy_completion_cscope()
2574 CheckFeature cscope
2575 set wildoptions&
2576 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2577 call assert_equal('"cscope ret', @:)
2578 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2579 call assert_equal('"cscope reset', @:)
2580 set wildoptions=fuzzy
2581 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2582 call assert_equal('"cscope reset', @:)
2583 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2584 call assert_equal('"cscope re*t', @:)
2585 set wildoptions&
2586endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002587
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002588" :diffget/:diffput buffer name fuzzy completion
2589func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002590 new SomeBuffer
2591 diffthis
2592 new OtherBuffer
2593 diffthis
2594 set wildoptions&
2595 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2596 call assert_equal('"diffget sbuf', @:)
2597 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2598 call assert_equal('"diffput sbuf', @:)
2599 set wildoptions=fuzzy
2600 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2601 call assert_equal('"diffget SomeBuffer', @:)
2602 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2603 call assert_equal('"diffput SomeBuffer', @:)
2604 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002605 set wildoptions&
2606endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002607
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002608" " directory name fuzzy completion - NOT supported
2609" func Test_fuzzy_completion_dirname()
2610" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002611
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002612" environment variable name fuzzy completion
2613func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002614 set wildoptions&
2615 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2616 call assert_equal('"echo $VUT', @:)
2617 set wildoptions=fuzzy
2618 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2619 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002620 set wildoptions&
2621endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002622
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002623" autocmd event fuzzy completion
2624func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002625 set wildoptions&
2626 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2627 call assert_equal('"autocmd BWout', @:)
2628 set wildoptions=fuzzy
2629 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2630 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002631 set wildoptions&
2632endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002633
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002634" vim expression fuzzy completion
2635func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002636 let g:PerPlaceCount = 10
2637 set wildoptions&
2638 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2639 call assert_equal('"let c = ppc', @:)
2640 set wildoptions=fuzzy
2641 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2642 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002643 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002644endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002645
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002646" " file name fuzzy completion - NOT supported
2647" func Test_fuzzy_completion_filename()
2648" endfunc
2649
2650" " files in path fuzzy completion - NOT supported
2651" func Test_fuzzy_completion_filesinpath()
2652" endfunc
2653
2654" " filetype name fuzzy completion - NOT supported
2655" func Test_fuzzy_completion_filetype()
2656" endfunc
2657
2658" user defined function name completion
2659func Test_fuzzy_completion_userdefined_func()
2660 set wildoptions&
2661 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2662 call assert_equal('"call Test_f_u_f', @:)
2663 set wildoptions=fuzzy
2664 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2665 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2666 set wildoptions&
2667endfunc
2668
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002669" <SNR> functions should be sorted to the end
2670func Test_fuzzy_completion_userdefined_snr_func()
2671 func s:Sendmail()
2672 endfunc
2673 func SendSomemail()
2674 endfunc
2675 func S1e2n3dmail()
2676 endfunc
2677 set wildoptions=fuzzy
2678 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002679 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002680 set wildoptions&
2681 delfunc s:Sendmail
2682 delfunc SendSomemail
2683 delfunc S1e2n3dmail
2684endfunc
2685
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002686" user defined command name completion
2687func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002688 set wildoptions&
2689 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2690 call assert_equal('"MsFeat', @:)
2691 set wildoptions=fuzzy
2692 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2693 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002694 set wildoptions&
2695endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002696
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002697" " :help tag fuzzy completion - NOT supported
2698" func Test_fuzzy_completion_helptag()
2699" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002700
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002701" highlight group name fuzzy completion
2702func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002703 set wildoptions&
2704 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2705 call assert_equal('"highlight SKey', @:)
2706 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2707 call assert_equal('"highlight SpecialKey', @:)
2708 set wildoptions=fuzzy
2709 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2710 call assert_equal('"highlight SpecialKey', @:)
2711 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2712 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002713 set wildoptions&
2714endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002715
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002716" :history suboptions fuzzy completion
2717func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002718 set wildoptions&
2719 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2720 call assert_equal('"history dg', @:)
2721 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2722 call assert_equal('"history search', @:)
2723 set wildoptions=fuzzy
2724 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal('"history debug', @:)
2726 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2727 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002728 set wildoptions&
2729endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002730
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002731" :language locale name fuzzy completion
2732func Test_fuzzy_completion_lang()
2733 CheckUnix
2734 set wildoptions&
2735 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2736 call assert_equal('"lang psx', @:)
2737 set wildoptions=fuzzy
2738 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2739 call assert_equal('"lang POSIX', @:)
2740 set wildoptions&
2741endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002742
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002743" :mapclear buffer argument fuzzy completion
2744func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002745 set wildoptions&
2746 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2747 call assert_equal('"mapclear buf', @:)
2748 set wildoptions=fuzzy
2749 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2750 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002751 set wildoptions&
2752endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002753
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002754" map name fuzzy completion
2755func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002756 " test regex completion works
2757 set wildoptions=fuzzy
2758 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2759 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002760 nmap <plug>MyLongMap :p<CR>
2761 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2762 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2763 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2764 call assert_equal("\"nmap MLM \t", @:)
2765 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2766 call assert_equal("\"nmap <F2> one two \t", @:)
2767 " duplicate entries should be removed
2768 vmap <plug>MyLongMap :<C-U>#<CR>
2769 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2771 nunmap <plug>MyLongMap
2772 vunmap <plug>MyLongMap
2773 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2774 call assert_equal("\"nmap ABC\t", @:)
2775 " results should be sorted by best match
2776 nmap <Plug>format :
2777 nmap <Plug>goformat :
2778 nmap <Plug>TestFOrmat :
2779 nmap <Plug>fendoff :
2780 nmap <Plug>state :
2781 nmap <Plug>FendingOff :
2782 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2783 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2784 nunmap <Plug>format
2785 nunmap <Plug>goformat
2786 nunmap <Plug>TestFOrmat
2787 nunmap <Plug>fendoff
2788 nunmap <Plug>state
2789 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002790 set wildoptions&
2791endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002792
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002793" abbreviation fuzzy completion
2794func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002795 set wildoptions=fuzzy
2796 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2797 call assert_equal("\"iabbr <nowait>", @:)
2798 iabbr WaitForCompletion WFC
2799 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2800 call assert_equal("\"iabbr WaitForCompletion", @:)
2801 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2802 call assert_equal("\"iabbr a1z\t", @:)
2803 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002804 set wildoptions&
2805endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002806
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002807" menu name fuzzy completion
2808func Test_fuzzy_completion_menu()
2809 CheckGui
2810 set wildoptions&
2811 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2812 call assert_equal('"menu pup', @:)
2813 set wildoptions=fuzzy
2814 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2815 call assert_equal('"menu PopUp.', @:)
2816 set wildoptions&
2817endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002818
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002819" :messages suboptions fuzzy completion
2820func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002821 set wildoptions&
2822 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2823 call assert_equal('"messages clr', @:)
2824 set wildoptions=fuzzy
2825 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002827 set wildoptions&
2828endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002829
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002830" :set option name fuzzy completion
2831func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832 set wildoptions&
2833 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"set brkopt', @:)
2835 set wildoptions=fuzzy
2836 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2837 call assert_equal('"set breakindentopt', @:)
2838 set wildoptions&
2839 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2840 call assert_equal('"set fixendofline', @:)
2841 set wildoptions=fuzzy
2842 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2843 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002844 set wildoptions&
2845endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002846
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002847" :set <term_option>
2848func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002849 set wildoptions&
2850 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2851 call assert_equal('"set t_EC', @:)
2852 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2853 call assert_equal('"set <t_EC>', @:)
2854 set wildoptions=fuzzy
2855 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"set t_EC', @:)
2857 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002859 set wildoptions&
2860endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002861
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002862" " :packadd directory name fuzzy completion - NOT supported
2863" func Test_fuzzy_completion_packadd()
2864" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002865
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002866" " shell command name fuzzy completion - NOT supported
2867" func Test_fuzzy_completion_shellcmd()
2868" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002869
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870" :sign suboptions fuzzy completion
2871func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002872 set wildoptions&
2873 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2874 call assert_equal('"sign ufe', @:)
2875 set wildoptions=fuzzy
2876 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2877 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002878 set wildoptions&
2879endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002880
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002881" :syntax suboptions fuzzy completion
2882func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002883 set wildoptions&
2884 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2885 call assert_equal('"syntax kwd', @:)
2886 set wildoptions=fuzzy
2887 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002889 set wildoptions&
2890endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002891
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002892" syntax group name fuzzy completion
2893func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002894 set wildoptions&
2895 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2896 call assert_equal('"syntax list mpar', @:)
2897 set wildoptions=fuzzy
2898 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002900 set wildoptions&
2901endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002902
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903" :syntime suboptions fuzzy completion
2904func Test_fuzzy_completion_syntime()
2905 CheckFeature profile
2906 set wildoptions&
2907 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2908 call assert_equal('"syntime clr', @:)
2909 set wildoptions=fuzzy
2910 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2911 call assert_equal('"syntime clear', @:)
2912 set wildoptions&
2913endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002914
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002915" " tag name fuzzy completion - NOT supported
2916" func Test_fuzzy_completion_tagname()
2917" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002918
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002919" " tag name and file fuzzy completion - NOT supported
2920" func Test_fuzzy_completion_tagfile()
2921" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002922
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002923" " user names fuzzy completion - how to test this functionality?
2924" func Test_fuzzy_completion_username()
2925" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002927" user defined variable name fuzzy completion
2928func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929 let g:SomeVariable=10
2930 set wildoptions&
2931 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2932 call assert_equal('"let SVar', @:)
2933 set wildoptions=fuzzy
2934 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2935 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002936 set wildoptions&
2937endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002938
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002939" Test for sorting the results by the best match
2940func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002941 %bw!
2942 command T123format :
2943 command T123goformat :
2944 command T123TestFOrmat :
2945 command T123fendoff :
2946 command T123state :
2947 command T123FendingOff :
2948 set wildoptions=fuzzy
2949 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2950 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2951 delcommand T123format
2952 delcommand T123goformat
2953 delcommand T123TestFOrmat
2954 delcommand T123fendoff
2955 delcommand T123state
2956 delcommand T123FendingOff
2957 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958 set wildoptions&
2959endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002960
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002961" Test for fuzzy completion of a command with lower case letters and a number
2962func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002963 command Foo2Bar :
2964 set wildoptions=fuzzy
2965 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal('"Foo2Bar', @:)
2967 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2968 call assert_equal('"Foo2Bar', @:)
2969 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal('"Foo2Bar', @:)
2971 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002972 set wildoptions&
2973endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002974
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002975" Test for command completion for a command starting with 'k'
2976func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002977 command KillKillKill :
2978 set wildoptions&
2979 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2980 call assert_equal("\"killkill\<Tab>", @:)
2981 set wildoptions=fuzzy
2982 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2983 call assert_equal('"KillKillKill', @:)
2984 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002985 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002986endfunc
2987
2988" Test for fuzzy completion for user defined custom completion function
2989func Test_fuzzy_completion_custom_func()
2990 func Tcompl(a, c, p)
2991 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
2992 endfunc
2993 command -nargs=* -complete=custom,Tcompl Fuzzy :
2994 set wildoptions&
2995 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal("\"Fuzzy format", @:)
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 ttt", @:)
3001 set wildoptions=fuzzy
3002 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3003 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3004 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3005 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3006 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal("\"Fuzzy xy", @:)
3008 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3009 call assert_equal("\"Fuzzy TestFOrmat", @:)
3010 delcom Fuzzy
3011 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003012endfunc
3013
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003014" Test for :breakadd argument completion
3015func Test_cmdline_complete_breakadd()
3016 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3017 call assert_equal("\"breakadd expr file func here", @:)
3018 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3019 call assert_equal("\"breakadd expr", @:)
3020 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3021 call assert_equal("\"breakadd expr", @:)
3022 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3023 call assert_equal("\"breakadd here", @:)
3024 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3025 call assert_equal("\"breakadd here", @:)
3026 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal("\"breakadd abc", @:)
3028 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3029 let l = getcompletion('not', 'breakpoint')
3030 call assert_equal([], l)
3031
3032 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003033 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003034 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3035 call assert_equal("\"breakadd file Xscript", @:)
3036 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3037 call assert_equal("\"breakadd file Xscript", @:)
3038 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3039 call assert_equal("\"breakadd file 20 Xscript", @:)
3040 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal("\"breakadd file 20 Xscript", @:)
3042 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3044 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3045 call assert_equal("\"breakadd file 20\t", @:)
3046 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3047 call assert_equal("\"breakadd file 20x\t", @:)
3048 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3049 call assert_equal("\"breakadd file Xscript ", @:)
3050 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3051 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003052
3053 " Test for :breakadd func [lnum] <function>
3054 func Xbreak_func()
3055 endfunc
3056 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal("\"breakadd func Xbreak_func", @:)
3058 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3059 call assert_equal("\"breakadd func Xbreak_func", @:)
3060 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3062 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3063 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3064 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3065 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3066 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal("\"breakadd func 20\t", @:)
3068 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_equal("\"breakadd func 20x\t", @:)
3070 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3071 call assert_equal("\"breakadd func Xbreak_func ", @:)
3072 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal("\"breakadd func X1B2C3", @:)
3074 delfunc Xbreak_func
3075
3076 " Test for :breakadd expr <expression>
3077 let g:Xtest_var = 10
3078 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal("\"breakadd expr Xtest_var", @:)
3080 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal("\"breakadd expr Xtest_var", @:)
3082 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3083 call assert_equal("\"breakadd expr Xtest_var ", @:)
3084 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal("\"breakadd expr X1B2C3", @:)
3086 unlet g:Xtest_var
3087
3088 " Test for :breakadd here
3089 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"breakadd here Xtest", @:)
3091 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal("\"breakadd here Xtest", @:)
3093 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"breakadd here ", @:)
3095endfunc
3096
3097" Test for :breakdel argument completion
3098func Test_cmdline_complete_breakdel()
3099 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal("\"breakdel file func here", @:)
3101 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3102 call assert_equal("\"breakdel file", @:)
3103 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakdel file", @:)
3105 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakdel here", @:)
3107 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakdel here", @:)
3109 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"breakdel abc", @:)
3111
3112 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003113 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003114 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3115 call assert_equal("\"breakdel file Xscript", @:)
3116 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3117 call assert_equal("\"breakdel file Xscript", @:)
3118 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3119 call assert_equal("\"breakdel file 20 Xscript", @:)
3120 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3121 call assert_equal("\"breakdel file 20 Xscript", @:)
3122 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3123 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3124 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3125 call assert_equal("\"breakdel file 20\t", @:)
3126 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3127 call assert_equal("\"breakdel file 20x\t", @:)
3128 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3129 call assert_equal("\"breakdel file Xscript ", @:)
3130 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3131 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003132
3133 " Test for :breakdel func [lnum] <function>
3134 func Xbreak_func()
3135 endfunc
3136 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal("\"breakdel func Xbreak_func", @:)
3138 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3139 call assert_equal("\"breakdel func Xbreak_func", @:)
3140 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3141 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3142 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3143 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3144 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3145 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3146 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3147 call assert_equal("\"breakdel func 20\t", @:)
3148 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal("\"breakdel func 20x\t", @:)
3150 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal("\"breakdel func Xbreak_func ", @:)
3152 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3153 call assert_equal("\"breakdel func X1B2C3", @:)
3154 delfunc Xbreak_func
3155
3156 " Test for :breakdel here
3157 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakdel here Xtest", @:)
3159 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakdel here Xtest", @:)
3161 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003163endfunc
3164
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003165" Test for :scriptnames argument completion
3166func Test_cmdline_complete_scriptnames()
3167 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003168 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003169 source Xa1b2c3.vim
3170 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3171 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3172 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3173 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3174 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3175 call assert_equal("\"script b2c3", @:)
3176 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3177 call assert_match("\"script 2\<Tab>$", @:)
3178 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3179 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3180 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"script ", @:)
3182 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3183 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3184 new
3185 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3186 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3187 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003188 set wildmenu&
3189endfunc
3190
Bram Moolenaard8893442022-05-06 20:38:47 +01003191" this was going over the end of IObuff
3192func Test_report_error_with_composing()
3193 let caught = 'no'
3194 try
3195 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3196 catch /E492:/
3197 let caught = 'yes'
3198 endtry
3199 call assert_equal('yes', caught)
3200endfunc
3201
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003202" Test for expanding 2-letter and 3-letter :substitute command arguments.
3203" These commands don't accept an argument.
3204func Test_cmdline_complete_substitute_short()
3205 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3206 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3207 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3208 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3209 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3210 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3212 endfor
3213endfunc
3214
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003215" Test for :! shell command argument completion
3216func Test_cmdline_complete_bang_cmd_argument()
3217 set wildoptions=fuzzy
3218 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3219 call assert_equal('"!vim test_cmdline.vim', @:)
3220 set wildoptions&
3221 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3222 call assert_equal('"!vim test_cmdline.vim', @:)
3223endfunc
3224
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003225func Check_completion()
3226 call assert_equal('let a', getcmdline())
3227 call assert_equal(6, getcmdpos())
3228 call assert_equal(7, getcmdscreenpos())
3229 call assert_equal('var', getcmdcompltype())
3230 return ''
3231endfunc
3232
3233func Test_screenpos_and_completion()
3234 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3235endfunc
3236
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003237func Test_recursive_register()
3238 let @= = ''
3239 silent! ?e/
3240 let caught = 'no'
3241 try
3242 normal //
3243 catch /E169:/
3244 let caught = 'yes'
3245 endtry
3246 call assert_equal('yes', caught)
3247endfunc
3248
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003249func Test_long_error_message()
3250 " the error should be truncated, not overrun IObuff
3251 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3252endfunc
3253
zeertzjq6791adc2022-07-26 20:42:25 +01003254func Test_cmdline_redraw_tabline()
3255 CheckRunVimInTerminal
3256
3257 let lines =<< trim END
3258 set showtabline=2
3259 autocmd CmdlineEnter * set tabline=foo
3260 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003261 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003262 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3263 call term_sendkeys(buf, ':')
3264 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3265
3266 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003267endfunc
3268
zeertzjqb82a2ab2022-08-21 14:33:57 +01003269func Test_wildmenu_pum_disable_while_shown()
3270 set wildoptions=pum
3271 set wildmenu
3272 cnoremap <F2> <Cmd>set nowildmenu<CR>
3273 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3274 call assert_equal(0, pumvisible())
3275 cunmap <F2>
3276 set wildoptions& wildmenu&
3277endfunc
3278
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003279func Test_setcmdline()
3280 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003281 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003282 call assert_equal(0, setcmdline(a:text))
3283 call assert_equal(a:text, getcmdline())
3284 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003285 call assert_equal(getcmdtype(), g:cmdtype)
3286 unlet g:cmdtype
3287 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003288
3289 call assert_equal(0, setcmdline(a:text, a:pos))
3290 call assert_equal(a:text, getcmdline())
3291 call assert_equal(a:pos, getcmdpos())
3292
3293 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003294 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3295 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003296
3297 return ''
3298 endfunc
3299
3300 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3301 call assert_equal('set rtp?', @:)
3302
zeertzjq54acb902022-08-29 16:21:25 +01003303 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3304 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3305 call assert_equal('foo', g:str)
3306 unlet g:str
3307
3308 delfunc SetText
3309
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003310 " setcmdline() returns 1 when not editing the command line.
3311 call assert_equal(1, 'foo'->setcmdline())
3312
3313 " Called in custom function
3314 func CustomComplete(A, L, P)
3315 call assert_equal(0, setcmdline("DoCmd "))
3316 return "January\nFebruary\nMars\n"
3317 endfunc
3318
3319 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3320 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3321 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003322 delcom DoCmd
3323 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003324
3325 " Called in <expr>
3326 cnoremap <expr>a setcmdline('let foo=')
3327 call feedkeys(":a\<CR>", 'tx')
3328 call assert_equal('let foo=0', @:)
3329 cunmap a
3330endfunc
3331
Bram Moolenaar309976e2019-12-05 18:16:33 +01003332" vim: shiftwidth=2 sts=2 expandtab