blob: 9eca9186fa9b265a45841ff07975207be5dd5fc6 [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 Moolenaard4cf9fc2022-08-11 14:13:37 +0100277 " reducing window size and then setting cmdheight
278 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(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200330 unmap ,f
331 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200332 unmap <Left>
333 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200334
335 set cpo-=< cpo-=B cpo-=k
336 map <Left> left
337 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200339 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200340 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200341 unmap <Left>
342
343 set cpo+=<
344 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200345 exe "set t_k6=\<Esc>[17~"
346 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200347 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200349 if !has('gui_running')
350 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
351 call assert_equal("\"map <F6>x", getreg(':'))
352 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200353 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200354 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200355 set cpo-=<
356
357 set cpo+=B
358 map <Left> left
359 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"map <Left>', getreg(':'))
361 unmap <Left>
362 set cpo-=B
363
364 set cpo+=k
365 map <Left> left
366 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal('"map <Left>', getreg(':'))
368 unmap <Left>
369 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370
Bram Moolenaar531be472020-09-23 22:38:05 +0200371 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
372
Bram Moolenaar1776a282019-05-03 16:05:41 +0200373 unmap <Middle>x
374 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100375endfunc
376
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100377func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100378 hi Aardig ctermfg=green
379 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000380 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000382 call assert_equal('"match none', @:)
383 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
384 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385endfunc
386
387func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100388 hi Aardig ctermfg=green
389 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200391 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"hi default Aardig', getreg(':'))
393 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100395 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi link', getreg(':'))
397 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi default', getreg(':'))
399 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200401 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
402 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
403 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
404 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200405
406 " A cleared group does not show up in completions.
407 hi Anders ctermfg=green
408 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
409 hi clear Aardig
410 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
411 hi clear Anders
412 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100413endfunc
414
Bram Moolenaar75e15672020-06-28 13:10:22 +0200415" Test for command-line expansion of "hi Ni " (easter egg)
416func Test_highlight_easter_egg()
417 call test_override('ui_delay', 1)
418 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"hi Ni \<Tab>", @:)
420 call test_override('ALL', 0)
421endfunc
422
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200423func Test_getcompletion()
424 let groupcount = len(getcompletion('', 'event'))
425 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200426 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427 call assert_true(matchcount > 0)
428 call assert_true(groupcount > matchcount)
429
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200430 if has('menu')
431 source $VIMRUNTIME/menu.vim
432 let matchcount = len(getcompletion('', 'menu'))
433 call assert_true(matchcount > 0)
434 call assert_equal(['File.'], getcompletion('File', 'menu'))
435 call assert_true(matchcount > 0)
436 let matchcount = len(getcompletion('File.', 'menu'))
437 call assert_true(matchcount > 0)
438 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200439
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200440 let l = getcompletion('v:n', 'var')
441 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200442 let l = getcompletion('v:notexists', 'var')
443 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200444
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200445 args a.c b.c
446 let l = getcompletion('', 'arglist')
447 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000448 let l = getcompletion('a.', 'buffer')
449 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200450 %argdelete
451
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200452 let l = getcompletion('', 'augroup')
453 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200454 let l = getcompletion('blahblah', 'augroup')
455 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200456
457 let l = getcompletion('', 'behave')
458 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200459 let l = getcompletion('not', 'behave')
460 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200461
462 let l = getcompletion('', 'color')
463 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200464 let l = getcompletion('dirty', 'color')
465 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200466
467 let l = getcompletion('', 'command')
468 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200469 let l = getcompletion('awake', 'command')
470 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200471
472 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200473 call assert_true(index(l, 'samples/') >= 0)
474 let l = getcompletion('NoMatch', 'dir')
475 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200476
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100477 if glob('~/*') !=# ''
478 let l = getcompletion('~/', 'dir')
479 call assert_true(l[0][0] ==# '~')
480 endif
481
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200482 let l = getcompletion('exe', 'expression')
483 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200484 let l = getcompletion('kill', 'expression')
485 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200486
487 let l = getcompletion('tag', 'function')
488 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200489 let l = getcompletion('paint', 'function')
490 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200491
Kota Kato90c23532023-01-18 15:27:38 +0000492 if !has('ruby')
493 " global_functions[] has an entry but it doesn't have an implemention
494 let l = getcompletion('ruby', 'function')
495 call assert_equal([], l)
496 endif
497
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200498 let Flambda = {-> 'hello'}
499 let l = getcompletion('', 'function')
500 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200501 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200502
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200503 let l = getcompletion('run', 'file')
504 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200505 let l = getcompletion('walk', 'file')
506 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200507 set wildignore=*.vim
508 let l = getcompletion('run', 'file', 1)
509 call assert_true(index(l, 'runtest.vim') < 0)
510 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000511 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100512 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000513 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
514 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200515
516 let l = getcompletion('ha', 'filetype')
517 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200518 let l = getcompletion('horse', 'filetype')
519 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200520
521 let l = getcompletion('z', 'syntax')
522 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200523 let l = getcompletion('emacs', 'syntax')
524 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200525
526 let l = getcompletion('jikes', 'compiler')
527 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200528 let l = getcompletion('break', 'compiler')
529 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200530
531 let l = getcompletion('last', 'help')
532 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200533 let l = getcompletion('giveup', 'help')
534 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200535
536 let l = getcompletion('time', 'option')
537 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200538 let l = getcompletion('space', 'option')
539 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200540
541 let l = getcompletion('er', 'highlight')
542 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200543 let l = getcompletion('dark', 'highlight')
544 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200545
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200546 let l = getcompletion('', 'messages')
547 call assert_true(index(l, 'clear') >= 0)
548 let l = getcompletion('not', 'messages')
549 call assert_equal([], l)
550
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200551 let l = getcompletion('', 'mapclear')
552 call assert_true(index(l, '<buffer>') >= 0)
553 let l = getcompletion('not', 'mapclear')
554 call assert_equal([], l)
555
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200556 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200557 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200558 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
559 let root = has('win32') ? 'C:\\' : '/'
560 let l = getcompletion(root, 'shellcmd')
561 let expected = map(filter(glob(root . '*', 0, 1),
562 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
563 call assert_equal(expected, l)
564
Bram Moolenaarb650b982016-08-05 20:35:13 +0200565 if has('cscope')
566 let l = getcompletion('', 'cscope')
567 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
568 call assert_equal(cmds, l)
569 " using cmdline completion must not change the result
570 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
571 let l = getcompletion('', 'cscope')
572 call assert_equal(cmds, l)
573 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
574 let l = getcompletion('find ', 'cscope')
575 call assert_equal(keys, l)
576 endif
577
Bram Moolenaar7522f692016-08-06 14:12:50 +0200578 if has('signs')
579 sign define Testing linehl=Comment
580 let l = getcompletion('', 'sign')
581 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
582 call assert_equal(cmds, l)
583 " using cmdline completion must not change the result
584 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
585 let l = getcompletion('', 'sign')
586 call assert_equal(cmds, l)
587 let l = getcompletion('list ', 'sign')
588 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000589 let l = getcompletion('de*', 'sign')
590 call assert_equal(['define'], l)
591 let l = getcompletion('p?', 'sign')
592 call assert_equal(['place'], l)
593 let l = getcompletion('j.', 'sign')
594 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200595 endif
596
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200597 " Command line completion tests
598 let l = getcompletion('cd ', 'cmdline')
599 call assert_true(index(l, 'samples/') >= 0)
600 let l = getcompletion('cd NoMatch', 'cmdline')
601 call assert_equal([], l)
602 let l = getcompletion('let v:n', 'cmdline')
603 call assert_true(index(l, 'v:null') >= 0)
604 let l = getcompletion('let v:notexists', 'cmdline')
605 call assert_equal([], l)
606 let l = getcompletion('call tag', 'cmdline')
607 call assert_true(index(l, 'taglist(') >= 0)
608 let l = getcompletion('call paint', 'cmdline')
609 call assert_equal([], l)
610
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100611 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000612 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100613 return "oneA\noneB\noneC"
614 endfunc
615 command -nargs=1 -complete=custom,T MyCmd
616 let l = getcompletion('MyCmd ', 'cmdline')
617 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000618 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100619
620 delcommand MyCmd
621 delfunc T
ii144785fe02021-11-21 12:13:56 +0000622 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100623
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200624 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200625 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200626 if has('cmdline_hist')
627 call add(names, 'history')
628 endif
629 if has('gettext')
630 call add(names, 'locale')
631 endif
632 if has('profile')
633 call add(names, 'syntime')
634 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200635
636 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100637 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200638
639 for name in names
640 let matchcount = len(getcompletion('', name))
641 call assert_true(matchcount >= 0, 'No matches for ' . name)
642 endfor
643
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200644 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200645
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000646 edit a~b
647 enew
648 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
649 bw a~b
650
651 if has('unix')
652 edit Xtest\
653 enew
654 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
655 bw Xtest\
656 endif
657
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200658 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200659 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100660 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200661endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200662
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000663func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000664 " Get a dialog in the GUI
665 CheckNotGui
666
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000667 " This was using uninitialized memory.
668 let lines =<< trim END
669 set verbose=6
670 norm @=ٷ
671 qall!
672 END
673 call writefile(lines, 'XmultiScript', 'D')
674 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
675endfunc
676
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000677" Test for getcompletion() with "fuzzy" in 'wildoptions'
678func Test_getcompletion_wildoptions()
679 let save_wildoptions = &wildoptions
680 set wildoptions&
681 let l = getcompletion('space', 'option')
682 call assert_equal([], l)
683 let l = getcompletion('ier', 'command')
684 call assert_equal([], l)
685 set wildoptions=fuzzy
686 let l = getcompletion('space', 'option')
687 call assert_true(index(l, 'backspace') >= 0)
688 let l = getcompletion('ier', 'command')
689 call assert_true(index(l, 'compiler') >= 0)
690 let &wildoptions = save_wildoptions
691endfunc
692
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000693func Test_complete_autoload_error()
694 let save_rtp = &rtp
695 let lines =<< trim END
696 vim9script
697 export def Complete(..._): string
698 return 'match'
699 enddef
700 echo this will cause an error
701 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100702 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000703 call writefile(lines, 'Xdir/autoload/script.vim')
704 exe 'set rtp+=' .. getcwd() .. '/Xdir'
705
706 let lines =<< trim END
707 vim9script
708 import autoload 'script.vim'
709 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
710 &wildcharm = char2nr("\<Tab>")
711 feedkeys(":Cmd \<Tab>", 'xt')
712 END
713 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
714
715 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000716endfunc
717
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100718func Test_fullcommand()
719 let tests = {
720 \ '': '',
721 \ ':': '',
722 \ ':::': '',
723 \ ':::5': '',
724 \ 'not_a_cmd': '',
725 \ 'Check': '',
726 \ 'syntax': 'syntax',
727 \ ':syntax': 'syntax',
728 \ '::::syntax': 'syntax',
729 \ 'sy': 'syntax',
730 \ 'syn': 'syntax',
731 \ 'synt': 'syntax',
732 \ ':sy': 'syntax',
733 \ '::::sy': 'syntax',
734 \ 'match': 'match',
735 \ '2match': 'match',
736 \ '3match': 'match',
737 \ 'aboveleft': 'aboveleft',
738 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100739 \ 'en': 'endif',
740 \ 'end': 'endif',
741 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100742 \ 's': 'substitute',
743 \ '5s': 'substitute',
744 \ ':5s': 'substitute',
745 \ "'<,'>s": 'substitute',
746 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100747 \ 'CheckLin': 'CheckLinux',
748 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100749 \ }
750
751 for [in, want] in items(tests)
752 call assert_equal(want, fullcommand(in))
753 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200754 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100755
756 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200757
758 command -buffer BufferLocalCommand :
759 command GlobalCommand :
760 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
761 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
762 delcommand BufferLocalCommand
763 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100764endfunc
765
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200766func Test_shellcmd_completion()
767 let save_path = $PATH
768
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100769 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200770 call writefile([''], 'Xpathdir/Xfile.exe')
771 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
772
773 " Set PATH to example directory without trailing slash.
774 let $PATH = getcwd() . '/Xpathdir'
775
776 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
777 " dirs in the PATH, even though they won't be executed. We check that only
778 " subdirs of the PWD and executables from the PATH are included in the
779 " suggestions.
780 let actual = getcompletion('X', 'shellcmd')
781 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
782 call insert(expected, 'Xfile.exe')
783 call assert_equal(expected, actual)
784
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200785 let $PATH = save_path
786endfunc
787
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200788func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100789 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200790 call writefile(['asdfasdf'], 'a/b/fileXname')
791 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000792 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200793 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200794endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100795
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100796func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100797 let @a = "def"
798 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
799 call assert_equal('"abc def ghi', @:)
800
801 new
802 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
803
804 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
805 call assert_equal('"aaa asdf bbb', @:)
806
807 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
808 call assert_equal('"aaa /tmp/some bbb', @:)
809
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200810 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
811 call assert_equal('"aaa '.getline(1).' bbb', @:)
812
Bram Moolenaar21efc362016-12-03 14:05:49 +0100813 set incsearch
814 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
815 call assert_equal('"aaa verylongword bbb', @:)
816
817 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
818 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100819
820 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
821 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100822 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200823
824 " Error while typing a command used to cause that it was not executed
825 " in the end.
826 new
827 try
828 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
829 catch /^Vim\%((\a\+)\)\=:E32/
830 " ignore error E32
831 endtry
832 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100833
Bram Moolenaar578fe942020-02-27 21:32:51 +0100834 " Try to paste an invalid register using <C-R>
835 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
836 call assert_equal('"onetwo', @:)
837
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100838 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100839 let @a = "xy\<C-H>z"
840 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
841 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100842 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
843 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100844 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
845 call assert_equal("\"xy\<C-H>z", @:)
846
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100847 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
848 let @a = "xy\<C-V>z"
849 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
850 call assert_equal('"xyz', @:)
851 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
852 call assert_equal("\"xy\<C-V>z", @:)
853
Bram Moolenaar578fe942020-02-27 21:32:51 +0100854 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
855
Bram Moolenaar72532d32018-04-07 19:09:09 +0200856 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100857endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100858
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100859func Test_cmdline_remove_char()
860 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100861
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100862 for e in ['utf8', 'latin1']
863 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100864
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100865 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
866 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100867
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100868 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
869 call assert_equal('"abcdef', @:)
870
871 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
872 call assert_equal('"abc ghi', @:, e)
873
874 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
875 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100876
877 " This was going before the start in latin1.
878 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100879 endfor
880
881 let &encoding = encoding_save
882endfunc
883
884func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200885 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100886
887 set keymap=esperanto
888 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
889 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
890 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100891endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100892
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100893func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100894 new
895 2;'(
896 2;')
897 quit
898endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100899
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100900func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100901 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100902 new
903 source Xtest.vim
904 " Trigger calling validate_cursor()
905 diffsp Xtest.vim
906 quit!
907 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100908endfunc
909
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100910func Test_mark_from_line_zero()
911 " this was reading past the end of the first (empty) line
912 new
913 norm oxxxx
914 call assert_fails("0;'(", 'E20:')
915 bwipe!
916endfunc
917
Bram Moolenaarba47b512017-01-24 21:18:19 +0100918func Test_cmdline_complete_wildoptions()
919 help
920 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
921 let a = join(sort(split(@:)),' ')
922 set wildoptions=tagfile
923 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
924 let b = join(sort(split(@:)),' ')
925 call assert_equal(a, b)
926 bw!
927endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100928
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200929func Test_cmdline_complete_user_cmd()
930 command! -complete=color -nargs=1 Foo :
931 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
932 call assert_equal('"Foo blue', @:)
933 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
934 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000935 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
936 call assert_equal('"Foo a blue', @:)
937 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
938 call assert_equal('"Foo b\', @:)
939 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
940 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200941 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100942
943 redraw
944 call assert_equal('~', Screenline(&lines - 1))
945 command! FooOne :
946 command! FooTwo :
947
948 set nowildmenu
949 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
950 call assert_equal('"FooOne', @:)
951 call assert_equal('~', Screenline(&lines - 1))
952
953 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
954 call assert_equal('"FooTwo', @:)
955 call assert_equal('~', Screenline(&lines - 1))
956
957 delcommand FooOne
958 delcommand FooTwo
959 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200960endfunc
961
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100962func Test_complete_user_cmd()
963 command FooBar echo 'global'
964 command -buffer FooBar echo 'local'
965 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
966 call assert_equal('"FooBar', @:)
967
968 delcommand -buffer FooBar
969 delcommand FooBar
970endfunc
971
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100972func s:ScriptLocalFunction()
973 echo 'yes'
974endfunc
975
976func Test_cmdline_complete_user_func()
977 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200978 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100979 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
980 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100981
982 " g: prefix also works
983 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
984 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200985
986 " using g: prefix does not result in just "g:" matches from a lambda
987 let Fx = { a -> a }
988 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
989 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200990
991 " existence of script-local dict function does not break user function name
992 " completion
993 function s:a_dict_func() dict
994 endfunction
995 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
996 call assert_match('"call Test_cmdline_complete_user_', @:)
997 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100998endfunc
999
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001000func Test_cmdline_complete_user_names()
1001 if has('unix') && executable('whoami')
1002 let whoami = systemlist('whoami')[0]
1003 let first_letter = whoami[0]
1004 if len(first_letter) > 0
1005 " Trying completion of :e ~x where x is the first letter of
1006 " the user name should complete to at least the user name.
1007 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1008 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1009 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001010 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001011 " Just in case: check that the system has an Administrator account.
1012 let names = system('net user')
1013 if names =~ 'Administrator'
1014 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001015 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001016 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001017 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001018 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001019 else
1020 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001021 endif
1022endfunc
1023
Bram Moolenaar297610b2019-12-27 17:20:55 +01001024func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001025 CheckExecutable whoami
1026 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1027 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001028endfunc
1029
Bram Moolenaar8b633132020-03-20 18:20:51 +01001030func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001031 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1032 call assert_equal(lang, v:lc_time)
1033
1034 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1035 call assert_equal(lang, v:ctype)
1036
1037 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1038 call assert_equal(lang, v:collate)
1039
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001040 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001041 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001042
1043 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001044 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001045
Bram Moolenaarec680282020-06-12 19:35:32 +02001046 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001047
Bram Moolenaarec680282020-06-12 19:35:32 +02001048 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1049 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001050
Bram Moolenaarec680282020-06-12 19:35:32 +02001051 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1052 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001053
Bram Moolenaarec680282020-06-12 19:35:32 +02001054 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1055 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001056
1057 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1058 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001059endfunc
1060
Bram Moolenaar297610b2019-12-27 17:20:55 +01001061func Test_cmdline_complete_env_variable()
1062 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001063 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1064 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001065 unlet $X_VIM_TEST_COMPLETE_ENV
1066endfunc
1067
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001068func Test_cmdline_complete_expression()
1069 let g:SomeVar = 'blah'
1070 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1071 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1072 call assert_match('"' .. cmd .. ' SomeVar', @:)
1073 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1074 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1075 endfor
1076 unlet g:SomeVar
1077endfunc
1078
Bram Moolenaar47016f52021-08-26 16:39:58 +02001079" Unique function name for completion below
1080func s:WeirdFunc()
1081 echo 'weird'
1082endfunc
1083
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001084" Test for various command-line completion
1085func Test_cmdline_complete_various()
1086 " completion for a command starting with a comment
1087 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1088 call assert_equal("\" :|\"\<C-A>", @:)
1089
1090 " completion for a range followed by a comment
1091 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1092 call assert_equal("\"1,2\"\<C-A>", @:)
1093
1094 " completion for :k command
1095 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1096 call assert_equal("\"ka\<C-A>", @:)
1097
1098 " completion for short version of the :s command
1099 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1100 call assert_equal("\"sI \<C-A>", @:)
1101
1102 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001103 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001104 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001105 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001106 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001107 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1108 call assert_equal("\"w >> Xfile1", @:)
1109 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001110
1111 " completion for :w ! and :r ! commands
1112 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1113 call assert_equal("\"w !invalid_xyz_cmd", @:)
1114 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"r !invalid_xyz_cmd", @:)
1116
1117 " completion for :>> and :<< commands
1118 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1119 call assert_equal("\">>>\<C-A>", @:)
1120 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1121 call assert_equal("\"<<<\<C-A>", @:)
1122
1123 " completion for command with +cmd argument
1124 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1125 call assert_equal("\"buffer +/pat Xabc", @:)
1126 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1127 call assert_equal("\"buffer +/pat\<C-A>", @:)
1128
1129 " completion for a command with a trailing comment
1130 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"ls \" comment\<C-A>", @:)
1132
1133 " completion for a command with a trailing command
1134 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1135 call assert_equal("\"ls | ls", @:)
1136
1137 " completion for a command with an CTRL-V escaped argument
1138 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1140
1141 " completion for a command that doesn't take additional arguments
1142 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1143 call assert_equal("\"all abc\<C-A>", @:)
1144
zeertzjqd3de1782022-09-01 12:58:52 +01001145 " completion for :wincmd with :horizontal modifier
1146 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1147 call assert_equal("\"horizontal wincmd", @:)
1148
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001149 " completion for a command with a command modifier
1150 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1151 call assert_equal("\"topleft new", @:)
1152
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001153 " completion for vim9 and legacy commands
1154 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1155 call assert_equal("\"vim9 call strlen(", @:)
1156 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1157 call assert_equal("\"legac call strlen(", @:)
1158
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001159 " completion for the :disassemble command
1160 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1161 call assert_equal("\"disas debug", @:)
1162 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1163 call assert_equal("\"disas profile", @:)
1164 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1165 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1166 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1167 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001168 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1169 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001170
Bram Moolenaar47016f52021-08-26 16:39:58 +02001171 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001172 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001173
naohiro onodfe04db2021-09-12 15:45:10 +02001174 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1175 call assert_match('"disas <SNR>\d\+_', @:)
1176 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1177 call assert_match('"disas debug <SNR>\d\+_', @:)
1178
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001179 " completion for the :match command
1180 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1181 call assert_equal("\"match Search /pat/\<C-A>", @:)
1182
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001183 " completion for the :doautocmd command
1184 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1185 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1186
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001187 " completion of autocmd group after comma
1188 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1189 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1190
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001191 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001192 call writefile([], 'Xvarfile1', 'D')
1193 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001194 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1195 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001196
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001197 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001198 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001199 augroup END
1200 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001201 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001202
1203 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001204 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1205 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001206 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1207 call assert_equal("\"au XTest.test", @:)
1208
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001209 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001210
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001211 " autocmd pattern completion
1212 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1213 call assert_equal("\"au BufEnter *.py\t", @:)
1214
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001215 " completion for the :unlet command
1216 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1217 call assert_equal("\"unlet one two", @:)
1218
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001219 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001220 " FIXME: what should happen on MS-Windows?
1221 if !has('win32')
1222 edit \{someFile}
1223 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1224 call assert_equal("\"buf {someFile}", @:)
1225 bwipe {someFile}
1226 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001227
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001228 " completion for the :bdelete command
1229 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1230 call assert_equal("\"bdel a b c", @:)
1231
1232 " completion for the :mapclear command
1233 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1234 call assert_equal("\"mapclear <buffer>", @:)
1235
1236 " completion for user defined commands with menu names
1237 menu Test.foo :ls<CR>
1238 com -nargs=* -complete=menu MyCmd
1239 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1240 call assert_equal('"MyCmd Test.', @:)
1241 delcom MyCmd
1242 unmenu Test
1243
1244 " completion for user defined commands with mappings
1245 mapclear
1246 map <F3> :ls<CR>
1247 com -nargs=* -complete=mapping MyCmd
1248 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001249 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001250 mapclear
1251 delcom MyCmd
1252
1253 " completion for :set path= with multiple backslashes
1254 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1255 call assert_equal('"set path=a\\\ b', @:)
1256
1257 " completion for :set dir= with a backslash
1258 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1259 call assert_equal('"set dir=a\ b', @:)
1260
1261 " completion for the :py3 commands
1262 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1263 call assert_equal('"py3 py3do py3file', @:)
1264
Bram Moolenaardf749a22021-03-28 15:29:43 +02001265 " completion for the :vim9 commands
1266 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1267 call assert_equal('"vim9cmd vim9script', @:)
1268
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001269 " redir @" is not the start of a comment. So complete after that
1270 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1271 call assert_equal('"redir @" | cwindow', @:)
1272
1273 " completion after a backtick
1274 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1275 call assert_equal('"e `a1b2c', @:)
1276
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001277 " completion for :language command with an invalid argument
1278 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1279 call assert_equal("\"language dummy \t", @:)
1280
1281 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001282 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1283 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001284
1285 " completion with ambiguous user defined commands
1286 com TCmd1 echo 'TCmd1'
1287 com TCmd2 echo 'TCmd2'
1288 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1289 call assert_equal('"TCmd ', @:)
1290 delcom TCmd1
1291 delcom TCmd2
1292
1293 " completion after a range followed by a pipe (|) character
1294 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1295 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001296
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001297 " completion after a :global command
1298 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1299 call assert_equal('"g/a/chistory', @:)
1300 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1301 call assert_equal("\"g/a\\/chist\t", @:)
1302
Bram Moolenaar9c929712020-09-07 22:05:28 +02001303 " use <Esc> as the 'wildchar' for completion
1304 set wildchar=<Esc>
1305 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1306 call assert_equal('"g/a\xb/clearjumps', @:)
1307 " pressing <esc> twice should cancel the command
1308 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1309 call assert_equal('"g/a\xb/clearjumps', @:)
1310 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001311
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001312 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001313 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001314 call writefile([], '~Xtest')
1315 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1316 call assert_equal('"e \~Xtest', @:)
1317 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001318
1319 " should be able to complete a file name that has a '*'
1320 call writefile([], 'Xx*Yy')
1321 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1322 call assert_equal('"e Xx\*Yy', @:)
1323 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001324
1325 " use a literal star
1326 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1327 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001328 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001329
1330 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1331 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001332endfunc
1333
1334" Test for 'wildignorecase'
1335func Test_cmdline_wildignorecase()
1336 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001337 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001338 set wildignorecase
1339 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1340 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001341 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001342 let g:Sline = ''
1343 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1344 call assert_equal('"e xt', @:)
1345 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001346 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001347endfunc
1348
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001349func Test_cmdline_write_alternatefile()
1350 new
1351 call setline('.', ['one', 'two'])
1352 f foo.txt
1353 new
1354 f #-A
1355 call assert_equal('foo.txt-A', expand('%'))
1356 f #<-B.txt
1357 call assert_equal('foo-B.txt', expand('%'))
1358 f %<
1359 call assert_equal('foo-B', expand('%'))
1360 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001361 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001362 bw!
1363 f foo-B.txt
1364 f %<-A
1365 call assert_equal('foo-B-A', expand('%'))
1366 bw!
1367 bw!
1368endfunc
1369
Bram Moolenaarf5724372022-09-02 19:45:15 +01001370func Test_cmdline_expand_cur_alt_file()
1371 enew
1372 file http://some.com/file.txt
1373 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1374 call assert_equal('"e http://some.com/file.txt', @:)
1375 edit another
1376 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1377 call assert_equal('"e http://some.com/file.txt', @:)
1378 bwipe
1379 bwipe http://some.com/file.txt
1380endfunc
1381
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001382" using a leading backslash here
1383set cpo+=C
1384
1385func Test_cmdline_search_range()
1386 new
1387 call setline(1, ['a', 'b', 'c', 'd'])
1388 /d
1389 1,\/s/b/B/
1390 call assert_equal('B', getline(2))
1391
1392 /a
1393 $
1394 \?,4s/c/C/
1395 call assert_equal('C', getline(3))
1396
1397 call setline(1, ['a', 'b', 'c', 'd'])
1398 %s/c/c/
1399 1,\&s/b/B/
1400 call assert_equal('B', getline(2))
1401
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001402 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001403 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001404
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001405 bwipe!
1406endfunc
1407
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001408" Test for the tick mark (') in an excmd range
1409func Test_tick_mark_in_range()
1410 " If only the tick is passed as a range and no command is specified, there
1411 " should not be an error
1412 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001413 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001414 call assert_fails("',print", 'E78:')
1415endfunc
1416
1417" Test for using a line number followed by a search pattern as range
1418func Test_lnum_and_pattern_as_range()
1419 new
1420 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1421 let @" = ''
1422 2/foo/yank
1423 call assert_equal("foo 3\n", @")
1424 call assert_equal(1, line('.'))
1425 close!
1426endfunc
1427
Bram Moolenaar65189a12017-02-06 22:22:17 +01001428" Tests for getcmdline(), getcmdpos() and getcmdtype()
1429func Check_cmdline(cmdtype)
1430 call assert_equal('MyCmd a', getcmdline())
1431 call assert_equal(8, getcmdpos())
1432 call assert_equal(a:cmdtype, getcmdtype())
1433 return ''
1434endfunc
1435
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001436set cpo&
1437
Bram Moolenaar65189a12017-02-06 22:22:17 +01001438func Test_getcmdtype()
1439 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1440
1441 let cmdtype = ''
1442 debuggreedy
1443 call feedkeys(":debug echo 'test'\<CR>", "t")
1444 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1445 call feedkeys("cont\<CR>", "xt")
1446 0debuggreedy
1447 call assert_equal('>', cmdtype)
1448
1449 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1450 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1451
1452 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001453 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001454
1455 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1456
1457 cnoremap <expr> <F6> Check_cmdline('=')
1458 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1459 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001460
1461 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001462endfunc
1463
Bram Moolenaar52604f22017-04-07 16:17:39 +02001464func Test_verbosefile()
1465 set verbosefile=Xlog
1466 echomsg 'foo'
1467 echomsg 'bar'
1468 set verbosefile=
1469 let log = readfile('Xlog')
1470 call assert_match("foo\nbar", join(log, "\n"))
1471 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001472
1473 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001474 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001475endfunc
1476
Bram Moolenaar4facea32019-10-12 20:17:40 +02001477func Test_verbose_option()
1478 CheckScreendump
1479
1480 let lines =<< trim [SCRIPT]
1481 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1482 call feedkeys("\r", 't') " for the hit-enter prompt
1483 set verbose=20
1484 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001485 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001486
1487 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001488 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001489 call term_sendkeys(buf, ":DoSomething\<CR>")
1490 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1491
1492 " clean up
1493 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001494endfunc
1495
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001496func Test_setcmdpos()
1497 func InsertTextAtPos(text, pos)
1498 call assert_equal(0, setcmdpos(a:pos))
1499 return a:text
1500 endfunc
1501
1502 " setcmdpos() with position in the middle of the command line.
1503 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1504 call assert_equal('"1ab2', @:)
1505
1506 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1507 call assert_equal('"1b2a', @:)
1508
1509 " setcmdpos() with position beyond the end of the command line.
1510 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1511 call assert_equal('"12ab', @:)
1512
1513 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001514 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001515endfunc
1516
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001517func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001518 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001519 let encoding_save = &encoding
1520
1521 for e in encodings
1522 exe 'set encoding=' . e
1523
1524 " Test overstrike in the middle of the command line.
1525 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001526 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001527
1528 " Test overstrike going beyond end of command line.
1529 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001530 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001531
1532 " Test toggling insert/overstrike a few times.
1533 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001534 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001535 endfor
1536
Bram Moolenaar30276f22019-01-24 17:59:39 +01001537 " Test overstrike with multi-byte characters.
1538 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001539 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001540
1541 let &encoding = encoding_save
1542endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001543
Bram Moolenaar52410572019-10-27 05:12:45 +01001544func Test_buffers_lastused()
1545 " check that buffers are sorted by time when wildmode has lastused
1546 call test_settime(1550020000) " middle
1547 edit bufa
1548 enew
1549 call test_settime(1550030000) " newest
1550 edit bufb
1551 enew
1552 call test_settime(1550010000) " oldest
1553 edit bufc
1554 enew
1555 call test_settime(0)
1556 enew
1557
1558 call assert_equal(['bufa', 'bufb', 'bufc'],
1559 \ getcompletion('', 'buffer'))
1560
1561 let save_wildmode = &wildmode
1562 set wildmode=full:lastused
1563
1564 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1565 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1566 call assert_equal('b bufb', X)
1567 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1568 call assert_equal('b bufa', X)
1569 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1570 call assert_equal('b bufc', X)
1571 enew
1572
1573 edit other
1574 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1575 call assert_equal('b bufb', X)
1576 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1577 call assert_equal('b bufa', X)
1578 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1579 call assert_equal('b bufc', X)
1580 enew
1581
1582 let &wildmode = save_wildmode
1583
1584 bwipeout bufa
1585 bwipeout bufb
1586 bwipeout bufc
1587endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001588
Bram Moolenaar479950f2020-01-19 15:45:17 +01001589func Test_cmdlineclear_tabenter()
1590 CheckScreendump
1591
1592 let lines =<< trim [SCRIPT]
1593 call setline(1, range(30))
1594 [SCRIPT]
1595
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001596 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001597 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001598 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001599 " in one tab make the command line higher with CTRL-W -
1600 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1601 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1602
1603 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001604endfunc
1605
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001606" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001607func Test_cmdline_expand_special()
1608 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001609 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001610 call assert_fails('e <afile>', 'E495:')
1611 call assert_fails('e <abuf>', 'E496:')
1612 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001613
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001614 call writefile([], 'Xfile.cpp', 'D')
1615 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001616 new Xfile.cpp
1617 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1618 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1619 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001620endfunc
1621
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001622" Test for backtick expression in the command line
1623func Test_cmd_backtick()
1624 %argd
1625 argadd `=['a', 'b', 'c']`
1626 call assert_equal(['a', 'b', 'c'], argv())
1627 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001628
1629 argadd `echo abc def`
1630 call assert_equal(['abc def'], argv())
1631 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001632endfunc
1633
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001634" Test for the :! command
1635func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001636 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001637
1638 let lines =<< trim [SCRIPT]
1639 " Test for no previous command
1640 call assert_fails('!!', 'E34:')
1641 set nomore
1642 " Test for cmdline expansion with :!
1643 call setline(1, 'foo!')
1644 silent !echo <cWORD> > Xfile.out
1645 call assert_equal(['foo!'], readfile('Xfile.out'))
1646 " Test for using previous command
1647 silent !echo \! !
1648 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1649 call writefile(v:errors, 'Xresult')
1650 call delete('Xfile.out')
1651 qall!
1652 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001653 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001654 if RunVim([], [], '--clean -S Xscript')
1655 call assert_equal([], readfile('Xresult'))
1656 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001657 call delete('Xresult')
1658endfunc
1659
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001660" Test error: "E135: *Filter* Autocommands must not change current buffer"
1661func Test_cmd_bang_E135()
1662 new
1663 call setline(1, ['a', 'b', 'c', 'd'])
1664 augroup test_cmd_filter_E135
1665 au!
1666 autocmd FilterReadPost * help
1667 augroup END
1668 call assert_fails('2,3!echo "x"', 'E135:')
1669
1670 augroup test_cmd_filter_E135
1671 au!
1672 augroup END
1673 %bwipe!
1674endfunc
1675
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001676func Test_cmd_bang_args()
1677 new
1678 :.!
1679 call assert_equal(0, v:shell_error)
1680
1681 " Note that below there is one space char after the '!'. This caused a
1682 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1683 :.!
1684 call assert_equal(0, v:shell_error)
1685 bwipe!
1686
1687 CheckUnix
1688 :.!pwd
1689 call assert_equal(0, v:shell_error)
1690 :.! pwd
1691 call assert_equal(0, v:shell_error)
1692
1693 " Note there is one space after 'pwd'.
1694 :.! pwd
1695 call assert_equal(0, v:shell_error)
1696
1697 " Note there are two spaces after 'pwd'.
1698 :.! pwd
1699 call assert_equal(0, v:shell_error)
1700 :.!ls ~
1701 call assert_equal(0, v:shell_error)
1702
1703 " Note there is one space char after '~'.
1704 :.!ls ~
1705 call assert_equal(0, v:shell_error)
1706
1707 " Note there are two spaces after '~'.
1708 :.!ls ~
1709 call assert_equal(0, v:shell_error)
1710
1711 :.!echo "foo"
1712 call assert_equal(getline('.'), "foo")
1713 :.!echo "foo "
1714 call assert_equal(getline('.'), "foo ")
1715 :.!echo " foo "
1716 call assert_equal(getline('.'), " foo ")
1717 :.!echo " foo "
1718 call assert_equal(getline('.'), " foo ")
1719
1720 %bwipe!
1721endfunc
1722
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001723" Test for using ~ for home directory in cmdline completion matches
1724func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001725 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001726 call writefile([], 'Xexpdir/Xfile1')
1727 call writefile([], 'Xexpdir/Xfile2')
1728 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001729 let save_HOME = $HOME
1730 let $HOME = getcwd()
1731 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1732 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1733 let $HOME = save_HOME
1734 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001735endfunc
1736
Bram Moolenaar578fe942020-02-27 21:32:51 +01001737" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1738" or insert mode (when 'insertmode' is set)
1739func Test_cmdline_ctrl_g()
1740 new
1741 call setline(1, 'abc')
1742 call cursor(1, 3)
1743 " If command line is entered from insert mode, using C-\ C-G should back to
1744 " insert mode
1745 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1746 call assert_equal('abxyc', getline(1))
1747 call assert_equal(4, col('.'))
1748
1749 " If command line is entered in 'insertmode', using C-\ C-G should back to
1750 " 'insertmode'
1751 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1752 call assert_equal('ab12xyc', getline(1))
1753 close!
1754endfunc
1755
Bram Moolenaar578fe942020-02-27 21:32:51 +01001756" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001757func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001758 func T(a, c, p)
1759 return "oneA\noneB\noneC"
1760 endfunc
1761 command -nargs=1 -complete=custom,T MyCmd
1762
Bram Moolenaar578fe942020-02-27 21:32:51 +01001763 set nowildmenu
1764 set wildmode=full,list
1765 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001766 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001767 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001768 call assert_equal('"MyCmd oneA', @:)
1769
1770 set wildmode=longest,full
1771 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1772 call assert_equal('"MyCmd one', @:)
1773 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1774 call assert_equal('"MyCmd oneC', @:)
1775
1776 set wildmode=longest
1777 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1778 call assert_equal('"MyCmd one', @:)
1779
1780 set wildmode=list:longest
1781 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001782 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001783 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001784 call assert_equal('"MyCmd one', @:)
1785
1786 set wildmode=""
1787 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1788 call assert_equal('"MyCmd oneA', @:)
1789
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001790 " Test for wildmode=longest with 'fileignorecase' set
1791 set wildmode=longest
1792 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001793 argadd AAA AAAA AAAAA
1794 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1795 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001796 set fileignorecase&
1797
1798 " Test for listing files with wildmode=list
1799 set wildmode=list
1800 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001801 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001802 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001803 call assert_equal('"b A', @:)
1804
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001805 " when using longest completion match, matches shorter than the argument
1806 " should be ignored (happens with :help)
1807 set wildmode=longest,full
1808 set wildmenu
1809 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1810 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001811 " non existing file
1812 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1813 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001814 set wildmenu&
1815
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001816 " Test for longest file name completion with 'fileignorecase'
1817 " On MS-Windows, file names are case insensitive.
1818 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001819 call writefile([], 'XTESTfoo', 'D')
1820 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001821 set nofileignorecase
1822 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1823 call assert_equal('"e XTESTfoo', @:)
1824 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1825 call assert_equal('"e Xtestbar', @:)
1826 set fileignorecase
1827 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1828 call assert_equal('"e Xtest', @:)
1829 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1830 call assert_equal('"e Xtest', @:)
1831 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001832 endif
1833
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001834 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001835 delcommand MyCmd
1836 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001837 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001838 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001839endfunc
1840
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001841func Test_wildmode()
1842 " Test with utf-8 encoding
1843 call Wildmode_tests()
1844
1845 " Test with latin1 encoding
1846 let save_encoding = &encoding
1847 set encoding=latin1
1848 call Wildmode_tests()
1849 let &encoding = save_encoding
1850endfunc
1851
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001852func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001853 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001854 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001855 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001856 let lines =<< trim END
1857 func vim8#Complete(a, c, p)
1858 return "oneA\noneB\noneC"
1859 endfunc
1860 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001861 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001862
1863 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1864 set nowildmenu
1865 set wildmode=full,list
1866 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1867 call assert_equal('"MyCmd oneA oneB oneC', @:)
1868
1869 let &rtp = save_rtp
1870 set wildmode& wildmenu&
1871 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001872endfunc
1873
Bram Moolenaar578fe942020-02-27 21:32:51 +01001874" Test for interrupting the command-line completion
1875func Test_interrupt_compl()
1876 func F(lead, cmdl, p)
1877 if a:lead =~ 'tw'
1878 call interrupt()
1879 return
1880 endif
1881 return "one\ntwo\nthree"
1882 endfunc
1883 command -nargs=1 -complete=custom,F Tcmd
1884
1885 set nowildmenu
1886 set wildmode=full
1887 let interrupted = 0
1888 try
1889 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1890 catch /^Vim:Interrupt$/
1891 let interrupted = 1
1892 endtry
1893 call assert_equal(1, interrupted)
1894
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001895 let interrupted = 0
1896 try
1897 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1898 catch /^Vim:Interrupt$/
1899 let interrupted = 1
1900 endtry
1901 call assert_equal(1, interrupted)
1902
Bram Moolenaar578fe942020-02-27 21:32:51 +01001903 delcommand Tcmd
1904 delfunc F
1905 set wildmode&
1906endfunc
1907
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001908" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001909func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001910 let str = ":one two\<C-U>"
1911 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001912 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001913 let str ..= "\<Left>five\<Right>"
1914 let str ..= "\<Home>two "
1915 let str ..= "\<C-Left>one "
1916 let str ..= "\<C-Right> three"
1917 let str ..= "\<End>\<S-Left>four "
1918 let str ..= "\<S-Right> six"
1919 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1920 call feedkeys(str, 'xt')
1921 call assert_equal("\"one two three four five six seven", @:)
1922endfunc
1923
1924" Test for moving the cursor on the / command line in 'rightleft' mode
1925func Test_cmdline_edit_rightleft()
1926 CheckFeature rightleft
1927 set rightleft
1928 set rightleftcmd=search
1929 let str = "/one two\<C-U>"
1930 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001931 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001932 let str ..= "\<Right>five\<Left>"
1933 let str ..= "\<Home>two "
1934 let str ..= "\<C-Right>one "
1935 let str ..= "\<C-Left> three"
1936 let str ..= "\<End>\<S-Right>four "
1937 let str ..= "\<S-Left> six"
1938 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1939 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1940 call assert_equal("\"one two three four five six seven", @/)
1941 set rightleftcmd&
1942 set rightleft&
1943endfunc
1944
1945" Test for using <C-\>e in the command line to evaluate an expression
1946func Test_cmdline_expr()
1947 " Evaluate an expression from the beginning of a command line
1948 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1949 call assert_equal('"hello', @:)
1950
1951 " Use an invalid expression for <C-\>e
1952 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1953
1954 " Insert literal <CTRL-\> in the command line
1955 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1956 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001957endfunc
1958
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001959" This was making the insert position negative
1960func Test_cmdline_expr_register()
1961 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1962endfunc
1963
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001964" Test for 'imcmdline' and 'imsearch'
1965" This test doesn't actually test the input method functionality.
1966func Test_cmdline_inputmethod()
1967 new
1968 call setline(1, ['', 'abc', ''])
1969 set imcmdline
1970
1971 call feedkeys(":\"abc\<CR>", 'xt')
1972 call assert_equal("\"abc", @:)
1973 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1974 call assert_equal("\"abc", @:)
1975 call feedkeys("/abc\<CR>", 'xt')
1976 call assert_equal([2, 1], [line('.'), col('.')])
1977 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1978 call assert_equal([2, 1], [line('.'), col('.')])
1979
1980 set imsearch=2
1981 call cursor(1, 1)
1982 call feedkeys("/abc\<CR>", 'xt')
1983 call assert_equal([2, 1], [line('.'), col('.')])
1984 call cursor(1, 1)
1985 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1986 call assert_equal([2, 1], [line('.'), col('.')])
1987 set imdisable
1988 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1989 call assert_equal([2, 1], [line('.'), col('.')])
1990 set imdisable&
1991 set imsearch&
1992
1993 set imcmdline&
1994 %bwipe!
1995endfunc
1996
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001997" Test for using CTRL-_ in the command line with 'allowrevins'
1998func Test_cmdline_revins()
1999 CheckNotMSWindows
2000 CheckFeature rightleft
2001 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2002 call assert_equal("\"abc\<c-_>", @:)
2003 set allowrevins
2004 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2005 call assert_equal('"abcñèæ', @:)
2006 set allowrevins&
2007endfunc
2008
2009" Test for typing UTF-8 composing characters in the command line
2010func Test_cmdline_composing_chars()
2011 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2012 call assert_equal('"ゔ', @:)
2013endfunc
2014
Bram Moolenaar0e717042020-04-27 19:29:01 +02002015" test that ";" works to find a match at the start of the first line
2016func Test_zero_line_search()
2017 new
2018 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2019 call cursor(1,1)
2020 0;/pattern/d
2021 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2022 q!
2023endfunc
2024
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002025func Test_read_shellcmd()
2026 CheckUnix
2027 if executable('ls')
2028 " There should be ls in the $PATH
2029 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2030 call assert_match('^"r! .*\<ls\>', @:)
2031 endif
2032
2033 if executable('rm')
2034 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2035 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2036 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002037
2038 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2039 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2040 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002041 endif
2042endfunc
2043
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002044" Test for going up and down the directory tree using 'wildmenu'
2045func Test_wildmenu_dirstack()
2046 CheckUnix
2047 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002048 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002049 call writefile([], 'Xwildmenu/file1_1.txt')
2050 call writefile([], 'Xwildmenu/file1_2.txt')
2051 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2052 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2053 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2054 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2055 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2056 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002057 set wildmenu
2058
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002059 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002060 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002061 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002062 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002063 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002064 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002065 call assert_equal('"e ../../dir3/', @:)
2066 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2067 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002068 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002069 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002070 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002071 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002072 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002073 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2074 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002075
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002076 set wildmenu&
2077endfunc
2078
obcat71c6f7a2021-05-13 20:23:10 +02002079" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002080" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2081" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002082func Test_recalling_cmdline()
2083 CheckFeature cmdline_hist
2084
2085 let g:cmdlines = []
2086 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2087
2088 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002089 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2090 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2091 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2092 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002093 "\ TODO: {'name': 'debug', ...}
2094 \]
2095 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002096 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2097 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2098 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2099 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2100 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002101 \]
2102 let prefix = 'vi'
2103 for h in histories
2104 call histadd(h.name, 'vim')
2105 call histadd(h.name, 'virtue')
2106 call histadd(h.name, 'Virgo')
2107 call histadd(h.name, 'vogue')
2108 call histadd(h.name, 'emacs')
2109 for k in keypairs
2110 let g:cmdlines = []
2111 let keyseqs = h.enter
2112 \ .. prefix
2113 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2114 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2115 \ .. h.exit
2116 call feedkeys(keyseqs, 'xt')
2117 call histdel(h.name, -1) " delete the history added by feedkeys above
2118 let expect = k.prefixmatch
2119 \ ? ['virtue', 'vim', 'virtue', prefix]
2120 \ : ['emacs', 'vogue', 'emacs', prefix]
2121 call assert_equal(expect, g:cmdlines)
2122 endfor
2123 endfor
2124
2125 unlet g:cmdlines
2126 cunmap <Plug>(save-cmdline)
2127endfunc
2128
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002129func Test_cmd_map_cmdlineChanged()
2130 let g:log = []
2131 cnoremap <F1> l<Cmd><CR>s
2132 augroup test
2133 autocmd!
2134 autocmd CmdlineChanged : let g:log += [getcmdline()]
2135 augroup END
2136
2137 call feedkeys(":\<F1>\<CR>", 'xt')
2138 call assert_equal(['l', 'ls'], g:log)
2139
Bram Moolenaar796139a2021-05-18 21:38:45 +02002140 let @b = 'b'
2141 cnoremap <F1> a<C-R>b
2142 let g:log = []
2143 call feedkeys(":\<F1>\<CR>", 'xt')
2144 call assert_equal(['a', 'ab'], g:log)
2145
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002146 unlet g:log
2147 cunmap <F1>
2148 augroup test
2149 autocmd!
2150 augroup END
2151endfunc
2152
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002153" Test for the 'suffixes' option
2154func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002155 call writefile([], 'Xsuffile', 'D')
2156 call writefile([], 'Xsuffile.c', 'D')
2157 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002158 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002159 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2160 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2161 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2162 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002163 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002164 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2165 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2166 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2167 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002168 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002169 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2170 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2171 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2172 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002173 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002174 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002175 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2176 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002177endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002178
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002179" Test for using a popup menu for the command line completion matches
2180" (wildoptions=pum)
2181func Test_wildmenu_pum()
2182 CheckRunVimInTerminal
2183
2184 let commands =<< trim [CODE]
2185 set wildmenu
2186 set wildoptions=pum
2187 set shm+=I
2188 set noruler
2189 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002190
2191 func CmdCompl(a, b, c)
2192 return repeat(['aaaa'], 120)
2193 endfunc
2194 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002195
2196 func MyStatusLine() abort
2197 return 'status'
2198 endfunc
2199 func SetupStatusline()
2200 set statusline=%!MyStatusLine()
2201 set laststatus=2
2202 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002203
2204 func MyTabLine()
2205 return 'my tab line'
2206 endfunc
2207 func SetupTabline()
2208 set statusline=
2209 set tabline=%!MyTabLine()
2210 set showtabline=2
2211 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002212
2213 func DoFeedKeys()
2214 let &wildcharm = char2nr("\t")
2215 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2216 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002217 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002218 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002219
2220 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2221
2222 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002223 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2224
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002225 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002226 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2228
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002229 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002230 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002231 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2232
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002233 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002234 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002235 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2236
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002237 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002238 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002239 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2240
2241 " pressing <C-E> should end completion and go back to the original match
2242 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002243 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2244
2245 " pressing <C-Y> should select the current match and end completion
2246 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002247 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2248
2249 " With 'wildmode' set to 'longest,full', completing a match should display
2250 " the longest match, the wildmenu should not be displayed.
2251 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2252 call TermWait(buf)
2253 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002254 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2255
2256 " pressing <Tab> should display the wildmenu
2257 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002258 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2259
2260 " pressing <Tab> second time should select the next entry in the menu
2261 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002262 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2263
2264 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002265 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002266 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2268
2269 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002270 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2271
2272 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002273 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2274
2275 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002276 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002277 call writefile([], 'Xnamedir/XfileA')
2278 call writefile([], 'Xnamedir/XdirA/XfileB')
2279 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002280
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002281 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002282 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2283
2284 " Pressing <Right> on a directory name should go into that directory
2285 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002286 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2287
2288 " Pressing <Left> on a directory name should go to the parent directory
2289 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002290 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2291
2292 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002293 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002294 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002295 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2296
2297 " Pressing <C-D> when the popup menu is displayed should remove the popup
2298 " menu
2299 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002300 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2301
2302 " Pressing <S-Tab> should open the popup menu with the last entry selected
2303 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002304 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2305
2306 " Pressing <Esc> should close the popup menu and cancel the cmd line
2307 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002308 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2309
2310 " Typing a character when the popup is open, should close the popup
2311 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002312 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2313
2314 " When the popup is open, entering the cmdline window should close the popup
2315 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002316 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2317 call term_sendkeys(buf, ":q\<CR>")
2318
2319 " After the last popup menu item, <C-N> should show the original string
2320 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2322
2323 " Use the popup menu for the command name
2324 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002325 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2326
2327 " Pressing the left arrow should remove the popup menu
2328 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002329 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2330
2331 " Pressing <BS> should remove the popup menu and erase the last character
2332 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002333 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2334
2335 " Pressing <C-W> should remove the popup menu and erase the previous word
2336 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002337 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2338
2339 " Pressing <C-U> should remove the popup menu and erase the entire line
2340 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002341 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2342
2343 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2344 " the cmdline from history
2345 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002346 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2347
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002348 " Check "list" still works
2349 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2350 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002351 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2352 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002353 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2354
rbtnn68cc2b82022-02-09 11:55:47 +00002355 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002356 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002357 call writefile([], 'Xnamedir/あいう/abc')
2358 call writefile([], 'Xnamedir/あいう/xyz')
2359 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002360
2361 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002362 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002363 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2364
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002365 " Pressing <C-A> when the popup menu is displayed should list all the
2366 " matches and pressing a key after that should remove the popup menu
2367 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2368 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2369 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2370
2371 " Pressing <C-A> when the popup menu is displayed should list all the
2372 " matches and pressing <Left> after that should move the cursor
2373 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2374 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2375 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2376
2377 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2378 " should be displayed correctly on the screen.
2379 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2380 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2381
2382 " After using <C-A> to expand all the filename matches, pressing <Up>
2383 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002384 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002385 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2386 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2387 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2388
2389 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2390 " crash Vim
2391 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2392 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2393
Bram Moolenaar414acd32022-02-10 21:09:45 +00002394 " After removing the pum the command line is redrawn
2395 call term_sendkeys(buf, ":edit foo\<CR>")
2396 call term_sendkeys(buf, ":edit bar\<CR>")
2397 call term_sendkeys(buf, ":ls\<CR>")
2398 call term_sendkeys(buf, ":com\<Tab> ")
2399 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002400 call term_sendkeys(buf, "\<C-U>\<CR>")
2401
2402 " Esc still works to abort the command when 'statusline' is set
2403 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2404 call term_sendkeys(buf, ":si\<Tab>")
2405 call term_sendkeys(buf, "\<Esc>")
2406 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002407
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002408 " Esc still works to abort the command when 'tabline' is set
2409 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2410 call term_sendkeys(buf, ":si\<Tab>")
2411 call term_sendkeys(buf, "\<Esc>")
2412 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2413
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002414 " popup is cleared also when 'lazyredraw' is set
2415 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2416 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2417 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2418 call term_sendkeys(buf, "\<Esc>")
2419
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002420 " Pressing <PageDown> should scroll the menu downward
2421 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2422 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2423 call term_sendkeys(buf, "\<PageDown>")
2424 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2425 call term_sendkeys(buf, "\<PageDown>")
2426 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2427 call term_sendkeys(buf, "\<PageDown>")
2428 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2429 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2430 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2431
2432 " Pressing <PageUp> should scroll the menu upward
2433 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2434 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2435 call term_sendkeys(buf, "\<PageUp>")
2436 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2437 call term_sendkeys(buf, "\<PageUp>")
2438 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2439 call term_sendkeys(buf, "\<PageUp>")
2440 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2441
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002442 call term_sendkeys(buf, "\<C-U>\<CR>")
2443 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002444endfunc
2445
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002446" Test for wildmenumode() with the cmdline popup menu
2447func Test_wildmenumode_with_pum()
2448 set wildmenu
2449 set wildoptions=pum
2450 cnoremap <expr> <F2> wildmenumode()
2451 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2452 call assert_equal('"sign define10', @:)
2453 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2454 call assert_equal('"sign define jump list place undefine unplace0', @:)
2455 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2456 call assert_equal('"sign 0', @:)
2457 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2458 call assert_equal('"sign define0', @:)
2459 set nowildmenu wildoptions&
2460 cunmap <F2>
2461endfunc
2462
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002463func Test_wildmenu_with_pum_foldexpr()
2464 CheckRunVimInTerminal
2465
2466 let lines =<< trim END
2467 call setline(1, ['folded one', 'folded two', 'some more text'])
2468 func MyFoldText()
2469 return 'foo'
2470 endfunc
2471 set foldtext=MyFoldText() wildoptions=pum
2472 normal ggzfj
2473 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002474 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002475 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2476 call term_sendkeys(buf, ":set\<Tab>")
2477 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2478
2479 call term_sendkeys(buf, "\<Esc>")
2480 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2481
2482 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002483endfunc
2484
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002485" Test for opening the cmdline completion popup menu from the terminal window.
2486" The popup menu should be positioned correctly over the status line of the
2487" bottom-most window.
2488func Test_wildmenu_pum_from_terminal()
2489 CheckRunVimInTerminal
2490 let python = PythonProg()
2491 call CheckPython(python)
2492
2493 %bw!
2494 let cmds = ['set wildmenu wildoptions=pum']
2495 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2496 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002497 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002498 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2499 call term_sendkeys(buf, "\r\r\r")
2500 call term_wait(buf)
2501 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2502 call term_wait(buf)
2503 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2504 call term_wait(buf)
2505 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002506endfunc
2507
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002508func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002509 CheckRunVimInTerminal
2510
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002511 " This was using freed memory. Run in a terminal to get the pum to update.
2512 let lines =<< trim END
2513 set wildoptions=pum
2514 set wildchar=<C-E>
2515 END
2516 call writefile(lines, 'XwildmenuTest', 'D')
2517 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2518
2519 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2520 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2521
2522 set wildoptions& wildchar&
2523endfunc
2524
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002525" Test for completion after a :substitute command followed by a pipe (|)
2526" character
2527func Test_cmdline_complete_substitute()
2528 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2529 call assert_equal("\"s | \t", @:)
2530 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2531 call assert_equal("\"s/ | \t", @:)
2532 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2533 call assert_equal("\"s/one | \t", @:)
2534 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2535 call assert_equal("\"s/one/ | \t", @:)
2536 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2537 call assert_equal("\"s/one/two | \t", @:)
2538 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2539 call assert_equal('"s/one/two/ | chistory', @:)
2540 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2541 call assert_equal("\"s/one/two/g \t", @:)
2542 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2543 call assert_equal("\"s/one/two/g | chistory", @:)
2544 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2545 call assert_equal("\"s/one/t\\/ | \t", @:)
2546 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2547 call assert_equal('"s/one/t"o/ | chistory', @:)
2548 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2549 call assert_equal('"s/one/t|o/ | chistory', @:)
2550 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2551 call assert_equal("\"&\t", @:)
2552endfunc
2553
2554" Test for the :dlist command completion
2555func Test_cmdline_complete_dlist()
2556 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2557 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2558 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2559 call assert_equal("\"dlist 10 /pat/ \t", @:)
2560 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2561 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2562 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2563 call assert_equal("\"dlist 10 /pat\\\t", @:)
2564 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2565 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2566endfunc
2567
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002568" argument list (only for :argdel) fuzzy completion
2569func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002570 argadd change.py count.py charge.py
2571 set wildoptions&
2572 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2573 call assert_equal('"argdel cge', @:)
2574 set wildoptions=fuzzy
2575 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2576 call assert_equal('"argdel change.py charge.py', @:)
2577 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002578 set wildoptions&
2579endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002580
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002581" autocmd group name fuzzy completion
2582func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002583 set wildoptions&
2584 augroup MyFuzzyGroup
2585 augroup END
2586 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2587 call assert_equal('"augroup mfg', @:)
2588 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2589 call assert_equal('"augroup MyFuzzyGroup', @:)
2590 set wildoptions=fuzzy
2591 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2592 call assert_equal('"augroup MyFuzzyGroup', @:)
2593 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2594 call assert_equal('"augroup My*p', @:)
2595 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002596 set wildoptions&
2597endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002598
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002599" buffer name fuzzy completion
2600func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002601 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002602 " Use a long name to reduce the risk of matching a random directory name
2603 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002604 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002605 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2606 call assert_equal('"b SRFWL', @:)
2607 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2608 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002609 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002610 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2611 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2612 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2613 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002614 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002615 set wildoptions&
2616endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002617
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002618" buffer name (full path) fuzzy completion
2619func Test_fuzzy_completion_bufname_fullpath()
2620 CheckUnix
2621 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002622 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002623 edit Xcmd/Xstate/Xfile.js
2624 cd Xcmd/Xstate
2625 enew
2626 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2627 call assert_equal('"b CmdStateFile', @:)
2628 set wildoptions=fuzzy
2629 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2630 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2631 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002632 set wildoptions&
2633endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002634
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002635" :behave suboptions fuzzy completion
2636func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002637 set wildoptions&
2638 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2639 call assert_equal('"behave xm', @:)
2640 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2641 call assert_equal('"behave xterm', @:)
2642 set wildoptions=fuzzy
2643 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2644 call assert_equal('"behave xterm', @:)
2645 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2646 call assert_equal('"behave xt*m', @:)
2647 let g:Sline = ''
2648 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2649 call assert_equal('mswin', g:Sline)
2650 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002651 set wildoptions&
2652endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002653
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002654" " colorscheme name fuzzy completion - NOT supported
2655" func Test_fuzzy_completion_colorscheme()
2656" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002657
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002658" built-in command name fuzzy completion
2659func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002660 set wildoptions&
2661 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2662 call assert_equal('"sbwin', @:)
2663 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2664 call assert_equal('"sbrewind', @:)
2665 set wildoptions=fuzzy
2666 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2667 call assert_equal('"sbrewind', @:)
2668 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2669 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002670 set wildoptions&
2671endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002672
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002673" " compiler name fuzzy completion - NOT supported
2674" func Test_fuzzy_completion_compiler()
2675" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002676
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002677" :cscope suboptions fuzzy completion
2678func Test_fuzzy_completion_cscope()
2679 CheckFeature cscope
2680 set wildoptions&
2681 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2682 call assert_equal('"cscope ret', @:)
2683 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2684 call assert_equal('"cscope reset', @:)
2685 set wildoptions=fuzzy
2686 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2687 call assert_equal('"cscope reset', @:)
2688 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2689 call assert_equal('"cscope re*t', @:)
2690 set wildoptions&
2691endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002692
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002693" :diffget/:diffput buffer name fuzzy completion
2694func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002695 new SomeBuffer
2696 diffthis
2697 new OtherBuffer
2698 diffthis
2699 set wildoptions&
2700 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2701 call assert_equal('"diffget sbuf', @:)
2702 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2703 call assert_equal('"diffput sbuf', @:)
2704 set wildoptions=fuzzy
2705 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2706 call assert_equal('"diffget SomeBuffer', @:)
2707 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2708 call assert_equal('"diffput SomeBuffer', @:)
2709 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002710 set wildoptions&
2711endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002712
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002713" " directory name fuzzy completion - NOT supported
2714" func Test_fuzzy_completion_dirname()
2715" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002716
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002717" environment variable name fuzzy completion
2718func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002719 set wildoptions&
2720 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2721 call assert_equal('"echo $VUT', @:)
2722 set wildoptions=fuzzy
2723 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2724 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002725 set wildoptions&
2726endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002727
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002728" autocmd event fuzzy completion
2729func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002730 set wildoptions&
2731 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2732 call assert_equal('"autocmd BWout', @:)
2733 set wildoptions=fuzzy
2734 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2735 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002736 set wildoptions&
2737endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002738
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002739" vim expression fuzzy completion
2740func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002741 let g:PerPlaceCount = 10
2742 set wildoptions&
2743 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2744 call assert_equal('"let c = ppc', @:)
2745 set wildoptions=fuzzy
2746 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2747 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002748 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002749endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002750
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002751" " file name fuzzy completion - NOT supported
2752" func Test_fuzzy_completion_filename()
2753" endfunc
2754
2755" " files in path fuzzy completion - NOT supported
2756" func Test_fuzzy_completion_filesinpath()
2757" endfunc
2758
2759" " filetype name fuzzy completion - NOT supported
2760" func Test_fuzzy_completion_filetype()
2761" endfunc
2762
2763" user defined function name completion
2764func Test_fuzzy_completion_userdefined_func()
2765 set wildoptions&
2766 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2767 call assert_equal('"call Test_f_u_f', @:)
2768 set wildoptions=fuzzy
2769 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2770 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2771 set wildoptions&
2772endfunc
2773
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002774" <SNR> functions should be sorted to the end
2775func Test_fuzzy_completion_userdefined_snr_func()
2776 func s:Sendmail()
2777 endfunc
2778 func SendSomemail()
2779 endfunc
2780 func S1e2n3dmail()
2781 endfunc
2782 set wildoptions=fuzzy
2783 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002784 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002785 set wildoptions&
2786 delfunc s:Sendmail
2787 delfunc SendSomemail
2788 delfunc S1e2n3dmail
2789endfunc
2790
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002791" user defined command name completion
2792func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002793 set wildoptions&
2794 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2795 call assert_equal('"MsFeat', @:)
2796 set wildoptions=fuzzy
2797 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2798 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002799 set wildoptions&
2800endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002801
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002802" " :help tag fuzzy completion - NOT supported
2803" func Test_fuzzy_completion_helptag()
2804" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002805
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002806" highlight group name fuzzy completion
2807func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002808 set wildoptions&
2809 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"highlight SKey', @:)
2811 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2812 call assert_equal('"highlight SpecialKey', @:)
2813 set wildoptions=fuzzy
2814 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2815 call assert_equal('"highlight SpecialKey', @:)
2816 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2817 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002818 set wildoptions&
2819endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002820
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002821" :history suboptions fuzzy completion
2822func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002823 set wildoptions&
2824 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2825 call assert_equal('"history dg', @:)
2826 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2827 call assert_equal('"history search', @:)
2828 set wildoptions=fuzzy
2829 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2830 call assert_equal('"history debug', @:)
2831 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2832 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002833 set wildoptions&
2834endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002835
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002836" :language locale name fuzzy completion
2837func Test_fuzzy_completion_lang()
2838 CheckUnix
2839 set wildoptions&
2840 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal('"lang psx', @:)
2842 set wildoptions=fuzzy
2843 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"lang POSIX', @:)
2845 set wildoptions&
2846endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002847
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002848" :mapclear buffer argument fuzzy completion
2849func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002850 set wildoptions&
2851 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2852 call assert_equal('"mapclear buf', @:)
2853 set wildoptions=fuzzy
2854 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2855 call assert_equal('"mapclear <buffer>', @:)
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" map name fuzzy completion
2860func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002861 " test regex completion works
2862 set wildoptions=fuzzy
2863 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2864 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002865 nmap <plug>MyLongMap :p<CR>
2866 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2867 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2868 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2869 call assert_equal("\"nmap MLM \t", @:)
2870 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2871 call assert_equal("\"nmap <F2> one two \t", @:)
2872 " duplicate entries should be removed
2873 vmap <plug>MyLongMap :<C-U>#<CR>
2874 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2876 nunmap <plug>MyLongMap
2877 vunmap <plug>MyLongMap
2878 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2879 call assert_equal("\"nmap ABC\t", @:)
2880 " results should be sorted by best match
2881 nmap <Plug>format :
2882 nmap <Plug>goformat :
2883 nmap <Plug>TestFOrmat :
2884 nmap <Plug>fendoff :
2885 nmap <Plug>state :
2886 nmap <Plug>FendingOff :
2887 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2888 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2889 nunmap <Plug>format
2890 nunmap <Plug>goformat
2891 nunmap <Plug>TestFOrmat
2892 nunmap <Plug>fendoff
2893 nunmap <Plug>state
2894 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002895 set wildoptions&
2896endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002897
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002898" abbreviation fuzzy completion
2899func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002900 set wildoptions=fuzzy
2901 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2902 call assert_equal("\"iabbr <nowait>", @:)
2903 iabbr WaitForCompletion WFC
2904 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2905 call assert_equal("\"iabbr WaitForCompletion", @:)
2906 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2907 call assert_equal("\"iabbr a1z\t", @:)
2908 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002909 set wildoptions&
2910endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002911
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002912" menu name fuzzy completion
2913func Test_fuzzy_completion_menu()
2914 CheckGui
2915 set wildoptions&
2916 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal('"menu pup', @:)
2918 set wildoptions=fuzzy
2919 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2920 call assert_equal('"menu PopUp.', @:)
2921 set wildoptions&
2922endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002923
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002924" :messages suboptions fuzzy completion
2925func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002926 set wildoptions&
2927 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2928 call assert_equal('"messages clr', @:)
2929 set wildoptions=fuzzy
2930 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2931 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002932 set wildoptions&
2933endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002934
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002935" :set option name fuzzy completion
2936func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002937 set wildoptions&
2938 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2939 call assert_equal('"set brkopt', @:)
2940 set wildoptions=fuzzy
2941 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2942 call assert_equal('"set breakindentopt', @:)
2943 set wildoptions&
2944 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2945 call assert_equal('"set fixendofline', @:)
2946 set wildoptions=fuzzy
2947 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2948 call assert_equal('"set fixendofline', @:)
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" :set <term_option>
2953func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002954 set wildoptions&
2955 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2956 call assert_equal('"set t_EC', @:)
2957 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2958 call assert_equal('"set <t_EC>', @:)
2959 set wildoptions=fuzzy
2960 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2961 call assert_equal('"set t_EC', @:)
2962 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2963 call assert_equal('"set <t_EC>', @:)
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" " :packadd directory name fuzzy completion - NOT supported
2968" func Test_fuzzy_completion_packadd()
2969" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002970
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002971" " shell command name fuzzy completion - NOT supported
2972" func Test_fuzzy_completion_shellcmd()
2973" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002974
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002975" :sign suboptions fuzzy completion
2976func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002977 set wildoptions&
2978 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2979 call assert_equal('"sign ufe', @:)
2980 set wildoptions=fuzzy
2981 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2982 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002983 set wildoptions&
2984endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002985
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002986" :syntax suboptions fuzzy completion
2987func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002988 set wildoptions&
2989 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2990 call assert_equal('"syntax kwd', @:)
2991 set wildoptions=fuzzy
2992 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2993 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002994 set wildoptions&
2995endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002996
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002997" syntax group name fuzzy completion
2998func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002999 set wildoptions&
3000 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3001 call assert_equal('"syntax list mpar', @:)
3002 set wildoptions=fuzzy
3003 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3004 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003005 set wildoptions&
3006endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003007
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003008" :syntime suboptions fuzzy completion
3009func Test_fuzzy_completion_syntime()
3010 CheckFeature profile
3011 set wildoptions&
3012 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3013 call assert_equal('"syntime clr', @:)
3014 set wildoptions=fuzzy
3015 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3016 call assert_equal('"syntime clear', @:)
3017 set wildoptions&
3018endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003019
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003020" " tag name fuzzy completion - NOT supported
3021" func Test_fuzzy_completion_tagname()
3022" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003023
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003024" " tag name and file fuzzy completion - NOT supported
3025" func Test_fuzzy_completion_tagfile()
3026" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003027
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003028" " user names fuzzy completion - how to test this functionality?
3029" func Test_fuzzy_completion_username()
3030" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003031
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003032" user defined variable name fuzzy completion
3033func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003034 let g:SomeVariable=10
3035 set wildoptions&
3036 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3037 call assert_equal('"let SVar', @:)
3038 set wildoptions=fuzzy
3039 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3040 call assert_equal('"let SomeVariable', @:)
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" Test for sorting the results by the best match
3045func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003046 %bw!
3047 command T123format :
3048 command T123goformat :
3049 command T123TestFOrmat :
3050 command T123fendoff :
3051 command T123state :
3052 command T123FendingOff :
3053 set wildoptions=fuzzy
3054 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3055 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3056 delcommand T123format
3057 delcommand T123goformat
3058 delcommand T123TestFOrmat
3059 delcommand T123fendoff
3060 delcommand T123state
3061 delcommand T123FendingOff
3062 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003063 set wildoptions&
3064endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003065
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003066" Test for fuzzy completion of a command with lower case letters and a number
3067func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003068 command Foo2Bar :
3069 set wildoptions=fuzzy
3070 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3071 call assert_equal('"Foo2Bar', @:)
3072 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal('"Foo2Bar', @:)
3074 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal('"Foo2Bar', @:)
3076 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003077 set wildoptions&
3078endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003079
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003080" Test for command completion for a command starting with 'k'
3081func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003082 command KillKillKill :
3083 set wildoptions&
3084 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3085 call assert_equal("\"killkill\<Tab>", @:)
3086 set wildoptions=fuzzy
3087 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal('"KillKillKill', @:)
3089 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003090 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003091endfunc
3092
3093" Test for fuzzy completion for user defined custom completion function
3094func Test_fuzzy_completion_custom_func()
3095 func Tcompl(a, c, p)
3096 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3097 endfunc
3098 command -nargs=* -complete=custom,Tcompl Fuzzy :
3099 set wildoptions&
3100 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3101 call assert_equal("\"Fuzzy format", @:)
3102 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3103 call assert_equal("\"Fuzzy xy", @:)
3104 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3105 call assert_equal("\"Fuzzy ttt", @:)
3106 set wildoptions=fuzzy
3107 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3109 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3111 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"Fuzzy xy", @:)
3113 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"Fuzzy TestFOrmat", @:)
3115 delcom Fuzzy
3116 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003117endfunc
3118
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003119" Test for :breakadd argument completion
3120func Test_cmdline_complete_breakadd()
3121 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3122 call assert_equal("\"breakadd expr file func here", @:)
3123 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3124 call assert_equal("\"breakadd expr", @:)
3125 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3126 call assert_equal("\"breakadd expr", @:)
3127 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakadd here", @:)
3129 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakadd here", @:)
3131 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal("\"breakadd abc", @:)
3133 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3134 let l = getcompletion('not', 'breakpoint')
3135 call assert_equal([], l)
3136
3137 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003138 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003139 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3140 call assert_equal("\"breakadd file Xscript", @:)
3141 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"breakadd file Xscript", @:)
3143 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_equal("\"breakadd file 20 Xscript", @:)
3145 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"breakadd file 20 Xscript", @:)
3147 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3149 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakadd file 20\t", @:)
3151 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakadd file 20x\t", @:)
3153 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakadd file Xscript ", @:)
3155 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003157
3158 " Test for :breakadd func [lnum] <function>
3159 func Xbreak_func()
3160 endfunc
3161 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd func Xbreak_func", @:)
3163 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3164 call assert_equal("\"breakadd func Xbreak_func", @:)
3165 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3166 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3167 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3169 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3171 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal("\"breakadd func 20\t", @:)
3173 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal("\"breakadd func 20x\t", @:)
3175 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal("\"breakadd func Xbreak_func ", @:)
3177 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal("\"breakadd func X1B2C3", @:)
3179 delfunc Xbreak_func
3180
3181 " Test for :breakadd expr <expression>
3182 let g:Xtest_var = 10
3183 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakadd expr Xtest_var", @:)
3185 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3186 call assert_equal("\"breakadd expr Xtest_var", @:)
3187 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3188 call assert_equal("\"breakadd expr Xtest_var ", @:)
3189 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"breakadd expr X1B2C3", @:)
3191 unlet g:Xtest_var
3192
3193 " Test for :breakadd here
3194 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3195 call assert_equal("\"breakadd here Xtest", @:)
3196 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3197 call assert_equal("\"breakadd here Xtest", @:)
3198 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3199 call assert_equal("\"breakadd here ", @:)
3200endfunc
3201
3202" Test for :breakdel argument completion
3203func Test_cmdline_complete_breakdel()
3204 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3205 call assert_equal("\"breakdel file func here", @:)
3206 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3207 call assert_equal("\"breakdel file", @:)
3208 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3209 call assert_equal("\"breakdel file", @:)
3210 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal("\"breakdel here", @:)
3212 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3213 call assert_equal("\"breakdel here", @:)
3214 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3215 call assert_equal("\"breakdel abc", @:)
3216
3217 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003218 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003219 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3220 call assert_equal("\"breakdel file Xscript", @:)
3221 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3222 call assert_equal("\"breakdel file Xscript", @:)
3223 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3224 call assert_equal("\"breakdel file 20 Xscript", @:)
3225 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel file 20 Xscript", @:)
3227 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3229 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakdel file 20\t", @:)
3231 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal("\"breakdel file 20x\t", @:)
3233 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal("\"breakdel file Xscript ", @:)
3235 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003237
3238 " Test for :breakdel func [lnum] <function>
3239 func Xbreak_func()
3240 endfunc
3241 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal("\"breakdel func Xbreak_func", @:)
3243 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3244 call assert_equal("\"breakdel func Xbreak_func", @:)
3245 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3246 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3247 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3249 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3251 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal("\"breakdel func 20\t", @:)
3253 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3254 call assert_equal("\"breakdel func 20x\t", @:)
3255 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal("\"breakdel func Xbreak_func ", @:)
3257 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakdel func X1B2C3", @:)
3259 delfunc Xbreak_func
3260
3261 " Test for :breakdel here
3262 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3263 call assert_equal("\"breakdel here Xtest", @:)
3264 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3265 call assert_equal("\"breakdel here Xtest", @:)
3266 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3267 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003268endfunc
3269
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003270" Test for :scriptnames argument completion
3271func Test_cmdline_complete_scriptnames()
3272 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003273 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003274 source Xa1b2c3.vim
3275 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3276 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3277 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3278 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3279 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3280 call assert_equal("\"script b2c3", @:)
3281 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3282 call assert_match("\"script 2\<Tab>$", @:)
3283 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3284 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3285 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal("\"script ", @:)
3287 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3288 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3289 new
3290 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3291 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3292 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003293 set wildmenu&
3294endfunc
3295
Bram Moolenaard8893442022-05-06 20:38:47 +01003296" this was going over the end of IObuff
3297func Test_report_error_with_composing()
3298 let caught = 'no'
3299 try
3300 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3301 catch /E492:/
3302 let caught = 'yes'
3303 endtry
3304 call assert_equal('yes', caught)
3305endfunc
3306
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003307" Test for expanding 2-letter and 3-letter :substitute command arguments.
3308" These commands don't accept an argument.
3309func Test_cmdline_complete_substitute_short()
3310 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3311 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3312 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3313 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3314 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3315 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3316 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3317 endfor
3318endfunc
3319
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003320" Test for :! shell command argument completion
3321func Test_cmdline_complete_bang_cmd_argument()
3322 set wildoptions=fuzzy
3323 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3324 call assert_equal('"!vim test_cmdline.vim', @:)
3325 set wildoptions&
3326 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3327 call assert_equal('"!vim test_cmdline.vim', @:)
3328endfunc
3329
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003330func Check_completion()
3331 call assert_equal('let a', getcmdline())
3332 call assert_equal(6, getcmdpos())
3333 call assert_equal(7, getcmdscreenpos())
3334 call assert_equal('var', getcmdcompltype())
3335 return ''
3336endfunc
3337
3338func Test_screenpos_and_completion()
3339 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3340endfunc
3341
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003342func Test_recursive_register()
3343 let @= = ''
3344 silent! ?e/
3345 let caught = 'no'
3346 try
3347 normal //
3348 catch /E169:/
3349 let caught = 'yes'
3350 endtry
3351 call assert_equal('yes', caught)
3352endfunc
3353
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003354func Test_long_error_message()
3355 " the error should be truncated, not overrun IObuff
3356 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3357endfunc
3358
zeertzjq6791adc2022-07-26 20:42:25 +01003359func Test_cmdline_redraw_tabline()
3360 CheckRunVimInTerminal
3361
3362 let lines =<< trim END
3363 set showtabline=2
3364 autocmd CmdlineEnter * set tabline=foo
3365 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003366 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003367 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3368 call term_sendkeys(buf, ':')
3369 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3370
3371 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003372endfunc
3373
zeertzjqb82a2ab2022-08-21 14:33:57 +01003374func Test_wildmenu_pum_disable_while_shown()
3375 set wildoptions=pum
3376 set wildmenu
3377 cnoremap <F2> <Cmd>set nowildmenu<CR>
3378 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3379 call assert_equal(0, pumvisible())
3380 cunmap <F2>
3381 set wildoptions& wildmenu&
3382endfunc
3383
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003384func Test_setcmdline()
3385 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003386 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003387 call assert_equal(0, setcmdline(a:text))
3388 call assert_equal(a:text, getcmdline())
3389 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003390 call assert_equal(getcmdtype(), g:cmdtype)
3391 unlet g:cmdtype
3392 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003393
3394 call assert_equal(0, setcmdline(a:text, a:pos))
3395 call assert_equal(a:text, getcmdline())
3396 call assert_equal(a:pos, getcmdpos())
3397
3398 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003399 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3400 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003401
3402 return ''
3403 endfunc
3404
3405 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3406 call assert_equal('set rtp?', @:)
3407
zeertzjq54acb902022-08-29 16:21:25 +01003408 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3409 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3410 call assert_equal('foo', g:str)
3411 unlet g:str
3412
3413 delfunc SetText
3414
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003415 " setcmdline() returns 1 when not editing the command line.
3416 call assert_equal(1, 'foo'->setcmdline())
3417
3418 " Called in custom function
3419 func CustomComplete(A, L, P)
3420 call assert_equal(0, setcmdline("DoCmd "))
3421 return "January\nFebruary\nMars\n"
3422 endfunc
3423
3424 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3425 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3426 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003427 delcom DoCmd
3428 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003429
3430 " Called in <expr>
3431 cnoremap <expr>a setcmdline('let foo=')
3432 call feedkeys(":a\<CR>", 'tx')
3433 call assert_equal('let foo=0', @:)
3434 cunmap a
3435endfunc
3436
Bram Moolenaar309976e2019-12-05 18:16:33 +01003437" vim: shiftwidth=2 sts=2 expandtab