blob: e79fa72bbad3b108290c35c76ef28ba1bb239688 [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
Bram Moolenaar0816f472022-10-05 15:42:32 +0100251 func EchoTwo()
252 set laststatus=2
253 set cmdheight=5
254 echo 'foo'
255 echo 'bar'
256 set cmdheight=1
257 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100258 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100259 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100260
261 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
262 call term_sendkeys(buf, ":resize -3\<CR>")
263 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
264
265 " using the space available doesn't change the status line
266 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
267 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
268
269 " using more space moves the status line up
270 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
271 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
272
273 " reducing cmdheight moves status line down
274 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
275 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
276
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000277 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100278 call term_sendkeys(buf, ":resize -1\<CR>")
279 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
280 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
281
Bram Moolenaar0816f472022-10-05 15:42:32 +0100282 " setting 'cmdheight' works after outputting two messages
283 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
284 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
285
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 " clean up
287 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288endfunc
289
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100290func Test_cmdheight_tabline()
291 CheckScreendump
292
293 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
294 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
295
296 " clean up
297 call StopVimInTerminal(buf)
298endfunc
299
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100300func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100301 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <unique> <silent>', getreg(':'))
303 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <script> <unique>', getreg(':'))
305 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <expr> <script>', getreg(':'))
307 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <buffer> <expr>', getreg(':'))
309 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"map <nowait> <buffer>', getreg(':'))
311 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <special> <nowait>', getreg(':'))
313 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200315
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 map <Middle>x middle
317
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200318 map ,f commaf
319 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 map <Left> left
321 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200322 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
323 call assert_equal('"map ,f', getreg(':'))
324 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
325 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
328 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200329 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000330 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
331 call assert_equal("\"map <M-Left>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200332 unmap ,f
333 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200334 unmap <Left>
335 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200336
zeertzjqc3a26c62023-02-17 16:40:20 +0000337 set cpo-=< cpo-=k
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200338 map <Left> left
339 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200341 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200342 call assert_equal("\"map <M\<Tab>", getreg(':'))
zeertzjqc3a26c62023-02-17 16:40:20 +0000343 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200345 unmap <Left>
346
347 set cpo+=<
348 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200349 exe "set t_k6=\<Esc>[17~"
350 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200351 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
352 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200353 if !has('gui_running')
354 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
355 call assert_equal("\"map <F6>x", getreg(':'))
356 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200357 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200358 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200359 set cpo-=<
360
361 set cpo+=B
362 map <Left> left
363 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
364 call assert_equal('"map <Left>', getreg(':'))
365 unmap <Left>
366 set cpo-=B
367
368 set cpo+=k
369 map <Left> left
370 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
371 call assert_equal('"map <Left>', getreg(':'))
372 unmap <Left>
373 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200374
Bram Moolenaar531be472020-09-23 22:38:05 +0200375 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
376
Bram Moolenaar1776a282019-05-03 16:05:41 +0200377 unmap <Middle>x
378 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100379endfunc
380
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100382 hi Aardig ctermfg=green
383 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000384 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000386 call assert_equal('"match none', @:)
387 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
388 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100389endfunc
390
391func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100392 hi Aardig ctermfg=green
393 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200395 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi default Aardig', getreg(':'))
397 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100399 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi link', getreg(':'))
401 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
402 call assert_equal('"hi default', getreg(':'))
403 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
404 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200405 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
406 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
407 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
408 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200409
410 " A cleared group does not show up in completions.
411 hi Anders ctermfg=green
412 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
413 hi clear Aardig
414 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
415 hi clear Anders
416 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100417endfunc
418
Bram Moolenaar75e15672020-06-28 13:10:22 +0200419" Test for command-line expansion of "hi Ni " (easter egg)
420func Test_highlight_easter_egg()
421 call test_override('ui_delay', 1)
422 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal("\"hi Ni \<Tab>", @:)
424 call test_override('ALL', 0)
425endfunc
426
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427func Test_getcompletion()
428 let groupcount = len(getcompletion('', 'event'))
429 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200430 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200431 call assert_true(matchcount > 0)
432 call assert_true(groupcount > matchcount)
433
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200434 if has('menu')
435 source $VIMRUNTIME/menu.vim
436 let matchcount = len(getcompletion('', 'menu'))
437 call assert_true(matchcount > 0)
438 call assert_equal(['File.'], getcompletion('File', 'menu'))
439 call assert_true(matchcount > 0)
440 let matchcount = len(getcompletion('File.', 'menu'))
441 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000442 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200443 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200444
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200445 let l = getcompletion('v:n', 'var')
446 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200447 let l = getcompletion('v:notexists', 'var')
448 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200449
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200450 args a.c b.c
451 let l = getcompletion('', 'arglist')
452 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000453 let l = getcompletion('a.', 'buffer')
454 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200455 %argdelete
456
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200457 let l = getcompletion('', 'augroup')
458 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('blahblah', 'augroup')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'behave')
463 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200464 let l = getcompletion('not', 'behave')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
467 let l = getcompletion('', 'color')
468 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('dirty', 'color')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
472 let l = getcompletion('', 'command')
473 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200474 let l = getcompletion('awake', 'command')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
477 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200478 call assert_true(index(l, 'samples/') >= 0)
479 let l = getcompletion('NoMatch', 'dir')
480 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200481
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100482 if glob('~/*') !=# ''
483 let l = getcompletion('~/', 'dir')
484 call assert_true(l[0][0] ==# '~')
485 endif
486
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487 let l = getcompletion('exe', 'expression')
488 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('kill', 'expression')
490 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200491
492 let l = getcompletion('tag', 'function')
493 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200494 let l = getcompletion('paint', 'function')
495 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200496
Kota Kato90c23532023-01-18 15:27:38 +0000497 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000498 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000499 let l = getcompletion('ruby', 'function')
500 call assert_equal([], l)
501 endif
502
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200503 let Flambda = {-> 'hello'}
504 let l = getcompletion('', 'function')
505 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200506 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200507
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200508 let l = getcompletion('run', 'file')
509 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200510 let l = getcompletion('walk', 'file')
511 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200512 set wildignore=*.vim
513 let l = getcompletion('run', 'file', 1)
514 call assert_true(index(l, 'runtest.vim') < 0)
515 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000516 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100517 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000518 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
519 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200520
521 let l = getcompletion('ha', 'filetype')
522 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200523 let l = getcompletion('horse', 'filetype')
524 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200525
526 let l = getcompletion('z', 'syntax')
527 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 let l = getcompletion('emacs', 'syntax')
529 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530
531 let l = getcompletion('jikes', 'compiler')
532 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200533 let l = getcompletion('break', 'compiler')
534 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200535
536 let l = getcompletion('last', 'help')
537 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200538 let l = getcompletion('giveup', 'help')
539 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200540
541 let l = getcompletion('time', 'option')
542 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200543 let l = getcompletion('space', 'option')
544 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200545
546 let l = getcompletion('er', 'highlight')
547 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200548 let l = getcompletion('dark', 'highlight')
549 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200550
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200551 let l = getcompletion('', 'messages')
552 call assert_true(index(l, 'clear') >= 0)
553 let l = getcompletion('not', 'messages')
554 call assert_equal([], l)
555
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200556 let l = getcompletion('', 'mapclear')
557 call assert_true(index(l, '<buffer>') >= 0)
558 let l = getcompletion('not', 'mapclear')
559 call assert_equal([], l)
560
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200561 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200562 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200563 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
564 let root = has('win32') ? 'C:\\' : '/'
565 let l = getcompletion(root, 'shellcmd')
566 let expected = map(filter(glob(root . '*', 0, 1),
567 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
568 call assert_equal(expected, l)
569
Bram Moolenaarb650b982016-08-05 20:35:13 +0200570 if has('cscope')
571 let l = getcompletion('', 'cscope')
572 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
573 call assert_equal(cmds, l)
574 " using cmdline completion must not change the result
575 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
576 let l = getcompletion('', 'cscope')
577 call assert_equal(cmds, l)
578 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
579 let l = getcompletion('find ', 'cscope')
580 call assert_equal(keys, l)
581 endif
582
Bram Moolenaar7522f692016-08-06 14:12:50 +0200583 if has('signs')
584 sign define Testing linehl=Comment
585 let l = getcompletion('', 'sign')
586 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
587 call assert_equal(cmds, l)
588 " using cmdline completion must not change the result
589 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
590 let l = getcompletion('', 'sign')
591 call assert_equal(cmds, l)
592 let l = getcompletion('list ', 'sign')
593 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000594 let l = getcompletion('de*', 'sign')
595 call assert_equal(['define'], l)
596 let l = getcompletion('p?', 'sign')
597 call assert_equal(['place'], l)
598 let l = getcompletion('j.', 'sign')
599 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200600 endif
601
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200602 " Command line completion tests
603 let l = getcompletion('cd ', 'cmdline')
604 call assert_true(index(l, 'samples/') >= 0)
605 let l = getcompletion('cd NoMatch', 'cmdline')
606 call assert_equal([], l)
607 let l = getcompletion('let v:n', 'cmdline')
608 call assert_true(index(l, 'v:null') >= 0)
609 let l = getcompletion('let v:notexists', 'cmdline')
610 call assert_equal([], l)
611 let l = getcompletion('call tag', 'cmdline')
612 call assert_true(index(l, 'taglist(') >= 0)
613 let l = getcompletion('call paint', 'cmdline')
614 call assert_equal([], l)
zeertzjqe4c79d32023-08-15 22:41:53 +0200615 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
616 call assert_equal(['<buffer>'], l)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200617
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100618 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000619 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100620 return "oneA\noneB\noneC"
621 endfunc
622 command -nargs=1 -complete=custom,T MyCmd
623 let l = getcompletion('MyCmd ', 'cmdline')
624 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000625 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100626
627 delcommand MyCmd
628 delfunc T
ii144785fe02021-11-21 12:13:56 +0000629 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100630
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200631 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200632 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200633 if has('cmdline_hist')
634 call add(names, 'history')
635 endif
636 if has('gettext')
637 call add(names, 'locale')
638 endif
639 if has('profile')
640 call add(names, 'syntime')
641 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200642
643 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100644 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200645
646 for name in names
647 let matchcount = len(getcompletion('', name))
648 call assert_true(matchcount >= 0, 'No matches for ' . name)
649 endfor
650
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200651 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200652
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000653 edit a~b
654 enew
655 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
656 bw a~b
657
658 if has('unix')
659 edit Xtest\
660 enew
661 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
662 bw Xtest\
663 endif
664
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200665 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200666 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100667 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200668endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200669
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000670func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000671 " Get a dialog in the GUI
672 CheckNotGui
673
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000674 " This was using uninitialized memory.
675 let lines =<< trim END
676 set verbose=6
677 norm @=ٷ
678 qall!
679 END
680 call writefile(lines, 'XmultiScript', 'D')
681 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
682endfunc
683
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000684" Test for getcompletion() with "fuzzy" in 'wildoptions'
685func Test_getcompletion_wildoptions()
686 let save_wildoptions = &wildoptions
687 set wildoptions&
688 let l = getcompletion('space', 'option')
689 call assert_equal([], l)
690 let l = getcompletion('ier', 'command')
691 call assert_equal([], l)
692 set wildoptions=fuzzy
693 let l = getcompletion('space', 'option')
694 call assert_true(index(l, 'backspace') >= 0)
695 let l = getcompletion('ier', 'command')
696 call assert_true(index(l, 'compiler') >= 0)
697 let &wildoptions = save_wildoptions
698endfunc
699
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000700func Test_complete_autoload_error()
701 let save_rtp = &rtp
702 let lines =<< trim END
703 vim9script
704 export def Complete(..._): string
705 return 'match'
706 enddef
707 echo this will cause an error
708 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100709 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000710 call writefile(lines, 'Xdir/autoload/script.vim')
711 exe 'set rtp+=' .. getcwd() .. '/Xdir'
712
713 let lines =<< trim END
714 vim9script
715 import autoload 'script.vim'
716 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
717 &wildcharm = char2nr("\<Tab>")
718 feedkeys(":Cmd \<Tab>", 'xt')
719 END
720 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
721
722 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000723endfunc
724
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100725func Test_fullcommand()
726 let tests = {
727 \ '': '',
728 \ ':': '',
729 \ ':::': '',
730 \ ':::5': '',
731 \ 'not_a_cmd': '',
732 \ 'Check': '',
733 \ 'syntax': 'syntax',
734 \ ':syntax': 'syntax',
735 \ '::::syntax': 'syntax',
736 \ 'sy': 'syntax',
737 \ 'syn': 'syntax',
738 \ 'synt': 'syntax',
739 \ ':sy': 'syntax',
740 \ '::::sy': 'syntax',
741 \ 'match': 'match',
742 \ '2match': 'match',
743 \ '3match': 'match',
744 \ 'aboveleft': 'aboveleft',
745 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100746 \ 'en': 'endif',
747 \ 'end': 'endif',
748 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100749 \ 's': 'substitute',
750 \ '5s': 'substitute',
751 \ ':5s': 'substitute',
752 \ "'<,'>s": 'substitute',
753 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100754 \ 'CheckLin': 'CheckLinux',
755 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100756 \ }
757
758 for [in, want] in items(tests)
759 call assert_equal(want, fullcommand(in))
760 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200761 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100762
763 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200764
765 command -buffer BufferLocalCommand :
766 command GlobalCommand :
767 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
768 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
769 delcommand BufferLocalCommand
770 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100771endfunc
772
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200773func Test_shellcmd_completion()
774 let save_path = $PATH
775
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100776 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200777 call writefile([''], 'Xpathdir/Xfile.exe')
778 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
779
780 " Set PATH to example directory without trailing slash.
781 let $PATH = getcwd() . '/Xpathdir'
782
783 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
784 " dirs in the PATH, even though they won't be executed. We check that only
785 " subdirs of the PWD and executables from the PATH are included in the
786 " suggestions.
787 let actual = getcompletion('X', 'shellcmd')
788 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
789 call insert(expected, 'Xfile.exe')
790 call assert_equal(expected, actual)
791
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200792 let $PATH = save_path
793endfunc
794
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200795func Test_expand_star_star()
Bram Moolenaarbf630112023-05-19 21:41:02 +0100796 call mkdir('a/b/c', 'pR')
797 call writefile(['asdfasdf'], 'a/b/c/fileXname')
798 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
799 call assert_equal('find a/b/c/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200800 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200801endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100802
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100803func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100804 let @a = "def"
805 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
806 call assert_equal('"abc def ghi', @:)
807
808 new
809 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
810
811 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
812 call assert_equal('"aaa asdf bbb', @:)
813
814 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
815 call assert_equal('"aaa /tmp/some bbb', @:)
816
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200817 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
818 call assert_equal('"aaa '.getline(1).' bbb', @:)
819
Bram Moolenaar21efc362016-12-03 14:05:49 +0100820 set incsearch
821 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
822 call assert_equal('"aaa verylongword bbb', @:)
823
824 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
825 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100826
827 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
828 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100829 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200830
831 " Error while typing a command used to cause that it was not executed
832 " in the end.
833 new
834 try
835 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
836 catch /^Vim\%((\a\+)\)\=:E32/
837 " ignore error E32
838 endtry
839 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100840
Bram Moolenaar578fe942020-02-27 21:32:51 +0100841 " Try to paste an invalid register using <C-R>
842 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
843 call assert_equal('"onetwo', @:)
844
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100845 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100846 let @a = "xy\<C-H>z"
847 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
848 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100849 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
850 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100851 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
852 call assert_equal("\"xy\<C-H>z", @:)
853
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100854 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
855 let @a = "xy\<C-V>z"
856 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
857 call assert_equal('"xyz', @:)
858 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
859 call assert_equal("\"xy\<C-V>z", @:)
860
Bram Moolenaar578fe942020-02-27 21:32:51 +0100861 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
862
Bram Moolenaar72532d32018-04-07 19:09:09 +0200863 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100864endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100865
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100866func Test_cmdline_remove_char()
867 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100868
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100869 for e in ['utf8', 'latin1']
870 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100871
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100872 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
873 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100874
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100875 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
876 call assert_equal('"abcdef', @:)
877
878 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
879 call assert_equal('"abc ghi', @:, e)
880
881 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
882 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100883
884 " This was going before the start in latin1.
885 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100886 endfor
887
888 let &encoding = encoding_save
889endfunc
890
891func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200892 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100893
894 set keymap=esperanto
895 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
896 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
897 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100898endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100899
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100900func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100901 new
902 2;'(
903 2;')
904 quit
905endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100906
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100907func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100908 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100909 new
910 source Xtest.vim
911 " Trigger calling validate_cursor()
912 diffsp Xtest.vim
913 quit!
914 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100915endfunc
916
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100917func Test_mark_from_line_zero()
918 " this was reading past the end of the first (empty) line
919 new
920 norm oxxxx
921 call assert_fails("0;'(", 'E20:')
922 bwipe!
923endfunc
924
Bram Moolenaarba47b512017-01-24 21:18:19 +0100925func Test_cmdline_complete_wildoptions()
926 help
927 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
928 let a = join(sort(split(@:)),' ')
929 set wildoptions=tagfile
930 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
931 let b = join(sort(split(@:)),' ')
932 call assert_equal(a, b)
933 bw!
934endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100935
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200936func Test_cmdline_complete_user_cmd()
937 command! -complete=color -nargs=1 Foo :
938 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
939 call assert_equal('"Foo blue', @:)
940 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
941 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000942 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
943 call assert_equal('"Foo a blue', @:)
944 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
945 call assert_equal('"Foo b\', @:)
946 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
947 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200948 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100949
950 redraw
951 call assert_equal('~', Screenline(&lines - 1))
952 command! FooOne :
953 command! FooTwo :
954
955 set nowildmenu
956 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
957 call assert_equal('"FooOne', @:)
958 call assert_equal('~', Screenline(&lines - 1))
959
960 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
961 call assert_equal('"FooTwo', @:)
962 call assert_equal('~', Screenline(&lines - 1))
963
964 delcommand FooOne
965 delcommand FooTwo
966 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200967endfunc
968
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100969func Test_complete_user_cmd()
970 command FooBar echo 'global'
971 command -buffer FooBar echo 'local'
972 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
973 call assert_equal('"FooBar', @:)
974
975 delcommand -buffer FooBar
976 delcommand FooBar
977endfunc
978
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100979func s:ScriptLocalFunction()
980 echo 'yes'
981endfunc
982
983func Test_cmdline_complete_user_func()
984 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200985 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100986 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
987 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100988
989 " g: prefix also works
990 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
991 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200992
993 " using g: prefix does not result in just "g:" matches from a lambda
994 let Fx = { a -> a }
995 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
996 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200997
998 " existence of script-local dict function does not break user function name
999 " completion
1000 function s:a_dict_func() dict
1001 endfunction
1002 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
1003 call assert_match('"call Test_cmdline_complete_user_', @:)
1004 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +01001005endfunc
1006
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001007func Test_cmdline_complete_user_names()
1008 if has('unix') && executable('whoami')
1009 let whoami = systemlist('whoami')[0]
1010 let first_letter = whoami[0]
1011 if len(first_letter) > 0
1012 " Trying completion of :e ~x where x is the first letter of
1013 " the user name should complete to at least the user name.
1014 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1015 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1016 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001017 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001018 " Just in case: check that the system has an Administrator account.
1019 let names = system('net user')
1020 if names =~ 'Administrator'
1021 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001022 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001023 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001024 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001025 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001026 else
1027 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001028 endif
1029endfunc
1030
Bram Moolenaar297610b2019-12-27 17:20:55 +01001031func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001032 CheckExecutable whoami
1033 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1034 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001035endfunc
1036
Bram Moolenaar8b633132020-03-20 18:20:51 +01001037func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001038 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1039 call assert_equal(lang, v:lc_time)
1040
1041 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1042 call assert_equal(lang, v:ctype)
1043
1044 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1045 call assert_equal(lang, v:collate)
1046
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001047 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001048 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001049
1050 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001051 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001052
Bram Moolenaarec680282020-06-12 19:35:32 +02001053 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001054
Bram Moolenaarec680282020-06-12 19:35:32 +02001055 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1056 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001057
Bram Moolenaarec680282020-06-12 19:35:32 +02001058 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1059 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001060
Bram Moolenaarec680282020-06-12 19:35:32 +02001061 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1062 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001063
1064 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1065 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001066endfunc
1067
Bram Moolenaar297610b2019-12-27 17:20:55 +01001068func Test_cmdline_complete_env_variable()
1069 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001070 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1071 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001072 unlet $X_VIM_TEST_COMPLETE_ENV
1073endfunc
1074
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001075func Test_cmdline_complete_expression()
1076 let g:SomeVar = 'blah'
1077 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1078 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1079 call assert_match('"' .. cmd .. ' SomeVar', @:)
1080 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1081 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1082 endfor
1083 unlet g:SomeVar
1084endfunc
1085
Bram Moolenaar47016f52021-08-26 16:39:58 +02001086" Unique function name for completion below
1087func s:WeirdFunc()
1088 echo 'weird'
1089endfunc
1090
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001091" Test for various command-line completion
1092func Test_cmdline_complete_various()
1093 " completion for a command starting with a comment
1094 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1095 call assert_equal("\" :|\"\<C-A>", @:)
1096
1097 " completion for a range followed by a comment
1098 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1099 call assert_equal("\"1,2\"\<C-A>", @:)
1100
1101 " completion for :k command
1102 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1103 call assert_equal("\"ka\<C-A>", @:)
1104
1105 " completion for short version of the :s command
1106 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"sI \<C-A>", @:)
1108
1109 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001110 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001111 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001112 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001113 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001114 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"w >> Xfile1", @:)
1116 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001117
1118 " completion for :w ! and :r ! commands
1119 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1120 call assert_equal("\"w !invalid_xyz_cmd", @:)
1121 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1122 call assert_equal("\"r !invalid_xyz_cmd", @:)
1123
1124 " completion for :>> and :<< commands
1125 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1126 call assert_equal("\">>>\<C-A>", @:)
1127 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal("\"<<<\<C-A>", @:)
1129
1130 " completion for command with +cmd argument
1131 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1132 call assert_equal("\"buffer +/pat Xabc", @:)
1133 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1134 call assert_equal("\"buffer +/pat\<C-A>", @:)
1135
1136 " completion for a command with a trailing comment
1137 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1138 call assert_equal("\"ls \" comment\<C-A>", @:)
1139
1140 " completion for a command with a trailing command
1141 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1142 call assert_equal("\"ls | ls", @:)
1143
1144 " completion for a command with an CTRL-V escaped argument
1145 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1146 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1147
1148 " completion for a command that doesn't take additional arguments
1149 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1150 call assert_equal("\"all abc\<C-A>", @:)
1151
zeertzjqd3de1782022-09-01 12:58:52 +01001152 " completion for :wincmd with :horizontal modifier
1153 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1154 call assert_equal("\"horizontal wincmd", @:)
1155
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001156 " completion for a command with a command modifier
1157 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1158 call assert_equal("\"topleft new", @:)
1159
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001160 " completion for vim9 and legacy commands
1161 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1162 call assert_equal("\"vim9 call strlen(", @:)
1163 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1164 call assert_equal("\"legac call strlen(", @:)
1165
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001166 " completion for the :disassemble command
1167 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"disas debug", @:)
1169 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal("\"disas profile", @:)
1171 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1173 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001175 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1176 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001177
Bram Moolenaar47016f52021-08-26 16:39:58 +02001178 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001179 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001180
naohiro onodfe04db2021-09-12 15:45:10 +02001181 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1182 call assert_match('"disas <SNR>\d\+_', @:)
1183 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1184 call assert_match('"disas debug <SNR>\d\+_', @:)
1185
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001186 " completion for the :match command
1187 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1188 call assert_equal("\"match Search /pat/\<C-A>", @:)
1189
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001190 " completion for the :doautocmd command
1191 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1192 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1193
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001194 " completion of autocmd group after comma
1195 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1196 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1197
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001198 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001199 call writefile([], 'Xvarfile1', 'D')
1200 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001201 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1202 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001203
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001204 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001205 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001206 augroup END
1207 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001208 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001209
1210 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001211 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001213 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"au XTest.test", @:)
1215
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001216 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001217
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001218 " autocmd pattern completion
1219 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1220 call assert_equal("\"au BufEnter *.py\t", @:)
1221
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001222 " completion for the :unlet command
1223 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal("\"unlet one two", @:)
1225
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001226 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001227 " FIXME: what should happen on MS-Windows?
1228 if !has('win32')
1229 edit \{someFile}
1230 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1231 call assert_equal("\"buf {someFile}", @:)
1232 bwipe {someFile}
1233 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001234
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001235 " completion for the :bdelete command
1236 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1237 call assert_equal("\"bdel a b c", @:)
1238
1239 " completion for the :mapclear command
1240 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1241 call assert_equal("\"mapclear <buffer>", @:)
1242
1243 " completion for user defined commands with menu names
1244 menu Test.foo :ls<CR>
1245 com -nargs=* -complete=menu MyCmd
1246 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1247 call assert_equal('"MyCmd Test.', @:)
1248 delcom MyCmd
1249 unmenu Test
1250
1251 " completion for user defined commands with mappings
1252 mapclear
1253 map <F3> :ls<CR>
1254 com -nargs=* -complete=mapping MyCmd
1255 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001256 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001257 mapclear
1258 delcom MyCmd
1259
Yee Cheng Chin54844852023-10-09 18:12:31 +02001260 " Prepare for path completion
1261 call mkdir('Xa b c', 'D')
1262 defer delete('Xcomma,foobar.txt')
1263 call writefile([], 'Xcomma,foobar.txt')
1264
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001265 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001266 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1267 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1268 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001269
1270 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001271 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1272 call assert_equal('"set dir=Xa\ b\ c/', @:)
1273 set dir&
1274
1275 " completion for :set tags= / set dictionary= with escaped commas
1276 if has('win32')
1277 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1278 " '\,'
1279 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1280 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1281
1282 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1283 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1284
1285 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1286 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1287
1288 " completion for :set dictionary= with escaped commas (same behavior, but
1289 " different internal code path from 'set tags=' for escaping the output)
1290 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1291 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1292 else
1293 " In other platforms, backslashes are rounded down (since '\,' itself will
1294 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1295 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1296 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1297
1298 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1299 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1300
1301 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1302 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1303
1304 " completion for :set dictionary= with escaped commas (same behavior, but
1305 " different internal code path from 'set tags=' for escaping the output)
1306 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1307 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1308 endif
1309 set tags&
1310 set dictionary&
1311
1312 " completion for :set makeprg= with no escaped commas
1313 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1314 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1315
1316 if !has('win32')
1317 " Cannot create file with backslash in file name in Windows, so only test
1318 " this elsewhere.
1319 defer delete('Xcomma\,fooslash.txt')
1320 call writefile([], 'Xcomma\,fooslash.txt')
1321 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1322 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1323 endif
1324 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001325
1326 " completion for the :py3 commands
1327 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1328 call assert_equal('"py3 py3do py3file', @:)
1329
Bram Moolenaardf749a22021-03-28 15:29:43 +02001330 " completion for the :vim9 commands
1331 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1332 call assert_equal('"vim9cmd vim9script', @:)
1333
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001334 " redir @" is not the start of a comment. So complete after that
1335 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1336 call assert_equal('"redir @" | cwindow', @:)
1337
1338 " completion after a backtick
1339 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1340 call assert_equal('"e `a1b2c', @:)
1341
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001342 " completion for :language command with an invalid argument
1343 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1344 call assert_equal("\"language dummy \t", @:)
1345
1346 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001347 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1348 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001349
1350 " completion with ambiguous user defined commands
1351 com TCmd1 echo 'TCmd1'
1352 com TCmd2 echo 'TCmd2'
1353 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1354 call assert_equal('"TCmd ', @:)
1355 delcom TCmd1
1356 delcom TCmd2
1357
1358 " completion after a range followed by a pipe (|) character
1359 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1360 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001361
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001362 " completion after a :global command
1363 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1364 call assert_equal('"g/a/chistory', @:)
1365 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1366 call assert_equal("\"g/a\\/chist\t", @:)
1367
Bram Moolenaar9c929712020-09-07 22:05:28 +02001368 " use <Esc> as the 'wildchar' for completion
1369 set wildchar=<Esc>
1370 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1371 call assert_equal('"g/a\xb/clearjumps', @:)
1372 " pressing <esc> twice should cancel the command
1373 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1374 call assert_equal('"g/a\xb/clearjumps', @:)
1375 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001376
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001377 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001378 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001379 call writefile([], '~Xtest')
1380 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1381 call assert_equal('"e \~Xtest', @:)
1382 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001383
1384 " should be able to complete a file name that has a '*'
1385 call writefile([], 'Xx*Yy')
1386 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1387 call assert_equal('"e Xx\*Yy', @:)
1388 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001389
1390 " use a literal star
1391 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1392 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001393 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001394
1395 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1396 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001397endfunc
1398
zeertzjq094dd152023-06-15 22:51:57 +01001399" Test that expanding a pattern doesn't interfere with cmdline completion.
1400func Test_expand_during_cmdline_completion()
1401 func ExpandStuff()
1402 badd <script>:p:h/README.*
1403 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1404 $bwipe
1405 call assert_equal('README.txt', expand('README.*'))
1406 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1407 endfunc
1408 augroup test_CmdlineChanged
1409 autocmd!
1410 autocmd CmdlineChanged * call ExpandStuff()
1411 augroup END
1412
1413 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1414 call assert_equal('"sign place', @:)
1415
1416 augroup test_CmdlineChanged
1417 au!
1418 augroup END
1419 augroup! test_CmdlineChanged
1420 delfunc ExpandStuff
1421endfunc
1422
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001423" Test for 'wildignorecase'
1424func Test_cmdline_wildignorecase()
1425 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001426 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001427 set wildignorecase
1428 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1429 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001430 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001431 let g:Sline = ''
1432 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1433 call assert_equal('"e xt', @:)
1434 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001435 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001436endfunc
1437
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001438func Test_cmdline_write_alternatefile()
1439 new
1440 call setline('.', ['one', 'two'])
1441 f foo.txt
1442 new
1443 f #-A
1444 call assert_equal('foo.txt-A', expand('%'))
1445 f #<-B.txt
1446 call assert_equal('foo-B.txt', expand('%'))
1447 f %<
1448 call assert_equal('foo-B', expand('%'))
1449 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001450 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001451 bw!
1452 f foo-B.txt
1453 f %<-A
1454 call assert_equal('foo-B-A', expand('%'))
1455 bw!
1456 bw!
1457endfunc
1458
Bram Moolenaarf5724372022-09-02 19:45:15 +01001459func Test_cmdline_expand_cur_alt_file()
1460 enew
1461 file http://some.com/file.txt
1462 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1463 call assert_equal('"e http://some.com/file.txt', @:)
1464 edit another
1465 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1466 call assert_equal('"e http://some.com/file.txt', @:)
1467 bwipe
1468 bwipe http://some.com/file.txt
1469endfunc
1470
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001471" using a leading backslash here
1472set cpo+=C
1473
1474func Test_cmdline_search_range()
1475 new
1476 call setline(1, ['a', 'b', 'c', 'd'])
1477 /d
1478 1,\/s/b/B/
1479 call assert_equal('B', getline(2))
1480
1481 /a
1482 $
1483 \?,4s/c/C/
1484 call assert_equal('C', getline(3))
1485
1486 call setline(1, ['a', 'b', 'c', 'd'])
1487 %s/c/c/
1488 1,\&s/b/B/
1489 call assert_equal('B', getline(2))
1490
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001491 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001492 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001493
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001494 bwipe!
1495endfunc
1496
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001497" Test for the tick mark (') in an excmd range
1498func Test_tick_mark_in_range()
1499 " If only the tick is passed as a range and no command is specified, there
1500 " should not be an error
1501 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001502 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001503 call assert_fails("',print", 'E78:')
1504endfunc
1505
1506" Test for using a line number followed by a search pattern as range
1507func Test_lnum_and_pattern_as_range()
1508 new
1509 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1510 let @" = ''
1511 2/foo/yank
1512 call assert_equal("foo 3\n", @")
1513 call assert_equal(1, line('.'))
1514 close!
1515endfunc
1516
Bram Moolenaar65189a12017-02-06 22:22:17 +01001517" Tests for getcmdline(), getcmdpos() and getcmdtype()
1518func Check_cmdline(cmdtype)
1519 call assert_equal('MyCmd a', getcmdline())
1520 call assert_equal(8, getcmdpos())
1521 call assert_equal(a:cmdtype, getcmdtype())
1522 return ''
1523endfunc
1524
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001525set cpo&
1526
Bram Moolenaar65189a12017-02-06 22:22:17 +01001527func Test_getcmdtype()
1528 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1529
1530 let cmdtype = ''
1531 debuggreedy
1532 call feedkeys(":debug echo 'test'\<CR>", "t")
1533 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1534 call feedkeys("cont\<CR>", "xt")
1535 0debuggreedy
1536 call assert_equal('>', cmdtype)
1537
1538 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1539 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1540
1541 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001542 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001543
1544 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1545
1546 cnoremap <expr> <F6> Check_cmdline('=')
1547 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1548 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001549
1550 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001551endfunc
1552
Bram Moolenaar52604f22017-04-07 16:17:39 +02001553func Test_verbosefile()
1554 set verbosefile=Xlog
1555 echomsg 'foo'
1556 echomsg 'bar'
1557 set verbosefile=
1558 let log = readfile('Xlog')
1559 call assert_match("foo\nbar", join(log, "\n"))
1560 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001561
1562 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001563 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001564endfunc
1565
Bram Moolenaar4facea32019-10-12 20:17:40 +02001566func Test_verbose_option()
1567 CheckScreendump
1568
1569 let lines =<< trim [SCRIPT]
1570 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1571 call feedkeys("\r", 't') " for the hit-enter prompt
1572 set verbose=20
1573 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001574 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001575
1576 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001577 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001578 call term_sendkeys(buf, ":DoSomething\<CR>")
1579 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1580
1581 " clean up
1582 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001583endfunc
1584
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001585func Test_setcmdpos()
1586 func InsertTextAtPos(text, pos)
1587 call assert_equal(0, setcmdpos(a:pos))
1588 return a:text
1589 endfunc
1590
1591 " setcmdpos() with position in the middle of the command line.
1592 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1593 call assert_equal('"1ab2', @:)
1594
1595 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1596 call assert_equal('"1b2a', @:)
1597
1598 " setcmdpos() with position beyond the end of the command line.
1599 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1600 call assert_equal('"12ab', @:)
1601
1602 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001603 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001604endfunc
1605
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001606func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001607 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001608 let encoding_save = &encoding
1609
1610 for e in encodings
1611 exe 'set encoding=' . e
1612
1613 " Test overstrike in the middle of the command line.
1614 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001615 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001616
1617 " Test overstrike going beyond end of command line.
1618 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001619 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001620
1621 " Test toggling insert/overstrike a few times.
1622 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001623 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001624 endfor
1625
Bram Moolenaar30276f22019-01-24 17:59:39 +01001626 " Test overstrike with multi-byte characters.
1627 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001628 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001629
1630 let &encoding = encoding_save
1631endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001632
Bram Moolenaar52410572019-10-27 05:12:45 +01001633func Test_buffers_lastused()
1634 " check that buffers are sorted by time when wildmode has lastused
1635 call test_settime(1550020000) " middle
1636 edit bufa
1637 enew
1638 call test_settime(1550030000) " newest
1639 edit bufb
1640 enew
1641 call test_settime(1550010000) " oldest
1642 edit bufc
1643 enew
1644 call test_settime(0)
1645 enew
1646
1647 call assert_equal(['bufa', 'bufb', 'bufc'],
1648 \ getcompletion('', 'buffer'))
1649
1650 let save_wildmode = &wildmode
1651 set wildmode=full:lastused
1652
1653 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1654 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1655 call assert_equal('b bufb', X)
1656 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1657 call assert_equal('b bufa', X)
1658 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1659 call assert_equal('b bufc', X)
1660 enew
1661
1662 edit other
1663 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1664 call assert_equal('b bufb', X)
1665 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1666 call assert_equal('b bufa', X)
1667 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1668 call assert_equal('b bufc', X)
1669 enew
1670
1671 let &wildmode = save_wildmode
1672
1673 bwipeout bufa
1674 bwipeout bufb
1675 bwipeout bufc
1676endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001677
Bram Moolenaar479950f2020-01-19 15:45:17 +01001678func Test_cmdlineclear_tabenter()
1679 CheckScreendump
1680
1681 let lines =<< trim [SCRIPT]
1682 call setline(1, range(30))
1683 [SCRIPT]
1684
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001685 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001686 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001687 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001688 " in one tab make the command line higher with CTRL-W -
1689 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1690 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1691
1692 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001693endfunc
1694
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001695" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001696func Test_cmdline_expand_special()
1697 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001698 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001699 call assert_fails('e <afile>', 'E495:')
1700 call assert_fails('e <abuf>', 'E496:')
1701 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001702
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001703 call writefile([], 'Xfile.cpp', 'D')
1704 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001705 new Xfile.cpp
1706 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1707 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1708 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001709endfunc
1710
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001711" Test for backtick expression in the command line
1712func Test_cmd_backtick()
1713 %argd
1714 argadd `=['a', 'b', 'c']`
1715 call assert_equal(['a', 'b', 'c'], argv())
1716 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001717
1718 argadd `echo abc def`
1719 call assert_equal(['abc def'], argv())
1720 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001721endfunc
1722
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001723" Test for the :! command
1724func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001725 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001726
1727 let lines =<< trim [SCRIPT]
1728 " Test for no previous command
1729 call assert_fails('!!', 'E34:')
1730 set nomore
1731 " Test for cmdline expansion with :!
1732 call setline(1, 'foo!')
1733 silent !echo <cWORD> > Xfile.out
1734 call assert_equal(['foo!'], readfile('Xfile.out'))
1735 " Test for using previous command
1736 silent !echo \! !
1737 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1738 call writefile(v:errors, 'Xresult')
1739 call delete('Xfile.out')
1740 qall!
1741 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001742 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001743 if RunVim([], [], '--clean -S Xscript')
1744 call assert_equal([], readfile('Xresult'))
1745 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001746 call delete('Xresult')
1747endfunc
1748
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001749" Test error: "E135: *Filter* Autocommands must not change current buffer"
1750func Test_cmd_bang_E135()
1751 new
1752 call setline(1, ['a', 'b', 'c', 'd'])
1753 augroup test_cmd_filter_E135
1754 au!
1755 autocmd FilterReadPost * help
1756 augroup END
1757 call assert_fails('2,3!echo "x"', 'E135:')
1758
1759 augroup test_cmd_filter_E135
1760 au!
1761 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001762 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001763 %bwipe!
1764endfunc
1765
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001766func Test_cmd_bang_args()
1767 new
1768 :.!
1769 call assert_equal(0, v:shell_error)
1770
1771 " Note that below there is one space char after the '!'. This caused a
1772 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1773 :.!
1774 call assert_equal(0, v:shell_error)
1775 bwipe!
1776
1777 CheckUnix
1778 :.!pwd
1779 call assert_equal(0, v:shell_error)
1780 :.! pwd
1781 call assert_equal(0, v:shell_error)
1782
1783 " Note there is one space after 'pwd'.
1784 :.! pwd
1785 call assert_equal(0, v:shell_error)
1786
1787 " Note there are two spaces after 'pwd'.
1788 :.! pwd
1789 call assert_equal(0, v:shell_error)
1790 :.!ls ~
1791 call assert_equal(0, v:shell_error)
1792
1793 " Note there is one space char after '~'.
1794 :.!ls ~
1795 call assert_equal(0, v:shell_error)
1796
1797 " Note there are two spaces after '~'.
1798 :.!ls ~
1799 call assert_equal(0, v:shell_error)
1800
1801 :.!echo "foo"
1802 call assert_equal(getline('.'), "foo")
1803 :.!echo "foo "
1804 call assert_equal(getline('.'), "foo ")
1805 :.!echo " foo "
1806 call assert_equal(getline('.'), " foo ")
1807 :.!echo " foo "
1808 call assert_equal(getline('.'), " foo ")
1809
1810 %bwipe!
1811endfunc
1812
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001813" Test for using ~ for home directory in cmdline completion matches
1814func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001815 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001816 call writefile([], 'Xexpdir/Xfile1')
1817 call writefile([], 'Xexpdir/Xfile2')
1818 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001819 let save_HOME = $HOME
1820 let $HOME = getcwd()
1821 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1822 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1823 let $HOME = save_HOME
1824 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001825endfunc
1826
Bram Moolenaar578fe942020-02-27 21:32:51 +01001827" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1828" or insert mode (when 'insertmode' is set)
1829func Test_cmdline_ctrl_g()
1830 new
1831 call setline(1, 'abc')
1832 call cursor(1, 3)
1833 " If command line is entered from insert mode, using C-\ C-G should back to
1834 " insert mode
1835 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1836 call assert_equal('abxyc', getline(1))
1837 call assert_equal(4, col('.'))
1838
1839 " If command line is entered in 'insertmode', using C-\ C-G should back to
1840 " 'insertmode'
1841 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1842 call assert_equal('ab12xyc', getline(1))
1843 close!
1844endfunc
1845
Bram Moolenaar578fe942020-02-27 21:32:51 +01001846" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001847func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001848 func T(a, c, p)
1849 return "oneA\noneB\noneC"
1850 endfunc
1851 command -nargs=1 -complete=custom,T MyCmd
1852
Bram Moolenaar578fe942020-02-27 21:32:51 +01001853 set nowildmenu
1854 set wildmode=full,list
1855 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001856 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001857 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001858 call assert_equal('"MyCmd oneA', @:)
1859
1860 set wildmode=longest,full
1861 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1862 call assert_equal('"MyCmd one', @:)
1863 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1864 call assert_equal('"MyCmd oneC', @:)
1865
1866 set wildmode=longest
1867 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1868 call assert_equal('"MyCmd one', @:)
1869
1870 set wildmode=list:longest
1871 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001872 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001873 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001874 call assert_equal('"MyCmd one', @:)
1875
1876 set wildmode=""
1877 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1878 call assert_equal('"MyCmd oneA', @:)
1879
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001880 " Test for wildmode=longest with 'fileignorecase' set
1881 set wildmode=longest
1882 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001883 argadd AAA AAAA AAAAA
1884 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1885 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001886 set fileignorecase&
1887
1888 " Test for listing files with wildmode=list
1889 set wildmode=list
1890 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001891 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001892 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001893 call assert_equal('"b A', @:)
1894
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001895 " when using longest completion match, matches shorter than the argument
1896 " should be ignored (happens with :help)
1897 set wildmode=longest,full
1898 set wildmenu
1899 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1900 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001901 " non existing file
1902 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1903 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001904 set wildmenu&
1905
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001906 " Test for longest file name completion with 'fileignorecase'
1907 " On MS-Windows, file names are case insensitive.
1908 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001909 call writefile([], 'XTESTfoo', 'D')
1910 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001911 set nofileignorecase
1912 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1913 call assert_equal('"e XTESTfoo', @:)
1914 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1915 call assert_equal('"e Xtestbar', @:)
1916 set fileignorecase
1917 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1918 call assert_equal('"e Xtest', @:)
1919 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1920 call assert_equal('"e Xtest', @:)
1921 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001922 endif
1923
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001924 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001925 delcommand MyCmd
1926 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001927 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001928 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001929endfunc
1930
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001931func Test_wildmode()
1932 " Test with utf-8 encoding
1933 call Wildmode_tests()
1934
1935 " Test with latin1 encoding
1936 let save_encoding = &encoding
1937 set encoding=latin1
1938 call Wildmode_tests()
1939 let &encoding = save_encoding
1940endfunc
1941
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001942func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001943 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001944 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001945 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001946 let lines =<< trim END
1947 func vim8#Complete(a, c, p)
1948 return "oneA\noneB\noneC"
1949 endfunc
1950 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001951 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001952
1953 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1954 set nowildmenu
1955 set wildmode=full,list
1956 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1957 call assert_equal('"MyCmd oneA oneB oneC', @:)
1958
1959 let &rtp = save_rtp
1960 set wildmode& wildmenu&
1961 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001962endfunc
1963
Bram Moolenaar578fe942020-02-27 21:32:51 +01001964" Test for interrupting the command-line completion
1965func Test_interrupt_compl()
1966 func F(lead, cmdl, p)
1967 if a:lead =~ 'tw'
1968 call interrupt()
1969 return
1970 endif
1971 return "one\ntwo\nthree"
1972 endfunc
1973 command -nargs=1 -complete=custom,F Tcmd
1974
1975 set nowildmenu
1976 set wildmode=full
1977 let interrupted = 0
1978 try
1979 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1980 catch /^Vim:Interrupt$/
1981 let interrupted = 1
1982 endtry
1983 call assert_equal(1, interrupted)
1984
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001985 let interrupted = 0
1986 try
1987 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1988 catch /^Vim:Interrupt$/
1989 let interrupted = 1
1990 endtry
1991 call assert_equal(1, interrupted)
1992
Bram Moolenaar578fe942020-02-27 21:32:51 +01001993 delcommand Tcmd
1994 delfunc F
1995 set wildmode&
1996endfunc
1997
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001998" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001999func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002000 let str = ":one two\<C-U>"
2001 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002002 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002003 let str ..= "\<Left>five\<Right>"
2004 let str ..= "\<Home>two "
2005 let str ..= "\<C-Left>one "
2006 let str ..= "\<C-Right> three"
2007 let str ..= "\<End>\<S-Left>four "
2008 let str ..= "\<S-Right> six"
2009 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2010 call feedkeys(str, 'xt')
2011 call assert_equal("\"one two three four five six seven", @:)
2012endfunc
2013
2014" Test for moving the cursor on the / command line in 'rightleft' mode
2015func Test_cmdline_edit_rightleft()
2016 CheckFeature rightleft
2017 set rightleft
2018 set rightleftcmd=search
2019 let str = "/one two\<C-U>"
2020 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002021 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002022 let str ..= "\<Right>five\<Left>"
2023 let str ..= "\<Home>two "
2024 let str ..= "\<C-Right>one "
2025 let str ..= "\<C-Left> three"
2026 let str ..= "\<End>\<S-Right>four "
2027 let str ..= "\<S-Left> six"
2028 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2029 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2030 call assert_equal("\"one two three four five six seven", @/)
2031 set rightleftcmd&
2032 set rightleft&
2033endfunc
2034
2035" Test for using <C-\>e in the command line to evaluate an expression
2036func Test_cmdline_expr()
2037 " Evaluate an expression from the beginning of a command line
2038 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2039 call assert_equal('"hello', @:)
2040
2041 " Use an invalid expression for <C-\>e
2042 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2043
2044 " Insert literal <CTRL-\> in the command line
2045 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2046 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002047endfunc
2048
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002049" This was making the insert position negative
2050func Test_cmdline_expr_register()
2051 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2052endfunc
2053
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002054" Test for 'imcmdline' and 'imsearch'
2055" This test doesn't actually test the input method functionality.
2056func Test_cmdline_inputmethod()
2057 new
2058 call setline(1, ['', 'abc', ''])
2059 set imcmdline
2060
2061 call feedkeys(":\"abc\<CR>", 'xt')
2062 call assert_equal("\"abc", @:)
2063 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2064 call assert_equal("\"abc", @:)
2065 call feedkeys("/abc\<CR>", 'xt')
2066 call assert_equal([2, 1], [line('.'), col('.')])
2067 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2068 call assert_equal([2, 1], [line('.'), col('.')])
2069
2070 set imsearch=2
2071 call cursor(1, 1)
2072 call feedkeys("/abc\<CR>", 'xt')
2073 call assert_equal([2, 1], [line('.'), col('.')])
2074 call cursor(1, 1)
2075 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2076 call assert_equal([2, 1], [line('.'), col('.')])
2077 set imdisable
2078 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2079 call assert_equal([2, 1], [line('.'), col('.')])
2080 set imdisable&
2081 set imsearch&
2082
2083 set imcmdline&
2084 %bwipe!
2085endfunc
2086
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002087" Test for using CTRL-_ in the command line with 'allowrevins'
2088func Test_cmdline_revins()
2089 CheckNotMSWindows
2090 CheckFeature rightleft
2091 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2092 call assert_equal("\"abc\<c-_>", @:)
2093 set allowrevins
2094 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2095 call assert_equal('"abcñèæ', @:)
2096 set allowrevins&
2097endfunc
2098
2099" Test for typing UTF-8 composing characters in the command line
2100func Test_cmdline_composing_chars()
2101 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2102 call assert_equal('"ゔ', @:)
2103endfunc
2104
Bram Moolenaar0e717042020-04-27 19:29:01 +02002105" test that ";" works to find a match at the start of the first line
2106func Test_zero_line_search()
2107 new
2108 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2109 call cursor(1,1)
2110 0;/pattern/d
2111 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2112 q!
2113endfunc
2114
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002115func Test_read_shellcmd()
2116 CheckUnix
2117 if executable('ls')
2118 " There should be ls in the $PATH
2119 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2120 call assert_match('^"r! .*\<ls\>', @:)
2121 endif
2122
2123 if executable('rm')
2124 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2125 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2126 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002127
2128 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2129 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2130 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002131 endif
2132endfunc
2133
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002134" Test for going up and down the directory tree using 'wildmenu'
2135func Test_wildmenu_dirstack()
2136 CheckUnix
2137 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002138 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002139 call writefile([], 'Xwildmenu/file1_1.txt')
2140 call writefile([], 'Xwildmenu/file1_2.txt')
2141 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2142 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2143 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2144 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2145 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2146 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002147 set wildmenu
2148
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002149 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002150 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002151 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002152 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002153 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002154 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002155 call assert_equal('"e ../../dir3/', @:)
2156 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2157 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002158 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002159 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002160 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002161 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002162 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002163 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2164 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002165
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002166 set wildmenu&
2167endfunc
2168
obcat71c6f7a2021-05-13 20:23:10 +02002169" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002170" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2171" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002172func Test_recalling_cmdline()
2173 CheckFeature cmdline_hist
2174
2175 let g:cmdlines = []
2176 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2177
2178 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002179 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2180 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2181 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2182 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002183 "\ TODO: {'name': 'debug', ...}
2184 \]
2185 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002186 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2187 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2188 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2189 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2190 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002191 \]
2192 let prefix = 'vi'
2193 for h in histories
2194 call histadd(h.name, 'vim')
2195 call histadd(h.name, 'virtue')
2196 call histadd(h.name, 'Virgo')
2197 call histadd(h.name, 'vogue')
2198 call histadd(h.name, 'emacs')
2199 for k in keypairs
2200 let g:cmdlines = []
2201 let keyseqs = h.enter
2202 \ .. prefix
2203 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2204 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2205 \ .. h.exit
2206 call feedkeys(keyseqs, 'xt')
2207 call histdel(h.name, -1) " delete the history added by feedkeys above
2208 let expect = k.prefixmatch
2209 \ ? ['virtue', 'vim', 'virtue', prefix]
2210 \ : ['emacs', 'vogue', 'emacs', prefix]
2211 call assert_equal(expect, g:cmdlines)
2212 endfor
2213 endfor
2214
2215 unlet g:cmdlines
2216 cunmap <Plug>(save-cmdline)
2217endfunc
2218
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002219func Test_cmd_map_cmdlineChanged()
2220 let g:log = []
2221 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002222 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002223 autocmd!
2224 autocmd CmdlineChanged : let g:log += [getcmdline()]
2225 augroup END
2226
2227 call feedkeys(":\<F1>\<CR>", 'xt')
2228 call assert_equal(['l', 'ls'], g:log)
2229
Bram Moolenaar796139a2021-05-18 21:38:45 +02002230 let @b = 'b'
2231 cnoremap <F1> a<C-R>b
2232 let g:log = []
2233 call feedkeys(":\<F1>\<CR>", 'xt')
2234 call assert_equal(['a', 'ab'], g:log)
2235
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002236 unlet g:log
2237 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002238 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002239 autocmd!
2240 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002241 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002242endfunc
2243
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002244" Test for the 'suffixes' option
2245func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002246 call writefile([], 'Xsuffile', 'D')
2247 call writefile([], 'Xsuffile.c', 'D')
2248 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002249 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002250 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2251 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2252 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2253 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002254 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002255 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2256 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2257 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2258 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002259 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002260 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2261 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2262 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2263 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002264 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002265 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002266 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2267 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002268endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002269
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002270" Test for using a popup menu for the command line completion matches
2271" (wildoptions=pum)
2272func Test_wildmenu_pum()
2273 CheckRunVimInTerminal
2274
2275 let commands =<< trim [CODE]
2276 set wildmenu
2277 set wildoptions=pum
2278 set shm+=I
2279 set noruler
2280 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002281
2282 func CmdCompl(a, b, c)
2283 return repeat(['aaaa'], 120)
2284 endfunc
2285 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002286
2287 func MyStatusLine() abort
2288 return 'status'
2289 endfunc
2290 func SetupStatusline()
2291 set statusline=%!MyStatusLine()
2292 set laststatus=2
2293 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002294
2295 func MyTabLine()
2296 return 'my tab line'
2297 endfunc
2298 func SetupTabline()
2299 set statusline=
2300 set tabline=%!MyTabLine()
2301 set showtabline=2
2302 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002303
2304 func DoFeedKeys()
2305 let &wildcharm = char2nr("\t")
2306 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2307 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002308 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002309 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002310
2311 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2312
2313 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002314 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2315
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002316 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002317 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002318 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2319
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002320 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2323
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002324 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002325 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2327
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002328 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002329 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2331
2332 " pressing <C-E> should end completion and go back to the original match
2333 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2335
2336 " pressing <C-Y> should select the current match and end completion
2337 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2339
2340 " With 'wildmode' set to 'longest,full', completing a match should display
2341 " the longest match, the wildmenu should not be displayed.
2342 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2343 call TermWait(buf)
2344 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002345 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2346
2347 " pressing <Tab> should display the wildmenu
2348 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002349 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2350
2351 " pressing <Tab> second time should select the next entry in the menu
2352 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2354
2355 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002356 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002357 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002358 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2359
2360 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002361 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2362
2363 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002364 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2365
2366 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002367 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002368 call writefile([], 'Xnamedir/XfileA')
2369 call writefile([], 'Xnamedir/XdirA/XfileB')
2370 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002371
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002372 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002373 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2374
2375 " Pressing <Right> on a directory name should go into that directory
2376 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002377 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2378
2379 " Pressing <Left> on a directory name should go to the parent directory
2380 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002381 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2382
2383 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002384 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002385 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002386 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2387
2388 " Pressing <C-D> when the popup menu is displayed should remove the popup
2389 " menu
2390 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002391 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2392
2393 " Pressing <S-Tab> should open the popup menu with the last entry selected
2394 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002395 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2396
2397 " Pressing <Esc> should close the popup menu and cancel the cmd line
2398 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002399 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2400
2401 " Typing a character when the popup is open, should close the popup
2402 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002403 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2404
2405 " When the popup is open, entering the cmdline window should close the popup
2406 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002407 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2408 call term_sendkeys(buf, ":q\<CR>")
2409
2410 " After the last popup menu item, <C-N> should show the original string
2411 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002412 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2413
2414 " Use the popup menu for the command name
2415 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002416 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2417
2418 " Pressing the left arrow should remove the popup menu
2419 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002420 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2421
2422 " Pressing <BS> should remove the popup menu and erase the last character
2423 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002424 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2425
2426 " Pressing <C-W> should remove the popup menu and erase the previous word
2427 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002428 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2429
2430 " Pressing <C-U> should remove the popup menu and erase the entire line
2431 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002432 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2433
2434 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2435 " the cmdline from history
2436 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002437 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2438
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002439 " Check "list" still works
2440 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2441 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002442 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2443 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002444 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2445
rbtnn68cc2b82022-02-09 11:55:47 +00002446 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002447 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002448 call writefile([], 'Xnamedir/あいう/abc')
2449 call writefile([], 'Xnamedir/あいう/xyz')
2450 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002451
2452 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002453 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002454 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2455
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002456 " Pressing <C-A> when the popup menu is displayed should list all the
2457 " matches and pressing a key after that should remove the popup menu
2458 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2459 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2460 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2461
2462 " Pressing <C-A> when the popup menu is displayed should list all the
2463 " matches and pressing <Left> after that should move the cursor
2464 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2465 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2466 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2467
2468 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2469 " should be displayed correctly on the screen.
2470 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2471 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2472
2473 " After using <C-A> to expand all the filename matches, pressing <Up>
2474 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002475 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002476 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2477 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2478 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2479
2480 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2481 " crash Vim
2482 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2483 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2484
Bram Moolenaar414acd32022-02-10 21:09:45 +00002485 " After removing the pum the command line is redrawn
2486 call term_sendkeys(buf, ":edit foo\<CR>")
2487 call term_sendkeys(buf, ":edit bar\<CR>")
2488 call term_sendkeys(buf, ":ls\<CR>")
2489 call term_sendkeys(buf, ":com\<Tab> ")
2490 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002491 call term_sendkeys(buf, "\<C-U>\<CR>")
2492
2493 " Esc still works to abort the command when 'statusline' is set
2494 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2495 call term_sendkeys(buf, ":si\<Tab>")
2496 call term_sendkeys(buf, "\<Esc>")
2497 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002498
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002499 " Esc still works to abort the command when 'tabline' is set
2500 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2501 call term_sendkeys(buf, ":si\<Tab>")
2502 call term_sendkeys(buf, "\<Esc>")
2503 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2504
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002505 " popup is cleared also when 'lazyredraw' is set
2506 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2507 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2508 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2509 call term_sendkeys(buf, "\<Esc>")
2510
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002511 " Pressing <PageDown> should scroll the menu downward
2512 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2513 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2514 call term_sendkeys(buf, "\<PageDown>")
2515 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2516 call term_sendkeys(buf, "\<PageDown>")
2517 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2518 call term_sendkeys(buf, "\<PageDown>")
2519 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2520 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2521 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2522
2523 " Pressing <PageUp> should scroll the menu upward
2524 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2525 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2526 call term_sendkeys(buf, "\<PageUp>")
2527 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2528 call term_sendkeys(buf, "\<PageUp>")
2529 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2530 call term_sendkeys(buf, "\<PageUp>")
2531 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2532
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002533 call term_sendkeys(buf, "\<C-U>\<CR>")
2534 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002535endfunc
2536
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002537" Test for wildmenumode() with the cmdline popup menu
2538func Test_wildmenumode_with_pum()
2539 set wildmenu
2540 set wildoptions=pum
2541 cnoremap <expr> <F2> wildmenumode()
2542 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2543 call assert_equal('"sign define10', @:)
2544 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2545 call assert_equal('"sign define jump list place undefine unplace0', @:)
2546 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2547 call assert_equal('"sign 0', @:)
2548 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2549 call assert_equal('"sign define0', @:)
2550 set nowildmenu wildoptions&
2551 cunmap <F2>
2552endfunc
2553
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002554func Test_wildmenu_with_pum_foldexpr()
2555 CheckRunVimInTerminal
2556
2557 let lines =<< trim END
2558 call setline(1, ['folded one', 'folded two', 'some more text'])
2559 func MyFoldText()
2560 return 'foo'
2561 endfunc
2562 set foldtext=MyFoldText() wildoptions=pum
2563 normal ggzfj
2564 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002565 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002566 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2567 call term_sendkeys(buf, ":set\<Tab>")
2568 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2569
2570 call term_sendkeys(buf, "\<Esc>")
2571 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2572
2573 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002574endfunc
2575
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002576" Test for opening the cmdline completion popup menu from the terminal window.
2577" The popup menu should be positioned correctly over the status line of the
2578" bottom-most window.
2579func Test_wildmenu_pum_from_terminal()
2580 CheckRunVimInTerminal
2581 let python = PythonProg()
2582 call CheckPython(python)
2583
2584 %bw!
2585 let cmds = ['set wildmenu wildoptions=pum']
2586 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2587 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002588 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002589 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2590 call term_sendkeys(buf, "\r\r\r")
2591 call term_wait(buf)
2592 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2593 call term_wait(buf)
2594 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2595 call term_wait(buf)
2596 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002597endfunc
2598
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002599func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002600 CheckRunVimInTerminal
2601
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002602 " This was using freed memory. Run in a terminal to get the pum to update.
2603 let lines =<< trim END
2604 set wildoptions=pum
2605 set wildchar=<C-E>
2606 END
2607 call writefile(lines, 'XwildmenuTest', 'D')
2608 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2609
2610 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2611 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2612
2613 set wildoptions& wildchar&
2614endfunc
2615
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002616" Test for completion after a :substitute command followed by a pipe (|)
2617" character
2618func Test_cmdline_complete_substitute()
2619 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2620 call assert_equal("\"s | \t", @:)
2621 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2622 call assert_equal("\"s/ | \t", @:)
2623 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2624 call assert_equal("\"s/one | \t", @:)
2625 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2626 call assert_equal("\"s/one/ | \t", @:)
2627 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2628 call assert_equal("\"s/one/two | \t", @:)
2629 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2630 call assert_equal('"s/one/two/ | chistory', @:)
2631 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2632 call assert_equal("\"s/one/two/g \t", @:)
2633 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2634 call assert_equal("\"s/one/two/g | chistory", @:)
2635 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2636 call assert_equal("\"s/one/t\\/ | \t", @:)
2637 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2638 call assert_equal('"s/one/t"o/ | chistory', @:)
2639 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2640 call assert_equal('"s/one/t|o/ | chistory', @:)
2641 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2642 call assert_equal("\"&\t", @:)
2643endfunc
2644
2645" Test for the :dlist command completion
2646func Test_cmdline_complete_dlist()
2647 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2648 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2649 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2650 call assert_equal("\"dlist 10 /pat/ \t", @:)
2651 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2652 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2653 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2654 call assert_equal("\"dlist 10 /pat\\\t", @:)
2655 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2656 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2657endfunc
2658
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002659" argument list (only for :argdel) fuzzy completion
2660func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002661 argadd change.py count.py charge.py
2662 set wildoptions&
2663 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2664 call assert_equal('"argdel cge', @:)
2665 set wildoptions=fuzzy
2666 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2667 call assert_equal('"argdel change.py charge.py', @:)
2668 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002669 set wildoptions&
2670endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002671
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002672" autocmd group name fuzzy completion
2673func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002674 set wildoptions&
2675 augroup MyFuzzyGroup
2676 augroup END
2677 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2678 call assert_equal('"augroup mfg', @:)
2679 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2680 call assert_equal('"augroup MyFuzzyGroup', @:)
2681 set wildoptions=fuzzy
2682 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2683 call assert_equal('"augroup MyFuzzyGroup', @:)
2684 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2685 call assert_equal('"augroup My*p', @:)
2686 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002687 set wildoptions&
2688endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002689
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002690" buffer name fuzzy completion
2691func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002692 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002693 " Use a long name to reduce the risk of matching a random directory name
2694 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002695 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002696 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2697 call assert_equal('"b SRFWL', @:)
2698 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2699 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002700 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002701 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2702 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2703 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2704 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002705 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002706 set wildoptions&
2707endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002708
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002709" buffer name (full path) fuzzy completion
2710func Test_fuzzy_completion_bufname_fullpath()
2711 CheckUnix
2712 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002713 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002714 edit Xcmd/Xstate/Xfile.js
2715 cd Xcmd/Xstate
2716 enew
2717 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"b CmdStateFile', @:)
2719 set wildoptions=fuzzy
2720 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2721 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2722 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002723 set wildoptions&
2724endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002725
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002726" :behave suboptions fuzzy completion
2727func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728 set wildoptions&
2729 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2730 call assert_equal('"behave xm', @:)
2731 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2732 call assert_equal('"behave xterm', @:)
2733 set wildoptions=fuzzy
2734 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2735 call assert_equal('"behave xterm', @:)
2736 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2737 call assert_equal('"behave xt*m', @:)
2738 let g:Sline = ''
2739 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2740 call assert_equal('mswin', g:Sline)
2741 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002742 set wildoptions&
2743endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002744
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002745" " colorscheme name fuzzy completion - NOT supported
2746" func Test_fuzzy_completion_colorscheme()
2747" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002748
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002749" built-in command name fuzzy completion
2750func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002751 set wildoptions&
2752 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2753 call assert_equal('"sbwin', @:)
2754 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2755 call assert_equal('"sbrewind', @:)
2756 set wildoptions=fuzzy
2757 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2758 call assert_equal('"sbrewind', @:)
2759 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2760 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002761 set wildoptions&
2762endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002763
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002764" " compiler name fuzzy completion - NOT supported
2765" func Test_fuzzy_completion_compiler()
2766" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002767
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002768" :cscope suboptions fuzzy completion
2769func Test_fuzzy_completion_cscope()
2770 CheckFeature cscope
2771 set wildoptions&
2772 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2773 call assert_equal('"cscope ret', @:)
2774 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2775 call assert_equal('"cscope reset', @:)
2776 set wildoptions=fuzzy
2777 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2778 call assert_equal('"cscope reset', @:)
2779 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2780 call assert_equal('"cscope re*t', @:)
2781 set wildoptions&
2782endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002783
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002784" :diffget/:diffput buffer name fuzzy completion
2785func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002786 new SomeBuffer
2787 diffthis
2788 new OtherBuffer
2789 diffthis
2790 set wildoptions&
2791 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2792 call assert_equal('"diffget sbuf', @:)
2793 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2794 call assert_equal('"diffput sbuf', @:)
2795 set wildoptions=fuzzy
2796 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2797 call assert_equal('"diffget SomeBuffer', @:)
2798 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2799 call assert_equal('"diffput SomeBuffer', @:)
2800 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002801 set wildoptions&
2802endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002803
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002804" " directory name fuzzy completion - NOT supported
2805" func Test_fuzzy_completion_dirname()
2806" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002807
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002808" environment variable name fuzzy completion
2809func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002810 set wildoptions&
2811 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2812 call assert_equal('"echo $VUT', @:)
2813 set wildoptions=fuzzy
2814 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2815 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002816 set wildoptions&
2817endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002818
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002819" autocmd event fuzzy completion
2820func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002821 set wildoptions&
2822 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2823 call assert_equal('"autocmd BWout', @:)
2824 set wildoptions=fuzzy
2825 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"autocmd BufWipeout', @:)
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" vim expression fuzzy completion
2831func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832 let g:PerPlaceCount = 10
2833 set wildoptions&
2834 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2835 call assert_equal('"let c = ppc', @:)
2836 set wildoptions=fuzzy
2837 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2838 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002839 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002840endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002841
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002842" " file name fuzzy completion - NOT supported
2843" func Test_fuzzy_completion_filename()
2844" endfunc
2845
2846" " files in path fuzzy completion - NOT supported
2847" func Test_fuzzy_completion_filesinpath()
2848" endfunc
2849
2850" " filetype name fuzzy completion - NOT supported
2851" func Test_fuzzy_completion_filetype()
2852" endfunc
2853
2854" user defined function name completion
2855func Test_fuzzy_completion_userdefined_func()
2856 set wildoptions&
2857 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2858 call assert_equal('"call Test_f_u_f', @:)
2859 set wildoptions=fuzzy
2860 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2861 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2862 set wildoptions&
2863endfunc
2864
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002865" <SNR> functions should be sorted to the end
2866func Test_fuzzy_completion_userdefined_snr_func()
2867 func s:Sendmail()
2868 endfunc
2869 func SendSomemail()
2870 endfunc
2871 func S1e2n3dmail()
2872 endfunc
2873 set wildoptions=fuzzy
2874 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002875 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002876 set wildoptions&
2877 delfunc s:Sendmail
2878 delfunc SendSomemail
2879 delfunc S1e2n3dmail
2880endfunc
2881
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002882" user defined command name completion
2883func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002884 set wildoptions&
2885 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2886 call assert_equal('"MsFeat', @:)
2887 set wildoptions=fuzzy
2888 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2889 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890 set wildoptions&
2891endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002892
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002893" " :help tag fuzzy completion - NOT supported
2894" func Test_fuzzy_completion_helptag()
2895" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002896
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002897" highlight group name fuzzy completion
2898func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002899 set wildoptions&
2900 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2901 call assert_equal('"highlight SKey', @:)
2902 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2903 call assert_equal('"highlight SpecialKey', @:)
2904 set wildoptions=fuzzy
2905 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal('"highlight SpecialKey', @:)
2907 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2908 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002909 set wildoptions&
2910endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002911
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002912" :history suboptions fuzzy completion
2913func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002914 set wildoptions&
2915 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2916 call assert_equal('"history dg', @:)
2917 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2918 call assert_equal('"history search', @:)
2919 set wildoptions=fuzzy
2920 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2921 call assert_equal('"history debug', @:)
2922 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2923 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002924 set wildoptions&
2925endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002927" :language locale name fuzzy completion
2928func Test_fuzzy_completion_lang()
2929 CheckUnix
2930 set wildoptions&
2931 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2932 call assert_equal('"lang psx', @:)
2933 set wildoptions=fuzzy
2934 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2935 call assert_equal('"lang POSIX', @:)
2936 set wildoptions&
2937endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002938
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002939" :mapclear buffer argument fuzzy completion
2940func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002941 set wildoptions&
2942 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2943 call assert_equal('"mapclear buf', @:)
2944 set wildoptions=fuzzy
2945 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2946 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002947 set wildoptions&
2948endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002949
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002950" map name fuzzy completion
2951func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002952 " test regex completion works
2953 set wildoptions=fuzzy
2954 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2955 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002956 nmap <plug>MyLongMap :p<CR>
2957 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2958 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2959 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2960 call assert_equal("\"nmap MLM \t", @:)
2961 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2962 call assert_equal("\"nmap <F2> one two \t", @:)
2963 " duplicate entries should be removed
2964 vmap <plug>MyLongMap :<C-U>#<CR>
2965 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2966 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2967 nunmap <plug>MyLongMap
2968 vunmap <plug>MyLongMap
2969 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal("\"nmap ABC\t", @:)
2971 " results should be sorted by best match
2972 nmap <Plug>format :
2973 nmap <Plug>goformat :
2974 nmap <Plug>TestFOrmat :
2975 nmap <Plug>fendoff :
2976 nmap <Plug>state :
2977 nmap <Plug>FendingOff :
2978 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2979 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2980 nunmap <Plug>format
2981 nunmap <Plug>goformat
2982 nunmap <Plug>TestFOrmat
2983 nunmap <Plug>fendoff
2984 nunmap <Plug>state
2985 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002986 set wildoptions&
2987endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002988
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002989" abbreviation fuzzy completion
2990func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002991 set wildoptions=fuzzy
2992 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2993 call assert_equal("\"iabbr <nowait>", @:)
2994 iabbr WaitForCompletion WFC
2995 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal("\"iabbr WaitForCompletion", @:)
2997 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00002999
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003000 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003001 set wildoptions&
3002endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003003
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003004" menu name fuzzy completion
3005func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003006 CheckFeature menu
3007
3008 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003009 set wildoptions&
3010 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3011 call assert_equal('"menu pup', @:)
3012 set wildoptions=fuzzy
3013 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3014 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003015
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003016 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003017 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003018endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003019
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003020" :messages suboptions fuzzy completion
3021func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003022 set wildoptions&
3023 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3024 call assert_equal('"messages clr', @:)
3025 set wildoptions=fuzzy
3026 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3027 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003028 set wildoptions&
3029endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003030
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003031" :set option name fuzzy completion
3032func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003033 set wildoptions&
3034 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3035 call assert_equal('"set brkopt', @:)
3036 set wildoptions=fuzzy
3037 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal('"set breakindentopt', @:)
3039 set wildoptions&
3040 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3041 call assert_equal('"set fixendofline', @:)
3042 set wildoptions=fuzzy
3043 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3044 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003045 set wildoptions&
3046endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003047
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003048" :set <term_option>
3049func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003050 set wildoptions&
3051 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal('"set t_EC', @:)
3053 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal('"set <t_EC>', @:)
3055 set wildoptions=fuzzy
3056 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal('"set t_EC', @:)
3058 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3059 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003060 set wildoptions&
3061endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003062
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003063" " :packadd directory name fuzzy completion - NOT supported
3064" func Test_fuzzy_completion_packadd()
3065" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003066
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003067" " shell command name fuzzy completion - NOT supported
3068" func Test_fuzzy_completion_shellcmd()
3069" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003070
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003071" :sign suboptions fuzzy completion
3072func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003073 set wildoptions&
3074 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal('"sign ufe', @:)
3076 set wildoptions=fuzzy
3077 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3078 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003079 set wildoptions&
3080endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003081
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003082" :syntax suboptions fuzzy completion
3083func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003084 set wildoptions&
3085 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal('"syntax kwd', @:)
3087 set wildoptions=fuzzy
3088 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3089 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003090 set wildoptions&
3091endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003092
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003093" syntax group name fuzzy completion
3094func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003095 set wildoptions&
3096 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal('"syntax list mpar', @:)
3098 set wildoptions=fuzzy
3099 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3100 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003101 set wildoptions&
3102endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003103
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003104" :syntime suboptions fuzzy completion
3105func Test_fuzzy_completion_syntime()
3106 CheckFeature profile
3107 set wildoptions&
3108 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3109 call assert_equal('"syntime clr', @:)
3110 set wildoptions=fuzzy
3111 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal('"syntime clear', @:)
3113 set wildoptions&
3114endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003115
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003116" " tag name fuzzy completion - NOT supported
3117" func Test_fuzzy_completion_tagname()
3118" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003119
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003120" " tag name and file fuzzy completion - NOT supported
3121" func Test_fuzzy_completion_tagfile()
3122" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003123
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003124" " user names fuzzy completion - how to test this functionality?
3125" func Test_fuzzy_completion_username()
3126" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003127
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003128" user defined variable name fuzzy completion
3129func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003130 let g:SomeVariable=10
3131 set wildoptions&
3132 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3133 call assert_equal('"let SVar', @:)
3134 set wildoptions=fuzzy
3135 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003137 set wildoptions&
3138endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003139
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003140" Test for sorting the results by the best match
3141func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003142 %bw!
3143 command T123format :
3144 command T123goformat :
3145 command T123TestFOrmat :
3146 command T123fendoff :
3147 command T123state :
3148 command T123FendingOff :
3149 set wildoptions=fuzzy
3150 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3151 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3152 delcommand T123format
3153 delcommand T123goformat
3154 delcommand T123TestFOrmat
3155 delcommand T123fendoff
3156 delcommand T123state
3157 delcommand T123FendingOff
3158 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003159 set wildoptions&
3160endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003161
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003162" Test for fuzzy completion of a command with lower case letters and a number
3163func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003164 command Foo2Bar :
3165 set wildoptions=fuzzy
3166 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3167 call assert_equal('"Foo2Bar', @:)
3168 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3169 call assert_equal('"Foo2Bar', @:)
3170 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3171 call assert_equal('"Foo2Bar', @:)
3172 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003173 set wildoptions&
3174endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003175
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003176" Test for command completion for a command starting with 'k'
3177func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003178 command KillKillKill :
3179 set wildoptions&
3180 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3181 call assert_equal("\"killkill\<Tab>", @:)
3182 set wildoptions=fuzzy
3183 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal('"KillKillKill', @:)
3185 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003186 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003187endfunc
3188
3189" Test for fuzzy completion for user defined custom completion function
3190func Test_fuzzy_completion_custom_func()
3191 func Tcompl(a, c, p)
3192 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3193 endfunc
3194 command -nargs=* -complete=custom,Tcompl Fuzzy :
3195 set wildoptions&
3196 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"Fuzzy format", @:)
3198 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"Fuzzy xy", @:)
3200 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"Fuzzy ttt", @:)
3202 set wildoptions=fuzzy
3203 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3204 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3205 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3206 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3207 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3208 call assert_equal("\"Fuzzy xy", @:)
3209 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3210 call assert_equal("\"Fuzzy TestFOrmat", @:)
3211 delcom Fuzzy
3212 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003213endfunc
3214
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003215" Test for :breakadd argument completion
3216func Test_cmdline_complete_breakadd()
3217 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3218 call assert_equal("\"breakadd expr file func here", @:)
3219 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakadd expr", @:)
3221 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakadd expr", @:)
3223 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakadd here", @:)
3225 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakadd here", @:)
3227 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakadd abc", @:)
3229 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3230 let l = getcompletion('not', 'breakpoint')
3231 call assert_equal([], l)
3232
3233 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003234 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003235 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakadd file Xscript", @:)
3237 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3238 call assert_equal("\"breakadd file Xscript", @:)
3239 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal("\"breakadd file 20 Xscript", @:)
3241 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal("\"breakadd file 20 Xscript", @:)
3243 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3245 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal("\"breakadd file 20\t", @:)
3247 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal("\"breakadd file 20x\t", @:)
3249 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal("\"breakadd file Xscript ", @:)
3251 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003253
3254 " Test for :breakadd func [lnum] <function>
3255 func Xbreak_func()
3256 endfunc
3257 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakadd func Xbreak_func", @:)
3259 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_equal("\"breakadd func Xbreak_func", @:)
3261 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3263 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3265 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3267 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3268 call assert_equal("\"breakadd func 20\t", @:)
3269 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3270 call assert_equal("\"breakadd func 20x\t", @:)
3271 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3272 call assert_equal("\"breakadd func Xbreak_func ", @:)
3273 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3274 call assert_equal("\"breakadd func X1B2C3", @:)
3275 delfunc Xbreak_func
3276
3277 " Test for :breakadd expr <expression>
3278 let g:Xtest_var = 10
3279 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"breakadd expr Xtest_var", @:)
3281 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_equal("\"breakadd expr Xtest_var", @:)
3283 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal("\"breakadd expr Xtest_var ", @:)
3285 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal("\"breakadd expr X1B2C3", @:)
3287 unlet g:Xtest_var
3288
3289 " Test for :breakadd here
3290 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3291 call assert_equal("\"breakadd here Xtest", @:)
3292 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3293 call assert_equal("\"breakadd here Xtest", @:)
3294 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3295 call assert_equal("\"breakadd here ", @:)
3296endfunc
3297
3298" Test for :breakdel argument completion
3299func Test_cmdline_complete_breakdel()
3300 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3301 call assert_equal("\"breakdel file func here", @:)
3302 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3303 call assert_equal("\"breakdel file", @:)
3304 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3305 call assert_equal("\"breakdel file", @:)
3306 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3307 call assert_equal("\"breakdel here", @:)
3308 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3309 call assert_equal("\"breakdel here", @:)
3310 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3311 call assert_equal("\"breakdel abc", @:)
3312
3313 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003314 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003315 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3316 call assert_equal("\"breakdel file Xscript", @:)
3317 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3318 call assert_equal("\"breakdel file Xscript", @:)
3319 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_equal("\"breakdel file 20 Xscript", @:)
3321 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3322 call assert_equal("\"breakdel file 20 Xscript", @:)
3323 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3324 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3325 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3326 call assert_equal("\"breakdel file 20\t", @:)
3327 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3328 call assert_equal("\"breakdel file 20x\t", @:)
3329 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3330 call assert_equal("\"breakdel file Xscript ", @:)
3331 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3332 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003333
3334 " Test for :breakdel func [lnum] <function>
3335 func Xbreak_func()
3336 endfunc
3337 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3338 call assert_equal("\"breakdel func Xbreak_func", @:)
3339 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3340 call assert_equal("\"breakdel func Xbreak_func", @:)
3341 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3342 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3343 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3344 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3345 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3346 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3347 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3348 call assert_equal("\"breakdel func 20\t", @:)
3349 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3350 call assert_equal("\"breakdel func 20x\t", @:)
3351 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3352 call assert_equal("\"breakdel func Xbreak_func ", @:)
3353 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3354 call assert_equal("\"breakdel func X1B2C3", @:)
3355 delfunc Xbreak_func
3356
3357 " Test for :breakdel here
3358 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3359 call assert_equal("\"breakdel here Xtest", @:)
3360 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3361 call assert_equal("\"breakdel here Xtest", @:)
3362 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3363 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003364endfunc
3365
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003366" Test for :scriptnames argument completion
3367func Test_cmdline_complete_scriptnames()
3368 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003369 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003370 source Xa1b2c3.vim
3371 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3372 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3373 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3374 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3375 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3376 call assert_equal("\"script b2c3", @:)
3377 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3378 call assert_match("\"script 2\<Tab>$", @:)
3379 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3380 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3381 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3382 call assert_equal("\"script ", @:)
3383 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3384 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3385 new
3386 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3387 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3388 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003389 set wildmenu&
3390endfunc
3391
Bram Moolenaard8893442022-05-06 20:38:47 +01003392" this was going over the end of IObuff
3393func Test_report_error_with_composing()
3394 let caught = 'no'
3395 try
3396 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3397 catch /E492:/
3398 let caught = 'yes'
3399 endtry
3400 call assert_equal('yes', caught)
3401endfunc
3402
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003403" Test for expanding 2-letter and 3-letter :substitute command arguments.
3404" These commands don't accept an argument.
3405func Test_cmdline_complete_substitute_short()
3406 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3407 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3408 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3409 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3410 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3411 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3412 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3413 endfor
3414endfunc
3415
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003416" Test for :! shell command argument completion
3417func Test_cmdline_complete_bang_cmd_argument()
3418 set wildoptions=fuzzy
3419 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3420 call assert_equal('"!vim test_cmdline.vim', @:)
3421 set wildoptions&
3422 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3423 call assert_equal('"!vim test_cmdline.vim', @:)
3424endfunc
3425
zeertzjq961b2e52023-04-17 15:53:24 +01003426func Call_cmd_funcs()
3427 return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003428endfunc
3429
3430func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003431 call assert_equal(0, getcmdpos())
3432 call assert_equal(0, getcmdscreenpos())
3433 call assert_equal('', getcmdcompltype())
3434
3435 cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
3436 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
3437 call assert_equal("\"let a[6, 7, 'var']", @:)
3438 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
3439 call assert_equal("\"quit [6, 7, '']", @:)
3440 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
3441 call assert_equal("\"nosuchcommand [15, 16, '']", @:)
3442 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003443endfunc
3444
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003445func Test_recursive_register()
3446 let @= = ''
3447 silent! ?e/
3448 let caught = 'no'
3449 try
3450 normal //
3451 catch /E169:/
3452 let caught = 'yes'
3453 endtry
3454 call assert_equal('yes', caught)
3455endfunc
3456
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003457func Test_long_error_message()
3458 " the error should be truncated, not overrun IObuff
3459 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3460endfunc
3461
zeertzjq6791adc2022-07-26 20:42:25 +01003462func Test_cmdline_redraw_tabline()
3463 CheckRunVimInTerminal
3464
3465 let lines =<< trim END
3466 set showtabline=2
3467 autocmd CmdlineEnter * set tabline=foo
3468 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003469 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003470 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3471 call term_sendkeys(buf, ':')
3472 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3473
3474 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003475endfunc
3476
zeertzjqb82a2ab2022-08-21 14:33:57 +01003477func Test_wildmenu_pum_disable_while_shown()
3478 set wildoptions=pum
3479 set wildmenu
3480 cnoremap <F2> <Cmd>set nowildmenu<CR>
3481 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3482 call assert_equal(0, pumvisible())
3483 cunmap <F2>
3484 set wildoptions& wildmenu&
3485endfunc
3486
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003487func Test_setcmdline()
3488 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003489 call assert_equal(0, setcmdline(test_null_string()))
3490 call assert_equal('', getcmdline())
3491 call assert_equal(1, getcmdpos())
3492
3493 call assert_equal(0, setcmdline(''[: -1]))
3494 call assert_equal('', getcmdline())
3495 call assert_equal(1, getcmdpos())
3496
zeertzjq54acb902022-08-29 16:21:25 +01003497 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003498 call assert_equal(0, setcmdline(a:text))
3499 call assert_equal(a:text, getcmdline())
3500 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003501 call assert_equal(getcmdtype(), g:cmdtype)
3502 unlet g:cmdtype
3503 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003504
3505 call assert_equal(0, setcmdline(a:text, a:pos))
3506 call assert_equal(a:text, getcmdline())
3507 call assert_equal(a:pos, getcmdpos())
3508
3509 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003510 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3511 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003512
3513 return ''
3514 endfunc
3515
3516 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3517 call assert_equal('set rtp?', @:)
3518
zeertzjq54acb902022-08-29 16:21:25 +01003519 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3520 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3521 call assert_equal('foo', g:str)
3522 unlet g:str
3523
3524 delfunc SetText
3525
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003526 " setcmdline() returns 1 when not editing the command line.
3527 call assert_equal(1, 'foo'->setcmdline())
3528
3529 " Called in custom function
3530 func CustomComplete(A, L, P)
3531 call assert_equal(0, setcmdline("DoCmd "))
3532 return "January\nFebruary\nMars\n"
3533 endfunc
3534
3535 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3536 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3537 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003538 delcom DoCmd
3539 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003540
3541 " Called in <expr>
3542 cnoremap <expr>a setcmdline('let foo=')
3543 call feedkeys(":a\<CR>", 'tx')
3544 call assert_equal('let foo=0', @:)
3545 cunmap a
3546endfunc
3547
Sean Dewarfc8a6012023-04-17 16:41:20 +01003548func Test_rulerformat_position()
3549 CheckScreendump
3550
3551 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3552 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3553 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3554 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3555 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3556
3557 " clean up
3558 call StopVimInTerminal(buf)
3559endfunc
3560
zeertzjqe4c79d32023-08-15 22:41:53 +02003561func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003562 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003563
zeertzjqe4c79d32023-08-15 22:41:53 +02003564 call assert_equal(getcompletion('', 'cmdline'),
3565 \ getcompletion('TestCompletion ', 'cmdline'))
3566 call assert_equal(['<buffer>'],
3567 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3568
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003569 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003570endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003571
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003572func Test_custom_completion()
3573 func CustomComplete1(lead, line, pos)
3574 return "a\nb\nc"
3575 endfunc
3576 func CustomComplete2(lead, line, pos)
3577 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3578 endfunc
3579 func Check_custom_completion()
3580 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3581 return ''
3582 endfunc
3583 func Check_customlist_completion()
3584 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3585 return ''
3586 endfunc
3587
3588 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3589 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3590
3591 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3592 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3593
3594 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3595 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3596
3597 call assert_equal(getcompletion('', 'custom,CustomComplete1'), ['a', 'b', 'c'])
3598 call assert_equal(getcompletion('', 'customlist,CustomComplete2'), ['a', 'b'])
3599 call assert_equal(getcompletion('b', 'customlist,CustomComplete2'), ['b'])
3600
3601 delcom Test1
3602 delcom Test2
3603
3604 delfunc CustomComplete1
3605 delfunc CustomComplete2
3606 delfunc Check_custom_completion
3607 delfunc Check_customlist_completion
3608endfunc
3609
zeertzjq28a23602023-09-29 19:58:35 +02003610func Test_custom_completion_with_glob()
3611 func TestGlobComplete(A, L, P)
3612 return split(glob('Xglob*'), "\n")
3613 endfunc
3614
3615 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3616 call writefile([], 'Xglob1', 'D')
3617 call writefile([], 'Xglob2', 'D')
3618
3619 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3620 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3621
3622 delcommand TestGlobComplete
3623 delfunc TestGlobComplete
3624endfunc
3625
Bram Moolenaar309976e2019-12-05 18:16:33 +01003626" vim: shiftwidth=2 sts=2 expandtab