blob: e1c336a950006dbd6413ac56e135ec1a58c1987c [file] [log] [blame]
Bram Moolenaarae3150e2016-06-11 23:22:36 +02001" Tests for editing the command line.
2
Bram Moolenaar4facea32019-10-12 20:17:40 +02003source check.vim
4source screendump.vim
Bram Moolenaar24ebd832020-03-16 21:25:24 +01005source view_util.vim
Bram Moolenaarc82dd862020-06-07 17:30:33 +02006source shared.vim
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00007import './vim9.vim' as v9
Bram Moolenaar4facea32019-10-12 20:17:40 +02008
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00009func SetUp()
10 func SaveLastScreenLine()
11 let g:Sline = Screenline(&lines - 1)
12 return ''
13 endfunc
14 cnoremap <expr> <F4> SaveLastScreenLine()
15endfunc
16
17func TearDown()
18 delfunc SaveLastScreenLine
19 cunmap <F4>
20endfunc
21
Bram Moolenaarae3150e2016-06-11 23:22:36 +020022func Test_complete_tab()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010023 call writefile(['testfile'], 'Xtestfile', 'D')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020024 call feedkeys(":e Xtest\t\r", "tx")
25 call assert_equal('testfile', getline(1))
Albert Liu6024c042021-08-27 20:59:35 +020026
27 " Pressing <Tab> after '%' completes the current file, also on MS-Windows
28 call feedkeys(":e %\t\r", "tx")
29 call assert_equal('e Xtestfile', @:)
Bram Moolenaarae3150e2016-06-11 23:22:36 +020030endfunc
31
32func Test_complete_list()
33 " We can't see the output, but at least we check the code runs properly.
34 call feedkeys(":e test\<C-D>\r", "tx")
35 call assert_equal('test', expand('%:t'))
Bram Moolenaar578fe942020-02-27 21:32:51 +010036
37 " If a command doesn't support completion, then CTRL-D should be literally
38 " used.
39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
40 call assert_equal("\"chistory \<C-D>", @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000041
42 " Test for displaying the tail of the completion matches
43 set wildmode=longest,full
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010044 call mkdir('Xtest', 'R')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000045 call writefile([], 'Xtest/a.c')
46 call writefile([], 'Xtest/a.h')
47 let g:Sline = ''
48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
49 call assert_equal('a.c a.h', g:Sline)
50 call assert_equal('"e Xtest/', @:)
51 if has('win32')
52 " Test for 'completeslash'
53 set completeslash=backslash
54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
55 call assert_equal('"e Xtest\', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000056 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
57 call assert_equal('"e Xtest\a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000058 set completeslash=slash
59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
60 call assert_equal('"e Xtest/', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +000061 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xtest/a.', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000063 set completeslash&
64 endif
65
66 " Test for displaying the tail with wildcards
67 let g:Sline = ''
68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
70 call assert_equal('"e Xtes?/', @:)
71 let g:Sline = ''
72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
74 call assert_equal('"e Xtes*/', @:)
75 let g:Sline = ''
76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
77 call assert_equal(':e Xtes[/', g:Sline)
78 call assert_equal('"e Xtes[/', @:)
79
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +000080 set wildmode&
Bram Moolenaarae3150e2016-06-11 23:22:36 +020081endfunc
82
83func Test_complete_wildmenu()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010084 call mkdir('Xwilddir1/Xdir2', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010085 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
86 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
87 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020089 set wildmenu
Bram Moolenaar37db6422019-03-28 21:26:23 +010090
91 " Pressing <Tab> completes, and moves to next files when pressing again.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010092 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +010093 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010094 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
Bram Moolenaarae3150e2016-06-11 23:22:36 +020095 call assert_equal('testfile2', getline(1))
96
Bram Moolenaar37db6422019-03-28 21:26:23 +010097 " <S-Tab> is like <Tab> but begin with the last match and then go to
98 " previous.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010099 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100100 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100101 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100102 call assert_equal('testfile1', getline(1))
103
104 " <Left>/<Right> to move to previous/next file.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100105 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100106 call assert_equal('testfile1', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100107 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100108 call assert_equal('testfile2', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100109 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100110 call assert_equal('testfile1', getline(1))
111
112 " <Up>/<Down> to go up/down directories.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100113 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100114 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100115 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
Bram Moolenaar37db6422019-03-28 21:26:23 +0100116 call assert_equal('testfile1', getline(1))
117
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100118 " this fails in some Unix GUIs, not sure why
119 if !has('unix') || !has('gui_running')
120 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
121 " different than 'wildchar'.
122 set wildcharm=<C-Z>
123 cnoremap <C-J> <Down><C-Z>
124 cnoremap <C-K> <Up><C-Z>
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100125 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100126 call assert_equal('testfile3', getline(1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100127 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
Bram Moolenaar3e112ac2020-12-28 13:41:53 +0100128 call assert_equal('testfile1', getline(1))
129 set wildcharm=0
130 cunmap <C-J>
131 cunmap <C-K>
132 endif
Bram Moolenaarb0ac4ea2020-12-26 12:06:54 +0100133
Bram Moolenaar578fe942020-02-27 21:32:51 +0100134 " Test for canceling the wild menu by adding a character
135 redrawstatus
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100136 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
137 call assert_equal('"e Xwilddir1/Xdir2/x', @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100138
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100139 " Completion using a relative path
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 cd Xwilddir1/Xdir2
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100141 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
142 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
143 cd -
144
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +0000145 " test for wildmenumode()
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100146 cnoremap <expr> <F2> wildmenumode()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
148 call assert_equal('"cd Xwilddir1/0', @:)
149 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
150 call assert_equal('"e Xwilddir1/Xdir2/1', @:)
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100151 cunmap <F2>
152
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +0000153 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
154 " After this pressing <Left> or <Right> should not change the selection.
155 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
156 call assert_equal('"sign define', @:)
157 call histadd('cmd', 'TestWildMenu')
158 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
159 call assert_equal('"TestWildMenu', @:)
160
Bram Moolenaar37db6422019-03-28 21:26:23 +0100161 " cleanup
162 %bwipe
Bram Moolenaarae3150e2016-06-11 23:22:36 +0200163 set nowildmenu
164endfunc
Bram Moolenaar4b2ce122020-11-21 21:41:41 +0100165
Bram Moolenaara60053b2020-09-03 16:50:13 +0200166func Test_wildmenu_screendump()
167 CheckScreendump
168
169 let lines =<< trim [SCRIPT]
170 set wildmenu hlsearch
171 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100172 call writefile(lines, 'XTest_wildmenu', 'D')
Bram Moolenaara60053b2020-09-03 16:50:13 +0200173
174 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
175 call term_sendkeys(buf, ":vim\<Tab>")
176 call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
177
178 call term_sendkeys(buf, "\<Tab>")
179 call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
180
181 call term_sendkeys(buf, "\<Tab>")
182 call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
183
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100184 call term_sendkeys(buf, "\<Tab>\<Tab>")
Bram Moolenaara60053b2020-09-03 16:50:13 +0200185 call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
186 call term_sendkeys(buf, "\<Esc>")
187
188 " clean up
189 call StopVimInTerminal(buf)
Bram Moolenaara60053b2020-09-03 16:50:13 +0200190endfunc
191
Bram Moolenaara653e532022-04-19 11:38:24 +0100192func Test_redraw_in_autocmd()
193 CheckScreendump
194
195 let lines =<< trim END
196 set cmdheight=2
197 autocmd CmdlineChanged * redraw
198 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100199 call writefile(lines, 'XTest_redraw', 'D')
Bram Moolenaara653e532022-04-19 11:38:24 +0100200
201 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
202 call term_sendkeys(buf, ":for i in range(3)\<CR>")
203 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
204
205 call term_sendkeys(buf, "let i =")
206 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
207
208 " clean up
209 call term_sendkeys(buf, "\<CR>")
210 call StopVimInTerminal(buf)
Bram Moolenaara653e532022-04-19 11:38:24 +0100211endfunc
212
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100213func Test_redrawstatus_in_autocmd()
214 CheckScreendump
215
216 let lines =<< trim END
zeertzjqc14bfc32022-09-20 13:17:57 +0100217 set laststatus=2
218 set statusline=%=:%{getcmdline()}
zeertzjq320d9102022-09-20 17:12:13 +0100219 autocmd CmdlineChanged * redrawstatus
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100220 END
221 call writefile(lines, 'XTest_redrawstatus', 'D')
222
223 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
zeertzjqc14bfc32022-09-20 13:17:57 +0100224 " :redrawstatus is postponed if messages have scrolled
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100225 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
226 call term_sendkeys(buf, ":foobar")
227 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
zeertzjqc14bfc32022-09-20 13:17:57 +0100228 " it is not postponed if messages have not scrolled
zeertzjq320d9102022-09-20 17:12:13 +0100229 call term_sendkeys(buf, "\<Esc>:for in in range(3)")
zeertzjqc14bfc32022-09-20 13:17:57 +0100230 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
zeertzjq320d9102022-09-20 17:12:13 +0100231 " with cmdheight=1 messages have scrolled when typing :endfor
232 call term_sendkeys(buf, "\<CR>:endfor")
233 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
234 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
235 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
236 call term_sendkeys(buf, ":for in in range(3)")
237 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
238 call term_sendkeys(buf, "\<CR>:endfor")
239 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
Bram Moolenaarbcd69242022-09-19 21:16:12 +0100240
241 " clean up
242 call term_sendkeys(buf, "\<CR>")
243 call StopVimInTerminal(buf)
244endfunc
245
Bram Moolenaarf797e302022-08-11 13:17:30 +0100246func Test_changing_cmdheight()
247 CheckScreendump
248
249 let lines =<< trim END
250 set cmdheight=1 laststatus=2
Bram Moolenaar0816f472022-10-05 15:42:32 +0100251 func EchoTwo()
252 set laststatus=2
253 set cmdheight=5
254 echo 'foo'
255 echo 'bar'
256 set cmdheight=1
257 endfunc
Bram Moolenaarf797e302022-08-11 13:17:30 +0100258 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100259 call writefile(lines, 'XTest_cmdheight', 'D')
Bram Moolenaarf797e302022-08-11 13:17:30 +0100260
261 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
262 call term_sendkeys(buf, ":resize -3\<CR>")
263 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
264
265 " using the space available doesn't change the status line
266 call term_sendkeys(buf, ":set cmdheight+=3\<CR>")
267 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
268
269 " using more space moves the status line up
270 call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
271 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
272
273 " reducing cmdheight moves status line down
274 call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
275 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
276
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000277 " reducing window size and then setting cmdheight
Bram Moolenaard4cf9fc2022-08-11 14:13:37 +0100278 call term_sendkeys(buf, ":resize -1\<CR>")
279 call term_sendkeys(buf, ":set cmdheight=1\<CR>")
280 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
281
Bram Moolenaar0816f472022-10-05 15:42:32 +0100282 " setting 'cmdheight' works after outputting two messages
283 call term_sendkeys(buf, ":call EchoTwo()\<CR>")
284 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
285
Bram Moolenaarf797e302022-08-11 13:17:30 +0100286 " clean up
287 call StopVimInTerminal(buf)
Bram Moolenaarf797e302022-08-11 13:17:30 +0100288endfunc
289
Bram Moolenaarc9f5f732022-10-06 11:39:06 +0100290func Test_cmdheight_tabline()
291 CheckScreendump
292
293 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
294 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
295
296 " clean up
297 call StopVimInTerminal(buf)
298endfunc
299
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100300func Test_map_completion()
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100301 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
302 call assert_equal('"map <unique> <silent>', getreg(':'))
303 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
304 call assert_equal('"map <script> <unique>', getreg(':'))
305 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
306 call assert_equal('"map <expr> <script>', getreg(':'))
307 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
308 call assert_equal('"map <buffer> <expr>', getreg(':'))
309 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
310 call assert_equal('"map <nowait> <buffer>', getreg(':'))
311 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
312 call assert_equal('"map <special> <nowait>', getreg(':'))
313 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
314 call assert_equal('"map <silent> <special>', getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200315
Bram Moolenaar1776a282019-05-03 16:05:41 +0200316 map <Middle>x middle
317
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200318 map ,f commaf
319 map ,g commaf
Bram Moolenaar1776a282019-05-03 16:05:41 +0200320 map <Left> left
321 map <A-Left>x shiftleft
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200322 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
323 call assert_equal('"map ,f', getreg(':'))
324 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
325 call assert_equal('"map ,g', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200326 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
327 call assert_equal('"map <Left>', getreg(':'))
328 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200329 call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200330 unmap ,f
331 unmap ,g
Bram Moolenaar1776a282019-05-03 16:05:41 +0200332 unmap <Left>
333 unmap <A-Left>x
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200334
335 set cpo-=< cpo-=B cpo-=k
336 map <Left> left
337 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
338 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar1776a282019-05-03 16:05:41 +0200339 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
Bram Moolenaar92b9e602019-05-03 16:49:25 +0200340 call assert_equal("\"map <M\<Tab>", getreg(':'))
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200341 unmap <Left>
342
343 set cpo+=<
344 map <Left> left
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200345 exe "set t_k6=\<Esc>[17~"
346 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200347 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
348 call assert_equal('"map <Left>', getreg(':'))
Bram Moolenaar510671a2019-05-04 19:26:56 +0200349 if !has('gui_running')
350 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
351 call assert_equal("\"map <F6>x", getreg(':'))
352 endif
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200353 unmap <Left>
Bram Moolenaar61df0c72019-05-03 21:10:36 +0200354 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
Bram Moolenaar2cb9f022019-05-03 15:13:57 +0200355 set cpo-=<
356
357 set cpo+=B
358 map <Left> left
359 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
360 call assert_equal('"map <Left>', getreg(':'))
361 unmap <Left>
362 set cpo-=B
363
364 set cpo+=k
365 map <Left> left
366 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
367 call assert_equal('"map <Left>', getreg(':'))
368 unmap <Left>
369 set cpo-=k
Bram Moolenaar1776a282019-05-03 16:05:41 +0200370
Bram Moolenaar531be472020-09-23 22:38:05 +0200371 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
372
Bram Moolenaar1776a282019-05-03 16:05:41 +0200373 unmap <Middle>x
374 set cpo&vim
Bram Moolenaarcf5fdf72017-03-02 23:05:51 +0100375endfunc
376
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100377func Test_match_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100378 hi Aardig ctermfg=green
379 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000380 call assert_equal('"match Aardig', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100381 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000382 call assert_equal('"match none', @:)
383 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
384 call assert_equal('"match | chistory', @:)
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100385endfunc
386
387func Test_highlight_completion()
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100388 hi Aardig ctermfg=green
389 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
390 call assert_equal('"hi Aardig', getreg(':'))
Bram Moolenaarea588152017-04-10 22:45:30 +0200391 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
392 call assert_equal('"hi default Aardig', getreg(':'))
393 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
394 call assert_equal('"hi clear Aardig', getreg(':'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100395 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
396 call assert_equal('"hi link', getreg(':'))
397 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
398 call assert_equal('"hi default', getreg(':'))
399 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
400 call assert_equal('"hi clear', getreg(':'))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200401 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
402 call assert_equal('"hi clear Aardig Aardig', getreg(':'))
403 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
404 call assert_equal("\"hi Aardig \t", getreg(':'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200405
406 " A cleared group does not show up in completions.
407 hi Anders ctermfg=green
408 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
409 hi clear Aardig
410 call assert_equal(['Anders'], getcompletion('A', 'highlight'))
411 hi clear Anders
412 call assert_equal([], getcompletion('A', 'highlight'))
Bram Moolenaar15eedf12017-01-22 19:25:33 +0100413endfunc
414
Bram Moolenaar75e15672020-06-28 13:10:22 +0200415" Test for command-line expansion of "hi Ni " (easter egg)
416func Test_highlight_easter_egg()
417 call test_override('ui_delay', 1)
418 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"hi Ni \<Tab>", @:)
420 call test_override('ALL', 0)
421endfunc
422
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200423func Test_getcompletion()
424 let groupcount = len(getcompletion('', 'event'))
425 call assert_true(groupcount > 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +0200426 let matchcount = len('File'->getcompletion('event'))
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200427 call assert_true(matchcount > 0)
428 call assert_true(groupcount > matchcount)
429
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200430 if has('menu')
431 source $VIMRUNTIME/menu.vim
432 let matchcount = len(getcompletion('', 'menu'))
433 call assert_true(matchcount > 0)
434 call assert_equal(['File.'], getcompletion('File', 'menu'))
435 call assert_true(matchcount > 0)
436 let matchcount = len(getcompletion('File.', 'menu'))
437 call assert_true(matchcount > 0)
zeertzjq145a6af2023-01-22 12:41:55 +0000438 source $VIMRUNTIME/delmenu.vim
Bram Moolenaar0d3e24b2016-07-09 19:20:59 +0200439 endif
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200440
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200441 let l = getcompletion('v:n', 'var')
442 call assert_true(index(l, 'v:null') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200443 let l = getcompletion('v:notexists', 'var')
444 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200445
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200446 args a.c b.c
447 let l = getcompletion('', 'arglist')
448 call assert_equal(['a.c', 'b.c'], l)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +0000449 let l = getcompletion('a.', 'buffer')
450 call assert_equal(['a.c'], l)
Bram Moolenaarcd43eff2018-03-29 15:55:38 +0200451 %argdelete
452
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200453 let l = getcompletion('', 'augroup')
454 call assert_true(index(l, 'END') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200455 let l = getcompletion('blahblah', 'augroup')
456 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200457
458 let l = getcompletion('', 'behave')
459 call assert_true(index(l, 'mswin') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200460 let l = getcompletion('not', 'behave')
461 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200462
463 let l = getcompletion('', 'color')
464 call assert_true(index(l, 'default') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200465 let l = getcompletion('dirty', 'color')
466 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200467
468 let l = getcompletion('', 'command')
469 call assert_true(index(l, 'sleep') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200470 let l = getcompletion('awake', 'command')
471 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200472
473 let l = getcompletion('', 'dir')
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200474 call assert_true(index(l, 'samples/') >= 0)
475 let l = getcompletion('NoMatch', 'dir')
476 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200477
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100478 if glob('~/*') !=# ''
479 let l = getcompletion('~/', 'dir')
480 call assert_true(l[0][0] ==# '~')
481 endif
482
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200483 let l = getcompletion('exe', 'expression')
484 call assert_true(index(l, 'executable(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200485 let l = getcompletion('kill', 'expression')
486 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200487
488 let l = getcompletion('tag', 'function')
489 call assert_true(index(l, 'taglist(') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200490 let l = getcompletion('paint', 'function')
491 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200492
Kota Kato90c23532023-01-18 15:27:38 +0000493 if !has('ruby')
Bram Moolenaara9a6b032023-02-05 18:00:42 +0000494 " global_functions[] has an entry but it doesn't have an implementation
Kota Kato90c23532023-01-18 15:27:38 +0000495 let l = getcompletion('ruby', 'function')
496 call assert_equal([], l)
497 endif
498
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200499 let Flambda = {-> 'hello'}
500 let l = getcompletion('', 'function')
501 let l = filter(l, {i, v -> v =~ 'lambda'})
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200502 call assert_equal([], l)
Bram Moolenaarb49edc12016-07-23 15:47:34 +0200503
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200504 let l = getcompletion('run', 'file')
505 call assert_true(index(l, 'runtest.vim') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200506 let l = getcompletion('walk', 'file')
507 call assert_equal([], l)
Bram Moolenaare9d58a62016-08-13 15:07:41 +0200508 set wildignore=*.vim
509 let l = getcompletion('run', 'file', 1)
510 call assert_true(index(l, 'runtest.vim') < 0)
511 set wildignore&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000512 " Directory name with space character
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100513 call mkdir('Xdir with space', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000514 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
515 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200516
517 let l = getcompletion('ha', 'filetype')
518 call assert_true(index(l, 'hamster') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200519 let l = getcompletion('horse', 'filetype')
520 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200521
522 let l = getcompletion('z', 'syntax')
523 call assert_true(index(l, 'zimbu') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200524 let l = getcompletion('emacs', 'syntax')
525 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200526
527 let l = getcompletion('jikes', 'compiler')
528 call assert_true(index(l, 'jikes') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200529 let l = getcompletion('break', 'compiler')
530 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200531
532 let l = getcompletion('last', 'help')
533 call assert_true(index(l, ':tablast') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200534 let l = getcompletion('giveup', 'help')
535 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200536
537 let l = getcompletion('time', 'option')
538 call assert_true(index(l, 'timeoutlen') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200539 let l = getcompletion('space', 'option')
540 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200541
542 let l = getcompletion('er', 'highlight')
543 call assert_true(index(l, 'ErrorMsg') >= 0)
Bram Moolenaarb56195e2016-07-28 22:53:37 +0200544 let l = getcompletion('dark', 'highlight')
545 call assert_equal([], l)
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200546
Bram Moolenaar9e507ca2016-10-15 15:39:39 +0200547 let l = getcompletion('', 'messages')
548 call assert_true(index(l, 'clear') >= 0)
549 let l = getcompletion('not', 'messages')
550 call assert_equal([], l)
551
Bram Moolenaarcae92dc2017-08-06 15:22:15 +0200552 let l = getcompletion('', 'mapclear')
553 call assert_true(index(l, '<buffer>') >= 0)
554 let l = getcompletion('not', 'mapclear')
555 call assert_equal([], l)
556
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200557 let l = getcompletion('.', 'shellcmd')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200558 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200559 call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
560 let root = has('win32') ? 'C:\\' : '/'
561 let l = getcompletion(root, 'shellcmd')
562 let expected = map(filter(glob(root . '*', 0, 1),
563 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
564 call assert_equal(expected, l)
565
Bram Moolenaarb650b982016-08-05 20:35:13 +0200566 if has('cscope')
567 let l = getcompletion('', 'cscope')
568 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
569 call assert_equal(cmds, l)
570 " using cmdline completion must not change the result
571 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
572 let l = getcompletion('', 'cscope')
573 call assert_equal(cmds, l)
574 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
575 let l = getcompletion('find ', 'cscope')
576 call assert_equal(keys, l)
577 endif
578
Bram Moolenaar7522f692016-08-06 14:12:50 +0200579 if has('signs')
580 sign define Testing linehl=Comment
581 let l = getcompletion('', 'sign')
582 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
583 call assert_equal(cmds, l)
584 " using cmdline completion must not change the result
585 call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
586 let l = getcompletion('', 'sign')
587 call assert_equal(cmds, l)
588 let l = getcompletion('list ', 'sign')
589 call assert_equal(['Testing'], l)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000590 let l = getcompletion('de*', 'sign')
591 call assert_equal(['define'], l)
592 let l = getcompletion('p?', 'sign')
593 call assert_equal(['place'], l)
594 let l = getcompletion('j.', 'sign')
595 call assert_equal(['jump'], l)
Bram Moolenaar7522f692016-08-06 14:12:50 +0200596 endif
597
Bram Moolenaar1f1fd442020-06-07 18:45:14 +0200598 " Command line completion tests
599 let l = getcompletion('cd ', 'cmdline')
600 call assert_true(index(l, 'samples/') >= 0)
601 let l = getcompletion('cd NoMatch', 'cmdline')
602 call assert_equal([], l)
603 let l = getcompletion('let v:n', 'cmdline')
604 call assert_true(index(l, 'v:null') >= 0)
605 let l = getcompletion('let v:notexists', 'cmdline')
606 call assert_equal([], l)
607 let l = getcompletion('call tag', 'cmdline')
608 call assert_true(index(l, 'taglist(') >= 0)
609 let l = getcompletion('call paint', 'cmdline')
610 call assert_equal([], l)
611
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100612 func T(a, c, p)
ii144785fe02021-11-21 12:13:56 +0000613 let g:cmdline_compl_params = [a:a, a:c, a:p]
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100614 return "oneA\noneB\noneC"
615 endfunc
616 command -nargs=1 -complete=custom,T MyCmd
617 let l = getcompletion('MyCmd ', 'cmdline')
618 call assert_equal(['oneA', 'oneB', 'oneC'], l)
ii144785fe02021-11-21 12:13:56 +0000619 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100620
621 delcommand MyCmd
622 delfunc T
ii144785fe02021-11-21 12:13:56 +0000623 unlet g:cmdline_compl_params
Shougo Matsushitaae38a9d2021-10-21 11:39:53 +0100624
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200625 " For others test if the name is recognized.
Bram Moolenaar62fe66f2018-05-22 16:58:47 +0200626 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user']
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200627 if has('cmdline_hist')
628 call add(names, 'history')
629 endif
630 if has('gettext')
631 call add(names, 'locale')
632 endif
633 if has('profile')
634 call add(names, 'syntime')
635 endif
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200636
637 set tags=Xtags
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100638 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags', 'D')
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200639
640 for name in names
641 let matchcount = len(getcompletion('', name))
642 call assert_true(matchcount >= 0, 'No matches for ' . name)
643 endfor
644
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200645 set tags&
Bram Moolenaarc1fb7632016-07-17 23:34:21 +0200646
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +0000647 edit a~b
648 enew
649 call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
650 bw a~b
651
652 if has('unix')
653 edit Xtest\
654 enew
655 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
656 bw Xtest\
657 endif
658
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200659 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200660 call assert_fails('call getcompletion("", "burp")', 'E475:')
Yegappan Lakshmanan8deb2b32022-09-02 15:15:27 +0100661 call assert_fails('call getcompletion("abc", [])', 'E1174:')
Bram Moolenaaraa4d7322016-07-09 18:50:29 +0200662endfunc
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200663
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000664func Test_multibyte_expression()
Bram Moolenaar2468add2023-01-04 18:59:57 +0000665 " Get a dialog in the GUI
666 CheckNotGui
667
Bram Moolenaarc32949b2023-01-04 15:56:51 +0000668 " This was using uninitialized memory.
669 let lines =<< trim END
670 set verbose=6
671 norm @=ٷ
672 qall!
673 END
674 call writefile(lines, 'XmultiScript', 'D')
675 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
676endfunc
677
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +0000678" Test for getcompletion() with "fuzzy" in 'wildoptions'
679func Test_getcompletion_wildoptions()
680 let save_wildoptions = &wildoptions
681 set wildoptions&
682 let l = getcompletion('space', 'option')
683 call assert_equal([], l)
684 let l = getcompletion('ier', 'command')
685 call assert_equal([], l)
686 set wildoptions=fuzzy
687 let l = getcompletion('space', 'option')
688 call assert_true(index(l, 'backspace') >= 0)
689 let l = getcompletion('ier', 'command')
690 call assert_true(index(l, 'compiler') >= 0)
691 let &wildoptions = save_wildoptions
692endfunc
693
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000694func Test_complete_autoload_error()
695 let save_rtp = &rtp
696 let lines =<< trim END
697 vim9script
698 export def Complete(..._): string
699 return 'match'
700 enddef
701 echo this will cause an error
702 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100703 call mkdir('Xdir/autoload', 'pR')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000704 call writefile(lines, 'Xdir/autoload/script.vim')
705 exe 'set rtp+=' .. getcwd() .. '/Xdir'
706
707 let lines =<< trim END
708 vim9script
709 import autoload 'script.vim'
710 command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
711 &wildcharm = char2nr("\<Tab>")
712 feedkeys(":Cmd \<Tab>", 'xt')
713 END
714 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
715
716 let &rtp = save_rtp
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +0000717endfunc
718
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100719func Test_fullcommand()
720 let tests = {
721 \ '': '',
722 \ ':': '',
723 \ ':::': '',
724 \ ':::5': '',
725 \ 'not_a_cmd': '',
726 \ 'Check': '',
727 \ 'syntax': 'syntax',
728 \ ':syntax': 'syntax',
729 \ '::::syntax': 'syntax',
730 \ 'sy': 'syntax',
731 \ 'syn': 'syntax',
732 \ 'synt': 'syntax',
733 \ ':sy': 'syntax',
734 \ '::::sy': 'syntax',
735 \ 'match': 'match',
736 \ '2match': 'match',
737 \ '3match': 'match',
738 \ 'aboveleft': 'aboveleft',
739 \ 'abo': 'aboveleft',
Bram Moolenaaraa534142022-09-15 21:46:02 +0100740 \ 'en': 'endif',
741 \ 'end': 'endif',
742 \ 'endi': 'endif',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100743 \ 's': 'substitute',
744 \ '5s': 'substitute',
745 \ ':5s': 'substitute',
746 \ "'<,'>s": 'substitute',
747 \ ":'<,'>s": 'substitute',
LemonBoycc766a82022-04-04 15:46:58 +0100748 \ 'CheckLin': 'CheckLinux',
749 \ 'CheckLinux': 'CheckLinux',
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100750 \ }
751
752 for [in, want] in items(tests)
753 call assert_equal(want, fullcommand(in))
754 endfor
Bram Moolenaar4c8e8c62021-05-26 19:49:09 +0200755 call assert_equal('', fullcommand(test_null_string()))
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100756
757 call assert_equal('syntax', 'syn'->fullcommand())
Bram Moolenaar80c88ea2021-09-08 14:29:46 +0200758
759 command -buffer BufferLocalCommand :
760 command GlobalCommand :
761 call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
762 call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
763 delcommand BufferLocalCommand
764 delcommand GlobalCommand
Bram Moolenaar038e09e2021-02-06 12:38:51 +0100765endfunc
766
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200767func Test_shellcmd_completion()
768 let save_path = $PATH
769
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100770 call mkdir('Xpathdir/Xpathsubdir', 'pR')
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200771 call writefile([''], 'Xpathdir/Xfile.exe')
772 call setfperm('Xpathdir/Xfile.exe', 'rwx------')
773
774 " Set PATH to example directory without trailing slash.
775 let $PATH = getcwd() . '/Xpathdir'
776
777 " Test for the ":!<TAB>" case. Previously, this would include subdirs of
778 " dirs in the PATH, even though they won't be executed. We check that only
779 " subdirs of the PWD and executables from the PATH are included in the
780 " suggestions.
781 let actual = getcompletion('X', 'shellcmd')
782 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
783 call insert(expected, 'Xfile.exe')
784 call assert_equal(expected, actual)
785
Bram Moolenaar6ab9e422018-07-28 19:20:13 +0200786 let $PATH = save_path
787endfunc
788
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200789func Test_expand_star_star()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100790 call mkdir('a/b', 'pR')
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200791 call writefile(['asdfasdf'], 'a/b/fileXname')
792 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000793 call assert_equal('find a/b/fileXname', @:)
Bram Moolenaar1773ddf2016-08-28 13:38:54 +0200794 bwipe!
Bram Moolenaar73d4e4c2016-08-27 21:55:13 +0200795endfunc
Bram Moolenaar21efc362016-12-03 14:05:49 +0100796
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100797func Test_cmdline_paste()
Bram Moolenaar21efc362016-12-03 14:05:49 +0100798 let @a = "def"
799 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
800 call assert_equal('"abc def ghi', @:)
801
802 new
803 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
804
805 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
806 call assert_equal('"aaa asdf bbb', @:)
807
808 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
809 call assert_equal('"aaa /tmp/some bbb', @:)
810
Bram Moolenaare2c8d832018-05-01 19:24:03 +0200811 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
812 call assert_equal('"aaa '.getline(1).' bbb', @:)
813
Bram Moolenaar21efc362016-12-03 14:05:49 +0100814 set incsearch
815 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
816 call assert_equal('"aaa verylongword bbb', @:)
817
818 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
819 call assert_equal('"aaa a;b-c*d bbb', @:)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100820
821 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
822 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
Bram Moolenaar21efc362016-12-03 14:05:49 +0100823 bwipe!
Bram Moolenaar72532d32018-04-07 19:09:09 +0200824
825 " Error while typing a command used to cause that it was not executed
826 " in the end.
827 new
828 try
829 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
830 catch /^Vim\%((\a\+)\)\=:E32/
831 " ignore error E32
832 endtry
833 call assert_equal("Xtestfile", bufname("%"))
Bram Moolenaar8d588cc2020-02-25 21:47:45 +0100834
Bram Moolenaar578fe942020-02-27 21:32:51 +0100835 " Try to paste an invalid register using <C-R>
836 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
837 call assert_equal('"onetwo', @:)
838
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100839 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
Bram Moolenaar578fe942020-02-27 21:32:51 +0100840 let @a = "xy\<C-H>z"
841 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
842 call assert_equal('"xz', @:)
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100843 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
844 call assert_equal("\"xy\<C-H>z", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +0100845 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
846 call assert_equal("\"xy\<C-H>z", @:)
847
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +0100848 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
849 let @a = "xy\<C-V>z"
850 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
851 call assert_equal('"xyz', @:)
852 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
853 call assert_equal("\"xy\<C-V>z", @:)
854
Bram Moolenaar578fe942020-02-27 21:32:51 +0100855 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
856
Bram Moolenaar72532d32018-04-07 19:09:09 +0200857 bwipe!
Bram Moolenaar21efc362016-12-03 14:05:49 +0100858endfunc
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100859
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100860func Test_cmdline_remove_char()
861 let encoding_save = &encoding
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100862
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100863 for e in ['utf8', 'latin1']
864 exe 'set encoding=' . e
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100865
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100866 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
867 call assert_equal('"abc ef', @:, e)
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100868
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100869 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
870 call assert_equal('"abcdef', @:)
871
872 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
873 call assert_equal('"abc ghi', @:, e)
874
875 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
876 call assert_equal('"def', @:, e)
Bram Moolenaaref02f162022-05-07 10:49:10 +0100877
878 " This was going before the start in latin1.
879 call feedkeys(": \<C-W>\<CR>", 'tx')
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100880 endfor
881
882 let &encoding = encoding_save
883endfunc
884
885func Test_cmdline_keymap_ctrl_hat()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200886 CheckFeature keymap
Bram Moolenaar59cb0412019-12-18 22:26:31 +0100887
888 set keymap=esperanto
889 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
890 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
891 set keymap=
Bram Moolenaareaaa9bb2016-12-09 18:42:20 +0100892endfunc
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100893
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100894func Test_illegal_address1()
Bram Moolenaarfe38b492016-12-11 21:34:23 +0100895 new
896 2;'(
897 2;')
898 quit
899endfunc
Bram Moolenaarba47b512017-01-24 21:18:19 +0100900
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100901func Test_illegal_address2()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100902 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D')
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100903 new
904 source Xtest.vim
905 " Trigger calling validate_cursor()
906 diffsp Xtest.vim
907 quit!
908 bwipe!
Bram Moolenaarf1f6f3f2017-02-09 22:28:20 +0100909endfunc
910
Bram Moolenaarf7c7c3f2022-06-22 19:08:38 +0100911func Test_mark_from_line_zero()
912 " this was reading past the end of the first (empty) line
913 new
914 norm oxxxx
915 call assert_fails("0;'(", 'E20:')
916 bwipe!
917endfunc
918
Bram Moolenaarba47b512017-01-24 21:18:19 +0100919func Test_cmdline_complete_wildoptions()
920 help
921 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
922 let a = join(sort(split(@:)),' ')
923 set wildoptions=tagfile
924 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
925 let b = join(sort(split(@:)),' ')
926 call assert_equal(a, b)
927 bw!
928endfunc
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +0100929
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200930func Test_cmdline_complete_user_cmd()
931 command! -complete=color -nargs=1 Foo :
932 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
933 call assert_equal('"Foo blue', @:)
934 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
935 call assert_equal('"Foo blue', @:)
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +0000936 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
937 call assert_equal('"Foo a blue', @:)
938 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
939 call assert_equal('"Foo b\', @:)
940 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
941 call assert_equal('"Foo b\x', @:)
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200942 delcommand Foo
Bram Moolenaar300175f2022-08-21 18:38:21 +0100943
944 redraw
945 call assert_equal('~', Screenline(&lines - 1))
946 command! FooOne :
947 command! FooTwo :
948
949 set nowildmenu
950 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
951 call assert_equal('"FooOne', @:)
952 call assert_equal('~', Screenline(&lines - 1))
953
954 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
955 call assert_equal('"FooTwo', @:)
956 call assert_equal('~', Screenline(&lines - 1))
957
958 delcommand FooOne
959 delcommand FooTwo
960 set wildmenu&
Bram Moolenaara33ddbb2017-03-29 21:30:04 +0200961endfunc
962
Bram Moolenaarc2842ad2022-07-26 17:23:47 +0100963func Test_complete_user_cmd()
964 command FooBar echo 'global'
965 command -buffer FooBar echo 'local'
966 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
967 call assert_equal('"FooBar', @:)
968
969 delcommand -buffer FooBar
970 delcommand FooBar
971endfunc
972
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100973func s:ScriptLocalFunction()
974 echo 'yes'
975endfunc
976
977func Test_cmdline_complete_user_func()
978 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
naohiro ono5aec7552021-08-19 21:20:41 +0200979 call assert_match('"func Test_cmdline_complete_user_', @:)
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100980 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
981 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
Bram Moolenaar1bb4de52021-01-13 19:48:46 +0100982
983 " g: prefix also works
984 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
985 call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
Bram Moolenaar069f9082021-08-13 17:48:25 +0200986
987 " using g: prefix does not result in just "g:" matches from a lambda
988 let Fx = { a -> a }
989 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
990 call assert_match('"echo g:[A-Z]', @:)
naohiro ono5aec7552021-08-19 21:20:41 +0200991
992 " existence of script-local dict function does not break user function name
993 " completion
994 function s:a_dict_func() dict
995 endfunction
996 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
997 call assert_match('"call Test_cmdline_complete_user_', @:)
998 delfunction s:a_dict_func
Bram Moolenaarcc390ff2020-02-29 22:06:30 +0100999endfunc
1000
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001001func Test_cmdline_complete_user_names()
1002 if has('unix') && executable('whoami')
1003 let whoami = systemlist('whoami')[0]
1004 let first_letter = whoami[0]
1005 if len(first_letter) > 0
1006 " Trying completion of :e ~x where x is the first letter of
1007 " the user name should complete to at least the user name.
1008 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
1009 call assert_match('^"e \~.*\<' . whoami . '\>', @:)
1010 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001011 elseif has('win32')
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001012 " Just in case: check that the system has an Administrator account.
1013 let names = system('net user')
1014 if names =~ 'Administrator'
1015 " Trying completion of :e ~A should complete to Administrator.
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001016 " There could be other names starting with "A" before Administrator.
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001017 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
Bram Moolenaar346d2a32019-01-27 20:43:41 +01001018 call assert_match('^"e \~.*Administrator', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001019 endif
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001020 else
1021 throw 'Skipped: does not work on this platform'
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001022 endif
1023endfunc
1024
Bram Moolenaar297610b2019-12-27 17:20:55 +01001025func Test_cmdline_complete_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001026 CheckExecutable whoami
1027 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
1028 call assert_match('^".*\<whoami\>', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001029endfunc
1030
Bram Moolenaar8b633132020-03-20 18:20:51 +01001031func Test_cmdline_complete_languages()
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001032 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
1033 call assert_equal(lang, v:lc_time)
1034
1035 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
1036 call assert_equal(lang, v:ctype)
1037
1038 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
1039 call assert_equal(lang, v:collate)
1040
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001041 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001042 call assert_equal(lang, v:lang)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001043
1044 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001045 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001046
Bram Moolenaarec680282020-06-12 19:35:32 +02001047 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001048
Bram Moolenaarec680282020-06-12 19:35:32 +02001049 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
1050 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001051
Bram Moolenaarec680282020-06-12 19:35:32 +02001052 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
1053 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001054
Bram Moolenaarec680282020-06-12 19:35:32 +02001055 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
1056 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001057
1058 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
1059 call assert_match('^"language .*\<' . lang . '\>', @:)
Bram Moolenaar5f8f2d32018-06-19 19:09:09 +02001060endfunc
1061
Bram Moolenaar297610b2019-12-27 17:20:55 +01001062func Test_cmdline_complete_env_variable()
1063 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
Bram Moolenaar297610b2019-12-27 17:20:55 +01001064 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
1065 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +01001066 unlet $X_VIM_TEST_COMPLETE_ENV
1067endfunc
1068
Bram Moolenaar4941b5e2020-12-24 17:15:53 +01001069func Test_cmdline_complete_expression()
1070 let g:SomeVar = 'blah'
1071 for cmd in ['exe', 'echo', 'echon', 'echomsg']
1072 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1073 call assert_match('"' .. cmd .. ' SomeVar', @:)
1074 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
1075 call assert_match('"' .. cmd .. ' foo SomeVar', @:)
1076 endfor
1077 unlet g:SomeVar
1078endfunc
1079
Bram Moolenaar47016f52021-08-26 16:39:58 +02001080" Unique function name for completion below
1081func s:WeirdFunc()
1082 echo 'weird'
1083endfunc
1084
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001085" Test for various command-line completion
1086func Test_cmdline_complete_various()
1087 " completion for a command starting with a comment
1088 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
1089 call assert_equal("\" :|\"\<C-A>", @:)
1090
1091 " completion for a range followed by a comment
1092 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
1093 call assert_equal("\"1,2\"\<C-A>", @:)
1094
1095 " completion for :k command
1096 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
1097 call assert_equal("\"ka\<C-A>", @:)
1098
1099 " completion for short version of the :s command
1100 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
1101 call assert_equal("\"sI \<C-A>", @:)
1102
1103 " completion for :write command
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001104 call mkdir('Xcwdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001105 call writefile(['one'], 'Xcwdir/Xfile1')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001106 let save_cwd = getcwd()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001107 cd Xcwdir
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001108 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
1109 call assert_equal("\"w >> Xfile1", @:)
1110 call chdir(save_cwd)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001111
1112 " completion for :w ! and :r ! commands
1113 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1114 call assert_equal("\"w !invalid_xyz_cmd", @:)
1115 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
1116 call assert_equal("\"r !invalid_xyz_cmd", @:)
1117
1118 " completion for :>> and :<< commands
1119 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
1120 call assert_equal("\">>>\<C-A>", @:)
1121 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
1122 call assert_equal("\"<<<\<C-A>", @:)
1123
1124 " completion for command with +cmd argument
1125 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
1126 call assert_equal("\"buffer +/pat Xabc", @:)
1127 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
1128 call assert_equal("\"buffer +/pat\<C-A>", @:)
1129
1130 " completion for a command with a trailing comment
1131 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
1132 call assert_equal("\"ls \" comment\<C-A>", @:)
1133
1134 " completion for a command with a trailing command
1135 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
1136 call assert_equal("\"ls | ls", @:)
1137
1138 " completion for a command with an CTRL-V escaped argument
1139 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
1140 call assert_equal("\"ls \<C-V>a\<C-A>", @:)
1141
1142 " completion for a command that doesn't take additional arguments
1143 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
1144 call assert_equal("\"all abc\<C-A>", @:)
1145
zeertzjqd3de1782022-09-01 12:58:52 +01001146 " completion for :wincmd with :horizontal modifier
1147 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
1148 call assert_equal("\"horizontal wincmd", @:)
1149
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001150 " completion for a command with a command modifier
1151 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
1152 call assert_equal("\"topleft new", @:)
1153
Bram Moolenaare70e12b2021-06-13 17:20:08 +02001154 " completion for vim9 and legacy commands
1155 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1156 call assert_equal("\"vim9 call strlen(", @:)
1157 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
1158 call assert_equal("\"legac call strlen(", @:)
1159
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001160 " completion for the :disassemble command
1161 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
1162 call assert_equal("\"disas debug", @:)
1163 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
1164 call assert_equal("\"disas profile", @:)
1165 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1166 call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
1167 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1168 call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
naohiro ono9aecf792021-08-28 15:56:06 +02001169 call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
1170 call assert_equal("\"disas Test_cmdline_complete_various", @:)
Bram Moolenaar4ee9d8e2021-06-13 18:38:48 +02001171
Bram Moolenaar47016f52021-08-26 16:39:58 +02001172 call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt')
naohiro ono9aecf792021-08-28 15:56:06 +02001173 call assert_match('"disas <SNR>\d\+_WeirdFunc', @:)
Bram Moolenaar47016f52021-08-26 16:39:58 +02001174
naohiro onodfe04db2021-09-12 15:45:10 +02001175 call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt')
1176 call assert_match('"disas <SNR>\d\+_', @:)
1177 call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt')
1178 call assert_match('"disas debug <SNR>\d\+_', @:)
1179
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001180 " completion for the :match command
1181 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
1182 call assert_equal("\"match Search /pat/\<C-A>", @:)
1183
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001184 " completion for the :doautocmd command
1185 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
1186 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
1187
Bram Moolenaarafe8cf62020-10-05 20:07:18 +02001188 " completion of autocmd group after comma
1189 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
1190 call assert_equal("\"doautocmd BufNew,BufEnter", @:)
1191
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001192 " completion of file name in :doautocmd
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001193 call writefile([], 'Xvarfile1', 'D')
1194 call writefile([], 'Xvarfile2', 'D')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001195 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
1196 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001197
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001198 " completion for the :augroup command
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001199 augroup XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001200 augroup END
1201 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001202 call assert_equal("\"augroup XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001203
1204 " group name completion in :autocmd
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001205 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
1206 call assert_equal("\"au XTest.test", @:)
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001207 call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
1208 call assert_equal("\"au XTest.test", @:)
1209
Bram Moolenaarb4d82e22021-09-01 13:03:39 +02001210 augroup! XTest.test
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001211
Yegappan Lakshmanan00e977c2022-06-01 12:31:53 +01001212 " autocmd pattern completion
1213 call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
1214 call assert_equal("\"au BufEnter *.py\t", @:)
1215
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001216 " completion for the :unlet command
1217 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
1218 call assert_equal("\"unlet one two", @:)
1219
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001220 " completion for the :buffer command with curlies
Bram Moolenaar39c47c32021-10-17 18:05:26 +01001221 " FIXME: what should happen on MS-Windows?
1222 if !has('win32')
1223 edit \{someFile}
1224 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
1225 call assert_equal("\"buf {someFile}", @:)
1226 bwipe {someFile}
1227 endif
Bram Moolenaar21c1a0c2021-10-17 17:20:23 +01001228
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001229 " completion for the :bdelete command
1230 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
1231 call assert_equal("\"bdel a b c", @:)
1232
1233 " completion for the :mapclear command
1234 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
1235 call assert_equal("\"mapclear <buffer>", @:)
1236
1237 " completion for user defined commands with menu names
1238 menu Test.foo :ls<CR>
1239 com -nargs=* -complete=menu MyCmd
1240 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
1241 call assert_equal('"MyCmd Test.', @:)
1242 delcom MyCmd
1243 unmenu Test
1244
1245 " completion for user defined commands with mappings
1246 mapclear
1247 map <F3> :ls<CR>
1248 com -nargs=* -complete=mapping MyCmd
1249 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001250 call assert_equal('"MyCmd <F3> <F4>', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001251 mapclear
1252 delcom MyCmd
1253
1254 " completion for :set path= with multiple backslashes
1255 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1256 call assert_equal('"set path=a\\\ b', @:)
1257
1258 " completion for :set dir= with a backslash
1259 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
1260 call assert_equal('"set dir=a\ b', @:)
1261
1262 " completion for the :py3 commands
1263 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
1264 call assert_equal('"py3 py3do py3file', @:)
1265
Bram Moolenaardf749a22021-03-28 15:29:43 +02001266 " completion for the :vim9 commands
1267 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt')
1268 call assert_equal('"vim9cmd vim9script', @:)
1269
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001270 " redir @" is not the start of a comment. So complete after that
1271 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
1272 call assert_equal('"redir @" | cwindow', @:)
1273
1274 " completion after a backtick
1275 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
1276 call assert_equal('"e `a1b2c', @:)
1277
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001278 " completion for :language command with an invalid argument
1279 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
1280 call assert_equal("\"language dummy \t", @:)
1281
1282 " completion for commands after a :global command
Bram Moolenaar8b633132020-03-20 18:20:51 +01001283 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
1284 call assert_equal('"g/a\xb/clearjumps', @:)
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001285
1286 " completion with ambiguous user defined commands
1287 com TCmd1 echo 'TCmd1'
1288 com TCmd2 echo 'TCmd2'
1289 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
1290 call assert_equal('"TCmd ', @:)
1291 delcom TCmd1
1292 delcom TCmd2
1293
1294 " completion after a range followed by a pipe (|) character
1295 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
1296 call assert_equal('"1,10 | chistory', @:)
Bram Moolenaar9c929712020-09-07 22:05:28 +02001297
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001298 " completion after a :global command
1299 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
1300 call assert_equal('"g/a/chistory', @:)
1301 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
1302 call assert_equal("\"g/a\\/chist\t", @:)
1303
Bram Moolenaar9c929712020-09-07 22:05:28 +02001304 " use <Esc> as the 'wildchar' for completion
1305 set wildchar=<Esc>
1306 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
1307 call assert_equal('"g/a\xb/clearjumps', @:)
1308 " pressing <esc> twice should cancel the command
1309 call feedkeys(":chist\<Esc>\<Esc>", 'xt')
1310 call assert_equal('"g/a\xb/clearjumps', @:)
1311 set wildchar&
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001312
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001313 if has('unix')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001314 " should be able to complete a file name that starts with a '~'.
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001315 call writefile([], '~Xtest')
1316 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
1317 call assert_equal('"e \~Xtest', @:)
1318 call delete('~Xtest')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001319
1320 " should be able to complete a file name that has a '*'
1321 call writefile([], 'Xx*Yy')
1322 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
1323 call assert_equal('"e Xx\*Yy', @:)
1324 call delete('Xx*Yy')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00001325
1326 " use a literal star
1327 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
1328 call assert_equal('"e \*', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001329 endif
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001330
1331 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
1332 call assert_equal('"py3file', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001333endfunc
1334
1335" Test for 'wildignorecase'
1336func Test_cmdline_wildignorecase()
1337 CheckUnix
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001338 call writefile([], 'XTEST', 'D')
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001339 set wildignorecase
1340 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
1341 call assert_equal('"e XTEST', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001342 call assert_equal(['XTEST'], getcompletion('xt', 'file'))
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001343 let g:Sline = ''
1344 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
1345 call assert_equal('"e xt', @:)
1346 call assert_equal('XTEST', g:Sline)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001347 set wildignorecase&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001348endfunc
1349
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001350func Test_cmdline_write_alternatefile()
1351 new
1352 call setline('.', ['one', 'two'])
1353 f foo.txt
1354 new
1355 f #-A
1356 call assert_equal('foo.txt-A', expand('%'))
1357 f #<-B.txt
1358 call assert_equal('foo-B.txt', expand('%'))
1359 f %<
1360 call assert_equal('foo-B', expand('%'))
1361 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02001362 call assert_fails('f #<', 'E95:')
Bram Moolenaarc312b8b2017-10-28 17:53:04 +02001363 bw!
1364 f foo-B.txt
1365 f %<-A
1366 call assert_equal('foo-B-A', expand('%'))
1367 bw!
1368 bw!
1369endfunc
1370
Bram Moolenaarf5724372022-09-02 19:45:15 +01001371func Test_cmdline_expand_cur_alt_file()
1372 enew
1373 file http://some.com/file.txt
1374 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
1375 call assert_equal('"e http://some.com/file.txt', @:)
1376 edit another
1377 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
1378 call assert_equal('"e http://some.com/file.txt', @:)
1379 bwipe
1380 bwipe http://some.com/file.txt
1381endfunc
1382
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001383" using a leading backslash here
1384set cpo+=C
1385
1386func Test_cmdline_search_range()
1387 new
1388 call setline(1, ['a', 'b', 'c', 'd'])
1389 /d
1390 1,\/s/b/B/
1391 call assert_equal('B', getline(2))
1392
1393 /a
1394 $
1395 \?,4s/c/C/
1396 call assert_equal('C', getline(3))
1397
1398 call setline(1, ['a', 'b', 'c', 'd'])
1399 %s/c/c/
1400 1,\&s/b/B/
1401 call assert_equal('B', getline(2))
1402
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001403 let @/ = 'apple'
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001404 call assert_fails('\/print', ['E486:.*apple'])
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001405
Bram Moolenaarcbf20fb2017-02-03 21:19:04 +01001406 bwipe!
1407endfunc
1408
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001409" Test for the tick mark (') in an excmd range
1410func Test_tick_mark_in_range()
1411 " If only the tick is passed as a range and no command is specified, there
1412 " should not be an error
1413 call feedkeys(":'\<CR>", 'xt')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001414 call assert_equal("'", @:)
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001415 call assert_fails("',print", 'E78:')
1416endfunc
1417
1418" Test for using a line number followed by a search pattern as range
1419func Test_lnum_and_pattern_as_range()
1420 new
1421 call setline(1, ['foo 1', 'foo 2', 'foo 3'])
1422 let @" = ''
1423 2/foo/yank
1424 call assert_equal("foo 3\n", @")
1425 call assert_equal(1, line('.'))
1426 close!
1427endfunc
1428
Bram Moolenaar65189a12017-02-06 22:22:17 +01001429" Tests for getcmdline(), getcmdpos() and getcmdtype()
1430func Check_cmdline(cmdtype)
1431 call assert_equal('MyCmd a', getcmdline())
1432 call assert_equal(8, getcmdpos())
1433 call assert_equal(a:cmdtype, getcmdtype())
1434 return ''
1435endfunc
1436
Bram Moolenaar96e38a82019-09-09 18:35:33 +02001437set cpo&
1438
Bram Moolenaar65189a12017-02-06 22:22:17 +01001439func Test_getcmdtype()
1440 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
1441
1442 let cmdtype = ''
1443 debuggreedy
1444 call feedkeys(":debug echo 'test'\<CR>", "t")
1445 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
1446 call feedkeys("cont\<CR>", "xt")
1447 0debuggreedy
1448 call assert_equal('>', cmdtype)
1449
1450 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
1451 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
1452
1453 call feedkeys(":call input('Answer?')\<CR>", "t")
Bram Moolenaar31eb1392017-02-09 21:44:03 +01001454 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
Bram Moolenaar65189a12017-02-06 22:22:17 +01001455
1456 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
1457
1458 cnoremap <expr> <F6> Check_cmdline('=')
1459 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
1460 cunmap <F6>
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001461
1462 call assert_equal('', getcmdline())
Bram Moolenaar65189a12017-02-06 22:22:17 +01001463endfunc
1464
Bram Moolenaar52604f22017-04-07 16:17:39 +02001465func Test_verbosefile()
1466 set verbosefile=Xlog
1467 echomsg 'foo'
1468 echomsg 'bar'
1469 set verbosefile=
1470 let log = readfile('Xlog')
1471 call assert_match("foo\nbar", join(log, "\n"))
1472 call delete('Xlog')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001473
1474 call mkdir('Xdir', 'D')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001475 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
Bram Moolenaar52604f22017-04-07 16:17:39 +02001476endfunc
1477
Bram Moolenaar4facea32019-10-12 20:17:40 +02001478func Test_verbose_option()
1479 CheckScreendump
1480
1481 let lines =<< trim [SCRIPT]
1482 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
1483 call feedkeys("\r", 't') " for the hit-enter prompt
1484 set verbose=20
1485 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001486 call writefile(lines, 'XTest_verbose', 'D')
Bram Moolenaar4facea32019-10-12 20:17:40 +02001487
1488 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001489 call TermWait(buf, 50)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001490 call term_sendkeys(buf, ":DoSomething\<CR>")
1491 call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
1492
1493 " clean up
1494 call StopVimInTerminal(buf)
Bram Moolenaar4facea32019-10-12 20:17:40 +02001495endfunc
1496
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001497func Test_setcmdpos()
1498 func InsertTextAtPos(text, pos)
1499 call assert_equal(0, setcmdpos(a:pos))
1500 return a:text
1501 endfunc
1502
1503 " setcmdpos() with position in the middle of the command line.
1504 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1505 call assert_equal('"1ab2', @:)
1506
1507 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
1508 call assert_equal('"1b2a', @:)
1509
1510 " setcmdpos() with position beyond the end of the command line.
1511 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
1512 call assert_equal('"12ab', @:)
1513
1514 " setcmdpos() returns 1 when not editing the command line.
Bram Moolenaar196b4662019-09-06 21:34:30 +02001515 call assert_equal(1, 3->setcmdpos())
Bram Moolenaarff3be4f2018-05-12 13:18:46 +02001516endfunc
1517
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001518func Test_cmdline_overstrike()
Bram Moolenaar30276f22019-01-24 17:59:39 +01001519 let encodings = ['latin1', 'utf8']
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001520 let encoding_save = &encoding
1521
1522 for e in encodings
1523 exe 'set encoding=' . e
1524
1525 " Test overstrike in the middle of the command line.
1526 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001527 call assert_equal('"0ab1cd4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001528
1529 " Test overstrike going beyond end of command line.
1530 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001531 call assert_equal('"0ab1cdefgh', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001532
1533 " Test toggling insert/overstrike a few times.
1534 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001535 call assert_equal('"ab0cd3ef4', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001536 endfor
1537
Bram Moolenaar30276f22019-01-24 17:59:39 +01001538 " Test overstrike with multi-byte characters.
1539 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001540 call assert_equal('"テabキcdエディタ', @:, e)
Bram Moolenaarc0676ba2018-12-31 21:03:02 +01001541
1542 let &encoding = encoding_save
1543endfunc
Bram Moolenaara046b372019-09-15 17:26:07 +02001544
Bram Moolenaar52410572019-10-27 05:12:45 +01001545func Test_buffers_lastused()
1546 " check that buffers are sorted by time when wildmode has lastused
1547 call test_settime(1550020000) " middle
1548 edit bufa
1549 enew
1550 call test_settime(1550030000) " newest
1551 edit bufb
1552 enew
1553 call test_settime(1550010000) " oldest
1554 edit bufc
1555 enew
1556 call test_settime(0)
1557 enew
1558
1559 call assert_equal(['bufa', 'bufb', 'bufc'],
1560 \ getcompletion('', 'buffer'))
1561
1562 let save_wildmode = &wildmode
1563 set wildmode=full:lastused
1564
1565 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
1566 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1567 call assert_equal('b bufb', X)
1568 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1569 call assert_equal('b bufa', X)
1570 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1571 call assert_equal('b bufc', X)
1572 enew
1573
1574 edit other
1575 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
1576 call assert_equal('b bufb', X)
1577 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1578 call assert_equal('b bufa', X)
1579 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
1580 call assert_equal('b bufc', X)
1581 enew
1582
1583 let &wildmode = save_wildmode
1584
1585 bwipeout bufa
1586 bwipeout bufb
1587 bwipeout bufc
1588endfunc
Bram Moolenaar85db5472019-12-04 15:11:08 +01001589
Bram Moolenaar479950f2020-01-19 15:45:17 +01001590func Test_cmdlineclear_tabenter()
1591 CheckScreendump
1592
1593 let lines =<< trim [SCRIPT]
1594 call setline(1, range(30))
1595 [SCRIPT]
1596
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001597 call writefile(lines, 'XtestCmdlineClearTabenter', 'D')
Bram Moolenaar479950f2020-01-19 15:45:17 +01001598 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001599 call TermWait(buf, 25)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001600 " in one tab make the command line higher with CTRL-W -
1601 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
1602 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
1603
1604 call StopVimInTerminal(buf)
Bram Moolenaar479950f2020-01-19 15:45:17 +01001605endfunc
1606
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001607" Test for expanding special keywords in cmdline
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001608func Test_cmdline_expand_special()
1609 %bwipe!
Bram Moolenaarb8bd2e62021-08-21 17:13:14 +02001610 call assert_fails('e #', 'E194:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001611 call assert_fails('e <afile>', 'E495:')
1612 call assert_fails('e <abuf>', 'E496:')
1613 call assert_fails('e <amatch>', 'E497:')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001614
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001615 call writefile([], 'Xfile.cpp', 'D')
1616 call writefile([], 'Xfile.java', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02001617 new Xfile.cpp
1618 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1619 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1620 close
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001621endfunc
1622
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001623" Test for backtick expression in the command line
1624func Test_cmd_backtick()
1625 %argd
1626 argadd `=['a', 'b', 'c']`
1627 call assert_equal(['a', 'b', 'c'], argv())
1628 %argd
Dominique Pellebfb2bb12021-08-14 21:11:51 +02001629
1630 argadd `echo abc def`
1631 call assert_equal(['abc def'], argv())
1632 %argd
Bram Moolenaarf0cee192020-02-16 13:33:56 +01001633endfunc
1634
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001635" Test for the :! command
1636func Test_cmd_bang()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001637 CheckUnix
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001638
1639 let lines =<< trim [SCRIPT]
1640 " Test for no previous command
1641 call assert_fails('!!', 'E34:')
1642 set nomore
1643 " Test for cmdline expansion with :!
1644 call setline(1, 'foo!')
1645 silent !echo <cWORD> > Xfile.out
1646 call assert_equal(['foo!'], readfile('Xfile.out'))
1647 " Test for using previous command
1648 silent !echo \! !
1649 call assert_equal(['! echo foo!'], readfile('Xfile.out'))
1650 call writefile(v:errors, 'Xresult')
1651 call delete('Xfile.out')
1652 qall!
1653 [SCRIPT]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001654 call writefile(lines, 'Xscript', 'D')
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001655 if RunVim([], [], '--clean -S Xscript')
1656 call assert_equal([], readfile('Xresult'))
1657 endif
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01001658 call delete('Xresult')
1659endfunc
1660
Bram Moolenaare0c3c3d2020-06-04 22:46:04 +02001661" Test error: "E135: *Filter* Autocommands must not change current buffer"
1662func Test_cmd_bang_E135()
1663 new
1664 call setline(1, ['a', 'b', 'c', 'd'])
1665 augroup test_cmd_filter_E135
1666 au!
1667 autocmd FilterReadPost * help
1668 augroup END
1669 call assert_fails('2,3!echo "x"', 'E135:')
1670
1671 augroup test_cmd_filter_E135
1672 au!
1673 augroup END
1674 %bwipe!
1675endfunc
1676
shane.xb.qian4e7590e2022-11-08 21:40:04 +00001677func Test_cmd_bang_args()
1678 new
1679 :.!
1680 call assert_equal(0, v:shell_error)
1681
1682 " Note that below there is one space char after the '!'. This caused a
1683 " shell error in the past, see https://github.com/vim/vim/issues/11495.
1684 :.!
1685 call assert_equal(0, v:shell_error)
1686 bwipe!
1687
1688 CheckUnix
1689 :.!pwd
1690 call assert_equal(0, v:shell_error)
1691 :.! pwd
1692 call assert_equal(0, v:shell_error)
1693
1694 " Note there is one space after 'pwd'.
1695 :.! pwd
1696 call assert_equal(0, v:shell_error)
1697
1698 " Note there are two spaces after 'pwd'.
1699 :.! pwd
1700 call assert_equal(0, v:shell_error)
1701 :.!ls ~
1702 call assert_equal(0, v:shell_error)
1703
1704 " Note there is one space char after '~'.
1705 :.!ls ~
1706 call assert_equal(0, v:shell_error)
1707
1708 " Note there are two spaces after '~'.
1709 :.!ls ~
1710 call assert_equal(0, v:shell_error)
1711
1712 :.!echo "foo"
1713 call assert_equal(getline('.'), "foo")
1714 :.!echo "foo "
1715 call assert_equal(getline('.'), "foo ")
1716 :.!echo " foo "
1717 call assert_equal(getline('.'), " foo ")
1718 :.!echo " foo "
1719 call assert_equal(getline('.'), " foo ")
1720
1721 %bwipe!
1722endfunc
1723
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001724" Test for using ~ for home directory in cmdline completion matches
1725func Test_cmdline_expand_home()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001726 call mkdir('Xexpdir', 'R')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001727 call writefile([], 'Xexpdir/Xfile1')
1728 call writefile([], 'Xexpdir/Xfile2')
1729 cd Xexpdir
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001730 let save_HOME = $HOME
1731 let $HOME = getcwd()
1732 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1733 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1734 let $HOME = save_HOME
1735 cd ..
Bram Moolenaar8d588cc2020-02-25 21:47:45 +01001736endfunc
1737
Bram Moolenaar578fe942020-02-27 21:32:51 +01001738" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1739" or insert mode (when 'insertmode' is set)
1740func Test_cmdline_ctrl_g()
1741 new
1742 call setline(1, 'abc')
1743 call cursor(1, 3)
1744 " If command line is entered from insert mode, using C-\ C-G should back to
1745 " insert mode
1746 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1747 call assert_equal('abxyc', getline(1))
1748 call assert_equal(4, col('.'))
1749
1750 " If command line is entered in 'insertmode', using C-\ C-G should back to
1751 " 'insertmode'
1752 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1753 call assert_equal('ab12xyc', getline(1))
1754 close!
1755endfunc
1756
Bram Moolenaar578fe942020-02-27 21:32:51 +01001757" Test for 'wildmode'
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001758func Wildmode_tests()
Bram Moolenaar578fe942020-02-27 21:32:51 +01001759 func T(a, c, p)
1760 return "oneA\noneB\noneC"
1761 endfunc
1762 command -nargs=1 -complete=custom,T MyCmd
1763
Bram Moolenaar578fe942020-02-27 21:32:51 +01001764 set nowildmenu
1765 set wildmode=full,list
1766 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001767 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001768 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001769 call assert_equal('"MyCmd oneA', @:)
1770
1771 set wildmode=longest,full
1772 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1773 call assert_equal('"MyCmd one', @:)
1774 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1775 call assert_equal('"MyCmd oneC', @:)
1776
1777 set wildmode=longest
1778 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1779 call assert_equal('"MyCmd one', @:)
1780
1781 set wildmode=list:longest
1782 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001783 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001784 call assert_equal('oneA oneB oneC', g:Sline)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001785 call assert_equal('"MyCmd one', @:)
1786
1787 set wildmode=""
1788 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1789 call assert_equal('"MyCmd oneA', @:)
1790
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001791 " Test for wildmode=longest with 'fileignorecase' set
1792 set wildmode=longest
1793 set fileignorecase
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001794 argadd AAA AAAA AAAAA
1795 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
1796 call assert_equal('"buffer AAA', @:)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001797 set fileignorecase&
1798
1799 " Test for listing files with wildmode=list
1800 set wildmode=list
1801 let g:Sline = ''
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001802 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001803 call assert_equal('AAA AAAA AAAAA', g:Sline)
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001804 call assert_equal('"b A', @:)
1805
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001806 " when using longest completion match, matches shorter than the argument
1807 " should be ignored (happens with :help)
1808 set wildmode=longest,full
1809 set wildmenu
1810 call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
1811 call assert_equal('"help a', @:)
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001812 " non existing file
1813 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
1814 call assert_equal('"e a1b2y3z4', @:)
Yegappan Lakshmanan4d03d872022-02-13 11:45:09 +00001815 set wildmenu&
1816
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001817 " Test for longest file name completion with 'fileignorecase'
1818 " On MS-Windows, file names are case insensitive.
1819 if has('unix')
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001820 call writefile([], 'XTESTfoo', 'D')
1821 call writefile([], 'Xtestbar', 'D')
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001822 set nofileignorecase
1823 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1824 call assert_equal('"e XTESTfoo', @:)
1825 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1826 call assert_equal('"e Xtestbar', @:)
1827 set fileignorecase
1828 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
1829 call assert_equal('"e Xtest', @:)
1830 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
1831 call assert_equal('"e Xtest', @:)
1832 set fileignorecase&
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001833 endif
1834
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001835 %argdelete
Bram Moolenaar578fe942020-02-27 21:32:51 +01001836 delcommand MyCmd
1837 delfunc T
Bram Moolenaar578fe942020-02-27 21:32:51 +01001838 set wildmode&
Bram Moolenaar24ebd832020-03-16 21:25:24 +01001839 %bwipe!
Bram Moolenaar578fe942020-02-27 21:32:51 +01001840endfunc
1841
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00001842func Test_wildmode()
1843 " Test with utf-8 encoding
1844 call Wildmode_tests()
1845
1846 " Test with latin1 encoding
1847 let save_encoding = &encoding
1848 set encoding=latin1
1849 call Wildmode_tests()
1850 let &encoding = save_encoding
1851endfunc
1852
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001853func Test_custom_complete_autoload()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01001854 call mkdir('Xcustdir/autoload', 'pR')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001855 let save_rtp = &rtp
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001856 exe 'set rtp=' .. getcwd() .. '/Xcustdir'
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001857 let lines =<< trim END
1858 func vim8#Complete(a, c, p)
1859 return "oneA\noneB\noneC"
1860 endfunc
1861 END
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001862 call writefile(lines, 'Xcustdir/autoload/vim8.vim')
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001863
1864 command -nargs=1 -complete=custom,vim8#Complete MyCmd
1865 set nowildmenu
1866 set wildmode=full,list
1867 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
1868 call assert_equal('"MyCmd oneA oneB oneC', @:)
1869
1870 let &rtp = save_rtp
1871 set wildmode& wildmenu&
1872 delcommand MyCmd
Bram Moolenaarda6d42c2022-03-17 11:46:55 +00001873endfunc
1874
Bram Moolenaar578fe942020-02-27 21:32:51 +01001875" Test for interrupting the command-line completion
1876func Test_interrupt_compl()
1877 func F(lead, cmdl, p)
1878 if a:lead =~ 'tw'
1879 call interrupt()
1880 return
1881 endif
1882 return "one\ntwo\nthree"
1883 endfunc
1884 command -nargs=1 -complete=custom,F Tcmd
1885
1886 set nowildmenu
1887 set wildmode=full
1888 let interrupted = 0
1889 try
1890 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1891 catch /^Vim:Interrupt$/
1892 let interrupted = 1
1893 endtry
1894 call assert_equal(1, interrupted)
1895
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00001896 let interrupted = 0
1897 try
1898 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
1899 catch /^Vim:Interrupt$/
1900 let interrupted = 1
1901 endtry
1902 call assert_equal(1, interrupted)
1903
Bram Moolenaar578fe942020-02-27 21:32:51 +01001904 delcommand Tcmd
1905 delfunc F
1906 set wildmode&
1907endfunc
1908
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001909" Test for moving the cursor on the : command line
Bram Moolenaar578fe942020-02-27 21:32:51 +01001910func Test_cmdline_edit()
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001911 let str = ":one two\<C-U>"
1912 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001913 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001914 let str ..= "\<Left>five\<Right>"
1915 let str ..= "\<Home>two "
1916 let str ..= "\<C-Left>one "
1917 let str ..= "\<C-Right> three"
1918 let str ..= "\<End>\<S-Left>four "
1919 let str ..= "\<S-Right> six"
1920 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1921 call feedkeys(str, 'xt')
1922 call assert_equal("\"one two three four five six seven", @:)
1923endfunc
1924
1925" Test for moving the cursor on the / command line in 'rightleft' mode
1926func Test_cmdline_edit_rightleft()
1927 CheckFeature rightleft
1928 set rightleft
1929 set rightleftcmd=search
1930 let str = "/one two\<C-U>"
1931 let str ..= "one two\<C-W>\<C-W>"
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001932 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
Bram Moolenaard30ae2f2020-02-29 14:23:58 +01001933 let str ..= "\<Right>five\<Left>"
1934 let str ..= "\<Home>two "
1935 let str ..= "\<C-Right>one "
1936 let str ..= "\<C-Left> three"
1937 let str ..= "\<End>\<S-Right>four "
1938 let str ..= "\<S-Left> six"
1939 let str ..= "\<C-B>\"\<C-E> seven\<CR>"
1940 call assert_fails("call feedkeys(str, 'xt')", 'E486:')
1941 call assert_equal("\"one two three four five six seven", @/)
1942 set rightleftcmd&
1943 set rightleft&
1944endfunc
1945
1946" Test for using <C-\>e in the command line to evaluate an expression
1947func Test_cmdline_expr()
1948 " Evaluate an expression from the beginning of a command line
1949 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
1950 call assert_equal('"hello', @:)
1951
1952 " Use an invalid expression for <C-\>e
1953 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
1954
1955 " Insert literal <CTRL-\> in the command line
1956 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
1957 call assert_equal("\"e \<C-\>\<C-Y>", @:)
Bram Moolenaar578fe942020-02-27 21:32:51 +01001958endfunc
1959
Bram Moolenaar6046ade2022-06-22 13:51:54 +01001960" This was making the insert position negative
1961func Test_cmdline_expr_register()
1962 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
1963endfunc
1964
Bram Moolenaar0546d7d2020-03-01 16:53:09 +01001965" Test for 'imcmdline' and 'imsearch'
1966" This test doesn't actually test the input method functionality.
1967func Test_cmdline_inputmethod()
1968 new
1969 call setline(1, ['', 'abc', ''])
1970 set imcmdline
1971
1972 call feedkeys(":\"abc\<CR>", 'xt')
1973 call assert_equal("\"abc", @:)
1974 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
1975 call assert_equal("\"abc", @:)
1976 call feedkeys("/abc\<CR>", 'xt')
1977 call assert_equal([2, 1], [line('.'), col('.')])
1978 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1979 call assert_equal([2, 1], [line('.'), col('.')])
1980
1981 set imsearch=2
1982 call cursor(1, 1)
1983 call feedkeys("/abc\<CR>", 'xt')
1984 call assert_equal([2, 1], [line('.'), col('.')])
1985 call cursor(1, 1)
1986 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1987 call assert_equal([2, 1], [line('.'), col('.')])
1988 set imdisable
1989 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
1990 call assert_equal([2, 1], [line('.'), col('.')])
1991 set imdisable&
1992 set imsearch&
1993
1994 set imcmdline&
1995 %bwipe!
1996endfunc
1997
Bram Moolenaar91ffc8a2020-03-02 20:54:22 +01001998" Test for using CTRL-_ in the command line with 'allowrevins'
1999func Test_cmdline_revins()
2000 CheckNotMSWindows
2001 CheckFeature rightleft
2002 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2003 call assert_equal("\"abc\<c-_>", @:)
2004 set allowrevins
2005 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
2006 call assert_equal('"abcñèæ', @:)
2007 set allowrevins&
2008endfunc
2009
2010" Test for typing UTF-8 composing characters in the command line
2011func Test_cmdline_composing_chars()
2012 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2013 call assert_equal('"ゔ', @:)
2014endfunc
2015
Bram Moolenaar0e717042020-04-27 19:29:01 +02002016" test that ";" works to find a match at the start of the first line
2017func Test_zero_line_search()
2018 new
2019 call setline(1, ["1, pattern", "2, ", "3, pattern"])
2020 call cursor(1,1)
2021 0;/pattern/d
2022 call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
2023 q!
2024endfunc
2025
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002026func Test_read_shellcmd()
2027 CheckUnix
2028 if executable('ls')
2029 " There should be ls in the $PATH
2030 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
2031 call assert_match('^"r! .*\<ls\>', @:)
2032 endif
2033
2034 if executable('rm')
2035 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
2036 call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
2037 call assert_match('^"r!.*\<rm\>', @:)
Bram Moolenaar743d0622020-07-03 18:15:06 +02002038
2039 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
2040 call assert_notmatch('^"r.*\<runtest.vim\>', @:)
2041 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
Bram Moolenaarc8cb8832020-06-18 21:14:30 +02002042 endif
2043endfunc
2044
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002045" Test for going up and down the directory tree using 'wildmenu'
2046func Test_wildmenu_dirstack()
2047 CheckUnix
2048 %bw!
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002049 call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002050 call writefile([], 'Xwildmenu/file1_1.txt')
2051 call writefile([], 'Xwildmenu/file1_2.txt')
2052 call writefile([], 'Xwildmenu/dir2/file2_1.txt')
2053 call writefile([], 'Xwildmenu/dir2/file2_2.txt')
2054 call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt')
2055 call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt')
2056 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt')
2057 call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt')
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002058 set wildmenu
2059
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002060 cd Xwildmenu/dir2/dir3/dir4
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002061 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002062 call assert_equal('"e file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002063 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002064 call assert_equal('"e ../dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002065 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002066 call assert_equal('"e ../../dir3/', @:)
2067 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
2068 call assert_equal('"e ../../../dir2/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002069 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002070 call assert_equal('"e ../../dir3/dir4/', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002071 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002072 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002073 cd -
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01002074 call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
2075 call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:)
Yegappan Lakshmananb31aec32022-02-16 12:44:29 +00002076
Bram Moolenaar4b2ce122020-11-21 21:41:41 +01002077 set wildmenu&
2078endfunc
2079
obcat71c6f7a2021-05-13 20:23:10 +02002080" Test for recalling newer or older cmdline from history with <Up>, <Down>,
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002081" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
2082" <C-n>.
obcat71c6f7a2021-05-13 20:23:10 +02002083func Test_recalling_cmdline()
2084 CheckFeature cmdline_hist
2085
2086 let g:cmdlines = []
2087 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
2088
2089 let histories = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002090 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
2091 \ #{name: 'search', enter: '/', exit: "\<Esc>"},
2092 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
2093 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
obcat71c6f7a2021-05-13 20:23:10 +02002094 "\ TODO: {'name': 'debug', ...}
2095 \]
2096 let keypairs = [
Yegappan Lakshmanan155b0882022-03-17 13:03:09 +00002097 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
2098 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
2099 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
2100 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
2101 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
obcat71c6f7a2021-05-13 20:23:10 +02002102 \]
2103 let prefix = 'vi'
2104 for h in histories
2105 call histadd(h.name, 'vim')
2106 call histadd(h.name, 'virtue')
2107 call histadd(h.name, 'Virgo')
2108 call histadd(h.name, 'vogue')
2109 call histadd(h.name, 'emacs')
2110 for k in keypairs
2111 let g:cmdlines = []
2112 let keyseqs = h.enter
2113 \ .. prefix
2114 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
2115 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
2116 \ .. h.exit
2117 call feedkeys(keyseqs, 'xt')
2118 call histdel(h.name, -1) " delete the history added by feedkeys above
2119 let expect = k.prefixmatch
2120 \ ? ['virtue', 'vim', 'virtue', prefix]
2121 \ : ['emacs', 'vogue', 'emacs', prefix]
2122 call assert_equal(expect, g:cmdlines)
2123 endfor
2124 endfor
2125
2126 unlet g:cmdlines
2127 cunmap <Plug>(save-cmdline)
2128endfunc
2129
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002130func Test_cmd_map_cmdlineChanged()
2131 let g:log = []
2132 cnoremap <F1> l<Cmd><CR>s
2133 augroup test
2134 autocmd!
2135 autocmd CmdlineChanged : let g:log += [getcmdline()]
2136 augroup END
2137
2138 call feedkeys(":\<F1>\<CR>", 'xt')
2139 call assert_equal(['l', 'ls'], g:log)
2140
Bram Moolenaar796139a2021-05-18 21:38:45 +02002141 let @b = 'b'
2142 cnoremap <F1> a<C-R>b
2143 let g:log = []
2144 call feedkeys(":\<F1>\<CR>", 'xt')
2145 call assert_equal(['a', 'ab'], g:log)
2146
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002147 unlet g:log
2148 cunmap <F1>
2149 augroup test
2150 autocmd!
2151 augroup END
2152endfunc
2153
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002154" Test for the 'suffixes' option
2155func Test_suffixes_opt()
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002156 call writefile([], 'Xsuffile', 'D')
2157 call writefile([], 'Xsuffile.c', 'D')
2158 call writefile([], 'Xsuffile.o', 'D')
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002159 set suffixes=
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002160 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2161 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
2162 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2163 call assert_equal('"e Xsuffile.c', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002164 set suffixes=.c
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002165 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2166 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
2167 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2168 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002169 set suffixes=,,
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002170 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
2171 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
2172 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
2173 call assert_equal('"e Xsuffile.o', @:)
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002174 set suffixes&
Yegappan Lakshmanan9773db62022-02-14 11:10:59 +00002175 " Test for getcompletion() with different patterns
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002176 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
2177 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +02002178endfunc
Bram Moolenaar847fe7d2021-05-15 13:19:16 +02002179
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002180" Test for using a popup menu for the command line completion matches
2181" (wildoptions=pum)
2182func Test_wildmenu_pum()
2183 CheckRunVimInTerminal
2184
2185 let commands =<< trim [CODE]
2186 set wildmenu
2187 set wildoptions=pum
2188 set shm+=I
2189 set noruler
2190 set noshowcmd
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002191
2192 func CmdCompl(a, b, c)
2193 return repeat(['aaaa'], 120)
2194 endfunc
2195 command -nargs=* -complete=customlist,CmdCompl Tcmd
Bram Moolenaar481acb12022-02-11 18:51:45 +00002196
2197 func MyStatusLine() abort
2198 return 'status'
2199 endfunc
2200 func SetupStatusline()
2201 set statusline=%!MyStatusLine()
2202 set laststatus=2
2203 endfunc
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002204
2205 func MyTabLine()
2206 return 'my tab line'
2207 endfunc
2208 func SetupTabline()
2209 set statusline=
2210 set tabline=%!MyTabLine()
2211 set showtabline=2
2212 endfunc
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002213
2214 func DoFeedKeys()
2215 let &wildcharm = char2nr("\t")
2216 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
2217 endfunc
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002218 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002219 call writefile(commands, 'Xtest', 'D')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002220
2221 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2222
2223 call term_sendkeys(buf, ":sign \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002224 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
2225
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002226 " going down the popup menu using <Down>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002227 call term_sendkeys(buf, "\<Down>\<Down>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002228 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
2229
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002230 " going down the popup menu using <C-N>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002231 call term_sendkeys(buf, "\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002232 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
2233
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002234 " going up the popup menu using <C-P>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002235 call term_sendkeys(buf, "\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002236 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
2237
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002238 " going up the popup menu using <Up>
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002239 call term_sendkeys(buf, "\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002240 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
2241
2242 " pressing <C-E> should end completion and go back to the original match
2243 call term_sendkeys(buf, "\<C-E>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002244 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
2245
2246 " pressing <C-Y> should select the current match and end completion
2247 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
2249
2250 " With 'wildmode' set to 'longest,full', completing a match should display
2251 " the longest match, the wildmenu should not be displayed.
2252 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
2253 call TermWait(buf)
2254 call term_sendkeys(buf, ":sign u\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002255 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
2256
2257 " pressing <Tab> should display the wildmenu
2258 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002259 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
2260
2261 " pressing <Tab> second time should select the next entry in the menu
2262 call term_sendkeys(buf, "\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002263 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
2264
2265 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002266 " showing popup menu in different columns in the cmdline
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002267 call term_sendkeys(buf, ":sign define \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002268 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
2269
2270 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
2272
2273 call term_sendkeys(buf, " \<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002274 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
2275
2276 " Directory name completion
Dominique Pellefebe1382022-09-14 12:51:49 +01002277 call mkdir('Xnamedir/XdirA/XdirB', 'pR')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002278 call writefile([], 'Xnamedir/XfileA')
2279 call writefile([], 'Xnamedir/XdirA/XfileB')
2280 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002281
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002282 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002283 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
2284
2285 " Pressing <Right> on a directory name should go into that directory
2286 call term_sendkeys(buf, "\<Right>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002287 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
2288
2289 " Pressing <Left> on a directory name should go to the parent directory
2290 call term_sendkeys(buf, "\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002291 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
2292
2293 " Pressing <C-A> when the popup menu is displayed should list all the
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002294 " matches but the popup menu should still remain
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002295 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002296 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
2297
2298 " Pressing <C-D> when the popup menu is displayed should remove the popup
2299 " menu
2300 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002301 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
2302
2303 " Pressing <S-Tab> should open the popup menu with the last entry selected
2304 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002305 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
2306
2307 " Pressing <Esc> should close the popup menu and cancel the cmd line
2308 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002309 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
2310
2311 " Typing a character when the popup is open, should close the popup
2312 call term_sendkeys(buf, ":sign \<Tab>x")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002313 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
2314
2315 " When the popup is open, entering the cmdline window should close the popup
2316 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
2318 call term_sendkeys(buf, ":q\<CR>")
2319
2320 " After the last popup menu item, <C-N> should show the original string
2321 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002322 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
2323
2324 " Use the popup menu for the command name
2325 call term_sendkeys(buf, "\<C-U>bu\<Tab>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002326 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
2327
2328 " Pressing the left arrow should remove the popup menu
2329 call term_sendkeys(buf, "\<Left>\<Left>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002330 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
2331
2332 " Pressing <BS> should remove the popup menu and erase the last character
2333 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002334 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
2335
2336 " Pressing <C-W> should remove the popup menu and erase the previous word
2337 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002338 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
2339
2340 " Pressing <C-U> should remove the popup menu and erase the entire line
2341 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002342 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
2343
2344 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
2345 " the cmdline from history
2346 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002347 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
2348
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002349 " Check "list" still works
2350 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
2351 call term_sendkeys(buf, ":cn\<Tab>")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002352 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
2353 call term_sendkeys(buf, "s")
Bram Moolenaar73a16c22022-02-08 17:40:36 +00002354 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
2355
rbtnn68cc2b82022-02-09 11:55:47 +00002356 " Tests a directory name contained full-width characters.
Dominique Pellefebe1382022-09-14 12:51:49 +01002357 call mkdir('Xnamedir/あいう', 'p')
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002358 call writefile([], 'Xnamedir/あいう/abc')
2359 call writefile([], 'Xnamedir/あいう/xyz')
2360 call writefile([], 'Xnamedir/あいう/123')
rbtnn68cc2b82022-02-09 11:55:47 +00002361
2362 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002363 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
rbtnn68cc2b82022-02-09 11:55:47 +00002364 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
2365
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002366 " Pressing <C-A> when the popup menu is displayed should list all the
2367 " matches and pressing a key after that should remove the popup menu
2368 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
2369 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
2370 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
2371
2372 " Pressing <C-A> when the popup menu is displayed should list all the
2373 " matches and pressing <Left> after that should move the cursor
2374 call term_sendkeys(buf, "\<C-U>abc\<Esc>")
2375 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
2376 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
2377
2378 " When <C-A> displays a lot of matches (screen scrolls), all the matches
2379 " should be displayed correctly on the screen.
2380 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
2381 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
2382
2383 " After using <C-A> to expand all the filename matches, pressing <Up>
2384 " should not open the popup menu again.
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01002385 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002386 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
2387 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
2388 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
2389
2390 " After using <C-A> to expand all the matches, pressing <S-Tab> used to
2391 " crash Vim
2392 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
2393 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
2394
Bram Moolenaar414acd32022-02-10 21:09:45 +00002395 " After removing the pum the command line is redrawn
2396 call term_sendkeys(buf, ":edit foo\<CR>")
2397 call term_sendkeys(buf, ":edit bar\<CR>")
2398 call term_sendkeys(buf, ":ls\<CR>")
2399 call term_sendkeys(buf, ":com\<Tab> ")
2400 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
Bram Moolenaar481acb12022-02-11 18:51:45 +00002401 call term_sendkeys(buf, "\<C-U>\<CR>")
2402
2403 " Esc still works to abort the command when 'statusline' is set
2404 call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
2405 call term_sendkeys(buf, ":si\<Tab>")
2406 call term_sendkeys(buf, "\<Esc>")
2407 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
Bram Moolenaar414acd32022-02-10 21:09:45 +00002408
Bram Moolenaare4835bf2022-02-14 19:17:53 +00002409 " Esc still works to abort the command when 'tabline' is set
2410 call term_sendkeys(buf, ":call SetupTabline()\<CR>")
2411 call term_sendkeys(buf, ":si\<Tab>")
2412 call term_sendkeys(buf, "\<Esc>")
2413 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
2414
Bram Moolenaar5c52be42022-02-27 14:28:31 +00002415 " popup is cleared also when 'lazyredraw' is set
2416 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
2417 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
2418 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
2419 call term_sendkeys(buf, "\<Esc>")
2420
Yegappan Lakshmanan5cffa8d2022-03-16 13:33:53 +00002421 " Pressing <PageDown> should scroll the menu downward
2422 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
2423 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
2424 call term_sendkeys(buf, "\<PageDown>")
2425 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
2426 call term_sendkeys(buf, "\<PageDown>")
2427 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
2428 call term_sendkeys(buf, "\<PageDown>")
2429 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
2430 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
2431 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
2432
2433 " Pressing <PageUp> should scroll the menu upward
2434 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
2435 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
2436 call term_sendkeys(buf, "\<PageUp>")
2437 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
2438 call term_sendkeys(buf, "\<PageUp>")
2439 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
2440 call term_sendkeys(buf, "\<PageUp>")
2441 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
2442
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002443 call term_sendkeys(buf, "\<C-U>\<CR>")
2444 call StopVimInTerminal(buf)
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00002445endfunc
2446
Yegappan Lakshmanan560dff42022-02-10 19:52:10 +00002447" Test for wildmenumode() with the cmdline popup menu
2448func Test_wildmenumode_with_pum()
2449 set wildmenu
2450 set wildoptions=pum
2451 cnoremap <expr> <F2> wildmenumode()
2452 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
2453 call assert_equal('"sign define10', @:)
2454 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
2455 call assert_equal('"sign define jump list place undefine unplace0', @:)
2456 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
2457 call assert_equal('"sign 0', @:)
2458 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
2459 call assert_equal('"sign define0', @:)
2460 set nowildmenu wildoptions&
2461 cunmap <F2>
2462endfunc
2463
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002464func Test_wildmenu_with_pum_foldexpr()
2465 CheckRunVimInTerminal
2466
2467 let lines =<< trim END
2468 call setline(1, ['folded one', 'folded two', 'some more text'])
2469 func MyFoldText()
2470 return 'foo'
2471 endfunc
2472 set foldtext=MyFoldText() wildoptions=pum
2473 normal ggzfj
2474 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002475 call writefile(lines, 'Xpumfold', 'D')
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002476 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10})
2477 call term_sendkeys(buf, ":set\<Tab>")
2478 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {})
2479
2480 call term_sendkeys(buf, "\<Esc>")
2481 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {})
2482
2483 call StopVimInTerminal(buf)
Bram Moolenaar11a57df2022-04-11 19:38:56 +01002484endfunc
2485
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002486" Test for opening the cmdline completion popup menu from the terminal window.
2487" The popup menu should be positioned correctly over the status line of the
2488" bottom-most window.
2489func Test_wildmenu_pum_from_terminal()
2490 CheckRunVimInTerminal
2491 let python = PythonProg()
2492 call CheckPython(python)
2493
2494 %bw!
2495 let cmds = ['set wildmenu wildoptions=pum']
2496 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
2497 call add(cmds, "call term_start('" .. pcmd .. "')")
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002498 call writefile(cmds, 'Xtest', 'D')
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002499 let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
2500 call term_sendkeys(buf, "\r\r\r")
2501 call term_wait(buf)
2502 call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
2503 call term_wait(buf)
2504 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
2505 call term_wait(buf)
2506 call StopVimInTerminal(buf)
Yegappan Lakshmanan1104a6d2022-03-31 12:34:15 +01002507endfunc
2508
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002509func Test_wildmenu_pum_clear_entries()
Bram Moolenaarb9603f62022-12-08 15:44:22 +00002510 CheckRunVimInTerminal
2511
Bram Moolenaar038e6d22022-12-08 12:00:50 +00002512 " This was using freed memory. Run in a terminal to get the pum to update.
2513 let lines =<< trim END
2514 set wildoptions=pum
2515 set wildchar=<C-E>
2516 END
2517 call writefile(lines, 'XwildmenuTest', 'D')
2518 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
2519
2520 call term_sendkeys(buf, ":\<C-E>\<C-E>")
2521 call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {})
2522
2523 set wildoptions& wildchar&
2524endfunc
2525
Yegappan Lakshmanane3846cf2022-02-15 11:35:54 +00002526" Test for completion after a :substitute command followed by a pipe (|)
2527" character
2528func Test_cmdline_complete_substitute()
2529 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
2530 call assert_equal("\"s | \t", @:)
2531 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
2532 call assert_equal("\"s/ | \t", @:)
2533 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
2534 call assert_equal("\"s/one | \t", @:)
2535 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
2536 call assert_equal("\"s/one/ | \t", @:)
2537 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
2538 call assert_equal("\"s/one/two | \t", @:)
2539 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
2540 call assert_equal('"s/one/two/ | chistory', @:)
2541 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
2542 call assert_equal("\"s/one/two/g \t", @:)
2543 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
2544 call assert_equal("\"s/one/two/g | chistory", @:)
2545 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
2546 call assert_equal("\"s/one/t\\/ | \t", @:)
2547 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
2548 call assert_equal('"s/one/t"o/ | chistory', @:)
2549 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
2550 call assert_equal('"s/one/t|o/ | chistory', @:)
2551 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
2552 call assert_equal("\"&\t", @:)
2553endfunc
2554
2555" Test for the :dlist command completion
2556func Test_cmdline_complete_dlist()
2557 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
2558 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
2559 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
2560 call assert_equal("\"dlist 10 /pat/ \t", @:)
2561 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
2562 call assert_equal("\"dlist 10 /pa\\t/\t", @:)
2563 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
2564 call assert_equal("\"dlist 10 /pat\\\t", @:)
2565 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
2566 call assert_equal("\"dlist 10 /pat/ | chistory", @:)
2567endfunc
2568
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002569" argument list (only for :argdel) fuzzy completion
2570func Test_fuzzy_completion_arglist()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002571 argadd change.py count.py charge.py
2572 set wildoptions&
2573 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2574 call assert_equal('"argdel cge', @:)
2575 set wildoptions=fuzzy
2576 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
2577 call assert_equal('"argdel change.py charge.py', @:)
2578 %argdelete
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002579 set wildoptions&
2580endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002581
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002582" autocmd group name fuzzy completion
2583func Test_fuzzy_completion_autocmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002584 set wildoptions&
2585 augroup MyFuzzyGroup
2586 augroup END
2587 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2588 call assert_equal('"augroup mfg', @:)
2589 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2590 call assert_equal('"augroup MyFuzzyGroup', @:)
2591 set wildoptions=fuzzy
2592 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
2593 call assert_equal('"augroup MyFuzzyGroup', @:)
2594 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
2595 call assert_equal('"augroup My*p', @:)
2596 augroup! MyFuzzyGroup
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002597 set wildoptions&
2598endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002599
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002600" buffer name fuzzy completion
2601func Test_fuzzy_completion_bufname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002602 set wildoptions&
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002603 " Use a long name to reduce the risk of matching a random directory name
2604 edit SomeRandomFileWithLetters.txt
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002605 enew
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002606 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2607 call assert_equal('"b SRFWL', @:)
2608 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2609 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002610 set wildoptions=fuzzy
Bram Moolenaar5ac4b1a2022-08-06 10:28:19 +01002611 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
2612 call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
2613 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
2614 call assert_equal('"b S*FileWithLetters.txt', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002615 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002616 set wildoptions&
2617endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002618
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002619" buffer name (full path) fuzzy completion
2620func Test_fuzzy_completion_bufname_fullpath()
2621 CheckUnix
2622 set wildoptions&
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01002623 call mkdir('Xcmd/Xstate/Xfile.js', 'pR')
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002624 edit Xcmd/Xstate/Xfile.js
2625 cd Xcmd/Xstate
2626 enew
2627 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2628 call assert_equal('"b CmdStateFile', @:)
2629 set wildoptions=fuzzy
2630 call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
2631 call assert_match('Xcmd/Xstate/Xfile.js$', @:)
2632 cd -
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002633 set wildoptions&
2634endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002635
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002636" :behave suboptions fuzzy completion
2637func Test_fuzzy_completion_behave()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002638 set wildoptions&
2639 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2640 call assert_equal('"behave xm', @:)
2641 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2642 call assert_equal('"behave xterm', @:)
2643 set wildoptions=fuzzy
2644 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
2645 call assert_equal('"behave xterm', @:)
2646 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
2647 call assert_equal('"behave xt*m', @:)
2648 let g:Sline = ''
2649 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
2650 call assert_equal('mswin', g:Sline)
2651 call assert_equal('"behave win', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002652 set wildoptions&
2653endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002654
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002655" " colorscheme name fuzzy completion - NOT supported
2656" func Test_fuzzy_completion_colorscheme()
2657" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002658
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002659" built-in command name fuzzy completion
2660func Test_fuzzy_completion_cmdname()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002661 set wildoptions&
2662 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2663 call assert_equal('"sbwin', @:)
2664 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2665 call assert_equal('"sbrewind', @:)
2666 set wildoptions=fuzzy
2667 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
2668 call assert_equal('"sbrewind', @:)
2669 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
2670 call assert_equal('"sbr*d', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002671 set wildoptions&
2672endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002673
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002674" " compiler name fuzzy completion - NOT supported
2675" func Test_fuzzy_completion_compiler()
2676" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002677
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002678" :cscope suboptions fuzzy completion
2679func Test_fuzzy_completion_cscope()
2680 CheckFeature cscope
2681 set wildoptions&
2682 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2683 call assert_equal('"cscope ret', @:)
2684 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2685 call assert_equal('"cscope reset', @:)
2686 set wildoptions=fuzzy
2687 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
2688 call assert_equal('"cscope reset', @:)
2689 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
2690 call assert_equal('"cscope re*t', @:)
2691 set wildoptions&
2692endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002693
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002694" :diffget/:diffput buffer name fuzzy completion
2695func Test_fuzzy_completion_diff()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002696 new SomeBuffer
2697 diffthis
2698 new OtherBuffer
2699 diffthis
2700 set wildoptions&
2701 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2702 call assert_equal('"diffget sbuf', @:)
2703 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2704 call assert_equal('"diffput sbuf', @:)
2705 set wildoptions=fuzzy
2706 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2707 call assert_equal('"diffget SomeBuffer', @:)
2708 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
2709 call assert_equal('"diffput SomeBuffer', @:)
2710 %bw!
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002711 set wildoptions&
2712endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002713
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002714" " directory name fuzzy completion - NOT supported
2715" func Test_fuzzy_completion_dirname()
2716" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002717
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002718" environment variable name fuzzy completion
2719func Test_fuzzy_completion_env()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002720 set wildoptions&
2721 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2722 call assert_equal('"echo $VUT', @:)
2723 set wildoptions=fuzzy
2724 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
2725 call assert_equal('"echo $VIMRUNTIME', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002726 set wildoptions&
2727endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002728
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002729" autocmd event fuzzy completion
2730func Test_fuzzy_completion_autocmd_event()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002731 set wildoptions&
2732 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2733 call assert_equal('"autocmd BWout', @:)
2734 set wildoptions=fuzzy
2735 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
2736 call assert_equal('"autocmd BufWipeout', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002737 set wildoptions&
2738endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002739
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002740" vim expression fuzzy completion
2741func Test_fuzzy_completion_expr()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002742 let g:PerPlaceCount = 10
2743 set wildoptions&
2744 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2745 call assert_equal('"let c = ppc', @:)
2746 set wildoptions=fuzzy
2747 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
2748 call assert_equal('"let c = PerPlaceCount', @:)
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002749 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002750endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002751
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002752" " file name fuzzy completion - NOT supported
2753" func Test_fuzzy_completion_filename()
2754" endfunc
2755
2756" " files in path fuzzy completion - NOT supported
2757" func Test_fuzzy_completion_filesinpath()
2758" endfunc
2759
2760" " filetype name fuzzy completion - NOT supported
2761" func Test_fuzzy_completion_filetype()
2762" endfunc
2763
2764" user defined function name completion
2765func Test_fuzzy_completion_userdefined_func()
2766 set wildoptions&
2767 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2768 call assert_equal('"call Test_f_u_f', @:)
2769 set wildoptions=fuzzy
2770 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
2771 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
2772 set wildoptions&
2773endfunc
2774
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002775" <SNR> functions should be sorted to the end
2776func Test_fuzzy_completion_userdefined_snr_func()
2777 func s:Sendmail()
2778 endfunc
2779 func SendSomemail()
2780 endfunc
2781 func S1e2n3dmail()
2782 endfunc
2783 set wildoptions=fuzzy
2784 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarfe8e9f62022-03-16 13:09:15 +00002785 call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
Yegappan Lakshmanan5de4c432022-02-28 13:28:38 +00002786 set wildoptions&
2787 delfunc s:Sendmail
2788 delfunc SendSomemail
2789 delfunc S1e2n3dmail
2790endfunc
2791
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002792" user defined command name completion
2793func Test_fuzzy_completion_userdefined_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002794 set wildoptions&
2795 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2796 call assert_equal('"MsFeat', @:)
2797 set wildoptions=fuzzy
2798 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
2799 call assert_equal('"MissingFeature', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002800 set wildoptions&
2801endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002802
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002803" " :help tag fuzzy completion - NOT supported
2804" func Test_fuzzy_completion_helptag()
2805" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002806
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002807" highlight group name fuzzy completion
2808func Test_fuzzy_completion_hlgroup()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002809 set wildoptions&
2810 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2811 call assert_equal('"highlight SKey', @:)
2812 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2813 call assert_equal('"highlight SpecialKey', @:)
2814 set wildoptions=fuzzy
2815 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
2816 call assert_equal('"highlight SpecialKey', @:)
2817 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
2818 call assert_equal('"highlight Sp*Key', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002819 set wildoptions&
2820endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002821
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002822" :history suboptions fuzzy completion
2823func Test_fuzzy_completion_history()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002824 set wildoptions&
2825 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2826 call assert_equal('"history dg', @:)
2827 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2828 call assert_equal('"history search', @:)
2829 set wildoptions=fuzzy
2830 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
2831 call assert_equal('"history debug', @:)
2832 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
2833 call assert_equal('"history se*h', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002834 set wildoptions&
2835endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002836
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002837" :language locale name fuzzy completion
2838func Test_fuzzy_completion_lang()
2839 CheckUnix
2840 set wildoptions&
2841 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2842 call assert_equal('"lang psx', @:)
2843 set wildoptions=fuzzy
2844 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
2845 call assert_equal('"lang POSIX', @:)
2846 set wildoptions&
2847endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002848
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002849" :mapclear buffer argument fuzzy completion
2850func Test_fuzzy_completion_mapclear()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002851 set wildoptions&
2852 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2853 call assert_equal('"mapclear buf', @:)
2854 set wildoptions=fuzzy
2855 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
2856 call assert_equal('"mapclear <buffer>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002857 set wildoptions&
2858endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002859
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002860" map name fuzzy completion
2861func Test_fuzzy_completion_mapname()
Yegappan Lakshmanan00333cb2022-02-26 16:05:08 +00002862 " test regex completion works
2863 set wildoptions=fuzzy
2864 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
2865 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002866 nmap <plug>MyLongMap :p<CR>
2867 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2868 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2869 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
2870 call assert_equal("\"nmap MLM \t", @:)
2871 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
2872 call assert_equal("\"nmap <F2> one two \t", @:)
2873 " duplicate entries should be removed
2874 vmap <plug>MyLongMap :<C-U>#<CR>
2875 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
2876 call assert_equal("\"nmap <Plug>MyLongMap", @:)
2877 nunmap <plug>MyLongMap
2878 vunmap <plug>MyLongMap
2879 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
2880 call assert_equal("\"nmap ABC\t", @:)
2881 " results should be sorted by best match
2882 nmap <Plug>format :
2883 nmap <Plug>goformat :
2884 nmap <Plug>TestFOrmat :
2885 nmap <Plug>fendoff :
2886 nmap <Plug>state :
2887 nmap <Plug>FendingOff :
2888 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
2889 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
2890 nunmap <Plug>format
2891 nunmap <Plug>goformat
2892 nunmap <Plug>TestFOrmat
2893 nunmap <Plug>fendoff
2894 nunmap <Plug>state
2895 nunmap <Plug>FendingOff
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002896 set wildoptions&
2897endfunc
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002898
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002899" abbreviation fuzzy completion
2900func Test_fuzzy_completion_abbr()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002901 set wildoptions=fuzzy
2902 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
2903 call assert_equal("\"iabbr <nowait>", @:)
2904 iabbr WaitForCompletion WFC
2905 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
2906 call assert_equal("\"iabbr WaitForCompletion", @:)
2907 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
2908 call assert_equal("\"iabbr a1z\t", @:)
zeertzjq145a6af2023-01-22 12:41:55 +00002909
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00002910 iunabbrev WaitForCompletion
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002911 set wildoptions&
2912endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002913
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002914" menu name fuzzy completion
2915func Test_fuzzy_completion_menu()
zeertzjq145a6af2023-01-22 12:41:55 +00002916 CheckFeature menu
2917
2918 source $VIMRUNTIME/menu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002919 set wildoptions&
2920 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2921 call assert_equal('"menu pup', @:)
2922 set wildoptions=fuzzy
2923 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
2924 call assert_equal('"menu PopUp.', @:)
zeertzjq145a6af2023-01-22 12:41:55 +00002925
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002926 set wildoptions&
zeertzjq145a6af2023-01-22 12:41:55 +00002927 source $VIMRUNTIME/delmenu.vim
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002928endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002929
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002930" :messages suboptions fuzzy completion
2931func Test_fuzzy_completion_messages()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002932 set wildoptions&
2933 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2934 call assert_equal('"messages clr', @:)
2935 set wildoptions=fuzzy
2936 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
2937 call assert_equal('"messages clear', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002938 set wildoptions&
2939endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002940
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002941" :set option name fuzzy completion
2942func Test_fuzzy_completion_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002943 set wildoptions&
2944 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2945 call assert_equal('"set brkopt', @:)
2946 set wildoptions=fuzzy
2947 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
2948 call assert_equal('"set breakindentopt', @:)
2949 set wildoptions&
2950 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2951 call assert_equal('"set fixendofline', @:)
2952 set wildoptions=fuzzy
2953 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
2954 call assert_equal('"set fixendofline', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002955 set wildoptions&
2956endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002957
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002958" :set <term_option>
2959func Test_fuzzy_completion_term_option()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002960 set wildoptions&
2961 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2962 call assert_equal('"set t_EC', @:)
2963 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2964 call assert_equal('"set <t_EC>', @:)
2965 set wildoptions=fuzzy
2966 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2967 call assert_equal('"set t_EC', @:)
2968 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
2969 call assert_equal('"set <t_EC>', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002970 set wildoptions&
2971endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002972
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002973" " :packadd directory name fuzzy completion - NOT supported
2974" func Test_fuzzy_completion_packadd()
2975" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002976
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002977" " shell command name fuzzy completion - NOT supported
2978" func Test_fuzzy_completion_shellcmd()
2979" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002980
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002981" :sign suboptions fuzzy completion
2982func Test_fuzzy_completion_sign()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002983 set wildoptions&
2984 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2985 call assert_equal('"sign ufe', @:)
2986 set wildoptions=fuzzy
2987 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
2988 call assert_equal('"sign undefine', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002989 set wildoptions&
2990endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002991
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00002992" :syntax suboptions fuzzy completion
2993func Test_fuzzy_completion_syntax_cmd()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00002994 set wildoptions&
2995 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2996 call assert_equal('"syntax kwd', @:)
2997 set wildoptions=fuzzy
2998 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
2999 call assert_equal('"syntax keyword', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003000 set wildoptions&
3001endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003002
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003003" syntax group name fuzzy completion
3004func Test_fuzzy_completion_syntax_group()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003005 set wildoptions&
3006 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3007 call assert_equal('"syntax list mpar', @:)
3008 set wildoptions=fuzzy
3009 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
3010 call assert_equal('"syntax list MatchParen', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003011 set wildoptions&
3012endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003013
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003014" :syntime suboptions fuzzy completion
3015func Test_fuzzy_completion_syntime()
3016 CheckFeature profile
3017 set wildoptions&
3018 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3019 call assert_equal('"syntime clr', @:)
3020 set wildoptions=fuzzy
3021 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
3022 call assert_equal('"syntime clear', @:)
3023 set wildoptions&
3024endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003025
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003026" " tag name fuzzy completion - NOT supported
3027" func Test_fuzzy_completion_tagname()
3028" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003029
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003030" " tag name and file fuzzy completion - NOT supported
3031" func Test_fuzzy_completion_tagfile()
3032" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003033
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003034" " user names fuzzy completion - how to test this functionality?
3035" func Test_fuzzy_completion_username()
3036" endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003037
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003038" user defined variable name fuzzy completion
3039func Test_fuzzy_completion_userdefined_var()
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003040 let g:SomeVariable=10
3041 set wildoptions&
3042 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3043 call assert_equal('"let SVar', @:)
3044 set wildoptions=fuzzy
3045 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
3046 call assert_equal('"let SomeVariable', @:)
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003047 set wildoptions&
3048endfunc
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003049
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003050" Test for sorting the results by the best match
3051func Test_fuzzy_completion_cmd_sort_results()
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003052 %bw!
3053 command T123format :
3054 command T123goformat :
3055 command T123TestFOrmat :
3056 command T123fendoff :
3057 command T123state :
3058 command T123FendingOff :
3059 set wildoptions=fuzzy
3060 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
3061 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
3062 delcommand T123format
3063 delcommand T123goformat
3064 delcommand T123TestFOrmat
3065 delcommand T123fendoff
3066 delcommand T123state
3067 delcommand T123FendingOff
3068 %bw
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003069 set wildoptions&
3070endfunc
Yegappan Lakshmanan5ec633b2022-02-25 15:24:24 +00003071
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003072" Test for fuzzy completion of a command with lower case letters and a number
3073func Test_fuzzy_completion_cmd_alnum()
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003074 command Foo2Bar :
3075 set wildoptions=fuzzy
3076 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
3077 call assert_equal('"Foo2Bar', @:)
3078 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
3079 call assert_equal('"Foo2Bar', @:)
3080 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
3081 call assert_equal('"Foo2Bar', @:)
3082 delcommand Foo2Bar
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003083 set wildoptions&
3084endfunc
Yegappan Lakshmanan4df5b332022-02-26 11:04:42 +00003085
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003086" Test for command completion for a command starting with 'k'
3087func Test_fuzzy_completion_cmd_k()
Yegappan Lakshmanan6caeda22022-02-27 12:07:30 +00003088 command KillKillKill :
3089 set wildoptions&
3090 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3091 call assert_equal("\"killkill\<Tab>", @:)
3092 set wildoptions=fuzzy
3093 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
3094 call assert_equal('"KillKillKill', @:)
3095 delcom KillKillKill
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003096 set wildoptions&
Yegappan Lakshmananafd4ae32022-02-27 21:03:21 +00003097endfunc
3098
3099" Test for fuzzy completion for user defined custom completion function
3100func Test_fuzzy_completion_custom_func()
3101 func Tcompl(a, c, p)
3102 return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
3103 endfunc
3104 command -nargs=* -complete=custom,Tcompl Fuzzy :
3105 set wildoptions&
3106 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3107 call assert_equal("\"Fuzzy format", @:)
3108 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3109 call assert_equal("\"Fuzzy xy", @:)
3110 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3111 call assert_equal("\"Fuzzy ttt", @:)
3112 set wildoptions=fuzzy
3113 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
3114 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
3115 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
3116 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
3117 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
3118 call assert_equal("\"Fuzzy xy", @:)
3119 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
3120 call assert_equal("\"Fuzzy TestFOrmat", @:)
3121 delcom Fuzzy
3122 set wildoptions&
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00003123endfunc
3124
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003125" Test for :breakadd argument completion
3126func Test_cmdline_complete_breakadd()
3127 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
3128 call assert_equal("\"breakadd expr file func here", @:)
3129 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3130 call assert_equal("\"breakadd expr", @:)
3131 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
3132 call assert_equal("\"breakadd expr", @:)
3133 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3134 call assert_equal("\"breakadd here", @:)
3135 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
3136 call assert_equal("\"breakadd here", @:)
3137 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
3138 call assert_equal("\"breakadd abc", @:)
3139 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
3140 let l = getcompletion('not', 'breakpoint')
3141 call assert_equal([], l)
3142
3143 " Test for :breakadd file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003144 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003145 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3146 call assert_equal("\"breakadd file Xscript", @:)
3147 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3148 call assert_equal("\"breakadd file Xscript", @:)
3149 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3150 call assert_equal("\"breakadd file 20 Xscript", @:)
3151 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3152 call assert_equal("\"breakadd file 20 Xscript", @:)
3153 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3154 call assert_equal("\"breakadd file 20x Xsc\t", @:)
3155 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3156 call assert_equal("\"breakadd file 20\t", @:)
3157 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3158 call assert_equal("\"breakadd file 20x\t", @:)
3159 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3160 call assert_equal("\"breakadd file Xscript ", @:)
3161 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3162 call assert_equal("\"breakadd file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003163
3164 " Test for :breakadd func [lnum] <function>
3165 func Xbreak_func()
3166 endfunc
3167 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3168 call assert_equal("\"breakadd func Xbreak_func", @:)
3169 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3170 call assert_equal("\"breakadd func Xbreak_func", @:)
3171 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3172 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3173 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3174 call assert_equal("\"breakadd func 20 Xbreak_func", @:)
3175 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3176 call assert_equal("\"breakadd func 20x Xbr\t", @:)
3177 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3178 call assert_equal("\"breakadd func 20\t", @:)
3179 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3180 call assert_equal("\"breakadd func 20x\t", @:)
3181 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3182 call assert_equal("\"breakadd func Xbreak_func ", @:)
3183 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3184 call assert_equal("\"breakadd func X1B2C3", @:)
3185 delfunc Xbreak_func
3186
3187 " Test for :breakadd expr <expression>
3188 let g:Xtest_var = 10
3189 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3190 call assert_equal("\"breakadd expr Xtest_var", @:)
3191 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3192 call assert_equal("\"breakadd expr Xtest_var", @:)
3193 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
3194 call assert_equal("\"breakadd expr Xtest_var ", @:)
3195 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3196 call assert_equal("\"breakadd expr X1B2C3", @:)
3197 unlet g:Xtest_var
3198
3199 " Test for :breakadd here
3200 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3201 call assert_equal("\"breakadd here Xtest", @:)
3202 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3203 call assert_equal("\"breakadd here Xtest", @:)
3204 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
3205 call assert_equal("\"breakadd here ", @:)
3206endfunc
3207
3208" Test for :breakdel argument completion
3209func Test_cmdline_complete_breakdel()
3210 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
3211 call assert_equal("\"breakdel file func here", @:)
3212 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3213 call assert_equal("\"breakdel file", @:)
3214 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
3215 call assert_equal("\"breakdel file", @:)
3216 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3217 call assert_equal("\"breakdel here", @:)
3218 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
3219 call assert_equal("\"breakdel here", @:)
3220 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
3221 call assert_equal("\"breakdel abc", @:)
3222
3223 " Test for :breakdel file [lnum] <file>
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003224 call writefile([], 'Xscript', 'D')
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003225 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3226 call assert_equal("\"breakdel file Xscript", @:)
3227 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3228 call assert_equal("\"breakdel file Xscript", @:)
3229 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3230 call assert_equal("\"breakdel file 20 Xscript", @:)
3231 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3232 call assert_equal("\"breakdel file 20 Xscript", @:)
3233 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
3234 call assert_equal("\"breakdel file 20x Xsc\t", @:)
3235 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
3236 call assert_equal("\"breakdel file 20\t", @:)
3237 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3238 call assert_equal("\"breakdel file 20x\t", @:)
3239 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
3240 call assert_equal("\"breakdel file Xscript ", @:)
3241 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3242 call assert_equal("\"breakdel file X1B2C3", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003243
3244 " Test for :breakdel func [lnum] <function>
3245 func Xbreak_func()
3246 endfunc
3247 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3248 call assert_equal("\"breakdel func Xbreak_func", @:)
3249 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3250 call assert_equal("\"breakdel func Xbreak_func", @:)
3251 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3252 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3253 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3254 call assert_equal("\"breakdel func 20 Xbreak_func", @:)
3255 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
3256 call assert_equal("\"breakdel func 20x Xbr\t", @:)
3257 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
3258 call assert_equal("\"breakdel func 20\t", @:)
3259 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
3260 call assert_equal("\"breakdel func 20x\t", @:)
3261 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
3262 call assert_equal("\"breakdel func Xbreak_func ", @:)
3263 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
3264 call assert_equal("\"breakdel func X1B2C3", @:)
3265 delfunc Xbreak_func
3266
3267 " Test for :breakdel here
3268 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3269 call assert_equal("\"breakdel here Xtest", @:)
3270 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
3271 call assert_equal("\"breakdel here Xtest", @:)
3272 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
3273 call assert_equal("\"breakdel here ", @:)
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003274endfunc
3275
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003276" Test for :scriptnames argument completion
3277func Test_cmdline_complete_scriptnames()
3278 set wildmenu
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003279 call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D')
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003280 source Xa1b2c3.vim
3281 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3282 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3283 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
3284 call assert_match("\"script .*Xa1b2c3.vim$", @:)
3285 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
3286 call assert_equal("\"script b2c3", @:)
3287 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
3288 call assert_match("\"script 2\<Tab>$", @:)
3289 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
3290 call assert_match("\"script .*Xa1b2c3.vim $", @:)
3291 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
3292 call assert_equal("\"script ", @:)
3293 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
3294 call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
3295 new
3296 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
3297 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
3298 bw!
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003299 set wildmenu&
3300endfunc
3301
Bram Moolenaard8893442022-05-06 20:38:47 +01003302" this was going over the end of IObuff
3303func Test_report_error_with_composing()
3304 let caught = 'no'
3305 try
3306 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
3307 catch /E492:/
3308 let caught = 'yes'
3309 endtry
3310 call assert_equal('yes', caught)
3311endfunc
3312
Yegappan Lakshmanan5e877ba2022-03-25 21:19:26 +00003313" Test for expanding 2-letter and 3-letter :substitute command arguments.
3314" These commands don't accept an argument.
3315func Test_cmdline_complete_substitute_short()
3316 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
3317 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
3318 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
3319 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
3320 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
3321 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
3322 call assert_equal('"' .. cmd .. " \<Tab>", @:)
3323 endfor
3324endfunc
3325
Yegappan Lakshmanan7db3a8e2022-07-26 22:01:36 +01003326" Test for :! shell command argument completion
3327func Test_cmdline_complete_bang_cmd_argument()
3328 set wildoptions=fuzzy
3329 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3330 call assert_equal('"!vim test_cmdline.vim', @:)
3331 set wildoptions&
3332 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
3333 call assert_equal('"!vim test_cmdline.vim', @:)
3334endfunc
3335
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003336func Check_completion()
3337 call assert_equal('let a', getcmdline())
3338 call assert_equal(6, getcmdpos())
3339 call assert_equal(7, getcmdscreenpos())
3340 call assert_equal('var', getcmdcompltype())
3341 return ''
3342endfunc
3343
3344func Test_screenpos_and_completion()
3345 call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
3346endfunc
3347
Bram Moolenaar51f0bfb2022-05-17 20:11:02 +01003348func Test_recursive_register()
3349 let @= = ''
3350 silent! ?e/
3351 let caught = 'no'
3352 try
3353 normal //
3354 catch /E169:/
3355 let caught = 'yes'
3356 endtry
3357 call assert_equal('yes', caught)
3358endfunc
3359
Bram Moolenaar44a3f332022-06-06 15:38:21 +01003360func Test_long_error_message()
3361 " the error should be truncated, not overrun IObuff
3362 silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
3363endfunc
3364
zeertzjq6791adc2022-07-26 20:42:25 +01003365func Test_cmdline_redraw_tabline()
3366 CheckRunVimInTerminal
3367
3368 let lines =<< trim END
3369 set showtabline=2
3370 autocmd CmdlineEnter * set tabline=foo
3371 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +01003372 call writefile(lines, 'Xcmdline_redraw_tabline', 'D')
zeertzjq6791adc2022-07-26 20:42:25 +01003373 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
3374 call term_sendkeys(buf, ':')
3375 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
3376
3377 call StopVimInTerminal(buf)
zeertzjq6791adc2022-07-26 20:42:25 +01003378endfunc
3379
zeertzjqb82a2ab2022-08-21 14:33:57 +01003380func Test_wildmenu_pum_disable_while_shown()
3381 set wildoptions=pum
3382 set wildmenu
3383 cnoremap <F2> <Cmd>set nowildmenu<CR>
3384 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
3385 call assert_equal(0, pumvisible())
3386 cunmap <F2>
3387 set wildoptions& wildmenu&
3388endfunc
3389
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003390func Test_setcmdline()
3391 func SetText(text, pos)
zeertzjq54acb902022-08-29 16:21:25 +01003392 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003393 call assert_equal(0, setcmdline(a:text))
3394 call assert_equal(a:text, getcmdline())
3395 call assert_equal(len(a:text) + 1, getcmdpos())
zeertzjq54acb902022-08-29 16:21:25 +01003396 call assert_equal(getcmdtype(), g:cmdtype)
3397 unlet g:cmdtype
3398 autocmd! CmdlineChanged
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003399
3400 call assert_equal(0, setcmdline(a:text, a:pos))
3401 call assert_equal(a:text, getcmdline())
3402 call assert_equal(a:pos, getcmdpos())
3403
3404 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
Yegappan Lakshmanan25f1e552022-08-28 17:25:04 +01003405 call assert_fails('call setcmdline({}, 0)', 'E1174:')
3406 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003407
3408 return ''
3409 endfunc
3410
3411 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
3412 call assert_equal('set rtp?', @:)
3413
zeertzjq54acb902022-08-29 16:21:25 +01003414 call feedkeys(":let g:str = input('? ')\<CR>", 't')
3415 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
3416 call assert_equal('foo', g:str)
3417 unlet g:str
3418
3419 delfunc SetText
3420
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003421 " setcmdline() returns 1 when not editing the command line.
3422 call assert_equal(1, 'foo'->setcmdline())
3423
3424 " Called in custom function
3425 func CustomComplete(A, L, P)
3426 call assert_equal(0, setcmdline("DoCmd "))
3427 return "January\nFebruary\nMars\n"
3428 endfunc
3429
3430 com! -nargs=* -complete=custom,CustomComplete DoCmd :
3431 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
3432 call assert_equal('"DoCmd January February Mars', @:)
zeertzjq54acb902022-08-29 16:21:25 +01003433 delcom DoCmd
3434 delfunc CustomComplete
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003435
3436 " Called in <expr>
3437 cnoremap <expr>a setcmdline('let foo=')
3438 call feedkeys(":a\<CR>", 'tx')
3439 call assert_equal('let foo=0', @:)
3440 cunmap a
3441endfunc
3442
Bram Moolenaar309976e2019-12-05 18:16:33 +01003443" vim: shiftwidth=2 sts=2 expandtab