blob: 27ca8bf841b5c06f03f32859978ca5a1c0215032 [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 Moolenaarf797e302022-08-11 13:17:30 +0100213func Test_changing_cmdheight()
214 CheckScreendump
215
216 let lines =<< trim END
217 set cmdheight=1 laststatus=2
218 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100219 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100220
221 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
222 call term_sendkeys(buf, ":resize -3\<CR>")
223 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
224
225 " using the space available doesn't change the status line
226 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
227 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
228
229 " using more space moves the status line up
230 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
231 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
232
233 " reducing cmdheight moves status line down
234 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
235 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
236
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100237 " reducing window size and then setting cmdheight
238 call term_sendkeys(buf, ":resize -1\<CR>")
239 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
240 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
241
Bram Moolenaarf797e302022-08-11 13:17:30 +0100242 " clean up
243 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100244endfunc
245
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100246func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100247 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
248 call assert_equal('"map <unique> <silent>', getreg(':'))
249 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
250 call assert_equal('"map <script> <unique>', getreg(':'))
251 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
252 call assert_equal('"map <expr> <script>', getreg(':'))
253 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
254 call assert_equal('"map <buffer> <expr>', getreg(':'))
255 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
256 call assert_equal('"map <nowait> <buffer>', getreg(':'))
257 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
258 call assert_equal('"map <special> <nowait>', getreg(':'))
259 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
260 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200261
Bram Moolenaar1776a282019-05-03 16:05:41 +0200262 map <Middle>x middle
263
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200264 map ,f commaf
265 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200266 map <Left> left
267 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200268 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
269 call assert_equal('"map ,f', getreg(':'))
270 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
271 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200272 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
273 call assert_equal('"map <Left>', getreg(':'))
274 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200275 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200276 unmap ,f
277 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200278 unmap <Left>
279 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200280
281 set cpo-=< cpo-=B cpo-=k
282 map <Left> left
283 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
284 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200285 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200286 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200287 unmap <Left>
288
289 set cpo+=<
290 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200291 exe "set t_k6=\<Esc>[17~"
292 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200293 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
294 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200295 if !has('gui_running')
296 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
297 call assert_equal("\"map <F6>x", getreg(':'))
298 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200299 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200300 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200301 set cpo-=<
302
303 set cpo+=B
304 map <Left> left
305 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <Left>', getreg(':'))
307 unmap <Left>
308 set cpo-=B
309
310 set cpo+=k
311 map <Left> left
312 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
313 call assert_equal('"map <Left>', getreg(':'))
314 unmap <Left>
315 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316
Bram Moolenaar531be472020-09-23 22:38:05 +0200317 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
318
Bram Moolenaar1776a282019-05-03 16:05:41 +0200319 unmap <Middle>x
320 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100321endfunc
322
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100323func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100324 hi Aardig ctermfg=green
325 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000326 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100327 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000328 call assert_equal('"match none', @:)
329 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
330 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100331endfunc
332
333func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100334 hi Aardig ctermfg=green
335 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
336 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200337 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"hi default Aardig', getreg(':'))
339 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
340 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100341 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
342 call assert_equal('"hi link', getreg(':'))
343 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
344 call assert_equal('"hi default', getreg(':'))
345 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
346 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200347 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
348 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
349 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
350 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200351
352 " A cleared group does not show up in completions.
353 hi Anders ctermfg=green
354 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
355 hi clear Aardig
356 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
357 hi clear Anders
358 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100359endfunc
360
Bram Moolenaar75e15672020-06-28 13:10:22 +0200361" Test for command-line expansion of "hi Ni " (easter egg)
362func Test_highlight_easter_egg()
363 call test_override('ui_delay', 1)
364 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
365 call assert_equal("\"hi Ni \<Tab>", @:)
366 call test_override('ALL', 0)
367endfunc
368
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200369func Test_getcompletion()
370 let groupcount = len(getcompletion('', 'event'))
371 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200372 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200373 call assert_true(matchcount > 0)
374 call assert_true(groupcount > matchcount)
375
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200376 if has('menu')
377 source $VIMRUNTIME/menu.vim
378 let matchcount = len(getcompletion('', 'menu'))
379 call assert_true(matchcount > 0)
380 call assert_equal(['File.'], getcompletion('File', 'menu'))
381 call assert_true(matchcount > 0)
382 let matchcount = len(getcompletion('File.', 'menu'))
383 call assert_true(matchcount > 0)
384 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200385
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200386 let l = getcompletion('v:n', 'var')
387 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200388 let l = getcompletion('v:notexists', 'var')
389 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200390
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200391 args a.c b.c
392 let l = getcompletion('', 'arglist')
393 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000394 let l = getcompletion('a.', 'buffer')
395 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200396 %argdelete
397
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200398 let l = getcompletion('', 'augroup')
399 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200400 let l = getcompletion('blahblah', 'augroup')
401 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200402
403 let l = getcompletion('', 'behave')
404 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200405 let l = getcompletion('not', 'behave')
406 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200407
408 let l = getcompletion('', 'color')
409 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200410 let l = getcompletion('dirty', 'color')
411 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200412
413 let l = getcompletion('', 'command')
414 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200415 let l = getcompletion('awake', 'command')
416 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200417
418 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200419 call assert_true(index(l, 'samples/') >= 0)
420 let l = getcompletion('NoMatch', 'dir')
421 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200422
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100423 if glob('~/*') !=# ''
424 let l = getcompletion('~/', 'dir')
425 call assert_true(l[0][0] ==# '~')
426 endif
427
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200428 let l = getcompletion('exe', 'expression')
429 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200430 let l = getcompletion('kill', 'expression')
431 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200432
433 let l = getcompletion('tag', 'function')
434 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200435 let l = getcompletion('paint', 'function')
436 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200437
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200438 let Flambda = {-> 'hello'}
439 let l = getcompletion('', 'function')
440 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200441 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200442
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200443 let l = getcompletion('run', 'file')
444 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200445 let l = getcompletion('walk', 'file')
446 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200447 set wildignore=*.vim
448 let l = getcompletion('run', 'file', 1)
449 call assert_true(index(l, 'runtest.vim') < 0)
450 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000451 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100452 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000453 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
454 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200455
456 let l = getcompletion('ha', 'filetype')
457 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200458 let l = getcompletion('horse', 'filetype')
459 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200460
461 let l = getcompletion('z', 'syntax')
462 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200463 let l = getcompletion('emacs', 'syntax')
464 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200465
466 let l = getcompletion('jikes', 'compiler')
467 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200468 let l = getcompletion('break', 'compiler')
469 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200470
471 let l = getcompletion('last', 'help')
472 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200473 let l = getcompletion('giveup', 'help')
474 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200475
476 let l = getcompletion('time', 'option')
477 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200478 let l = getcompletion('space', 'option')
479 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200480
481 let l = getcompletion('er', 'highlight')
482 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200483 let l = getcompletion('dark', 'highlight')
484 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200485
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200486 let l = getcompletion('', 'messages')
487 call assert_true(index(l, 'clear') >= 0)
488 let l = getcompletion('not', 'messages')
489 call assert_equal([], l)
490
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200491 let l = getcompletion('', 'mapclear')
492 call assert_true(index(l, '<buffer>') >= 0)
493 let l = getcompletion('not', 'mapclear')
494 call assert_equal([], l)
495
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200496 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200497 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200498 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
499 let root = has('win32') ? 'C:\\' : '/'
500 let l = getcompletion(root, 'shellcmd')
501 let expected = map(filter(glob(root . '*', 0, 1),
502 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
503 call assert_equal(expected, l)
504
Bram Moolenaarb650b982016-08-05 20:35:13 +0200505 if has('cscope')
506 let l = getcompletion('', 'cscope')
507 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
508 call assert_equal(cmds, l)
509 " using cmdline completion must not change the result
510 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
511 let l = getcompletion('', 'cscope')
512 call assert_equal(cmds, l)
513 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
514 let l = getcompletion('find ', 'cscope')
515 call assert_equal(keys, l)
516 endif
517
Bram Moolenaar7522f692016-08-06 14:12:50 +0200518 if has('signs')
519 sign define Testing linehl=Comment
520 let l = getcompletion('', 'sign')
521 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
522 call assert_equal(cmds, l)
523 " using cmdline completion must not change the result
524 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
525 let l = getcompletion('', 'sign')
526 call assert_equal(cmds, l)
527 let l = getcompletion('list ', 'sign')
528 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000529 let l = getcompletion('de*', 'sign')
530 call assert_equal(['define'], l)
531 let l = getcompletion('p?', 'sign')
532 call assert_equal(['place'], l)
533 let l = getcompletion('j.', 'sign')
534 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200535 endif
536
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200537 " Command line completion tests
538 let l = getcompletion('cd ', 'cmdline')
539 call assert_true(index(l, 'samples/') >= 0)
540 let l = getcompletion('cd NoMatch', 'cmdline')
541 call assert_equal([], l)
542 let l = getcompletion('let v:n', 'cmdline')
543 call assert_true(index(l, 'v:null') >= 0)
544 let l = getcompletion('let v:notexists', 'cmdline')
545 call assert_equal([], l)
546 let l = getcompletion('call tag', 'cmdline')
547 call assert_true(index(l, 'taglist(') >= 0)
548 let l = getcompletion('call paint', 'cmdline')
549 call assert_equal([], l)
550
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100551 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000552 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100553 return "oneA\noneB\noneC"
554 endfunc
555 command -nargs=1 -complete=custom,T MyCmd
556 let l = getcompletion('MyCmd ', 'cmdline')
557 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000558 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100559
560 delcommand MyCmd
561 delfunc T
ii144785fe02021-11-21 12:13:56 +0000562 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100563
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200564 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200565 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200566 if has('cmdline_hist')
567 call add(names, 'history')
568 endif
569 if has('gettext')
570 call add(names, 'locale')
571 endif
572 if has('profile')
573 call add(names, 'syntime')
574 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200575
576 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100577 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200578
579 for name in names
580 let matchcount = len(getcompletion('', name))
581 call assert_true(matchcount >= 0, 'No matches for ' . name)
582 endfor
583
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200584 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200585
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000586 edit a~b
587 enew
588 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
589 bw a~b
590
591 if has('unix')
592 edit Xtest\
593 enew
594 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
595 bw Xtest\
596 endif
597
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200598 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200599 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100600 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200601endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200602
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000603" Test for getcompletion() with "fuzzy" in 'wildoptions'
604func Test_getcompletion_wildoptions()
605 let save_wildoptions = &wildoptions
606 set wildoptions&
607 let l = getcompletion('space', 'option')
608 call assert_equal([], l)
609 let l = getcompletion('ier', 'command')
610 call assert_equal([], l)
611 set wildoptions=fuzzy
612 let l = getcompletion('space', 'option')
613 call assert_true(index(l, 'backspace') >= 0)
614 let l = getcompletion('ier', 'command')
615 call assert_true(index(l, 'compiler') >= 0)
616 let &wildoptions = save_wildoptions
617endfunc
618
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000619func Test_complete_autoload_error()
620 let save_rtp = &rtp
621 let lines =<< trim END
622 vim9script
623 export def Complete(..._): string
624 return 'match'
625 enddef
626 echo this will cause an error
627 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100628 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000629 call writefile(lines, 'Xdir/autoload/script.vim')
630 exe 'set rtp+=' .. getcwd() .. '/Xdir'
631
632 let lines =<< trim END
633 vim9script
634 import autoload 'script.vim'
635 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
636 &wildcharm = char2nr("\<Tab>")
637 feedkeys(":Cmd \<Tab>", 'xt')
638 END
639 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
640
641 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000642endfunc
643
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100644func Test_fullcommand()
645 let tests = {
646 \ '': '',
647 \ ':': '',
648 \ ':::': '',
649 \ ':::5': '',
650 \ 'not_a_cmd': '',
651 \ 'Check': '',
652 \ 'syntax': 'syntax',
653 \ ':syntax': 'syntax',
654 \ '::::syntax': 'syntax',
655 \ 'sy': 'syntax',
656 \ 'syn': 'syntax',
657 \ 'synt': 'syntax',
658 \ ':sy': 'syntax',
659 \ '::::sy': 'syntax',
660 \ 'match': 'match',
661 \ '2match': 'match',
662 \ '3match': 'match',
663 \ 'aboveleft': 'aboveleft',
664 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100665 \ 'en': 'endif',
666 \ 'end': 'endif',
667 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100668 \ 's': 'substitute',
669 \ '5s': 'substitute',
670 \ ':5s': 'substitute',
671 \ "'<,'>s": 'substitute',
672 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100673 \ 'CheckLin': 'CheckLinux',
674 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100675 \ }
676
677 for [in, want] in items(tests)
678 call assert_equal(want, fullcommand(in))
679 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200680 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100681
682 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200683
684 command -buffer BufferLocalCommand :
685 command GlobalCommand :
686 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
687 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
688 delcommand BufferLocalCommand
689 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100690endfunc
691
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200692func Test_shellcmd_completion()
693 let save_path = $PATH
694
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100695 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200696 call writefile([''], 'Xpathdir/Xfile.exe')
697 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
698
699 " Set PATH to example directory without trailing slash.
700 let $PATH = getcwd() . '/Xpathdir'
701
702 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
703 " dirs in the PATH, even though they won't be executed. We check that only
704 " subdirs of the PWD and executables from the PATH are included in the
705 " suggestions.
706 let actual = getcompletion('X', 'shellcmd')
707 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
708 call insert(expected, 'Xfile.exe')
709 call assert_equal(expected, actual)
710
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200711 let $PATH = save_path
712endfunc
713
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200714func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100715 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200716 call writefile(['asdfasdf'], 'a/b/fileXname')
717 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000718 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200719 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200720endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100721
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100722func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100723 let @a = "def"
724 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
725 call assert_equal('"abc def ghi', @:)
726
727 new
728 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
729
730 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
731 call assert_equal('"aaa asdf bbb', @:)
732
733 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
734 call assert_equal('"aaa /tmp/some bbb', @:)
735
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200736 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
737 call assert_equal('"aaa '.getline(1).' bbb', @:)
738
Bram Moolenaar21efc362016-12-03 14:05:49 +0100739 set incsearch
740 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
741 call assert_equal('"aaa verylongword bbb', @:)
742
743 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
744 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100745
746 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
747 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100748 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200749
750 " Error while typing a command used to cause that it was not executed
751 " in the end.
752 new
753 try
754 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
755 catch /^Vim\%((\a\+)\)\=:E32/
756 " ignore error E32
757 endtry
758 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100759
Bram Moolenaar578fe942020-02-27 21:32:51 +0100760 " Try to paste an invalid register using <C-R>
761 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
762 call assert_equal('"onetwo', @:)
763
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100764 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100765 let @a = "xy\<C-H>z"
766 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
767 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100768 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
769 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100770 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
771 call assert_equal("\"xy\<C-H>z", @:)
772
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100773 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
774 let @a = "xy\<C-V>z"
775 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
776 call assert_equal('"xyz', @:)
777 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
778 call assert_equal("\"xy\<C-V>z", @:)
779
Bram Moolenaar578fe942020-02-27 21:32:51 +0100780 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
781
Bram Moolenaar72532d32018-04-07 19:09:09 +0200782 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100783endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100784
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100785func Test_cmdline_remove_char()
786 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100787
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100788 for e in ['utf8', 'latin1']
789 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100790
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100791 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
792 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100793
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100794 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
795 call assert_equal('"abcdef', @:)
796
797 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
798 call assert_equal('"abc ghi', @:, e)
799
800 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
801 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100802
803 " This was going before the start in latin1.
804 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100805 endfor
806
807 let &encoding = encoding_save
808endfunc
809
810func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200811 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100812
813 set keymap=esperanto
814 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
815 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
816 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100817endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100818
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100819func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100820 new
821 2;'(
822 2;')
823 quit
824endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100825
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100826func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100827 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100828 new
829 source Xtest.vim
830 " Trigger calling validate_cursor()
831 diffsp Xtest.vim
832 quit!
833 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100834endfunc
835
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100836func Test_mark_from_line_zero()
837 " this was reading past the end of the first (empty) line
838 new
839 norm oxxxx
840 call assert_fails("0;'(", 'E20:')
841 bwipe!
842endfunc
843
Bram Moolenaarba47b512017-01-24 21:18:19 +0100844func Test_cmdline_complete_wildoptions()
845 help
846 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
847 let a = join(sort(split(@:)),' ')
848 set wildoptions=tagfile
849 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
850 let b = join(sort(split(@:)),' ')
851 call assert_equal(a, b)
852 bw!
853endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100854
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200855func Test_cmdline_complete_user_cmd()
856 command! -complete=color -nargs=1 Foo :
857 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
858 call assert_equal('"Foo blue', @:)
859 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
860 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000861 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
862 call assert_equal('"Foo a blue', @:)
863 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
864 call assert_equal('"Foo b\', @:)
865 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
866 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200867 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100868
869 redraw
870 call assert_equal('~', Screenline(&lines - 1))
871 command! FooOne :
872 command! FooTwo :
873
874 set nowildmenu
875 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
876 call assert_equal('"FooOne', @:)
877 call assert_equal('~', Screenline(&lines - 1))
878
879 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
880 call assert_equal('"FooTwo', @:)
881 call assert_equal('~', Screenline(&lines - 1))
882
883 delcommand FooOne
884 delcommand FooTwo
885 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200886endfunc
887
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100888func Test_complete_user_cmd()
889 command FooBar echo 'global'
890 command -buffer FooBar echo 'local'
891 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
892 call assert_equal('"FooBar', @:)
893
894 delcommand -buffer FooBar
895 delcommand FooBar
896endfunc
897
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100898func s:ScriptLocalFunction()
899 echo 'yes'
900endfunc
901
902func Test_cmdline_complete_user_func()
903 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200904 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100905 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
906 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100907
908 " g: prefix also works
909 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
910 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200911
912 " using g: prefix does not result in just "g:" matches from a lambda
913 let Fx = { a -> a }
914 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
915 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200916
917 " existence of script-local dict function does not break user function name
918 " completion
919 function s:a_dict_func() dict
920 endfunction
921 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
922 call assert_match('"call Test_cmdline_complete_user_', @:)
923 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100924endfunc
925
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200926func Test_cmdline_complete_user_names()
927 if has('unix') && executable('whoami')
928 let whoami = systemlist('whoami')[0]
929 let first_letter = whoami[0]
930 if len(first_letter) > 0
931 " Trying completion of :e ~x where x is the first letter of
932 " the user name should complete to at least the user name.
933 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
934 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
935 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200936 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200937 " Just in case: check that the system has an Administrator account.
938 let names = system('net user')
939 if names =~ 'Administrator'
940 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100941 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200942 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +0100943 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200944 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200945 else
946 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200947 endif
948endfunc
949
Bram Moolenaar297610b2019-12-27 17:20:55 +0100950func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200951 CheckExecutable whoami
952 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
953 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100954endfunc
955
Bram Moolenaar8b633132020-03-20 18:20:51 +0100956func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200957 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
958 call assert_equal(lang, v:lc_time)
959
960 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
961 call assert_equal(lang, v:ctype)
962
963 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
964 call assert_equal(lang, v:collate)
965
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200966 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200967 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200968
969 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200970 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200971
Bram Moolenaarec680282020-06-12 19:35:32 +0200972 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200973
Bram Moolenaarec680282020-06-12 19:35:32 +0200974 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
975 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200976
Bram Moolenaarec680282020-06-12 19:35:32 +0200977 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
978 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200979
Bram Moolenaarec680282020-06-12 19:35:32 +0200980 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
981 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +0200982
983 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
984 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +0200985endfunc
986
Bram Moolenaar297610b2019-12-27 17:20:55 +0100987func Test_cmdline_complete_env_variable()
988 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +0100989 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
990 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100991 unlet $X_VIM_TEST_COMPLETE_ENV
992endfunc
993
Bram Moolenaar4941b5e2020-12-24 17:15:53 +0100994func Test_cmdline_complete_expression()
995 let g:SomeVar = 'blah'
996 for cmd in ['exe', 'echo', 'echon', 'echomsg']
997 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
998 call assert_match('"' .. cmd .. ' SomeVar', @:)
999 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1000 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1001 endfor
1002 unlet g:SomeVar
1003endfunc
1004
Bram Moolenaar47016f52021-08-26 16:39:58 +02001005" Unique function name for completion below
1006func s:WeirdFunc()
1007 echo 'weird'
1008endfunc
1009
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001010" Test for various command-line completion
1011func Test_cmdline_complete_various()
1012 " completion for a command starting with a comment
1013 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1014 call assert_equal("\" :|\"\<C-A>", @:)
1015
1016 " completion for a range followed by a comment
1017 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1018 call assert_equal("\"1,2\"\<C-A>", @:)
1019
1020 " completion for :k command
1021 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1022 call assert_equal("\"ka\<C-A>", @:)
1023
1024 " completion for short version of the :s command
1025 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1026 call assert_equal("\"sI \<C-A>", @:)
1027
1028 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001029 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001030 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001031 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001032 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001033 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1034 call assert_equal("\"w >> Xfile1", @:)
1035 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001036
1037 " completion for :w ! and :r ! commands
1038 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1039 call assert_equal("\"w !invalid_xyz_cmd", @:)
1040 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1041 call assert_equal("\"r !invalid_xyz_cmd", @:)
1042
1043 " completion for :>> and :<< commands
1044 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1045 call assert_equal("\">>>\<C-A>", @:)
1046 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1047 call assert_equal("\"<<<\<C-A>", @:)
1048
1049 " completion for command with +cmd argument
1050 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1051 call assert_equal("\"buffer +/pat Xabc", @:)
1052 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1053 call assert_equal("\"buffer +/pat\<C-A>", @:)
1054
1055 " completion for a command with a trailing comment
1056 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1057 call assert_equal("\"ls \" comment\<C-A>", @:)
1058
1059 " completion for a command with a trailing command
1060 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1061 call assert_equal("\"ls | ls", @:)
1062
1063 " completion for a command with an CTRL-V escaped argument
1064 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1065 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1066
1067 " completion for a command that doesn't take additional arguments
1068 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1069 call assert_equal("\"all abc\<C-A>", @:)
1070
zeertzjqd3de1782022-09-01 12:58:52 +01001071 " completion for :wincmd with :horizontal modifier
1072 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1073 call assert_equal("\"horizontal wincmd", @:)
1074
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001075 " completion for a command with a command modifier
1076 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1077 call assert_equal("\"topleft new", @:)
1078
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001079 " completion for vim9 and legacy commands
1080 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1081 call assert_equal("\"vim9 call strlen(", @:)
1082 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1083 call assert_equal("\"legac call strlen(", @:)
1084
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001085 " completion for the :disassemble command
1086 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1087 call assert_equal("\"disas debug", @:)
1088 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal("\"disas profile", @:)
1090 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1091 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1092 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001094 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1095 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001096
Bram Moolenaar47016f52021-08-26 16:39:58 +02001097 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001098 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001099
naohiro onodfe04db2021-09-12 15:45:10 +02001100 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1101 call assert_match('"disas <SNR>\d\+_', @:)
1102 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1103 call assert_match('"disas debug <SNR>\d\+_', @:)
1104
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001105 " completion for the :match command
1106 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1107 call assert_equal("\"match Search /pat/\<C-A>", @:)
1108
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001109 " completion for the :doautocmd command
1110 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1111 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1112
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001113 " completion of autocmd group after comma
1114 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1115 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1116
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001117 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001118 call writefile([], 'Xvarfile1', 'D')
1119 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001120 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1121 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001122
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001123 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001124 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001125 augroup END
1126 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001127 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001128
1129 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001130 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1131 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001132 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1133 call assert_equal("\"au XTest.test", @:)
1134
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001135 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001136
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001137 " autocmd pattern completion
1138 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal("\"au BufEnter *.py\t", @:)
1140
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001141 " completion for the :unlet command
1142 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1143 call assert_equal("\"unlet one two", @:)
1144
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001145 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001146 " FIXME: what should happen on MS-Windows?
1147 if !has('win32')
1148 edit \{someFile}
1149 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1150 call assert_equal("\"buf {someFile}", @:)
1151 bwipe {someFile}
1152 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001153
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001154 " completion for the :bdelete command
1155 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1156 call assert_equal("\"bdel a b c", @:)
1157
1158 " completion for the :mapclear command
1159 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1160 call assert_equal("\"mapclear <buffer>", @:)
1161
1162 " completion for user defined commands with menu names
1163 menu Test.foo :ls<CR>
1164 com -nargs=* -complete=menu MyCmd
1165 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal('"MyCmd Test.', @:)
1167 delcom MyCmd
1168 unmenu Test
1169
1170 " completion for user defined commands with mappings
1171 mapclear
1172 map <F3> :ls<CR>
1173 com -nargs=* -complete=mapping MyCmd
1174 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001175 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001176 mapclear
1177 delcom MyCmd
1178
1179 " completion for :set path= with multiple backslashes
1180 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1181 call assert_equal('"set path=a\\\ b', @:)
1182
1183 " completion for :set dir= with a backslash
1184 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1185 call assert_equal('"set dir=a\ b', @:)
1186
1187 " completion for the :py3 commands
1188 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1189 call assert_equal('"py3 py3do py3file', @:)
1190
Bram Moolenaardf749a22021-03-28 15:29:43 +02001191 " completion for the :vim9 commands
1192 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1193 call assert_equal('"vim9cmd vim9script', @:)
1194
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001195 " redir @" is not the start of a comment. So complete after that
1196 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1197 call assert_equal('"redir @" | cwindow', @:)
1198
1199 " completion after a backtick
1200 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1201 call assert_equal('"e `a1b2c', @:)
1202
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001203 " completion for :language command with an invalid argument
1204 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1205 call assert_equal("\"language dummy \t", @:)
1206
1207 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001208 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1209 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001210
1211 " completion with ambiguous user defined commands
1212 com TCmd1 echo 'TCmd1'
1213 com TCmd2 echo 'TCmd2'
1214 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1215 call assert_equal('"TCmd ', @:)
1216 delcom TCmd1
1217 delcom TCmd2
1218
1219 " completion after a range followed by a pipe (|) character
1220 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1221 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001222
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001223 " completion after a :global command
1224 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1225 call assert_equal('"g/a/chistory', @:)
1226 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1227 call assert_equal("\"g/a\\/chist\t", @:)
1228
Bram Moolenaar9c929712020-09-07 22:05:28 +02001229 " use <Esc> as the 'wildchar' for completion
1230 set wildchar=<Esc>
1231 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1232 call assert_equal('"g/a\xb/clearjumps', @:)
1233 " pressing <esc> twice should cancel the command
1234 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1235 call assert_equal('"g/a\xb/clearjumps', @:)
1236 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001237
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001238 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001239 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001240 call writefile([], '~Xtest')
1241 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1242 call assert_equal('"e \~Xtest', @:)
1243 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001244
1245 " should be able to complete a file name that has a '*'
1246 call writefile([], 'Xx*Yy')
1247 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1248 call assert_equal('"e Xx\*Yy', @:)
1249 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001250
1251 " use a literal star
1252 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1253 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001254 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001255
1256 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1257 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001258endfunc
1259
1260" Test for 'wildignorecase'
1261func Test_cmdline_wildignorecase()
1262 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001263 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001264 set wildignorecase
1265 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1266 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001267 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001268 let g:Sline = ''
1269 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1270 call assert_equal('"e xt', @:)
1271 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001272 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001273endfunc
1274
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001275func Test_cmdline_write_alternatefile()
1276 new
1277 call setline('.', ['one', 'two'])
1278 f foo.txt
1279 new
1280 f #-A
1281 call assert_equal('foo.txt-A', expand('%'))
1282 f #<-B.txt
1283 call assert_equal('foo-B.txt', expand('%'))
1284 f %<
1285 call assert_equal('foo-B', expand('%'))
1286 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001287 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001288 bw!
1289 f foo-B.txt
1290 f %<-A
1291 call assert_equal('foo-B-A', expand('%'))
1292 bw!
1293 bw!
1294endfunc
1295
Bram Moolenaarf5724372022-09-02 19:45:15 +01001296func Test_cmdline_expand_cur_alt_file()
1297 enew
1298 file http://some.com/file.txt
1299 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1300 call assert_equal('"e http://some.com/file.txt', @:)
1301 edit another
1302 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1303 call assert_equal('"e http://some.com/file.txt', @:)
1304 bwipe
1305 bwipe http://some.com/file.txt
1306endfunc
1307
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001308" using a leading backslash here
1309set cpo+=C
1310
1311func Test_cmdline_search_range()
1312 new
1313 call setline(1, ['a', 'b', 'c', 'd'])
1314 /d
1315 1,\/s/b/B/
1316 call assert_equal('B', getline(2))
1317
1318 /a
1319 $
1320 \?,4s/c/C/
1321 call assert_equal('C', getline(3))
1322
1323 call setline(1, ['a', 'b', 'c', 'd'])
1324 %s/c/c/
1325 1,\&s/b/B/
1326 call assert_equal('B', getline(2))
1327
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001328 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001329 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001330
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001331 bwipe!
1332endfunc
1333
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001334" Test for the tick mark (') in an excmd range
1335func Test_tick_mark_in_range()
1336 " If only the tick is passed as a range and no command is specified, there
1337 " should not be an error
1338 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001339 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001340 call assert_fails("',print", 'E78:')
1341endfunc
1342
1343" Test for using a line number followed by a search pattern as range
1344func Test_lnum_and_pattern_as_range()
1345 new
1346 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1347 let @" = ''
1348 2/foo/yank
1349 call assert_equal("foo 3\n", @")
1350 call assert_equal(1, line('.'))
1351 close!
1352endfunc
1353
Bram Moolenaar65189a12017-02-06 22:22:17 +01001354" Tests for getcmdline(), getcmdpos() and getcmdtype()
1355func Check_cmdline(cmdtype)
1356 call assert_equal('MyCmd a', getcmdline())
1357 call assert_equal(8, getcmdpos())
1358 call assert_equal(a:cmdtype, getcmdtype())
1359 return ''
1360endfunc
1361
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001362set cpo&
1363
Bram Moolenaar65189a12017-02-06 22:22:17 +01001364func Test_getcmdtype()
1365 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1366
1367 let cmdtype = ''
1368 debuggreedy
1369 call feedkeys(":debug echo 'test'\<CR>", "t")
1370 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1371 call feedkeys("cont\<CR>", "xt")
1372 0debuggreedy
1373 call assert_equal('>', cmdtype)
1374
1375 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1376 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1377
1378 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001379 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001380
1381 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1382
1383 cnoremap <expr> <F6> Check_cmdline('=')
1384 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1385 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001386
1387 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001388endfunc
1389
Bram Moolenaar52604f22017-04-07 16:17:39 +02001390func Test_verbosefile()
1391 set verbosefile=Xlog
1392 echomsg 'foo'
1393 echomsg 'bar'
1394 set verbosefile=
1395 let log = readfile('Xlog')
1396 call assert_match("foo\nbar", join(log, "\n"))
1397 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001398
1399 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001400 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001401endfunc
1402
Bram Moolenaar4facea32019-10-12 20:17:40 +02001403func Test_verbose_option()
1404 CheckScreendump
1405
1406 let lines =<< trim [SCRIPT]
1407 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1408 call feedkeys("\r", 't') " for the hit-enter prompt
1409 set verbose=20
1410 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001411 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001412
1413 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001414 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001415 call term_sendkeys(buf, ":DoSomething\<CR>")
1416 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1417
1418 " clean up
1419 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001420endfunc
1421
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001422func Test_setcmdpos()
1423 func InsertTextAtPos(text, pos)
1424 call assert_equal(0, setcmdpos(a:pos))
1425 return a:text
1426 endfunc
1427
1428 " setcmdpos() with position in the middle of the command line.
1429 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1430 call assert_equal('"1ab2', @:)
1431
1432 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1433 call assert_equal('"1b2a', @:)
1434
1435 " setcmdpos() with position beyond the end of the command line.
1436 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1437 call assert_equal('"12ab', @:)
1438
1439 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001440 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001441endfunc
1442
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001443func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001444 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001445 let encoding_save = &encoding
1446
1447 for e in encodings
1448 exe 'set encoding=' . e
1449
1450 " Test overstrike in the middle of the command line.
1451 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001452 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001453
1454 " Test overstrike going beyond end of command line.
1455 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001456 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001457
1458 " Test toggling insert/overstrike a few times.
1459 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001460 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001461 endfor
1462
Bram Moolenaar30276f22019-01-24 17:59:39 +01001463 " Test overstrike with multi-byte characters.
1464 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001465 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001466
1467 let &encoding = encoding_save
1468endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001469
Bram Moolenaar52410572019-10-27 05:12:45 +01001470func Test_buffers_lastused()
1471 " check that buffers are sorted by time when wildmode has lastused
1472 call test_settime(1550020000) " middle
1473 edit bufa
1474 enew
1475 call test_settime(1550030000) " newest
1476 edit bufb
1477 enew
1478 call test_settime(1550010000) " oldest
1479 edit bufc
1480 enew
1481 call test_settime(0)
1482 enew
1483
1484 call assert_equal(['bufa', 'bufb', 'bufc'],
1485 \ getcompletion('', 'buffer'))
1486
1487 let save_wildmode = &wildmode
1488 set wildmode=full:lastused
1489
1490 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1491 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1492 call assert_equal('b bufb', X)
1493 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1494 call assert_equal('b bufa', X)
1495 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1496 call assert_equal('b bufc', X)
1497 enew
1498
1499 edit other
1500 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1501 call assert_equal('b bufb', X)
1502 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1503 call assert_equal('b bufa', X)
1504 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1505 call assert_equal('b bufc', X)
1506 enew
1507
1508 let &wildmode = save_wildmode
1509
1510 bwipeout bufa
1511 bwipeout bufb
1512 bwipeout bufc
1513endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001514
Bram Moolenaar479950f2020-01-19 15:45:17 +01001515func Test_cmdlineclear_tabenter()
1516 CheckScreendump
1517
1518 let lines =<< trim [SCRIPT]
1519 call setline(1, range(30))
1520 [SCRIPT]
1521
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001522 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001523 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001524 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001525 " in one tab make the command line higher with CTRL-W -
1526 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1527 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1528
1529 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001530endfunc
1531
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001532" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001533func Test_cmdline_expand_special()
1534 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001535 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001536 call assert_fails('e <afile>', 'E495:')
1537 call assert_fails('e <abuf>', 'E496:')
1538 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001539
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001540 call writefile([], 'Xfile.cpp', 'D')
1541 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001542 new Xfile.cpp
1543 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1544 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1545 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001546endfunc
1547
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001548" Test for backtick expression in the command line
1549func Test_cmd_backtick()
1550 %argd
1551 argadd `=['a', 'b', 'c']`
1552 call assert_equal(['a', 'b', 'c'], argv())
1553 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001554
1555 argadd `echo abc def`
1556 call assert_equal(['abc def'], argv())
1557 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001558endfunc
1559
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001560" Test for the :! command
1561func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001562 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001563
1564 let lines =<< trim [SCRIPT]
1565 " Test for no previous command
1566 call assert_fails('!!', 'E34:')
1567 set nomore
1568 " Test for cmdline expansion with :!
1569 call setline(1, 'foo!')
1570 silent !echo <cWORD> > Xfile.out
1571 call assert_equal(['foo!'], readfile('Xfile.out'))
1572 " Test for using previous command
1573 silent !echo \! !
1574 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1575 call writefile(v:errors, 'Xresult')
1576 call delete('Xfile.out')
1577 qall!
1578 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001579 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001580 if RunVim([], [], '--clean -S Xscript')
1581 call assert_equal([], readfile('Xresult'))
1582 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001583 call delete('Xresult')
1584endfunc
1585
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001586" Test error: "E135: *Filter* Autocommands must not change current buffer"
1587func Test_cmd_bang_E135()
1588 new
1589 call setline(1, ['a', 'b', 'c', 'd'])
1590 augroup test_cmd_filter_E135
1591 au!
1592 autocmd FilterReadPost * help
1593 augroup END
1594 call assert_fails('2,3!echo "x"', 'E135:')
1595
1596 augroup test_cmd_filter_E135
1597 au!
1598 augroup END
1599 %bwipe!
1600endfunc
1601
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001602" Test for using ~ for home directory in cmdline completion matches
1603func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001604 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001605 call writefile([], 'Xexpdir/Xfile1')
1606 call writefile([], 'Xexpdir/Xfile2')
1607 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001608 let save_HOME = $HOME
1609 let $HOME = getcwd()
1610 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1611 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1612 let $HOME = save_HOME
1613 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001614endfunc
1615
Bram Moolenaar578fe942020-02-27 21:32:51 +01001616" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1617" or insert mode (when 'insertmode' is set)
1618func Test_cmdline_ctrl_g()
1619 new
1620 call setline(1, 'abc')
1621 call cursor(1, 3)
1622 " If command line is entered from insert mode, using C-\ C-G should back to
1623 " insert mode
1624 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1625 call assert_equal('abxyc', getline(1))
1626 call assert_equal(4, col('.'))
1627
1628 " If command line is entered in 'insertmode', using C-\ C-G should back to
1629 " 'insertmode'
1630 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1631 call assert_equal('ab12xyc', getline(1))
1632 close!
1633endfunc
1634
Bram Moolenaar578fe942020-02-27 21:32:51 +01001635" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001636func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001637 func T(a, c, p)
1638 return "oneA\noneB\noneC"
1639 endfunc
1640 command -nargs=1 -complete=custom,T MyCmd
1641
Bram Moolenaar578fe942020-02-27 21:32:51 +01001642 set nowildmenu
1643 set wildmode=full,list
1644 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001645 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001646 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001647 call assert_equal('"MyCmd oneA', @:)
1648
1649 set wildmode=longest,full
1650 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1651 call assert_equal('"MyCmd one', @:)
1652 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1653 call assert_equal('"MyCmd oneC', @:)
1654
1655 set wildmode=longest
1656 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1657 call assert_equal('"MyCmd one', @:)
1658
1659 set wildmode=list:longest
1660 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001661 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001662 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001663 call assert_equal('"MyCmd one', @:)
1664
1665 set wildmode=""
1666 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1667 call assert_equal('"MyCmd oneA', @:)
1668
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001669 " Test for wildmode=longest with 'fileignorecase' set
1670 set wildmode=longest
1671 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001672 argadd AAA AAAA AAAAA
1673 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1674 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001675 set fileignorecase&
1676
1677 " Test for listing files with wildmode=list
1678 set wildmode=list
1679 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001680 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001681 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001682 call assert_equal('"b A', @:)
1683
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001684 " when using longest completion match, matches shorter than the argument
1685 " should be ignored (happens with :help)
1686 set wildmode=longest,full
1687 set wildmenu
1688 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1689 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001690 " non existing file
1691 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1692 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001693 set wildmenu&
1694
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001695 " Test for longest file name completion with 'fileignorecase'
1696 " On MS-Windows, file names are case insensitive.
1697 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001698 call writefile([], 'XTESTfoo', 'D')
1699 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001700 set nofileignorecase
1701 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1702 call assert_equal('"e XTESTfoo', @:)
1703 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1704 call assert_equal('"e Xtestbar', @:)
1705 set fileignorecase
1706 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1707 call assert_equal('"e Xtest', @:)
1708 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1709 call assert_equal('"e Xtest', @:)
1710 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001711 endif
1712
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001713 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001714 delcommand MyCmd
1715 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001716 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001717 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001718endfunc
1719
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001720func Test_wildmode()
1721 " Test with utf-8 encoding
1722 call Wildmode_tests()
1723
1724 " Test with latin1 encoding
1725 let save_encoding = &encoding
1726 set encoding=latin1
1727 call Wildmode_tests()
1728 let &encoding = save_encoding
1729endfunc
1730
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001731func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001732 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001733 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001734 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001735 let lines =<< trim END
1736 func vim8#Complete(a, c, p)
1737 return "oneA\noneB\noneC"
1738 endfunc
1739 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001740 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001741
1742 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1743 set nowildmenu
1744 set wildmode=full,list
1745 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1746 call assert_equal('"MyCmd oneA oneB oneC', @:)
1747
1748 let &rtp = save_rtp
1749 set wildmode& wildmenu&
1750 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001751endfunc
1752
Bram Moolenaar578fe942020-02-27 21:32:51 +01001753" Test for interrupting the command-line completion
1754func Test_interrupt_compl()
1755 func F(lead, cmdl, p)
1756 if a:lead =~ 'tw'
1757 call interrupt()
1758 return
1759 endif
1760 return "one\ntwo\nthree"
1761 endfunc
1762 command -nargs=1 -complete=custom,F Tcmd
1763
1764 set nowildmenu
1765 set wildmode=full
1766 let interrupted = 0
1767 try
1768 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1769 catch /^Vim:Interrupt$/
1770 let interrupted = 1
1771 endtry
1772 call assert_equal(1, interrupted)
1773
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001774 let interrupted = 0
1775 try
1776 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1777 catch /^Vim:Interrupt$/
1778 let interrupted = 1
1779 endtry
1780 call assert_equal(1, interrupted)
1781
Bram Moolenaar578fe942020-02-27 21:32:51 +01001782 delcommand Tcmd
1783 delfunc F
1784 set wildmode&
1785endfunc
1786
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001787" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001788func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001789 let str = ":one two\<C-U>"
1790 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001791 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001792 let str ..= "\<Left>five\<Right>"
1793 let str ..= "\<Home>two "
1794 let str ..= "\<C-Left>one "
1795 let str ..= "\<C-Right> three"
1796 let str ..= "\<End>\<S-Left>four "
1797 let str ..= "\<S-Right> six"
1798 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1799 call feedkeys(str, 'xt')
1800 call assert_equal("\"one two three four five six seven", @:)
1801endfunc
1802
1803" Test for moving the cursor on the / command line in 'rightleft' mode
1804func Test_cmdline_edit_rightleft()
1805 CheckFeature rightleft
1806 set rightleft
1807 set rightleftcmd=search
1808 let str = "/one two\<C-U>"
1809 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001810 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001811 let str ..= "\<Right>five\<Left>"
1812 let str ..= "\<Home>two "
1813 let str ..= "\<C-Right>one "
1814 let str ..= "\<C-Left> three"
1815 let str ..= "\<End>\<S-Right>four "
1816 let str ..= "\<S-Left> six"
1817 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1818 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1819 call assert_equal("\"one two three four five six seven", @/)
1820 set rightleftcmd&
1821 set rightleft&
1822endfunc
1823
1824" Test for using <C-\>e in the command line to evaluate an expression
1825func Test_cmdline_expr()
1826 " Evaluate an expression from the beginning of a command line
1827 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1828 call assert_equal('"hello', @:)
1829
1830 " Use an invalid expression for <C-\>e
1831 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1832
1833 " Insert literal <CTRL-\> in the command line
1834 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1835 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001836endfunc
1837
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001838" This was making the insert position negative
1839func Test_cmdline_expr_register()
1840 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1841endfunc
1842
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001843" Test for 'imcmdline' and 'imsearch'
1844" This test doesn't actually test the input method functionality.
1845func Test_cmdline_inputmethod()
1846 new
1847 call setline(1, ['', 'abc', ''])
1848 set imcmdline
1849
1850 call feedkeys(":\"abc\<CR>", 'xt')
1851 call assert_equal("\"abc", @:)
1852 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1853 call assert_equal("\"abc", @:)
1854 call feedkeys("/abc\<CR>", 'xt')
1855 call assert_equal([2, 1], [line('.'), col('.')])
1856 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1857 call assert_equal([2, 1], [line('.'), col('.')])
1858
1859 set imsearch=2
1860 call cursor(1, 1)
1861 call feedkeys("/abc\<CR>", 'xt')
1862 call assert_equal([2, 1], [line('.'), col('.')])
1863 call cursor(1, 1)
1864 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1865 call assert_equal([2, 1], [line('.'), col('.')])
1866 set imdisable
1867 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1868 call assert_equal([2, 1], [line('.'), col('.')])
1869 set imdisable&
1870 set imsearch&
1871
1872 set imcmdline&
1873 %bwipe!
1874endfunc
1875
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001876" Test for using CTRL-_ in the command line with 'allowrevins'
1877func Test_cmdline_revins()
1878 CheckNotMSWindows
1879 CheckFeature rightleft
1880 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
1881 call assert_equal("\"abc\<c-_>", @:)
1882 set allowrevins
1883 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
1884 call assert_equal('"abcñèæ', @:)
1885 set allowrevins&
1886endfunc
1887
1888" Test for typing UTF-8 composing characters in the command line
1889func Test_cmdline_composing_chars()
1890 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
1891 call assert_equal('"ゔ', @:)
1892endfunc
1893
Bram Moolenaar0e717042020-04-27 19:29:01 +02001894" test that ";" works to find a match at the start of the first line
1895func Test_zero_line_search()
1896 new
1897 call setline(1, ["1, pattern", "2, ", "3, pattern"])
1898 call cursor(1,1)
1899 0;/pattern/d
1900 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
1901 q!
1902endfunc
1903
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001904func Test_read_shellcmd()
1905 CheckUnix
1906 if executable('ls')
1907 " There should be ls in the $PATH
1908 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
1909 call assert_match('^"r! .*\<ls\>', @:)
1910 endif
1911
1912 if executable('rm')
1913 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
1914 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
1915 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02001916
1917 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
1918 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
1919 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02001920 endif
1921endfunc
1922
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001923" Test for going up and down the directory tree using 'wildmenu'
1924func Test_wildmenu_dirstack()
1925 CheckUnix
1926 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001927 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001928 call writefile([], 'Xwildmenu/file1_1.txt')
1929 call writefile([], 'Xwildmenu/file1_2.txt')
1930 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
1931 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
1932 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
1933 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
1934 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
1935 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001936 set wildmenu
1937
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001938 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001939 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001940 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001941 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001942 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001943 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001944 call assert_equal('"e ../../dir3/', @:)
1945 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
1946 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001947 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001948 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001949 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001950 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001951 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01001952 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
1953 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001954
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01001955 set wildmenu&
1956endfunc
1957
obcat71c6f7a2021-05-13 20:23:10 +02001958" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001959" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
1960" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02001961func Test_recalling_cmdline()
1962 CheckFeature cmdline_hist
1963
1964 let g:cmdlines = []
1965 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
1966
1967 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001968 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
1969 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
1970 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
1971 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02001972 "\ TODO: {'name': 'debug', ...}
1973 \]
1974 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00001975 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
1976 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
1977 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
1978 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
1979 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02001980 \]
1981 let prefix = 'vi'
1982 for h in histories
1983 call histadd(h.name, 'vim')
1984 call histadd(h.name, 'virtue')
1985 call histadd(h.name, 'Virgo')
1986 call histadd(h.name, 'vogue')
1987 call histadd(h.name, 'emacs')
1988 for k in keypairs
1989 let g:cmdlines = []
1990 let keyseqs = h.enter
1991 \ .. prefix
1992 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
1993 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
1994 \ .. h.exit
1995 call feedkeys(keyseqs, 'xt')
1996 call histdel(h.name, -1) " delete the history added by feedkeys above
1997 let expect = k.prefixmatch
1998 \ ? ['virtue', 'vim', 'virtue', prefix]
1999 \ : ['emacs', 'vogue', 'emacs', prefix]
2000 call assert_equal(expect, g:cmdlines)
2001 endfor
2002 endfor
2003
2004 unlet g:cmdlines
2005 cunmap <Plug>(save-cmdline)
2006endfunc
2007
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002008func Test_cmd_map_cmdlineChanged()
2009 let g:log = []
2010 cnoremap <F1> l<Cmd><CR>s
2011 augroup test
2012 autocmd!
2013 autocmd CmdlineChanged : let g:log += [getcmdline()]
2014 augroup END
2015
2016 call feedkeys(":\<F1>\<CR>", 'xt')
2017 call assert_equal(['l', 'ls'], g:log)
2018
Bram Moolenaar796139a2021-05-18 21:38:45 +02002019 let @b = 'b'
2020 cnoremap <F1> a<C-R>b
2021 let g:log = []
2022 call feedkeys(":\<F1>\<CR>", 'xt')
2023 call assert_equal(['a', 'ab'], g:log)
2024
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002025 unlet g:log
2026 cunmap <F1>
2027 augroup test
2028 autocmd!
2029 augroup END
2030endfunc
2031
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002032" Test for the 'suffixes' option
2033func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002034 call writefile([], 'Xsuffile', 'D')
2035 call writefile([], 'Xsuffile.c', 'D')
2036 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002037 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002038 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2039 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2040 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2041 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002042 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002043 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2044 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2045 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2046 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002047 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002048 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2049 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2050 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2051 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002052 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002053 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002054 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2055 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002056endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002057
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002058" Test for using a popup menu for the command line completion matches
2059" (wildoptions=pum)
2060func Test_wildmenu_pum()
2061 CheckRunVimInTerminal
2062
2063 let commands =<< trim [CODE]
2064 set wildmenu
2065 set wildoptions=pum
2066 set shm+=I
2067 set noruler
2068 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002069
2070 func CmdCompl(a, b, c)
2071 return repeat(['aaaa'], 120)
2072 endfunc
2073 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002074
2075 func MyStatusLine() abort
2076 return 'status'
2077 endfunc
2078 func SetupStatusline()
2079 set statusline=%!MyStatusLine()
2080 set laststatus=2
2081 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002082
2083 func MyTabLine()
2084 return 'my tab line'
2085 endfunc
2086 func SetupTabline()
2087 set statusline=
2088 set tabline=%!MyTabLine()
2089 set showtabline=2
2090 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002091
2092 func DoFeedKeys()
2093 let &wildcharm = char2nr("\t")
2094 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2095 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002096 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002097 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002098
2099 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2100
2101 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002102 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2103
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002104 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002105 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002106 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2107
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002108 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002109 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002110 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2111
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002112 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002113 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002114 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2115
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002116 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002117 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002118 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2119
2120 " pressing <C-E> should end completion and go back to the original match
2121 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002122 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2123
2124 " pressing <C-Y> should select the current match and end completion
2125 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002126 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2127
2128 " With 'wildmode' set to 'longest,full', completing a match should display
2129 " the longest match, the wildmenu should not be displayed.
2130 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2131 call TermWait(buf)
2132 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002133 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2134
2135 " pressing <Tab> should display the wildmenu
2136 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002137 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2138
2139 " pressing <Tab> second time should select the next entry in the menu
2140 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002141 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2142
2143 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002144 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002145 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002146 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2147
2148 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002149 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2150
2151 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002152 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2153
2154 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002155 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002156 call writefile([], 'Xnamedir/XfileA')
2157 call writefile([], 'Xnamedir/XdirA/XfileB')
2158 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002159
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002160 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002161 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2162
2163 " Pressing <Right> on a directory name should go into that directory
2164 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002165 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2166
2167 " Pressing <Left> on a directory name should go to the parent directory
2168 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002169 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2170
2171 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002172 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002173 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002174 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2175
2176 " Pressing <C-D> when the popup menu is displayed should remove the popup
2177 " menu
2178 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002179 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2180
2181 " Pressing <S-Tab> should open the popup menu with the last entry selected
2182 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002183 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2184
2185 " Pressing <Esc> should close the popup menu and cancel the cmd line
2186 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002187 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2188
2189 " Typing a character when the popup is open, should close the popup
2190 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002191 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2192
2193 " When the popup is open, entering the cmdline window should close the popup
2194 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002195 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2196 call term_sendkeys(buf, ":q\<CR>")
2197
2198 " After the last popup menu item, <C-N> should show the original string
2199 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002200 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2201
2202 " Use the popup menu for the command name
2203 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002204 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2205
2206 " Pressing the left arrow should remove the popup menu
2207 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002208 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2209
2210 " Pressing <BS> should remove the popup menu and erase the last character
2211 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002212 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2213
2214 " Pressing <C-W> should remove the popup menu and erase the previous word
2215 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002216 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2217
2218 " Pressing <C-U> should remove the popup menu and erase the entire line
2219 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002220 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2221
2222 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2223 " the cmdline from history
2224 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002225 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2226
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002227 " Check "list" still works
2228 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2229 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002230 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2231 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002232 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2233
rbtnn68cc2b82022-02-09 11:55:47 +00002234 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002235 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002236 call writefile([], 'Xnamedir/あいう/abc')
2237 call writefile([], 'Xnamedir/あいう/xyz')
2238 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002239
2240 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002241 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002242 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2243
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002244 " Pressing <C-A> when the popup menu is displayed should list all the
2245 " matches and pressing a key after that should remove the popup menu
2246 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2247 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2249
2250 " Pressing <C-A> when the popup menu is displayed should list all the
2251 " matches and pressing <Left> after that should move the cursor
2252 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2253 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2254 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2255
2256 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2257 " should be displayed correctly on the screen.
2258 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2259 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2260
2261 " After using <C-A> to expand all the filename matches, pressing <Up>
2262 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002263 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002264 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2265 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2266 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2267
2268 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2269 " crash Vim
2270 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2272
Bram Moolenaar414acd32022-02-10 21:09:45 +00002273 " After removing the pum the command line is redrawn
2274 call term_sendkeys(buf, ":edit foo\<CR>")
2275 call term_sendkeys(buf, ":edit bar\<CR>")
2276 call term_sendkeys(buf, ":ls\<CR>")
2277 call term_sendkeys(buf, ":com\<Tab> ")
2278 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002279 call term_sendkeys(buf, "\<C-U>\<CR>")
2280
2281 " Esc still works to abort the command when 'statusline' is set
2282 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2283 call term_sendkeys(buf, ":si\<Tab>")
2284 call term_sendkeys(buf, "\<Esc>")
2285 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002286
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002287 " Esc still works to abort the command when 'tabline' is set
2288 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2289 call term_sendkeys(buf, ":si\<Tab>")
2290 call term_sendkeys(buf, "\<Esc>")
2291 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2292
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002293 " popup is cleared also when 'lazyredraw' is set
2294 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2295 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2296 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2297 call term_sendkeys(buf, "\<Esc>")
2298
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002299 " Pressing <PageDown> should scroll the menu downward
2300 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2301 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2302 call term_sendkeys(buf, "\<PageDown>")
2303 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2304 call term_sendkeys(buf, "\<PageDown>")
2305 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2306 call term_sendkeys(buf, "\<PageDown>")
2307 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2308 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2310
2311 " Pressing <PageUp> should scroll the menu upward
2312 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2314 call term_sendkeys(buf, "\<PageUp>")
2315 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2316 call term_sendkeys(buf, "\<PageUp>")
2317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2318 call term_sendkeys(buf, "\<PageUp>")
2319 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2320
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002321 call term_sendkeys(buf, "\<C-U>\<CR>")
2322 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002323endfunc
2324
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002325" Test for wildmenumode() with the cmdline popup menu
2326func Test_wildmenumode_with_pum()
2327 set wildmenu
2328 set wildoptions=pum
2329 cnoremap <expr> <F2> wildmenumode()
2330 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2331 call assert_equal('"sign define10', @:)
2332 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2333 call assert_equal('"sign define jump list place undefine unplace0', @:)
2334 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2335 call assert_equal('"sign 0', @:)
2336 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2337 call assert_equal('"sign define0', @:)
2338 set nowildmenu wildoptions&
2339 cunmap <F2>
2340endfunc
2341
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002342func Test_wildmenu_with_pum_foldexpr()
2343 CheckRunVimInTerminal
2344
2345 let lines =<< trim END
2346 call setline(1, ['folded one', 'folded two', 'some more text'])
2347 func MyFoldText()
2348 return 'foo'
2349 endfunc
2350 set foldtext=MyFoldText() wildoptions=pum
2351 normal ggzfj
2352 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002353 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002354 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2355 call term_sendkeys(buf, ":set\<Tab>")
2356 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2357
2358 call term_sendkeys(buf, "\<Esc>")
2359 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2360
2361 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002362endfunc
2363
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002364" Test for opening the cmdline completion popup menu from the terminal window.
2365" The popup menu should be positioned correctly over the status line of the
2366" bottom-most window.
2367func Test_wildmenu_pum_from_terminal()
2368 CheckRunVimInTerminal
2369 let python = PythonProg()
2370 call CheckPython(python)
2371
2372 %bw!
2373 let cmds = ['set wildmenu wildoptions=pum']
2374 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2375 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002376 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002377 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2378 call term_sendkeys(buf, "\r\r\r")
2379 call term_wait(buf)
2380 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2381 call term_wait(buf)
2382 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2383 call term_wait(buf)
2384 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002385endfunc
2386
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002387" Test for completion after a :substitute command followed by a pipe (|)
2388" character
2389func Test_cmdline_complete_substitute()
2390 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2391 call assert_equal("\"s | \t", @:)
2392 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2393 call assert_equal("\"s/ | \t", @:)
2394 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2395 call assert_equal("\"s/one | \t", @:)
2396 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2397 call assert_equal("\"s/one/ | \t", @:)
2398 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2399 call assert_equal("\"s/one/two | \t", @:)
2400 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2401 call assert_equal('"s/one/two/ | chistory', @:)
2402 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2403 call assert_equal("\"s/one/two/g \t", @:)
2404 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2405 call assert_equal("\"s/one/two/g | chistory", @:)
2406 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2407 call assert_equal("\"s/one/t\\/ | \t", @:)
2408 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2409 call assert_equal('"s/one/t"o/ | chistory', @:)
2410 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2411 call assert_equal('"s/one/t|o/ | chistory', @:)
2412 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2413 call assert_equal("\"&\t", @:)
2414endfunc
2415
2416" Test for the :dlist command completion
2417func Test_cmdline_complete_dlist()
2418 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2419 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2420 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2421 call assert_equal("\"dlist 10 /pat/ \t", @:)
2422 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2423 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2424 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2425 call assert_equal("\"dlist 10 /pat\\\t", @:)
2426 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2427 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2428endfunc
2429
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002430" argument list (only for :argdel) fuzzy completion
2431func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002432 argadd change.py count.py charge.py
2433 set wildoptions&
2434 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2435 call assert_equal('"argdel cge', @:)
2436 set wildoptions=fuzzy
2437 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2438 call assert_equal('"argdel change.py charge.py', @:)
2439 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002440 set wildoptions&
2441endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002442
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002443" autocmd group name fuzzy completion
2444func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002445 set wildoptions&
2446 augroup MyFuzzyGroup
2447 augroup END
2448 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2449 call assert_equal('"augroup mfg', @:)
2450 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2451 call assert_equal('"augroup MyFuzzyGroup', @:)
2452 set wildoptions=fuzzy
2453 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2454 call assert_equal('"augroup MyFuzzyGroup', @:)
2455 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2456 call assert_equal('"augroup My*p', @:)
2457 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002458 set wildoptions&
2459endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002460
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002461" buffer name fuzzy completion
2462func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002463 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002464 " Use a long name to reduce the risk of matching a random directory name
2465 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002466 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002467 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2468 call assert_equal('"b SRFWL', @:)
2469 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2470 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002471 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002472 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2473 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2474 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2475 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002476 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002477 set wildoptions&
2478endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002479
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002480" buffer name (full path) fuzzy completion
2481func Test_fuzzy_completion_bufname_fullpath()
2482 CheckUnix
2483 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002484 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002485 edit Xcmd/Xstate/Xfile.js
2486 cd Xcmd/Xstate
2487 enew
2488 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2489 call assert_equal('"b CmdStateFile', @:)
2490 set wildoptions=fuzzy
2491 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2492 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2493 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002494 set wildoptions&
2495endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002496
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002497" :behave suboptions fuzzy completion
2498func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002499 set wildoptions&
2500 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2501 call assert_equal('"behave xm', @:)
2502 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2503 call assert_equal('"behave xterm', @:)
2504 set wildoptions=fuzzy
2505 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2506 call assert_equal('"behave xterm', @:)
2507 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2508 call assert_equal('"behave xt*m', @:)
2509 let g:Sline = ''
2510 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2511 call assert_equal('mswin', g:Sline)
2512 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002513 set wildoptions&
2514endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002515
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002516" " colorscheme name fuzzy completion - NOT supported
2517" func Test_fuzzy_completion_colorscheme()
2518" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002519
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002520" built-in command name fuzzy completion
2521func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002522 set wildoptions&
2523 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2524 call assert_equal('"sbwin', @:)
2525 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2526 call assert_equal('"sbrewind', @:)
2527 set wildoptions=fuzzy
2528 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2529 call assert_equal('"sbrewind', @:)
2530 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2531 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002532 set wildoptions&
2533endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002534
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002535" " compiler name fuzzy completion - NOT supported
2536" func Test_fuzzy_completion_compiler()
2537" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002538
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002539" :cscope suboptions fuzzy completion
2540func Test_fuzzy_completion_cscope()
2541 CheckFeature cscope
2542 set wildoptions&
2543 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2544 call assert_equal('"cscope ret', @:)
2545 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2546 call assert_equal('"cscope reset', @:)
2547 set wildoptions=fuzzy
2548 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2549 call assert_equal('"cscope reset', @:)
2550 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2551 call assert_equal('"cscope re*t', @:)
2552 set wildoptions&
2553endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002554
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002555" :diffget/:diffput buffer name fuzzy completion
2556func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002557 new SomeBuffer
2558 diffthis
2559 new OtherBuffer
2560 diffthis
2561 set wildoptions&
2562 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2563 call assert_equal('"diffget sbuf', @:)
2564 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2565 call assert_equal('"diffput sbuf', @:)
2566 set wildoptions=fuzzy
2567 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2568 call assert_equal('"diffget SomeBuffer', @:)
2569 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2570 call assert_equal('"diffput SomeBuffer', @:)
2571 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002572 set wildoptions&
2573endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002574
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002575" " directory name fuzzy completion - NOT supported
2576" func Test_fuzzy_completion_dirname()
2577" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002578
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002579" environment variable name fuzzy completion
2580func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002581 set wildoptions&
2582 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2583 call assert_equal('"echo $VUT', @:)
2584 set wildoptions=fuzzy
2585 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2586 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002587 set wildoptions&
2588endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002589
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002590" autocmd event fuzzy completion
2591func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002592 set wildoptions&
2593 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2594 call assert_equal('"autocmd BWout', @:)
2595 set wildoptions=fuzzy
2596 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2597 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002598 set wildoptions&
2599endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002600
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002601" vim expression fuzzy completion
2602func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002603 let g:PerPlaceCount = 10
2604 set wildoptions&
2605 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2606 call assert_equal('"let c = ppc', @:)
2607 set wildoptions=fuzzy
2608 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2609 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002610 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002611endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002612
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002613" " file name fuzzy completion - NOT supported
2614" func Test_fuzzy_completion_filename()
2615" endfunc
2616
2617" " files in path fuzzy completion - NOT supported
2618" func Test_fuzzy_completion_filesinpath()
2619" endfunc
2620
2621" " filetype name fuzzy completion - NOT supported
2622" func Test_fuzzy_completion_filetype()
2623" endfunc
2624
2625" user defined function name completion
2626func Test_fuzzy_completion_userdefined_func()
2627 set wildoptions&
2628 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2629 call assert_equal('"call Test_f_u_f', @:)
2630 set wildoptions=fuzzy
2631 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2632 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2633 set wildoptions&
2634endfunc
2635
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002636" <SNR> functions should be sorted to the end
2637func Test_fuzzy_completion_userdefined_snr_func()
2638 func s:Sendmail()
2639 endfunc
2640 func SendSomemail()
2641 endfunc
2642 func S1e2n3dmail()
2643 endfunc
2644 set wildoptions=fuzzy
2645 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002646 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002647 set wildoptions&
2648 delfunc s:Sendmail
2649 delfunc SendSomemail
2650 delfunc S1e2n3dmail
2651endfunc
2652
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002653" user defined command name completion
2654func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002655 set wildoptions&
2656 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2657 call assert_equal('"MsFeat', @:)
2658 set wildoptions=fuzzy
2659 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2660 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002661 set wildoptions&
2662endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002663
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002664" " :help tag fuzzy completion - NOT supported
2665" func Test_fuzzy_completion_helptag()
2666" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002667
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002668" highlight group name fuzzy completion
2669func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002670 set wildoptions&
2671 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2672 call assert_equal('"highlight SKey', @:)
2673 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2674 call assert_equal('"highlight SpecialKey', @:)
2675 set wildoptions=fuzzy
2676 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2677 call assert_equal('"highlight SpecialKey', @:)
2678 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2679 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002680 set wildoptions&
2681endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002682
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002683" :history suboptions fuzzy completion
2684func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002685 set wildoptions&
2686 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2687 call assert_equal('"history dg', @:)
2688 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2689 call assert_equal('"history search', @:)
2690 set wildoptions=fuzzy
2691 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2692 call assert_equal('"history debug', @:)
2693 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2694 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002695 set wildoptions&
2696endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002697
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002698" :language locale name fuzzy completion
2699func Test_fuzzy_completion_lang()
2700 CheckUnix
2701 set wildoptions&
2702 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2703 call assert_equal('"lang psx', @:)
2704 set wildoptions=fuzzy
2705 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2706 call assert_equal('"lang POSIX', @:)
2707 set wildoptions&
2708endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002709
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002710" :mapclear buffer argument fuzzy completion
2711func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002712 set wildoptions&
2713 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2714 call assert_equal('"mapclear buf', @:)
2715 set wildoptions=fuzzy
2716 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2717 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002718 set wildoptions&
2719endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002720
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002721" map name fuzzy completion
2722func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002723 " test regex completion works
2724 set wildoptions=fuzzy
2725 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2726 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002727 nmap <plug>MyLongMap :p<CR>
2728 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2729 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2730 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2731 call assert_equal("\"nmap MLM \t", @:)
2732 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal("\"nmap <F2> one two \t", @:)
2734 " duplicate entries should be removed
2735 vmap <plug>MyLongMap :<C-U>#<CR>
2736 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2737 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2738 nunmap <plug>MyLongMap
2739 vunmap <plug>MyLongMap
2740 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2741 call assert_equal("\"nmap ABC\t", @:)
2742 " results should be sorted by best match
2743 nmap <Plug>format :
2744 nmap <Plug>goformat :
2745 nmap <Plug>TestFOrmat :
2746 nmap <Plug>fendoff :
2747 nmap <Plug>state :
2748 nmap <Plug>FendingOff :
2749 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2750 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2751 nunmap <Plug>format
2752 nunmap <Plug>goformat
2753 nunmap <Plug>TestFOrmat
2754 nunmap <Plug>fendoff
2755 nunmap <Plug>state
2756 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002757 set wildoptions&
2758endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002759
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002760" abbreviation fuzzy completion
2761func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002762 set wildoptions=fuzzy
2763 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2764 call assert_equal("\"iabbr <nowait>", @:)
2765 iabbr WaitForCompletion WFC
2766 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2767 call assert_equal("\"iabbr WaitForCompletion", @:)
2768 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2769 call assert_equal("\"iabbr a1z\t", @:)
2770 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002771 set wildoptions&
2772endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002773
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002774" menu name fuzzy completion
2775func Test_fuzzy_completion_menu()
2776 CheckGui
2777 set wildoptions&
2778 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2779 call assert_equal('"menu pup', @:)
2780 set wildoptions=fuzzy
2781 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2782 call assert_equal('"menu PopUp.', @:)
2783 set wildoptions&
2784endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002785
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002786" :messages suboptions fuzzy completion
2787func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002788 set wildoptions&
2789 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2790 call assert_equal('"messages clr', @:)
2791 set wildoptions=fuzzy
2792 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2793 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002794 set wildoptions&
2795endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002796
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002797" :set option name fuzzy completion
2798func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002799 set wildoptions&
2800 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2801 call assert_equal('"set brkopt', @:)
2802 set wildoptions=fuzzy
2803 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2804 call assert_equal('"set breakindentopt', @:)
2805 set wildoptions&
2806 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2807 call assert_equal('"set fixendofline', @:)
2808 set wildoptions=fuzzy
2809 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2810 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002811 set wildoptions&
2812endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002813
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002814" :set <term_option>
2815func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002816 set wildoptions&
2817 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2818 call assert_equal('"set t_EC', @:)
2819 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2820 call assert_equal('"set <t_EC>', @:)
2821 set wildoptions=fuzzy
2822 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2823 call assert_equal('"set t_EC', @:)
2824 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2825 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002826 set wildoptions&
2827endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002828
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002829" " :packadd directory name fuzzy completion - NOT supported
2830" func Test_fuzzy_completion_packadd()
2831" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002832
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002833" " shell command name fuzzy completion - NOT supported
2834" func Test_fuzzy_completion_shellcmd()
2835" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002836
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837" :sign suboptions fuzzy completion
2838func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002839 set wildoptions&
2840 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2841 call assert_equal('"sign ufe', @:)
2842 set wildoptions=fuzzy
2843 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2844 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002845 set wildoptions&
2846endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002847
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002848" :syntax suboptions fuzzy completion
2849func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002850 set wildoptions&
2851 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2852 call assert_equal('"syntax kwd', @:)
2853 set wildoptions=fuzzy
2854 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2855 call assert_equal('"syntax keyword', @:)
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" syntax group name fuzzy completion
2860func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002861 set wildoptions&
2862 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2863 call assert_equal('"syntax list mpar', @:)
2864 set wildoptions=fuzzy
2865 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
2866 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002867 set wildoptions&
2868endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002869
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002870" :syntime suboptions fuzzy completion
2871func Test_fuzzy_completion_syntime()
2872 CheckFeature profile
2873 set wildoptions&
2874 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2875 call assert_equal('"syntime clr', @:)
2876 set wildoptions=fuzzy
2877 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
2878 call assert_equal('"syntime clear', @:)
2879 set wildoptions&
2880endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002881
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002882" " tag name fuzzy completion - NOT supported
2883" func Test_fuzzy_completion_tagname()
2884" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002885
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002886" " tag name and file fuzzy completion - NOT supported
2887" func Test_fuzzy_completion_tagfile()
2888" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002889
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002890" " user names fuzzy completion - how to test this functionality?
2891" func Test_fuzzy_completion_username()
2892" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002893
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002894" user defined variable name fuzzy completion
2895func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002896 let g:SomeVariable=10
2897 set wildoptions&
2898 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2899 call assert_equal('"let SVar', @:)
2900 set wildoptions=fuzzy
2901 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
2902 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002903 set wildoptions&
2904endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002905
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002906" Test for sorting the results by the best match
2907func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002908 %bw!
2909 command T123format :
2910 command T123goformat :
2911 command T123TestFOrmat :
2912 command T123fendoff :
2913 command T123state :
2914 command T123FendingOff :
2915 set wildoptions=fuzzy
2916 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
2917 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
2918 delcommand T123format
2919 delcommand T123goformat
2920 delcommand T123TestFOrmat
2921 delcommand T123fendoff
2922 delcommand T123state
2923 delcommand T123FendingOff
2924 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002925 set wildoptions&
2926endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00002927
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002928" Test for fuzzy completion of a command with lower case letters and a number
2929func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002930 command Foo2Bar :
2931 set wildoptions=fuzzy
2932 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
2933 call assert_equal('"Foo2Bar', @:)
2934 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
2935 call assert_equal('"Foo2Bar', @:)
2936 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
2937 call assert_equal('"Foo2Bar', @:)
2938 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002939 set wildoptions&
2940endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00002941
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002942" Test for command completion for a command starting with 'k'
2943func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002944 command KillKillKill :
2945 set wildoptions&
2946 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2947 call assert_equal("\"killkill\<Tab>", @:)
2948 set wildoptions=fuzzy
2949 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
2950 call assert_equal('"KillKillKill', @:)
2951 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002952 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002953endfunc
2954
2955" Test for fuzzy completion for user defined custom completion function
2956func Test_fuzzy_completion_custom_func()
2957 func Tcompl(a, c, p)
2958 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
2959 endfunc
2960 command -nargs=* -complete=custom,Tcompl Fuzzy :
2961 set wildoptions&
2962 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2963 call assert_equal("\"Fuzzy format", @:)
2964 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2965 call assert_equal("\"Fuzzy xy", @:)
2966 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal("\"Fuzzy ttt", @:)
2968 set wildoptions=fuzzy
2969 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
2970 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
2971 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
2972 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
2973 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
2974 call assert_equal("\"Fuzzy xy", @:)
2975 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
2976 call assert_equal("\"Fuzzy TestFOrmat", @:)
2977 delcom Fuzzy
2978 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002979endfunc
2980
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00002981" Test for :breakadd argument completion
2982func Test_cmdline_complete_breakadd()
2983 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
2984 call assert_equal("\"breakadd expr file func here", @:)
2985 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
2986 call assert_equal("\"breakadd expr", @:)
2987 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal("\"breakadd expr", @:)
2989 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
2990 call assert_equal("\"breakadd here", @:)
2991 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
2992 call assert_equal("\"breakadd here", @:)
2993 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
2994 call assert_equal("\"breakadd abc", @:)
2995 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
2996 let l = getcompletion('not', 'breakpoint')
2997 call assert_equal([], l)
2998
2999 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003000 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003001 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3002 call assert_equal("\"breakadd file Xscript", @:)
3003 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3004 call assert_equal("\"breakadd file Xscript", @:)
3005 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3006 call assert_equal("\"breakadd file 20 Xscript", @:)
3007 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3008 call assert_equal("\"breakadd file 20 Xscript", @:)
3009 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3011 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3012 call assert_equal("\"breakadd file 20\t", @:)
3013 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3014 call assert_equal("\"breakadd file 20x\t", @:)
3015 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3016 call assert_equal("\"breakadd file Xscript ", @:)
3017 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3018 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003019
3020 " Test for :breakadd func [lnum] <function>
3021 func Xbreak_func()
3022 endfunc
3023 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3024 call assert_equal("\"breakadd func Xbreak_func", @:)
3025 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3026 call assert_equal("\"breakadd func Xbreak_func", @:)
3027 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3028 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3029 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3030 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3031 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3032 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3033 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3034 call assert_equal("\"breakadd func 20\t", @:)
3035 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3036 call assert_equal("\"breakadd func 20x\t", @:)
3037 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3038 call assert_equal("\"breakadd func Xbreak_func ", @:)
3039 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3040 call assert_equal("\"breakadd func X1B2C3", @:)
3041 delfunc Xbreak_func
3042
3043 " Test for :breakadd expr <expression>
3044 let g:Xtest_var = 10
3045 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal("\"breakadd expr Xtest_var", @:)
3047 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3048 call assert_equal("\"breakadd expr Xtest_var", @:)
3049 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3050 call assert_equal("\"breakadd expr Xtest_var ", @:)
3051 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3052 call assert_equal("\"breakadd expr X1B2C3", @:)
3053 unlet g:Xtest_var
3054
3055 " Test for :breakadd here
3056 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3057 call assert_equal("\"breakadd here Xtest", @:)
3058 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3059 call assert_equal("\"breakadd here Xtest", @:)
3060 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal("\"breakadd here ", @:)
3062endfunc
3063
3064" Test for :breakdel argument completion
3065func Test_cmdline_complete_breakdel()
3066 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3067 call assert_equal("\"breakdel file func here", @:)
3068 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3069 call assert_equal("\"breakdel file", @:)
3070 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3071 call assert_equal("\"breakdel file", @:)
3072 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3073 call assert_equal("\"breakdel here", @:)
3074 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3075 call assert_equal("\"breakdel here", @:)
3076 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3077 call assert_equal("\"breakdel abc", @:)
3078
3079 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003080 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003081 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3082 call assert_equal("\"breakdel file Xscript", @:)
3083 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3084 call assert_equal("\"breakdel file Xscript", @:)
3085 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3086 call assert_equal("\"breakdel file 20 Xscript", @:)
3087 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3088 call assert_equal("\"breakdel file 20 Xscript", @:)
3089 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3090 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3091 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3092 call assert_equal("\"breakdel file 20\t", @:)
3093 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal("\"breakdel file 20x\t", @:)
3095 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3096 call assert_equal("\"breakdel file Xscript ", @:)
3097 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3098 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003099
3100 " Test for :breakdel func [lnum] <function>
3101 func Xbreak_func()
3102 endfunc
3103 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3104 call assert_equal("\"breakdel func Xbreak_func", @:)
3105 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3106 call assert_equal("\"breakdel func Xbreak_func", @:)
3107 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3108 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3109 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3110 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3111 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3112 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3113 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"breakdel func 20\t", @:)
3115 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"breakdel func 20x\t", @:)
3117 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"breakdel func Xbreak_func ", @:)
3119 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"breakdel func X1B2C3", @:)
3121 delfunc Xbreak_func
3122
3123 " Test for :breakdel here
3124 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3125 call assert_equal("\"breakdel here Xtest", @:)
3126 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3127 call assert_equal("\"breakdel here Xtest", @:)
3128 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3129 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003130endfunc
3131
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003132" Test for :scriptnames argument completion
3133func Test_cmdline_complete_scriptnames()
3134 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003135 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003136 source Xa1b2c3.vim
3137 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3138 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3139 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3140 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3141 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3142 call assert_equal("\"script b2c3", @:)
3143 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3144 call assert_match("\"script 2\<Tab>$", @:)
3145 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3147 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"script ", @:)
3149 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3150 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3151 new
3152 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3153 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3154 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003155 set wildmenu&
3156endfunc
3157
Bram Moolenaard8893442022-05-06 20:38:47 +01003158" this was going over the end of IObuff
3159func Test_report_error_with_composing()
3160 let caught = 'no'
3161 try
3162 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3163 catch /E492:/
3164 let caught = 'yes'
3165 endtry
3166 call assert_equal('yes', caught)
3167endfunc
3168
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003169" Test for expanding 2-letter and 3-letter :substitute command arguments.
3170" These commands don't accept an argument.
3171func Test_cmdline_complete_substitute_short()
3172 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3173 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3174 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3175 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3176 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3177 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3179 endfor
3180endfunc
3181
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003182" Test for :! shell command argument completion
3183func Test_cmdline_complete_bang_cmd_argument()
3184 set wildoptions=fuzzy
3185 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3186 call assert_equal('"!vim test_cmdline.vim', @:)
3187 set wildoptions&
3188 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3189 call assert_equal('"!vim test_cmdline.vim', @:)
3190endfunc
3191
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003192func Check_completion()
3193 call assert_equal('let a', getcmdline())
3194 call assert_equal(6, getcmdpos())
3195 call assert_equal(7, getcmdscreenpos())
3196 call assert_equal('var', getcmdcompltype())
3197 return ''
3198endfunc
3199
3200func Test_screenpos_and_completion()
3201 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3202endfunc
3203
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003204func Test_recursive_register()
3205 let @= = ''
3206 silent! ?e/
3207 let caught = 'no'
3208 try
3209 normal //
3210 catch /E169:/
3211 let caught = 'yes'
3212 endtry
3213 call assert_equal('yes', caught)
3214endfunc
3215
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003216func Test_long_error_message()
3217 " the error should be truncated, not overrun IObuff
3218 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3219endfunc
3220
zeertzjq6791adc2022-07-26 20:42:25 +01003221func Test_cmdline_redraw_tabline()
3222 CheckRunVimInTerminal
3223
3224 let lines =<< trim END
3225 set showtabline=2
3226 autocmd CmdlineEnter * set tabline=foo
3227 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003228 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003229 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3230 call term_sendkeys(buf, ':')
3231 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3232
3233 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003234endfunc
3235
zeertzjqb82a2ab2022-08-21 14:33:57 +01003236func Test_wildmenu_pum_disable_while_shown()
3237 set wildoptions=pum
3238 set wildmenu
3239 cnoremap <F2> <Cmd>set nowildmenu<CR>
3240 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3241 call assert_equal(0, pumvisible())
3242 cunmap <F2>
3243 set wildoptions& wildmenu&
3244endfunc
3245
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003246func Test_setcmdline()
3247 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003248 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003249 call assert_equal(0, setcmdline(a:text))
3250 call assert_equal(a:text, getcmdline())
3251 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003252 call assert_equal(getcmdtype(), g:cmdtype)
3253 unlet g:cmdtype
3254 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003255
3256 call assert_equal(0, setcmdline(a:text, a:pos))
3257 call assert_equal(a:text, getcmdline())
3258 call assert_equal(a:pos, getcmdpos())
3259
3260 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003261 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3262 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003263
3264 return ''
3265 endfunc
3266
3267 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3268 call assert_equal('set rtp?', @:)
3269
zeertzjq54acb902022-08-29 16:21:25 +01003270 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3271 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3272 call assert_equal('foo', g:str)
3273 unlet g:str
3274
3275 delfunc SetText
3276
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003277 " setcmdline() returns 1 when not editing the command line.
3278 call assert_equal(1, 'foo'->setcmdline())
3279
3280 " Called in custom function
3281 func CustomComplete(A, L, P)
3282 call assert_equal(0, setcmdline("DoCmd "))
3283 return "January\nFebruary\nMars\n"
3284 endfunc
3285
3286 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3287 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3288 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003289 delcom DoCmd
3290 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003291
3292 " Called in <expr>
3293 cnoremap <expr>a setcmdline('let foo=')
3294 call feedkeys(":a\<CR>", 'tx')
3295 call assert_equal('let foo=0', @:)
3296 cunmap a
3297endfunc
3298
Bram Moolenaar309976e2019-12-05 18:16:33 +01003299" vim: shiftwidth=2 sts=2 expandtab