blob: ddfeba28ff878bae3c34a6ed9c972174ff2aeda6 [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
Yee Cheng Chin989426b2023-10-14 11:46:51 +02001086func Test_cmdline_complete_argopt()
1087 " completion for ++opt=arg for file commands
1088 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
1089 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
1090 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
1091
1092 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
1093
1094 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
1095 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
1096 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
1097 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
1098 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
1099
1100 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
1101
1102 " completion should skip the ++opt and continue
1103 call writefile([], 'Xaaaaa.txt', 'D')
1104 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
1105 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
1106
1107 if has('terminal')
1108 " completion for terminal's [options]
1109 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
1110 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
1111 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
1112
1113 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
1114
1115 " :terminal completion should skip the ++opt when considering what is the
1116 " first option, which is a list of shell commands, unlike second option
1117 " onwards.
1118 let first_param = getcompletion('terminal ', 'cmdline')
1119 let second_param = getcompletion('terminal foo ', 'cmdline')
1120 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
1121 call assert_equal(first_param, skipped_opt_param)
1122 call assert_notequal(first_param, second_param)
1123 endif
1124endfunc
1125
Bram Moolenaar47016f52021-08-26 16:39:58 +02001126" Unique function name for completion below
1127func s:WeirdFunc()
1128 echo 'weird'
1129endfunc
1130
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001131" Test for various command-line completion
1132func Test_cmdline_complete_various()
1133 " completion for a command starting with a comment
1134 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\" :|\"\<C-A>", @:)
1136
1137 " completion for a range followed by a comment
1138 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal("\"1,2\"\<C-A>", @:)
1140
1141 " completion for :k command
1142 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1143 call assert_equal("\"ka\<C-A>", @:)
1144
1145 " completion for short version of the :s command
1146 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1147 call assert_equal("\"sI \<C-A>", @:)
1148
1149 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001150 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001151 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001152 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001153 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001154 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"w >> Xfile1", @:)
1156 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001157
1158 " completion for :w ! and :r ! commands
1159 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1160 call assert_equal("\"w !invalid_xyz_cmd", @:)
1161 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1162 call assert_equal("\"r !invalid_xyz_cmd", @:)
1163
1164 " completion for :>> and :<< commands
1165 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal("\">>>\<C-A>", @:)
1167 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"<<<\<C-A>", @:)
1169
1170 " completion for command with +cmd argument
1171 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1172 call assert_equal("\"buffer +/pat Xabc", @:)
1173 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1174 call assert_equal("\"buffer +/pat\<C-A>", @:)
1175
1176 " completion for a command with a trailing comment
1177 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1178 call assert_equal("\"ls \" comment\<C-A>", @:)
1179
1180 " completion for a command with a trailing command
1181 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1182 call assert_equal("\"ls | ls", @:)
1183
1184 " completion for a command with an CTRL-V escaped argument
1185 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1186 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1187
1188 " completion for a command that doesn't take additional arguments
1189 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1190 call assert_equal("\"all abc\<C-A>", @:)
1191
zeertzjqd3de1782022-09-01 12:58:52 +01001192 " completion for :wincmd with :horizontal modifier
1193 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1194 call assert_equal("\"horizontal wincmd", @:)
1195
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001196 " completion for a command with a command modifier
1197 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1198 call assert_equal("\"topleft new", @:)
1199
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001200 " completion for vim9 and legacy commands
1201 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1202 call assert_equal("\"vim9 call strlen(", @:)
1203 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1204 call assert_equal("\"legac call strlen(", @:)
1205
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001206 " completion for the :disassemble command
1207 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1208 call assert_equal("\"disas debug", @:)
1209 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1210 call assert_equal("\"disas profile", @:)
1211 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1212 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1213 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001215 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1216 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001217
Bram Moolenaar47016f52021-08-26 16:39:58 +02001218 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001219 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001220
naohiro onodfe04db2021-09-12 15:45:10 +02001221 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1222 call assert_match('"disas <SNR>\d\+_', @:)
1223 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1224 call assert_match('"disas debug <SNR>\d\+_', @:)
1225
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001226 " completion for the :match command
1227 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1228 call assert_equal("\"match Search /pat/\<C-A>", @:)
1229
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001230 " completion for the :doautocmd command
1231 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1232 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1233
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001234 " completion of autocmd group after comma
1235 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1236 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1237
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001238 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001239 call writefile([], 'Xvarfile1', 'D')
1240 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001241 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1242 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001243
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001244 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001245 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001246 augroup END
1247 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001248 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001249
1250 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001251 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1252 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001253 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1254 call assert_equal("\"au XTest.test", @:)
1255
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001256 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001257
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001258 " autocmd pattern completion
1259 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1260 call assert_equal("\"au BufEnter *.py\t", @:)
1261
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001262 " completion for the :unlet command
1263 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1264 call assert_equal("\"unlet one two", @:)
1265
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001266 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001267 " FIXME: what should happen on MS-Windows?
1268 if !has('win32')
1269 edit \{someFile}
1270 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1271 call assert_equal("\"buf {someFile}", @:)
1272 bwipe {someFile}
1273 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001274
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001275 " completion for the :bdelete command
1276 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1277 call assert_equal("\"bdel a b c", @:)
1278
1279 " completion for the :mapclear command
1280 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1281 call assert_equal("\"mapclear <buffer>", @:)
1282
1283 " completion for user defined commands with menu names
1284 menu Test.foo :ls<CR>
1285 com -nargs=* -complete=menu MyCmd
1286 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1287 call assert_equal('"MyCmd Test.', @:)
1288 delcom MyCmd
1289 unmenu Test
1290
1291 " completion for user defined commands with mappings
1292 mapclear
1293 map <F3> :ls<CR>
1294 com -nargs=* -complete=mapping MyCmd
1295 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001296 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001297 mapclear
1298 delcom MyCmd
1299
Yee Cheng Chin54844852023-10-09 18:12:31 +02001300 " Prepare for path completion
1301 call mkdir('Xa b c', 'D')
1302 defer delete('Xcomma,foobar.txt')
1303 call writefile([], 'Xcomma,foobar.txt')
1304
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001305 " completion for :set path= with multiple backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +02001306 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1307 call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
1308 set path&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001309
1310 " completion for :set dir= with a backslash
Yee Cheng Chin54844852023-10-09 18:12:31 +02001311 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1312 call assert_equal('"set dir=Xa\ b\ c/', @:)
1313 set dir&
1314
1315 " completion for :set tags= / set dictionary= with escaped commas
1316 if has('win32')
1317 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
1318 " '\,'
1319 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1320 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
1321
1322 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1323 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1324
1325 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1326 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
1327
1328 " completion for :set dictionary= with escaped commas (same behavior, but
1329 " different internal code path from 'set tags=' for escaping the output)
1330 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1331 call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
1332 else
1333 " In other platforms, backslashes are rounded down (since '\,' itself will
1334 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
1335 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1336 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
1337
1338 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1339 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
1340
1341 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1342 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1343
1344 " completion for :set dictionary= with escaped commas (same behavior, but
1345 " different internal code path from 'set tags=' for escaping the output)
1346 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1347 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
1348 endif
1349 set tags&
1350 set dictionary&
1351
1352 " completion for :set makeprg= with no escaped commas
1353 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1354 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
1355
1356 if !has('win32')
1357 " Cannot create file with backslash in file name in Windows, so only test
1358 " this elsewhere.
1359 defer delete('Xcomma\,fooslash.txt')
1360 call writefile([], 'Xcomma\,fooslash.txt')
1361 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
1362 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
1363 endif
1364 set makeprg&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001365
1366 " completion for the :py3 commands
1367 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1368 call assert_equal('"py3 py3do py3file', @:)
1369
Bram Moolenaardf749a22021-03-28 15:29:43 +02001370 " completion for the :vim9 commands
1371 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1372 call assert_equal('"vim9cmd vim9script', @:)
1373
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001374 " redir @" is not the start of a comment. So complete after that
1375 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1376 call assert_equal('"redir @" | cwindow', @:)
1377
1378 " completion after a backtick
1379 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1380 call assert_equal('"e `a1b2c', @:)
1381
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001382 " completion for :language command with an invalid argument
1383 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1384 call assert_equal("\"language dummy \t", @:)
1385
1386 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001387 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1388 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001389
1390 " completion with ambiguous user defined commands
1391 com TCmd1 echo 'TCmd1'
1392 com TCmd2 echo 'TCmd2'
1393 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1394 call assert_equal('"TCmd ', @:)
1395 delcom TCmd1
1396 delcom TCmd2
1397
1398 " completion after a range followed by a pipe (|) character
1399 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1400 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001401
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001402 " completion after a :global command
1403 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1404 call assert_equal('"g/a/chistory', @:)
1405 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1406 call assert_equal("\"g/a\\/chist\t", @:)
1407
Bram Moolenaar9c929712020-09-07 22:05:28 +02001408 " use <Esc> as the 'wildchar' for completion
1409 set wildchar=<Esc>
1410 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1411 call assert_equal('"g/a\xb/clearjumps', @:)
1412 " pressing <esc> twice should cancel the command
1413 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1414 call assert_equal('"g/a\xb/clearjumps', @:)
1415 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001416
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001417 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001418 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001419 call writefile([], '~Xtest')
1420 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1421 call assert_equal('"e \~Xtest', @:)
1422 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001423
1424 " should be able to complete a file name that has a '*'
1425 call writefile([], 'Xx*Yy')
1426 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1427 call assert_equal('"e Xx\*Yy', @:)
1428 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001429
1430 " use a literal star
1431 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1432 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001433 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001434
1435 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1436 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001437endfunc
1438
zeertzjq094dd152023-06-15 22:51:57 +01001439" Test that expanding a pattern doesn't interfere with cmdline completion.
1440func Test_expand_during_cmdline_completion()
1441 func ExpandStuff()
1442 badd <script>:p:h/README.*
1443 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
1444 $bwipe
1445 call assert_equal('README.txt', expand('README.*'))
1446 call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
1447 endfunc
1448 augroup test_CmdlineChanged
1449 autocmd!
1450 autocmd CmdlineChanged * call ExpandStuff()
1451 augroup END
1452
1453 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
1454 call assert_equal('"sign place', @:)
1455
1456 augroup test_CmdlineChanged
1457 au!
1458 augroup END
1459 augroup! test_CmdlineChanged
1460 delfunc ExpandStuff
1461endfunc
1462
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001463" Test for 'wildignorecase'
1464func Test_cmdline_wildignorecase()
1465 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001466 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001467 set wildignorecase
1468 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1469 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001470 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001471 let g:Sline = ''
1472 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1473 call assert_equal('"e xt', @:)
1474 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001475 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001476endfunc
1477
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001478func Test_cmdline_write_alternatefile()
1479 new
1480 call setline('.', ['one', 'two'])
1481 f foo.txt
1482 new
1483 f #-A
1484 call assert_equal('foo.txt-A', expand('%'))
1485 f #<-B.txt
1486 call assert_equal('foo-B.txt', expand('%'))
1487 f %<
1488 call assert_equal('foo-B', expand('%'))
1489 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001490 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001491 bw!
1492 f foo-B.txt
1493 f %<-A
1494 call assert_equal('foo-B-A', expand('%'))
1495 bw!
1496 bw!
1497endfunc
1498
Bram Moolenaarf5724372022-09-02 19:45:15 +01001499func Test_cmdline_expand_cur_alt_file()
1500 enew
1501 file http://some.com/file.txt
1502 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1503 call assert_equal('"e http://some.com/file.txt', @:)
1504 edit another
1505 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1506 call assert_equal('"e http://some.com/file.txt', @:)
1507 bwipe
1508 bwipe http://some.com/file.txt
1509endfunc
1510
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001511" using a leading backslash here
1512set cpo+=C
1513
1514func Test_cmdline_search_range()
1515 new
1516 call setline(1, ['a', 'b', 'c', 'd'])
1517 /d
1518 1,\/s/b/B/
1519 call assert_equal('B', getline(2))
1520
1521 /a
1522 $
1523 \?,4s/c/C/
1524 call assert_equal('C', getline(3))
1525
1526 call setline(1, ['a', 'b', 'c', 'd'])
1527 %s/c/c/
1528 1,\&s/b/B/
1529 call assert_equal('B', getline(2))
1530
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001531 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001532 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001533
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001534 bwipe!
1535endfunc
1536
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001537" Test for the tick mark (') in an excmd range
1538func Test_tick_mark_in_range()
1539 " If only the tick is passed as a range and no command is specified, there
1540 " should not be an error
1541 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001542 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001543 call assert_fails("',print", 'E78:')
1544endfunc
1545
1546" Test for using a line number followed by a search pattern as range
1547func Test_lnum_and_pattern_as_range()
1548 new
1549 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1550 let @" = ''
1551 2/foo/yank
1552 call assert_equal("foo 3\n", @")
1553 call assert_equal(1, line('.'))
1554 close!
1555endfunc
1556
Bram Moolenaar65189a12017-02-06 22:22:17 +01001557" Tests for getcmdline(), getcmdpos() and getcmdtype()
1558func Check_cmdline(cmdtype)
1559 call assert_equal('MyCmd a', getcmdline())
1560 call assert_equal(8, getcmdpos())
1561 call assert_equal(a:cmdtype, getcmdtype())
1562 return ''
1563endfunc
1564
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001565set cpo&
1566
Bram Moolenaar65189a12017-02-06 22:22:17 +01001567func Test_getcmdtype()
1568 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1569
1570 let cmdtype = ''
1571 debuggreedy
1572 call feedkeys(":debug echo 'test'\<CR>", "t")
1573 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1574 call feedkeys("cont\<CR>", "xt")
1575 0debuggreedy
1576 call assert_equal('>', cmdtype)
1577
1578 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1579 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1580
1581 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001582 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001583
1584 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1585
1586 cnoremap <expr> <F6> Check_cmdline('=')
1587 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1588 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001589
1590 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001591endfunc
1592
Bram Moolenaar52604f22017-04-07 16:17:39 +02001593func Test_verbosefile()
1594 set verbosefile=Xlog
1595 echomsg 'foo'
1596 echomsg 'bar'
1597 set verbosefile=
1598 let log = readfile('Xlog')
1599 call assert_match("foo\nbar", join(log, "\n"))
1600 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001601
1602 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001603 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001604endfunc
1605
Bram Moolenaar4facea32019-10-12 20:17:40 +02001606func Test_verbose_option()
1607 CheckScreendump
1608
1609 let lines =<< trim [SCRIPT]
1610 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1611 call feedkeys("\r", 't') " for the hit-enter prompt
1612 set verbose=20
1613 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001614 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001615
1616 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001617 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001618 call term_sendkeys(buf, ":DoSomething\<CR>")
1619 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1620
1621 " clean up
1622 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001623endfunc
1624
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001625func Test_setcmdpos()
1626 func InsertTextAtPos(text, pos)
1627 call assert_equal(0, setcmdpos(a:pos))
1628 return a:text
1629 endfunc
1630
1631 " setcmdpos() with position in the middle of the command line.
1632 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1633 call assert_equal('"1ab2', @:)
1634
1635 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1636 call assert_equal('"1b2a', @:)
1637
1638 " setcmdpos() with position beyond the end of the command line.
1639 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1640 call assert_equal('"12ab', @:)
1641
1642 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001643 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001644endfunc
1645
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001646func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001647 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001648 let encoding_save = &encoding
1649
1650 for e in encodings
1651 exe 'set encoding=' . e
1652
1653 " Test overstrike in the middle of the command line.
1654 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001655 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001656
1657 " Test overstrike going beyond end of command line.
1658 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001659 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001660
1661 " Test toggling insert/overstrike a few times.
1662 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001663 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001664 endfor
1665
Bram Moolenaar30276f22019-01-24 17:59:39 +01001666 " Test overstrike with multi-byte characters.
1667 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001668 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001669
1670 let &encoding = encoding_save
1671endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001672
Bram Moolenaar52410572019-10-27 05:12:45 +01001673func Test_buffers_lastused()
1674 " check that buffers are sorted by time when wildmode has lastused
1675 call test_settime(1550020000) " middle
1676 edit bufa
1677 enew
1678 call test_settime(1550030000) " newest
1679 edit bufb
1680 enew
1681 call test_settime(1550010000) " oldest
1682 edit bufc
1683 enew
1684 call test_settime(0)
1685 enew
1686
1687 call assert_equal(['bufa', 'bufb', 'bufc'],
1688 \ getcompletion('', 'buffer'))
1689
1690 let save_wildmode = &wildmode
1691 set wildmode=full:lastused
1692
1693 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1694 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1695 call assert_equal('b bufb', X)
1696 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1697 call assert_equal('b bufa', X)
1698 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1699 call assert_equal('b bufc', X)
1700 enew
1701
1702 edit other
1703 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1704 call assert_equal('b bufb', X)
1705 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1706 call assert_equal('b bufa', X)
1707 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1708 call assert_equal('b bufc', X)
1709 enew
1710
1711 let &wildmode = save_wildmode
1712
1713 bwipeout bufa
1714 bwipeout bufb
1715 bwipeout bufc
1716endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001717
Bram Moolenaar479950f2020-01-19 15:45:17 +01001718func Test_cmdlineclear_tabenter()
1719 CheckScreendump
1720
1721 let lines =<< trim [SCRIPT]
1722 call setline(1, range(30))
1723 [SCRIPT]
1724
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001725 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001726 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001727 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001728 " in one tab make the command line higher with CTRL-W -
1729 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1730 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1731
1732 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001733endfunc
1734
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001735" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001736func Test_cmdline_expand_special()
1737 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001738 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001739 call assert_fails('e <afile>', 'E495:')
1740 call assert_fails('e <abuf>', 'E496:')
1741 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001742
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001743 call writefile([], 'Xfile.cpp', 'D')
1744 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001745 new Xfile.cpp
1746 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1747 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1748 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001749endfunc
1750
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001751" Test for backtick expression in the command line
1752func Test_cmd_backtick()
1753 %argd
1754 argadd `=['a', 'b', 'c']`
1755 call assert_equal(['a', 'b', 'c'], argv())
1756 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001757
1758 argadd `echo abc def`
1759 call assert_equal(['abc def'], argv())
1760 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001761endfunc
1762
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001763" Test for the :! command
1764func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001765 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001766
1767 let lines =<< trim [SCRIPT]
1768 " Test for no previous command
1769 call assert_fails('!!', 'E34:')
1770 set nomore
1771 " Test for cmdline expansion with :!
1772 call setline(1, 'foo!')
1773 silent !echo <cWORD> > Xfile.out
1774 call assert_equal(['foo!'], readfile('Xfile.out'))
1775 " Test for using previous command
1776 silent !echo \! !
1777 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1778 call writefile(v:errors, 'Xresult')
1779 call delete('Xfile.out')
1780 qall!
1781 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001782 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001783 if RunVim([], [], '--clean -S Xscript')
1784 call assert_equal([], readfile('Xresult'))
1785 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001786 call delete('Xresult')
1787endfunc
1788
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001789" Test error: "E135: *Filter* Autocommands must not change current buffer"
1790func Test_cmd_bang_E135()
1791 new
1792 call setline(1, ['a', 'b', 'c', 'd'])
1793 augroup test_cmd_filter_E135
1794 au!
1795 autocmd FilterReadPost * help
1796 augroup END
1797 call assert_fails('2,3!echo "x"', 'E135:')
1798
1799 augroup test_cmd_filter_E135
1800 au!
1801 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01001802 augroup! test_cmd_filter_E135
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001803 %bwipe!
1804endfunc
1805
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001806func Test_cmd_bang_args()
1807 new
1808 :.!
1809 call assert_equal(0, v:shell_error)
1810
1811 " Note that below there is one space char after the '!'. This caused a
1812 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1813 :.!
1814 call assert_equal(0, v:shell_error)
1815 bwipe!
1816
1817 CheckUnix
1818 :.!pwd
1819 call assert_equal(0, v:shell_error)
1820 :.! pwd
1821 call assert_equal(0, v:shell_error)
1822
1823 " Note there is one space after 'pwd'.
1824 :.! pwd
1825 call assert_equal(0, v:shell_error)
1826
1827 " Note there are two spaces after 'pwd'.
1828 :.! pwd
1829 call assert_equal(0, v:shell_error)
1830 :.!ls ~
1831 call assert_equal(0, v:shell_error)
1832
1833 " Note there is one space char after '~'.
1834 :.!ls ~
1835 call assert_equal(0, v:shell_error)
1836
1837 " Note there are two spaces after '~'.
1838 :.!ls ~
1839 call assert_equal(0, v:shell_error)
1840
1841 :.!echo "foo"
1842 call assert_equal(getline('.'), "foo")
1843 :.!echo "foo "
1844 call assert_equal(getline('.'), "foo ")
1845 :.!echo " foo "
1846 call assert_equal(getline('.'), " foo ")
1847 :.!echo " foo "
1848 call assert_equal(getline('.'), " foo ")
1849
1850 %bwipe!
1851endfunc
1852
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001853" Test for using ~ for home directory in cmdline completion matches
1854func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001855 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001856 call writefile([], 'Xexpdir/Xfile1')
1857 call writefile([], 'Xexpdir/Xfile2')
1858 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001859 let save_HOME = $HOME
1860 let $HOME = getcwd()
1861 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1862 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1863 let $HOME = save_HOME
1864 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001865endfunc
1866
Bram Moolenaar578fe942020-02-27 21:32:51 +01001867" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1868" or insert mode (when 'insertmode' is set)
1869func Test_cmdline_ctrl_g()
1870 new
1871 call setline(1, 'abc')
1872 call cursor(1, 3)
1873 " If command line is entered from insert mode, using C-\ C-G should back to
1874 " insert mode
1875 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1876 call assert_equal('abxyc', getline(1))
1877 call assert_equal(4, col('.'))
1878
1879 " If command line is entered in 'insertmode', using C-\ C-G should back to
1880 " 'insertmode'
1881 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1882 call assert_equal('ab12xyc', getline(1))
1883 close!
1884endfunc
1885
Bram Moolenaar578fe942020-02-27 21:32:51 +01001886" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001887func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001888 func T(a, c, p)
1889 return "oneA\noneB\noneC"
1890 endfunc
1891 command -nargs=1 -complete=custom,T MyCmd
1892
Bram Moolenaar578fe942020-02-27 21:32:51 +01001893 set nowildmenu
1894 set wildmode=full,list
1895 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001896 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001897 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001898 call assert_equal('"MyCmd oneA', @:)
1899
1900 set wildmode=longest,full
1901 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1902 call assert_equal('"MyCmd one', @:)
1903 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1904 call assert_equal('"MyCmd oneC', @:)
1905
1906 set wildmode=longest
1907 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1908 call assert_equal('"MyCmd one', @:)
1909
1910 set wildmode=list:longest
1911 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001912 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001913 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001914 call assert_equal('"MyCmd one', @:)
1915
1916 set wildmode=""
1917 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1918 call assert_equal('"MyCmd oneA', @:)
1919
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001920 " Test for wildmode=longest with 'fileignorecase' set
1921 set wildmode=longest
1922 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001923 argadd AAA AAAA AAAAA
1924 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1925 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001926 set fileignorecase&
1927
1928 " Test for listing files with wildmode=list
1929 set wildmode=list
1930 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001931 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001932 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001933 call assert_equal('"b A', @:)
1934
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001935 " when using longest completion match, matches shorter than the argument
1936 " should be ignored (happens with :help)
1937 set wildmode=longest,full
1938 set wildmenu
1939 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1940 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001941 " non existing file
1942 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1943 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001944 set wildmenu&
1945
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001946 " Test for longest file name completion with 'fileignorecase'
1947 " On MS-Windows, file names are case insensitive.
1948 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001949 call writefile([], 'XTESTfoo', 'D')
1950 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001951 set nofileignorecase
1952 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1953 call assert_equal('"e XTESTfoo', @:)
1954 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1955 call assert_equal('"e Xtestbar', @:)
1956 set fileignorecase
1957 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1958 call assert_equal('"e Xtest', @:)
1959 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1960 call assert_equal('"e Xtest', @:)
1961 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001962 endif
1963
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001964 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001965 delcommand MyCmd
1966 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001967 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001968 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001969endfunc
1970
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001971func Test_wildmode()
1972 " Test with utf-8 encoding
1973 call Wildmode_tests()
1974
1975 " Test with latin1 encoding
1976 let save_encoding = &encoding
1977 set encoding=latin1
1978 call Wildmode_tests()
1979 let &encoding = save_encoding
1980endfunc
1981
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001982func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001983 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001984 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001985 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001986 let lines =<< trim END
1987 func vim8#Complete(a, c, p)
1988 return "oneA\noneB\noneC"
1989 endfunc
1990 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001991 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001992
1993 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1994 set nowildmenu
1995 set wildmode=full,list
1996 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1997 call assert_equal('"MyCmd oneA oneB oneC', @:)
1998
1999 let &rtp = save_rtp
2000 set wildmode& wildmenu&
2001 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00002002endfunc
2003
Bram Moolenaar578fe942020-02-27 21:32:51 +01002004" Test for interrupting the command-line completion
2005func Test_interrupt_compl()
2006 func F(lead, cmdl, p)
2007 if a:lead =~ 'tw'
2008 call interrupt()
2009 return
2010 endif
2011 return "one\ntwo\nthree"
2012 endfunc
2013 command -nargs=1 -complete=custom,F Tcmd
2014
2015 set nowildmenu
2016 set wildmode=full
2017 let interrupted = 0
2018 try
2019 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
2020 catch /^Vim:Interrupt$/
2021 let interrupted = 1
2022 endtry
2023 call assert_equal(1, interrupted)
2024
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002025 let interrupted = 0
2026 try
2027 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
2028 catch /^Vim:Interrupt$/
2029 let interrupted = 1
2030 endtry
2031 call assert_equal(1, interrupted)
2032
Bram Moolenaar578fe942020-02-27 21:32:51 +01002033 delcommand Tcmd
2034 delfunc F
2035 set wildmode&
2036endfunc
2037
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002038" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01002039func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002040 let str = ":one two\<C-U>"
2041 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002042 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002043 let str ..= "\<Left>five\<Right>"
2044 let str ..= "\<Home>two "
2045 let str ..= "\<C-Left>one "
2046 let str ..= "\<C-Right> three"
2047 let str ..= "\<End>\<S-Left>four "
2048 let str ..= "\<S-Right> six"
2049 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2050 call feedkeys(str, 'xt')
2051 call assert_equal("\"one two three four five six seven", @:)
2052endfunc
2053
2054" Test for moving the cursor on the / command line in 'rightleft' mode
2055func Test_cmdline_edit_rightleft()
2056 CheckFeature rightleft
2057 set rightleft
2058 set rightleftcmd=search
2059 let str = "/one two\<C-U>"
2060 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002061 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01002062 let str ..= "\<Right>five\<Left>"
2063 let str ..= "\<Home>two "
2064 let str ..= "\<C-Right>one "
2065 let str ..= "\<C-Left> three"
2066 let str ..= "\<End>\<S-Right>four "
2067 let str ..= "\<S-Left> six"
2068 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
2069 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
2070 call assert_equal("\"one two three four five six seven", @/)
2071 set rightleftcmd&
2072 set rightleft&
2073endfunc
2074
2075" Test for using <C-\>e in the command line to evaluate an expression
2076func Test_cmdline_expr()
2077 " Evaluate an expression from the beginning of a command line
2078 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
2079 call assert_equal('"hello', @:)
2080
2081 " Use an invalid expression for <C-\>e
2082 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
2083
2084 " Insert literal <CTRL-\> in the command line
2085 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
2086 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01002087endfunc
2088
Bram Moolenaar6046ade2022-06-22 13:51:54 +01002089" This was making the insert position negative
2090func Test_cmdline_expr_register()
2091 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
2092endfunc
2093
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01002094" Test for 'imcmdline' and 'imsearch'
2095" This test doesn't actually test the input method functionality.
2096func Test_cmdline_inputmethod()
2097 new
2098 call setline(1, ['', 'abc', ''])
2099 set imcmdline
2100
2101 call feedkeys(":\"abc\<CR>", 'xt')
2102 call assert_equal("\"abc", @:)
2103 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
2104 call assert_equal("\"abc", @:)
2105 call feedkeys("/abc\<CR>", 'xt')
2106 call assert_equal([2, 1], [line('.'), col('.')])
2107 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2108 call assert_equal([2, 1], [line('.'), col('.')])
2109
2110 set imsearch=2
2111 call cursor(1, 1)
2112 call feedkeys("/abc\<CR>", 'xt')
2113 call assert_equal([2, 1], [line('.'), col('.')])
2114 call cursor(1, 1)
2115 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2116 call assert_equal([2, 1], [line('.'), col('.')])
2117 set imdisable
2118 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
2119 call assert_equal([2, 1], [line('.'), col('.')])
2120 set imdisable&
2121 set imsearch&
2122
2123 set imcmdline&
2124 %bwipe!
2125endfunc
2126
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01002127" Test for using CTRL-_ in the command line with 'allowrevins'
2128func Test_cmdline_revins()
2129 CheckNotMSWindows
2130 CheckFeature rightleft
2131 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2132 call assert_equal("\"abc\<c-_>", @:)
2133 set allowrevins
2134 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2135 call assert_equal('"abcñèæ', @:)
2136 set allowrevins&
2137endfunc
2138
2139" Test for typing UTF-8 composing characters in the command line
2140func Test_cmdline_composing_chars()
2141 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2142 call assert_equal('"ゔ', @:)
2143endfunc
2144
Bram Moolenaar0e717042020-04-27 19:29:01 +02002145" test that ";" works to find a match at the start of the first line
2146func Test_zero_line_search()
2147 new
2148 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2149 call cursor(1,1)
2150 0;/pattern/d
2151 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2152 q!
2153endfunc
2154
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002155func Test_read_shellcmd()
2156 CheckUnix
2157 if executable('ls')
2158 " There should be ls in the $PATH
2159 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2160 call assert_match('^"r! .*\<ls\>', @:)
2161 endif
2162
2163 if executable('rm')
2164 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2165 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2166 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002167
2168 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2169 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2170 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002171 endif
2172endfunc
2173
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002174" Test for going up and down the directory tree using 'wildmenu'
2175func Test_wildmenu_dirstack()
2176 CheckUnix
2177 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002178 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002179 call writefile([], 'Xwildmenu/file1_1.txt')
2180 call writefile([], 'Xwildmenu/file1_2.txt')
2181 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2182 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2183 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2184 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2185 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2186 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002187 set wildmenu
2188
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002189 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002190 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002191 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002192 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002193 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002194 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002195 call assert_equal('"e ../../dir3/', @:)
2196 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2197 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002198 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002199 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002200 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002201 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002202 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002203 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2204 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002205
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002206 set wildmenu&
2207endfunc
2208
obcat71c6f7a2021-05-13 20:23:10 +02002209" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002210" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2211" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002212func Test_recalling_cmdline()
2213 CheckFeature cmdline_hist
2214
2215 let g:cmdlines = []
2216 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2217
2218 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002219 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2220 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2221 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2222 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002223 "\ TODO: {'name': 'debug', ...}
2224 \]
2225 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002226 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2227 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2228 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2229 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2230 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002231 \]
2232 let prefix = 'vi'
2233 for h in histories
2234 call histadd(h.name, 'vim')
2235 call histadd(h.name, 'virtue')
2236 call histadd(h.name, 'Virgo')
2237 call histadd(h.name, 'vogue')
2238 call histadd(h.name, 'emacs')
2239 for k in keypairs
2240 let g:cmdlines = []
2241 let keyseqs = h.enter
2242 \ .. prefix
2243 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2244 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2245 \ .. h.exit
2246 call feedkeys(keyseqs, 'xt')
2247 call histdel(h.name, -1) " delete the history added by feedkeys above
2248 let expect = k.prefixmatch
2249 \ ? ['virtue', 'vim', 'virtue', prefix]
2250 \ : ['emacs', 'vogue', 'emacs', prefix]
2251 call assert_equal(expect, g:cmdlines)
2252 endfor
2253 endfor
2254
2255 unlet g:cmdlines
2256 cunmap <Plug>(save-cmdline)
2257endfunc
2258
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002259func Test_cmd_map_cmdlineChanged()
2260 let g:log = []
2261 cnoremap <F1> l<Cmd><CR>s
zeertzjq094dd152023-06-15 22:51:57 +01002262 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002263 autocmd!
2264 autocmd CmdlineChanged : let g:log += [getcmdline()]
2265 augroup END
2266
2267 call feedkeys(":\<F1>\<CR>", 'xt')
2268 call assert_equal(['l', 'ls'], g:log)
2269
Bram Moolenaar796139a2021-05-18 21:38:45 +02002270 let @b = 'b'
2271 cnoremap <F1> a<C-R>b
2272 let g:log = []
2273 call feedkeys(":\<F1>\<CR>", 'xt')
2274 call assert_equal(['a', 'ab'], g:log)
2275
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002276 unlet g:log
2277 cunmap <F1>
zeertzjq094dd152023-06-15 22:51:57 +01002278 augroup test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002279 autocmd!
2280 augroup END
zeertzjq094dd152023-06-15 22:51:57 +01002281 augroup! test_CmdlineChanged
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002282endfunc
2283
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002284" Test for the 'suffixes' option
2285func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002286 call writefile([], 'Xsuffile', 'D')
2287 call writefile([], 'Xsuffile.c', 'D')
2288 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002289 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002290 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2291 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2292 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2293 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002294 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002295 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2296 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2297 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2298 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002299 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002300 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2301 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2302 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2303 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002304 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002305 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002306 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2307 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002308endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002309
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002310" Test for using a popup menu for the command line completion matches
2311" (wildoptions=pum)
2312func Test_wildmenu_pum()
2313 CheckRunVimInTerminal
2314
2315 let commands =<< trim [CODE]
2316 set wildmenu
2317 set wildoptions=pum
2318 set shm+=I
2319 set noruler
2320 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002321
2322 func CmdCompl(a, b, c)
2323 return repeat(['aaaa'], 120)
2324 endfunc
2325 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002326
2327 func MyStatusLine() abort
2328 return 'status'
2329 endfunc
2330 func SetupStatusline()
2331 set statusline=%!MyStatusLine()
2332 set laststatus=2
2333 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002334
2335 func MyTabLine()
2336 return 'my tab line'
2337 endfunc
2338 func SetupTabline()
2339 set statusline=
2340 set tabline=%!MyTabLine()
2341 set showtabline=2
2342 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002343
2344 func DoFeedKeys()
2345 let &wildcharm = char2nr("\t")
2346 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2347 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002348 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002349 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002350
2351 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2352
2353 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002354 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2355
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002356 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002357 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002358 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2359
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002360 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002361 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002362 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2363
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002364 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002365 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002366 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2367
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002368 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002369 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002370 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2371
2372 " pressing <C-E> should end completion and go back to the original match
2373 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002374 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2375
2376 " pressing <C-Y> should select the current match and end completion
2377 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002378 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2379
2380 " With 'wildmode' set to 'longest,full', completing a match should display
2381 " the longest match, the wildmenu should not be displayed.
2382 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2383 call TermWait(buf)
2384 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002385 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2386
2387 " pressing <Tab> should display the wildmenu
2388 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002389 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2390
2391 " pressing <Tab> second time should select the next entry in the menu
2392 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002393 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2394
2395 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002396 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002397 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002398 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2399
2400 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002401 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2402
2403 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002404 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2405
2406 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002407 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002408 call writefile([], 'Xnamedir/XfileA')
2409 call writefile([], 'Xnamedir/XdirA/XfileB')
2410 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002411
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002412 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002413 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2414
2415 " Pressing <Right> on a directory name should go into that directory
2416 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002417 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2418
2419 " Pressing <Left> on a directory name should go to the parent directory
2420 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002421 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2422
2423 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002424 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002425 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002426 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2427
2428 " Pressing <C-D> when the popup menu is displayed should remove the popup
2429 " menu
2430 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002431 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2432
2433 " Pressing <S-Tab> should open the popup menu with the last entry selected
2434 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002435 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2436
2437 " Pressing <Esc> should close the popup menu and cancel the cmd line
2438 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002439 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2440
2441 " Typing a character when the popup is open, should close the popup
2442 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002443 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2444
2445 " When the popup is open, entering the cmdline window should close the popup
2446 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002447 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2448 call term_sendkeys(buf, ":q\<CR>")
2449
2450 " After the last popup menu item, <C-N> should show the original string
2451 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002452 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2453
2454 " Use the popup menu for the command name
2455 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002456 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2457
2458 " Pressing the left arrow should remove the popup menu
2459 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002460 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2461
2462 " Pressing <BS> should remove the popup menu and erase the last character
2463 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002464 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2465
2466 " Pressing <C-W> should remove the popup menu and erase the previous word
2467 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002468 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2469
2470 " Pressing <C-U> should remove the popup menu and erase the entire line
2471 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002472 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2473
2474 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2475 " the cmdline from history
2476 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002477 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2478
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002479 " Check "list" still works
2480 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2481 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002482 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2483 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002484 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2485
rbtnn68cc2b82022-02-09 11:55:47 +00002486 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002487 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002488 call writefile([], 'Xnamedir/あいう/abc')
2489 call writefile([], 'Xnamedir/あいう/xyz')
2490 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002491
2492 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002493 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002494 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2495
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002496 " Pressing <C-A> when the popup menu is displayed should list all the
2497 " matches and pressing a key after that should remove the popup menu
2498 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2499 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2500 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2501
2502 " Pressing <C-A> when the popup menu is displayed should list all the
2503 " matches and pressing <Left> after that should move the cursor
2504 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2505 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2506 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2507
2508 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2509 " should be displayed correctly on the screen.
2510 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2511 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2512
2513 " After using <C-A> to expand all the filename matches, pressing <Up>
2514 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002515 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002516 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2517 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2518 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2519
2520 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2521 " crash Vim
2522 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2523 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2524
Bram Moolenaar414acd32022-02-10 21:09:45 +00002525 " After removing the pum the command line is redrawn
2526 call term_sendkeys(buf, ":edit foo\<CR>")
2527 call term_sendkeys(buf, ":edit bar\<CR>")
2528 call term_sendkeys(buf, ":ls\<CR>")
2529 call term_sendkeys(buf, ":com\<Tab> ")
2530 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002531 call term_sendkeys(buf, "\<C-U>\<CR>")
2532
2533 " Esc still works to abort the command when 'statusline' is set
2534 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2535 call term_sendkeys(buf, ":si\<Tab>")
2536 call term_sendkeys(buf, "\<Esc>")
2537 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002538
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002539 " Esc still works to abort the command when 'tabline' is set
2540 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2541 call term_sendkeys(buf, ":si\<Tab>")
2542 call term_sendkeys(buf, "\<Esc>")
2543 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2544
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002545 " popup is cleared also when 'lazyredraw' is set
2546 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2547 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2548 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2549 call term_sendkeys(buf, "\<Esc>")
2550
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002551 " Pressing <PageDown> should scroll the menu downward
2552 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2553 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2554 call term_sendkeys(buf, "\<PageDown>")
2555 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2556 call term_sendkeys(buf, "\<PageDown>")
2557 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2558 call term_sendkeys(buf, "\<PageDown>")
2559 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2560 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2561 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2562
2563 " Pressing <PageUp> should scroll the menu upward
2564 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2565 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2566 call term_sendkeys(buf, "\<PageUp>")
2567 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2568 call term_sendkeys(buf, "\<PageUp>")
2569 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2570 call term_sendkeys(buf, "\<PageUp>")
2571 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2572
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002573 call term_sendkeys(buf, "\<C-U>\<CR>")
2574 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002575endfunc
2576
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002577" Test for wildmenumode() with the cmdline popup menu
2578func Test_wildmenumode_with_pum()
2579 set wildmenu
2580 set wildoptions=pum
2581 cnoremap <expr> <F2> wildmenumode()
2582 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2583 call assert_equal('"sign define10', @:)
2584 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2585 call assert_equal('"sign define jump list place undefine unplace0', @:)
2586 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2587 call assert_equal('"sign 0', @:)
2588 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2589 call assert_equal('"sign define0', @:)
2590 set nowildmenu wildoptions&
2591 cunmap <F2>
2592endfunc
2593
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002594func Test_wildmenu_with_pum_foldexpr()
2595 CheckRunVimInTerminal
2596
2597 let lines =<< trim END
2598 call setline(1, ['folded one', 'folded two', 'some more text'])
2599 func MyFoldText()
2600 return 'foo'
2601 endfunc
2602 set foldtext=MyFoldText() wildoptions=pum
2603 normal ggzfj
2604 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002605 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002606 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2607 call term_sendkeys(buf, ":set\<Tab>")
2608 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2609
2610 call term_sendkeys(buf, "\<Esc>")
2611 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2612
2613 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002614endfunc
2615
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002616" Test for opening the cmdline completion popup menu from the terminal window.
2617" The popup menu should be positioned correctly over the status line of the
2618" bottom-most window.
2619func Test_wildmenu_pum_from_terminal()
2620 CheckRunVimInTerminal
2621 let python = PythonProg()
2622 call CheckPython(python)
2623
2624 %bw!
2625 let cmds = ['set wildmenu wildoptions=pum']
2626 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2627 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002628 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002629 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2630 call term_sendkeys(buf, "\r\r\r")
2631 call term_wait(buf)
2632 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2633 call term_wait(buf)
2634 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2635 call term_wait(buf)
2636 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002637endfunc
2638
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002639func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002640 CheckRunVimInTerminal
2641
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002642 " This was using freed memory. Run in a terminal to get the pum to update.
2643 let lines =<< trim END
2644 set wildoptions=pum
2645 set wildchar=<C-E>
2646 END
2647 call writefile(lines, 'XwildmenuTest', 'D')
2648 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2649
2650 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2651 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2652
2653 set wildoptions& wildchar&
2654endfunc
2655
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002656" Test for completion after a :substitute command followed by a pipe (|)
2657" character
2658func Test_cmdline_complete_substitute()
2659 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2660 call assert_equal("\"s | \t", @:)
2661 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2662 call assert_equal("\"s/ | \t", @:)
2663 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2664 call assert_equal("\"s/one | \t", @:)
2665 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2666 call assert_equal("\"s/one/ | \t", @:)
2667 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2668 call assert_equal("\"s/one/two | \t", @:)
2669 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2670 call assert_equal('"s/one/two/ | chistory', @:)
2671 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2672 call assert_equal("\"s/one/two/g \t", @:)
2673 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2674 call assert_equal("\"s/one/two/g | chistory", @:)
2675 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2676 call assert_equal("\"s/one/t\\/ | \t", @:)
2677 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2678 call assert_equal('"s/one/t"o/ | chistory', @:)
2679 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2680 call assert_equal('"s/one/t|o/ | chistory', @:)
2681 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2682 call assert_equal("\"&\t", @:)
2683endfunc
2684
2685" Test for the :dlist command completion
2686func Test_cmdline_complete_dlist()
2687 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2688 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2689 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2690 call assert_equal("\"dlist 10 /pat/ \t", @:)
2691 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2692 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2693 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2694 call assert_equal("\"dlist 10 /pat\\\t", @:)
2695 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2696 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2697endfunc
2698
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002699" argument list (only for :argdel) fuzzy completion
2700func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002701 argadd change.py count.py charge.py
2702 set wildoptions&
2703 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2704 call assert_equal('"argdel cge', @:)
2705 set wildoptions=fuzzy
2706 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2707 call assert_equal('"argdel change.py charge.py', @:)
2708 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002709 set wildoptions&
2710endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002711
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002712" autocmd group name fuzzy completion
2713func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002714 set wildoptions&
2715 augroup MyFuzzyGroup
2716 augroup END
2717 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2718 call assert_equal('"augroup mfg', @:)
2719 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2720 call assert_equal('"augroup MyFuzzyGroup', @:)
2721 set wildoptions=fuzzy
2722 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2723 call assert_equal('"augroup MyFuzzyGroup', @:)
2724 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal('"augroup My*p', @:)
2726 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002727 set wildoptions&
2728endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002729
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002730" buffer name fuzzy completion
2731func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002732 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002733 " Use a long name to reduce the risk of matching a random directory name
2734 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002735 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002736 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2737 call assert_equal('"b SRFWL', @:)
2738 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2739 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002740 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002741 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2742 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2743 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002745 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002746 set wildoptions&
2747endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002748
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002749" buffer name (full path) fuzzy completion
2750func Test_fuzzy_completion_bufname_fullpath()
2751 CheckUnix
2752 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002753 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002754 edit Xcmd/Xstate/Xfile.js
2755 cd Xcmd/Xstate
2756 enew
2757 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2758 call assert_equal('"b CmdStateFile', @:)
2759 set wildoptions=fuzzy
2760 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2761 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2762 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002763 set wildoptions&
2764endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002765
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002766" :behave suboptions fuzzy completion
2767func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002768 set wildoptions&
2769 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal('"behave xm', @:)
2771 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2772 call assert_equal('"behave xterm', @:)
2773 set wildoptions=fuzzy
2774 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2775 call assert_equal('"behave xterm', @:)
2776 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2777 call assert_equal('"behave xt*m', @:)
2778 let g:Sline = ''
2779 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2780 call assert_equal('mswin', g:Sline)
2781 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002782 set wildoptions&
2783endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002784
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002785" " colorscheme name fuzzy completion - NOT supported
2786" func Test_fuzzy_completion_colorscheme()
2787" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002788
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002789" built-in command name fuzzy completion
2790func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002791 set wildoptions&
2792 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2793 call assert_equal('"sbwin', @:)
2794 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal('"sbrewind', @:)
2796 set wildoptions=fuzzy
2797 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2798 call assert_equal('"sbrewind', @:)
2799 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2800 call assert_equal('"sbr*d', @:)
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" " compiler name fuzzy completion - NOT supported
2805" func Test_fuzzy_completion_compiler()
2806" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002807
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002808" :cscope suboptions fuzzy completion
2809func Test_fuzzy_completion_cscope()
2810 CheckFeature cscope
2811 set wildoptions&
2812 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal('"cscope ret', @:)
2814 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2815 call assert_equal('"cscope reset', @:)
2816 set wildoptions=fuzzy
2817 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2818 call assert_equal('"cscope reset', @:)
2819 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2820 call assert_equal('"cscope re*t', @:)
2821 set wildoptions&
2822endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002823
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002824" :diffget/:diffput buffer name fuzzy completion
2825func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002826 new SomeBuffer
2827 diffthis
2828 new OtherBuffer
2829 diffthis
2830 set wildoptions&
2831 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2832 call assert_equal('"diffget sbuf', @:)
2833 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2834 call assert_equal('"diffput sbuf', @:)
2835 set wildoptions=fuzzy
2836 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2837 call assert_equal('"diffget SomeBuffer', @:)
2838 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2839 call assert_equal('"diffput SomeBuffer', @:)
2840 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002841 set wildoptions&
2842endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002843
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002844" " directory name fuzzy completion - NOT supported
2845" func Test_fuzzy_completion_dirname()
2846" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002847
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002848" environment variable name fuzzy completion
2849func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002850 set wildoptions&
2851 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2852 call assert_equal('"echo $VUT', @:)
2853 set wildoptions=fuzzy
2854 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2855 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002856 set wildoptions&
2857endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002858
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002859" autocmd event fuzzy completion
2860func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002861 set wildoptions&
2862 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2863 call assert_equal('"autocmd BWout', @:)
2864 set wildoptions=fuzzy
2865 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2866 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002867 set wildoptions&
2868endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002869
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870" vim expression fuzzy completion
2871func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002872 let g:PerPlaceCount = 10
2873 set wildoptions&
2874 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal('"let c = ppc', @:)
2876 set wildoptions=fuzzy
2877 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2878 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002879 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002880endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002881
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002882" " file name fuzzy completion - NOT supported
2883" func Test_fuzzy_completion_filename()
2884" endfunc
2885
2886" " files in path fuzzy completion - NOT supported
2887" func Test_fuzzy_completion_filesinpath()
2888" endfunc
2889
2890" " filetype name fuzzy completion - NOT supported
2891" func Test_fuzzy_completion_filetype()
2892" endfunc
2893
2894" user defined function name completion
2895func Test_fuzzy_completion_userdefined_func()
2896 set wildoptions&
2897 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2898 call assert_equal('"call Test_f_u_f', @:)
2899 set wildoptions=fuzzy
2900 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2901 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2902 set wildoptions&
2903endfunc
2904
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002905" <SNR> functions should be sorted to the end
2906func Test_fuzzy_completion_userdefined_snr_func()
2907 func s:Sendmail()
2908 endfunc
2909 func SendSomemail()
2910 endfunc
2911 func S1e2n3dmail()
2912 endfunc
2913 set wildoptions=fuzzy
2914 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002915 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002916 set wildoptions&
2917 delfunc s:Sendmail
2918 delfunc SendSomemail
2919 delfunc S1e2n3dmail
2920endfunc
2921
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002922" user defined command name completion
2923func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002924 set wildoptions&
2925 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2926 call assert_equal('"MsFeat', @:)
2927 set wildoptions=fuzzy
2928 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2929 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930 set wildoptions&
2931endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002933" " :help tag fuzzy completion - NOT supported
2934" func Test_fuzzy_completion_helptag()
2935" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002936
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002937" highlight group name fuzzy completion
2938func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002939 set wildoptions&
2940 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2941 call assert_equal('"highlight SKey', @:)
2942 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2943 call assert_equal('"highlight SpecialKey', @:)
2944 set wildoptions=fuzzy
2945 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2946 call assert_equal('"highlight SpecialKey', @:)
2947 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2948 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002949 set wildoptions&
2950endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002951
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002952" :history suboptions fuzzy completion
2953func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002954 set wildoptions&
2955 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2956 call assert_equal('"history dg', @:)
2957 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2958 call assert_equal('"history search', @:)
2959 set wildoptions=fuzzy
2960 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('"history debug', @:)
2962 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2963 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002964 set wildoptions&
2965endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002966
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002967" :language locale name fuzzy completion
2968func Test_fuzzy_completion_lang()
2969 CheckUnix
2970 set wildoptions&
2971 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal('"lang psx', @:)
2973 set wildoptions=fuzzy
2974 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2975 call assert_equal('"lang POSIX', @:)
2976 set wildoptions&
2977endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002978
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002979" :mapclear buffer argument fuzzy completion
2980func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002981 set wildoptions&
2982 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2983 call assert_equal('"mapclear buf', @:)
2984 set wildoptions=fuzzy
2985 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2986 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002987 set wildoptions&
2988endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002989
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002990" map name fuzzy completion
2991func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002992 " test regex completion works
2993 set wildoptions=fuzzy
2994 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2995 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002996 nmap <plug>MyLongMap :p<CR>
2997 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2998 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2999 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
3000 call assert_equal("\"nmap MLM \t", @:)
3001 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal("\"nmap <F2> one two \t", @:)
3003 " duplicate entries should be removed
3004 vmap <plug>MyLongMap :<C-U>#<CR>
3005 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
3006 call assert_equal("\"nmap <Plug>MyLongMap", @:)
3007 nunmap <plug>MyLongMap
3008 vunmap <plug>MyLongMap
3009 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal("\"nmap ABC\t", @:)
3011 " results should be sorted by best match
3012 nmap <Plug>format :
3013 nmap <Plug>goformat :
3014 nmap <Plug>TestFOrmat :
3015 nmap <Plug>fendoff :
3016 nmap <Plug>state :
3017 nmap <Plug>FendingOff :
3018 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
3019 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
3020 nunmap <Plug>format
3021 nunmap <Plug>goformat
3022 nunmap <Plug>TestFOrmat
3023 nunmap <Plug>fendoff
3024 nunmap <Plug>state
3025 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003026 set wildoptions&
3027endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003028
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003029" abbreviation fuzzy completion
3030func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003031 set wildoptions=fuzzy
3032 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
3033 call assert_equal("\"iabbr <nowait>", @:)
3034 iabbr WaitForCompletion WFC
3035 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal("\"iabbr WaitForCompletion", @:)
3037 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003039
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003040 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003041 set wildoptions&
3042endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003043
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003044" menu name fuzzy completion
3045func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00003046 CheckFeature menu
3047
3048 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003049 set wildoptions&
3050 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3051 call assert_equal('"menu pup', @:)
3052 set wildoptions=fuzzy
3053 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
3054 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00003055
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003056 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00003057 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003058endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003059
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003060" :messages suboptions fuzzy completion
3061func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003062 set wildoptions&
3063 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3064 call assert_equal('"messages clr', @:)
3065 set wildoptions=fuzzy
3066 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003068 set wildoptions&
3069endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003070
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003071" :set option name fuzzy completion
3072func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003073 set wildoptions&
3074 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal('"set brkopt', @:)
3076 set wildoptions=fuzzy
3077 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
3078 call assert_equal('"set breakindentopt', @:)
3079 set wildoptions&
3080 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal('"set fixendofline', @:)
3082 set wildoptions=fuzzy
3083 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003085 set wildoptions&
3086endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003087
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003088" :set <term_option>
3089func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003090 set wildoptions&
3091 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal('"set t_EC', @:)
3093 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal('"set <t_EC>', @:)
3095 set wildoptions=fuzzy
3096 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3097 call assert_equal('"set t_EC', @:)
3098 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
3099 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003100 set wildoptions&
3101endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003102
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003103" " :packadd directory name fuzzy completion - NOT supported
3104" func Test_fuzzy_completion_packadd()
3105" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003106
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003107" " shell command name fuzzy completion - NOT supported
3108" func Test_fuzzy_completion_shellcmd()
3109" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003110
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003111" :sign suboptions fuzzy completion
3112func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003113 set wildoptions&
3114 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3115 call assert_equal('"sign ufe', @:)
3116 set wildoptions=fuzzy
3117 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003119 set wildoptions&
3120endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003121
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003122" :syntax suboptions fuzzy completion
3123func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003124 set wildoptions&
3125 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal('"syntax kwd', @:)
3127 set wildoptions=fuzzy
3128 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
3129 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003130 set wildoptions&
3131endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003132
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003133" syntax group name fuzzy completion
3134func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003135 set wildoptions&
3136 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3137 call assert_equal('"syntax list mpar', @:)
3138 set wildoptions=fuzzy
3139 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003141 set wildoptions&
3142endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003143
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003144" :syntime suboptions fuzzy completion
3145func Test_fuzzy_completion_syntime()
3146 CheckFeature profile
3147 set wildoptions&
3148 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3149 call assert_equal('"syntime clr', @:)
3150 set wildoptions=fuzzy
3151 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal('"syntime clear', @:)
3153 set wildoptions&
3154endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003155
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003156" " tag name fuzzy completion - NOT supported
3157" func Test_fuzzy_completion_tagname()
3158" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003159
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003160" " tag name and file fuzzy completion - NOT supported
3161" func Test_fuzzy_completion_tagfile()
3162" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003163
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003164" " user names fuzzy completion - how to test this functionality?
3165" func Test_fuzzy_completion_username()
3166" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003167
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003168" user defined variable name fuzzy completion
3169func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003170 let g:SomeVariable=10
3171 set wildoptions&
3172 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3173 call assert_equal('"let SVar', @:)
3174 set wildoptions=fuzzy
3175 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003177 set wildoptions&
3178endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003179
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003180" Test for sorting the results by the best match
3181func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003182 %bw!
3183 command T123format :
3184 command T123goformat :
3185 command T123TestFOrmat :
3186 command T123fendoff :
3187 command T123state :
3188 command T123FendingOff :
3189 set wildoptions=fuzzy
3190 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3191 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3192 delcommand T123format
3193 delcommand T123goformat
3194 delcommand T123TestFOrmat
3195 delcommand T123fendoff
3196 delcommand T123state
3197 delcommand T123FendingOff
3198 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003199 set wildoptions&
3200endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003201
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003202" Test for fuzzy completion of a command with lower case letters and a number
3203func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003204 command Foo2Bar :
3205 set wildoptions=fuzzy
3206 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3207 call assert_equal('"Foo2Bar', @:)
3208 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal('"Foo2Bar', @:)
3210 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal('"Foo2Bar', @:)
3212 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003213 set wildoptions&
3214endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003215
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003216" Test for command completion for a command starting with 'k'
3217func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003218 command KillKillKill :
3219 set wildoptions&
3220 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3221 call assert_equal("\"killkill\<Tab>", @:)
3222 set wildoptions=fuzzy
3223 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal('"KillKillKill', @:)
3225 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003226 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003227endfunc
3228
3229" Test for fuzzy completion for user defined custom completion function
3230func Test_fuzzy_completion_custom_func()
3231 func Tcompl(a, c, p)
3232 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3233 endfunc
3234 command -nargs=* -complete=custom,Tcompl Fuzzy :
3235 set wildoptions&
3236 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3237 call assert_equal("\"Fuzzy format", @:)
3238 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3239 call assert_equal("\"Fuzzy xy", @:)
3240 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3241 call assert_equal("\"Fuzzy ttt", @:)
3242 set wildoptions=fuzzy
3243 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3245 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3247 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal("\"Fuzzy xy", @:)
3249 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal("\"Fuzzy TestFOrmat", @:)
3251 delcom Fuzzy
3252 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003253endfunc
3254
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003255" Test for :breakadd argument completion
3256func Test_cmdline_complete_breakadd()
3257 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakadd expr file func here", @:)
3259 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_equal("\"breakadd expr", @:)
3261 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal("\"breakadd expr", @:)
3263 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"breakadd here", @:)
3265 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3266 call assert_equal("\"breakadd here", @:)
3267 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3268 call assert_equal("\"breakadd abc", @:)
3269 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3270 let l = getcompletion('not', 'breakpoint')
3271 call assert_equal([], l)
3272
3273 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003274 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003275 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3276 call assert_equal("\"breakadd file Xscript", @:)
3277 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3278 call assert_equal("\"breakadd file Xscript", @:)
3279 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"breakadd file 20 Xscript", @:)
3281 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_equal("\"breakadd file 20 Xscript", @:)
3283 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3285 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal("\"breakadd file 20\t", @:)
3287 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal("\"breakadd file 20x\t", @:)
3289 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_equal("\"breakadd file Xscript ", @:)
3291 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003293
3294 " Test for :breakadd func [lnum] <function>
3295 func Xbreak_func()
3296 endfunc
3297 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3298 call assert_equal("\"breakadd func Xbreak_func", @:)
3299 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3300 call assert_equal("\"breakadd func Xbreak_func", @:)
3301 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3302 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3303 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3304 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3305 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3306 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3307 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3308 call assert_equal("\"breakadd func 20\t", @:)
3309 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3310 call assert_equal("\"breakadd func 20x\t", @:)
3311 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3312 call assert_equal("\"breakadd func Xbreak_func ", @:)
3313 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3314 call assert_equal("\"breakadd func X1B2C3", @:)
3315 delfunc Xbreak_func
3316
3317 " Test for :breakadd expr <expression>
3318 let g:Xtest_var = 10
3319 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3320 call assert_equal("\"breakadd expr Xtest_var", @:)
3321 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3322 call assert_equal("\"breakadd expr Xtest_var", @:)
3323 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3324 call assert_equal("\"breakadd expr Xtest_var ", @:)
3325 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3326 call assert_equal("\"breakadd expr X1B2C3", @:)
3327 unlet g:Xtest_var
3328
3329 " Test for :breakadd here
3330 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3331 call assert_equal("\"breakadd here Xtest", @:)
3332 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3333 call assert_equal("\"breakadd here Xtest", @:)
3334 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3335 call assert_equal("\"breakadd here ", @:)
3336endfunc
3337
3338" Test for :breakdel argument completion
3339func Test_cmdline_complete_breakdel()
3340 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3341 call assert_equal("\"breakdel file func here", @:)
3342 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3343 call assert_equal("\"breakdel file", @:)
3344 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3345 call assert_equal("\"breakdel file", @:)
3346 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3347 call assert_equal("\"breakdel here", @:)
3348 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3349 call assert_equal("\"breakdel here", @:)
3350 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3351 call assert_equal("\"breakdel abc", @:)
3352
3353 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003354 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003355 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3356 call assert_equal("\"breakdel file Xscript", @:)
3357 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3358 call assert_equal("\"breakdel file Xscript", @:)
3359 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3360 call assert_equal("\"breakdel file 20 Xscript", @:)
3361 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3362 call assert_equal("\"breakdel file 20 Xscript", @:)
3363 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3364 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3365 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3366 call assert_equal("\"breakdel file 20\t", @:)
3367 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3368 call assert_equal("\"breakdel file 20x\t", @:)
3369 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3370 call assert_equal("\"breakdel file Xscript ", @:)
3371 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3372 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003373
3374 " Test for :breakdel func [lnum] <function>
3375 func Xbreak_func()
3376 endfunc
3377 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3378 call assert_equal("\"breakdel func Xbreak_func", @:)
3379 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3380 call assert_equal("\"breakdel func Xbreak_func", @:)
3381 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3382 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3383 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3384 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3385 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3386 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3387 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3388 call assert_equal("\"breakdel func 20\t", @:)
3389 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3390 call assert_equal("\"breakdel func 20x\t", @:)
3391 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3392 call assert_equal("\"breakdel func Xbreak_func ", @:)
3393 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3394 call assert_equal("\"breakdel func X1B2C3", @:)
3395 delfunc Xbreak_func
3396
3397 " Test for :breakdel here
3398 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3399 call assert_equal("\"breakdel here Xtest", @:)
3400 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3401 call assert_equal("\"breakdel here Xtest", @:)
3402 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3403 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003404endfunc
3405
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003406" Test for :scriptnames argument completion
3407func Test_cmdline_complete_scriptnames()
3408 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003409 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003410 source Xa1b2c3.vim
3411 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3412 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3413 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3414 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3415 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3416 call assert_equal("\"script b2c3", @:)
3417 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3418 call assert_match("\"script 2\<Tab>$", @:)
3419 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3420 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3421 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3422 call assert_equal("\"script ", @:)
3423 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3424 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3425 new
3426 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3427 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3428 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003429 set wildmenu&
3430endfunc
3431
Bram Moolenaard8893442022-05-06 20:38:47 +01003432" this was going over the end of IObuff
3433func Test_report_error_with_composing()
3434 let caught = 'no'
3435 try
3436 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3437 catch /E492:/
3438 let caught = 'yes'
3439 endtry
3440 call assert_equal('yes', caught)
3441endfunc
3442
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003443" Test for expanding 2-letter and 3-letter :substitute command arguments.
3444" These commands don't accept an argument.
3445func Test_cmdline_complete_substitute_short()
3446 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3447 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3448 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3449 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3450 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3451 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3452 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3453 endfor
3454endfunc
3455
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003456" Test for :! shell command argument completion
3457func Test_cmdline_complete_bang_cmd_argument()
3458 set wildoptions=fuzzy
3459 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3460 call assert_equal('"!vim test_cmdline.vim', @:)
3461 set wildoptions&
3462 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3463 call assert_equal('"!vim test_cmdline.vim', @:)
3464endfunc
3465
zeertzjq961b2e52023-04-17 15:53:24 +01003466func Call_cmd_funcs()
3467 return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003468endfunc
3469
3470func Test_screenpos_and_completion()
zeertzjq961b2e52023-04-17 15:53:24 +01003471 call assert_equal(0, getcmdpos())
3472 call assert_equal(0, getcmdscreenpos())
3473 call assert_equal('', getcmdcompltype())
3474
3475 cnoremap <expr> <F2> string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()])
3476 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
3477 call assert_equal("\"let a[6, 7, 'var']", @:)
3478 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
3479 call assert_equal("\"quit [6, 7, '']", @:)
3480 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
3481 call assert_equal("\"nosuchcommand [15, 16, '']", @:)
3482 cunmap <F2>
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003483endfunc
3484
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003485func Test_recursive_register()
3486 let @= = ''
3487 silent! ?e/
3488 let caught = 'no'
3489 try
3490 normal //
3491 catch /E169:/
3492 let caught = 'yes'
3493 endtry
3494 call assert_equal('yes', caught)
3495endfunc
3496
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003497func Test_long_error_message()
3498 " the error should be truncated, not overrun IObuff
3499 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3500endfunc
3501
zeertzjq6791adc2022-07-26 20:42:25 +01003502func Test_cmdline_redraw_tabline()
3503 CheckRunVimInTerminal
3504
3505 let lines =<< trim END
3506 set showtabline=2
3507 autocmd CmdlineEnter * set tabline=foo
3508 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003509 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003510 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3511 call term_sendkeys(buf, ':')
3512 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3513
3514 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003515endfunc
3516
zeertzjqb82a2ab2022-08-21 14:33:57 +01003517func Test_wildmenu_pum_disable_while_shown()
3518 set wildoptions=pum
3519 set wildmenu
3520 cnoremap <F2> <Cmd>set nowildmenu<CR>
3521 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3522 call assert_equal(0, pumvisible())
3523 cunmap <F2>
3524 set wildoptions& wildmenu&
3525endfunc
3526
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003527func Test_setcmdline()
3528 func SetText(text, pos)
zeertzjqac6cd312023-04-12 16:21:14 +01003529 call assert_equal(0, setcmdline(test_null_string()))
3530 call assert_equal('', getcmdline())
3531 call assert_equal(1, getcmdpos())
3532
3533 call assert_equal(0, setcmdline(''[: -1]))
3534 call assert_equal('', getcmdline())
3535 call assert_equal(1, getcmdpos())
3536
zeertzjq54acb902022-08-29 16:21:25 +01003537 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003538 call assert_equal(0, setcmdline(a:text))
3539 call assert_equal(a:text, getcmdline())
3540 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003541 call assert_equal(getcmdtype(), g:cmdtype)
3542 unlet g:cmdtype
3543 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003544
3545 call assert_equal(0, setcmdline(a:text, a:pos))
3546 call assert_equal(a:text, getcmdline())
3547 call assert_equal(a:pos, getcmdpos())
3548
3549 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003550 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3551 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003552
3553 return ''
3554 endfunc
3555
3556 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3557 call assert_equal('set rtp?', @:)
3558
zeertzjq54acb902022-08-29 16:21:25 +01003559 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3560 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3561 call assert_equal('foo', g:str)
3562 unlet g:str
3563
3564 delfunc SetText
3565
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003566 " setcmdline() returns 1 when not editing the command line.
3567 call assert_equal(1, 'foo'->setcmdline())
3568
3569 " Called in custom function
3570 func CustomComplete(A, L, P)
3571 call assert_equal(0, setcmdline("DoCmd "))
3572 return "January\nFebruary\nMars\n"
3573 endfunc
3574
3575 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3576 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3577 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003578 delcom DoCmd
3579 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003580
3581 " Called in <expr>
3582 cnoremap <expr>a setcmdline('let foo=')
3583 call feedkeys(":a\<CR>", 'tx')
3584 call assert_equal('let foo=0', @:)
3585 cunmap a
3586endfunc
3587
Sean Dewarfc8a6012023-04-17 16:41:20 +01003588func Test_rulerformat_position()
3589 CheckScreendump
3590
3591 let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
3592 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
3593 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
3594 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
3595 call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
3596
3597 " clean up
3598 call StopVimInTerminal(buf)
3599endfunc
3600
zeertzjqe4c79d32023-08-15 22:41:53 +02003601func Test_getcompletion_usercmd()
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003602 command! -nargs=* -complete=command TestCompletion echo <q-args>
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003603
zeertzjqe4c79d32023-08-15 22:41:53 +02003604 call assert_equal(getcompletion('', 'cmdline'),
3605 \ getcompletion('TestCompletion ', 'cmdline'))
3606 call assert_equal(['<buffer>'],
3607 \ getcompletion('TestCompletion map <bu', 'cmdline'))
3608
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003609 delcom TestCompletion
Christian Brabandt8ef1fbc2023-07-17 20:09:37 +02003610endfunc
zeertzjqe4c79d32023-08-15 22:41:53 +02003611
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003612func Test_custom_completion()
3613 func CustomComplete1(lead, line, pos)
3614 return "a\nb\nc"
3615 endfunc
3616 func CustomComplete2(lead, line, pos)
3617 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
3618 endfunc
3619 func Check_custom_completion()
3620 call assert_equal('custom,CustomComplete1', getcmdcompltype())
3621 return ''
3622 endfunc
3623 func Check_customlist_completion()
3624 call assert_equal('customlist,CustomComplete2', getcmdcompltype())
3625 return ''
3626 endfunc
3627
3628 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
3629 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
3630
3631 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
3632 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
3633
3634 call assert_fails("call getcompletion('', 'custom')", 'E475:')
3635 call assert_fails("call getcompletion('', 'customlist')", 'E475:')
3636
3637 call assert_equal(getcompletion('', 'custom,CustomComplete1'), ['a', 'b', 'c'])
3638 call assert_equal(getcompletion('', 'customlist,CustomComplete2'), ['a', 'b'])
3639 call assert_equal(getcompletion('b', 'customlist,CustomComplete2'), ['b'])
3640
3641 delcom Test1
3642 delcom Test2
3643
3644 delfunc CustomComplete1
3645 delfunc CustomComplete2
3646 delfunc Check_custom_completion
3647 delfunc Check_customlist_completion
3648endfunc
3649
zeertzjq28a23602023-09-29 19:58:35 +02003650func Test_custom_completion_with_glob()
3651 func TestGlobComplete(A, L, P)
3652 return split(glob('Xglob*'), "\n")
3653 endfunc
3654
3655 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
3656 call writefile([], 'Xglob1', 'D')
3657 call writefile([], 'Xglob2', 'D')
3658
3659 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
3660 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
3661
3662 delcommand TestGlobComplete
3663 delfunc TestGlobComplete
3664endfunc
3665
Bram Moolenaar309976e2019-12-05 18:16:33 +01003666" vim: shiftwidth=2 sts=2 expandtab